@@ -29,7 +29,6 @@ static const struct hook_prefixes nonascii_prefixes = {
2929static PyObject *
3030get_encoded_name (PyObject * name , const struct hook_prefixes * * hook_prefixes ) {
3131 PyObject * tmp ;
32- PyObject * modname = NULL ;
3332 Py_ssize_t name_len , lastdot ;
3433
3534 /* Get the short name (substring after last dot) */
@@ -51,31 +50,32 @@ get_encoded_name(PyObject *name, const struct hook_prefixes **hook_prefixes) {
5150 }
5251
5352 /* Encode to ASCII or Punycode, as needed */
53+ PyObject * encoded ;
5454 if (PyUnicode_IS_ASCII (name )) {
5555 * hook_prefixes = & ascii_only_prefixes ;
56- modname = PyUnicode_AsASCIIString (name );
56+ encoded = PyUnicode_AsASCIIString (name );
5757 } else {
5858 * hook_prefixes = & nonascii_prefixes ;
59- PyObject * encoded = PyUnicode_AsEncodedString (name , "punycode" , NULL );
60- if (encoded == NULL ) {
61- goto error ;
62- }
59+ encoded = PyUnicode_AsEncodedString (name , "punycode" , NULL );
60+ }
61+ if (encoded == NULL ) {
62+ goto error ;
63+ }
6364
64- /* Call encoded.replace('-', '_') */
65- modname = PyObject_VectorcallMethod (
66- & _Py_ID (replace ),
67- (PyObject * [3 ]) {
68- encoded ,
69- (PyObject * )& _Py_SINGLETON (bytes_characters )['-' ],
70- (PyObject * )& _Py_SINGLETON (bytes_characters )['_' ],
71- },
72- 3 | PY_VECTORCALL_ARGUMENTS_OFFSET ,
73- NULL );
74- Py_CLEAR (encoded );
75-
76- if (modname == NULL ) {
77- goto error ;
78- }
65+ /* Call encoded.replace('-', '_') */
66+ PyObject * modname = PyObject_VectorcallMethod (
67+ & _Py_ID (replace ),
68+ (PyObject * [3 ]) {
69+ encoded ,
70+ (PyObject * )& _Py_SINGLETON (bytes_characters )['-' ],
71+ (PyObject * )& _Py_SINGLETON (bytes_characters )['_' ],
72+ },
73+ 3 | PY_VECTORCALL_ARGUMENTS_OFFSET ,
74+ NULL );
75+ Py_CLEAR (encoded );
76+
77+ if (modname == NULL ) {
78+ goto error ;
7979 }
8080
8181 Py_DECREF (name );
0 commit comments