@@ -99,40 +99,38 @@ PyObject *normalizestring(const char *string)
99
99
100
100
PyObject * _PyCodec_Lookup (const char * encoding )
101
101
{
102
- PyObject * result , * v ;
103
- Py_ssize_t i , len ;
104
-
105
102
if (encoding == NULL ) {
106
103
PyErr_BadArgument ();
107
- goto onError ;
104
+ return NULL ;
108
105
}
109
106
110
107
PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
111
- if (interp -> codec_search_path == NULL && _PyCodecRegistry_Init ())
112
- goto onError ;
108
+ if (interp -> codec_search_path == NULL && _PyCodecRegistry_Init ()) {
109
+ return NULL ;
110
+ }
113
111
114
112
/* Convert the encoding to a normalized Python string: all
115
113
characters are converted to lower case, spaces and hyphens are
116
114
replaced with underscores. */
117
- v = normalizestring (encoding );
118
- if (v == NULL )
119
- goto onError ;
115
+ PyObject * v = normalizestring (encoding );
116
+ if (v == NULL ) {
117
+ return NULL ;
118
+ }
120
119
PyUnicode_InternInPlace (& v );
121
120
122
121
/* First, try to lookup the name in the registry dictionary */
123
- result = PyDict_GetItemWithError (interp -> codec_search_cache , v );
122
+ PyObject * result = PyDict_GetItemWithError (interp -> codec_search_cache , v );
124
123
if (result != NULL ) {
125
124
Py_INCREF (result );
126
125
Py_DECREF (v );
127
126
return result ;
128
127
}
129
128
else if (PyErr_Occurred ()) {
130
- Py_DECREF (v );
131
- return NULL ;
129
+ goto onError ;
132
130
}
133
131
134
132
/* Next, scan the search functions in order of registration */
135
- len = PyList_Size (interp -> codec_search_path );
133
+ const Py_ssize_t len = PyList_Size (interp -> codec_search_path );
136
134
if (len < 0 )
137
135
goto onError ;
138
136
if (len == 0 ) {
@@ -142,6 +140,7 @@ PyObject *_PyCodec_Lookup(const char *encoding)
142
140
goto onError ;
143
141
}
144
142
143
+ Py_ssize_t i ;
145
144
for (i = 0 ; i < len ; i ++ ) {
146
145
PyObject * func ;
147
146
@@ -175,9 +174,11 @@ PyObject *_PyCodec_Lookup(const char *encoding)
175
174
Py_DECREF (result );
176
175
goto onError ;
177
176
}
177
+ Py_DECREF (v );
178
178
return result ;
179
179
180
180
onError :
181
+ Py_DECREF (v );
181
182
return NULL ;
182
183
}
183
184
0 commit comments