@@ -186,6 +186,10 @@ PyObject *
186186_Py_make_parameters (PyObject * args )
187187{
188188 assert (PyTuple_Check (args ) || PyList_Check (args ));
189+ if (Py_EnterRecursiveCall (" in __parameter__ calculation" )) {
190+ return NULL ;
191+ }
192+
189193 const bool is_args_list = PyList_Check (args );
190194 PyObject * tuple_args = NULL ;
191195 if (is_args_list ) {
@@ -210,9 +214,7 @@ _Py_make_parameters(PyObject *args)
210214 }
211215 int rc = PyObject_HasAttrWithError (t , & _Py_ID (__typing_subst__ ));
212216 if (rc < 0 ) {
213- Py_DECREF (parameters );
214- Py_XDECREF (tuple_args );
215- return NULL ;
217+ goto error ;
216218 }
217219 if (rc ) {
218220 iparam += tuple_add (parameters , iparam , t );
@@ -221,18 +223,14 @@ _Py_make_parameters(PyObject *args)
221223 PyObject * subparams ;
222224 if (PyObject_GetOptionalAttr (t , & _Py_ID (__parameters__ ),
223225 & subparams ) < 0 ) {
224- Py_DECREF (parameters );
225- Py_XDECREF (tuple_args );
226- return NULL ;
226+ goto error ;
227227 }
228228 if (!subparams && (PyTuple_Check (t ) || PyList_Check (t ))) {
229229 // Recursively call _Py_make_parameters for lists/tuples and
230230 // add the results to the current parameters.
231231 subparams = _Py_make_parameters (t );
232232 if (subparams == NULL ) {
233- Py_DECREF (parameters );
234- Py_XDECREF (tuple_args );
235- return NULL ;
233+ goto error ;
236234 }
237235 }
238236 if (subparams && PyTuple_Check (subparams )) {
@@ -243,7 +241,7 @@ _Py_make_parameters(PyObject *args)
243241 if (_PyTuple_Resize (& parameters , len ) < 0 ) {
244242 Py_DECREF (subparams );
245243 Py_XDECREF (tuple_args );
246- return NULL ;
244+ goto cleanup ;
247245 }
248246 }
249247 for (Py_ssize_t j = 0 ; j < len2 ; j ++ ) {
@@ -256,13 +254,19 @@ _Py_make_parameters(PyObject *args)
256254 }
257255 if (iparam < len ) {
258256 if (_PyTuple_Resize (& parameters , iparam ) < 0 ) {
259- Py_XDECREF (parameters );
260- Py_XDECREF (tuple_args );
261- return NULL ;
257+ goto error ;
262258 }
263259 }
264260 Py_XDECREF (tuple_args );
261+ Py_LeaveRecursiveCall ();
265262 return parameters ;
263+
264+ error :
265+ Py_XDECREF (parameters );
266+ Py_XDECREF (tuple_args );
267+ cleanup :
268+ Py_LeaveRecursiveCall ();
269+ return NULL ;
266270}
267271
268272/* If obj is a generic alias, substitute type variables params
0 commit comments