@@ -91,8 +91,6 @@ PyObject *
9191_PyObject_FastCallDict (PyObject * callable , PyObject * const * args ,
9292 size_t nargsf , PyObject * kwargs )
9393{
94- STACKLESS_GETARG ();
95- PyObject * result ;
9694 /* _PyObject_FastCallDict() must not be called with an exception set,
9795 because it can clear it (directly or indirectly) and so the
9896 caller loses its exception */
@@ -110,6 +108,7 @@ _PyObject_FastCallDict(PyObject *callable, PyObject *const *args,
110108 return _PyObject_MakeTpCall (callable , args , nargs , kwargs );
111109 }
112110
111+ STACKLESS_GETARG ();
113112 PyObject * res ;
114113 if (kwargs == NULL ) {
115114 res = func (callable , args , nargsf , NULL );
@@ -137,6 +136,7 @@ _PyObject_FastCallDict(PyObject *callable, PyObject *const *args,
137136PyObject *
138137_PyObject_MakeTpCall (PyObject * callable , PyObject * const * args , Py_ssize_t nargs , PyObject * keywords )
139138{
139+ STACKLESS_GETARG ();
140140 /* Slow path: build a temporary tuple for positional arguments and a
141141 * temporary dictionary for keyword arguments (if any) */
142142 ternaryfunc call = Py_TYPE (callable )-> tp_call ;
@@ -173,11 +173,19 @@ _PyObject_MakeTpCall(PyObject *callable, PyObject *const *args, Py_ssize_t nargs
173173 }
174174
175175 PyObject * result = NULL ;
176- if (Py_EnterRecursiveCall (" while calling a Python object" ) == 0 )
176+ /* only do recursion adjustment if there is no danger of soft-switching.
177+ * Were a soft-switch to occur, the re-adjustment of the recursion depth
178+ * would happen for the wrong frame.
179+ */
180+ if (stackless ||
181+ Py_EnterRecursiveCall (" while calling a Python object" ) == 0 )
177182 {
183+ STACKLESS_PROMOTE (callable );
178184 result = call (callable , argstuple , kwdict );
179- Py_LeaveRecursiveCall ();
185+ if (!stackless )
186+ Py_LeaveRecursiveCall ();
180187 }
188+ STACKLESS_ASSERT ();
181189
182190 Py_DECREF (argstuple );
183191 if (kwdict != keywords ) {
@@ -192,6 +200,7 @@ _PyObject_MakeTpCall(PyObject *callable, PyObject *const *args, Py_ssize_t nargs
192200PyObject *
193201PyVectorcall_Call (PyObject * callable , PyObject * tuple , PyObject * kwargs )
194202{
203+ STACKLESS_GETARG ();
195204 vectorcallfunc func = _PyVectorcall_Function (callable );
196205 if (func == NULL ) {
197206 PyErr_Format (PyExc_TypeError , "'%.200s' object does not support vectorcall" ,
@@ -222,7 +231,6 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
222231PyObject *
223232PyObject_Call (PyObject * callable , PyObject * args , PyObject * kwargs )
224233{
225- STACKLESS_GETARG ();
226234 ternaryfunc call ;
227235 PyObject * result ;
228236
@@ -242,37 +250,27 @@ PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
242250 return cfunction_call_varargs (callable , args , kwargs );
243251 }
244252 else {
253+ STACKLESS_GETARG ();
245254 call = callable -> ob_type -> tp_call ;
246255 if (call == NULL ) {
247256 PyErr_Format (PyExc_TypeError , "'%.200s' object is not callable" ,
248257 callable -> ob_type -> tp_name );
249258 return NULL ;
250259 }
251260
252- #ifdef STACKLESS
253- /* only do recursion adjustment if there is no danger
254- * of soft-switching, i.e. if we are not being called by
255- * run_cframe. Were a soft-switch to occur, the re-adjustment
256- * of the recursion depth would happen for the wrong frame.
261+ /* only do recursion adjustment if there is no danger of soft-switching.
262+ * Were a soft-switch to occur, the re-adjustment of the recursion depth
263+ * would happen for the wrong frame.
257264 */
258- if (!stackless )
259- #endif
260- if (Py_EnterRecursiveCall (" while calling a Python object" ))
265+ if (!stackless && Py_EnterRecursiveCall (" while calling a Python object" ))
261266 return NULL ;
262267
263268 STACKLESS_PROMOTE (callable );
264269 result = (* call )(callable , args , kwargs );
265270 STACKLESS_ASSERT ();
266271
267- #ifdef STACKLESS
268- /* only do recursion adjustment if there is no danger
269- * of soft-switching, i.e. if we are not being called by
270- * run_cframe. Were a soft-switch to occur, the re-adjustment
271- * of the recursion depth would happen for the wrong frame.
272- */
273272 if (!stackless )
274- #endif
275- Py_LeaveRecursiveCall ();
273+ Py_LeaveRecursiveCall ();
276274
277275 return _Py_CheckFunctionResult (callable , result , NULL );
278276 }
@@ -526,15 +524,12 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self,
526524 int flags = method -> ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS );
527525 PyObject * result = NULL ;
528526
529- #ifdef STACKLESS
530- /* only do recursion adjustment if there is no danger
531- * of soft-switching, i.e. if we are not being called by
532- * run_cframe. Were a soft-switch to occur, the re-adjustment
533- * of the recursion depth would happen for the wrong frame.
527+ /* only do recursion adjustment if there is no danger of soft-switching.
528+ * Were a soft-switch to occur, the re-adjustment of the recursion depth
529+ * would happen for the wrong frame.
534530 */
535- if (!stackless )
536- #endif
537- if (Py_EnterRecursiveCall (" while calling a Python object" )) {
531+ if (!stackless &&
532+ Py_EnterRecursiveCall (" while calling a Python object" )) {
538533 return NULL ;
539534 }
540535
@@ -647,15 +642,8 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self,
647642 method -> ml_name );
648643
649644exit :
650- #ifdef STACKLESS
651- /* only do recursion adjustment if there is no danger
652- * of soft-switching, i.e. if we are not being called by
653- * run_cframe. Were a soft-switch to occur, the re-adjustment
654- * of the recursion depth would happen for the wrong frame.
655- */
656645 if (!stackless )
657- #endif
658- Py_LeaveRecursiveCall ();
646+ Py_LeaveRecursiveCall ();
659647 return result ;
660648}
661649
@@ -700,15 +688,12 @@ _PyMethodDef_RawFastCallKeywords(PyMethodDef *method, PyObject *self,
700688 Py_ssize_t nkwargs = kwnames == NULL ? 0 : PyTuple_GET_SIZE (kwnames );
701689 PyObject * result = NULL ;
702690
703- #ifdef STACKLESS
704- /* only do recursion adjustment if there is no danger
705- * of soft-switching, i.e. if we are not being called by
706- * run_cframe. Were a soft-switch to occur, the re-adjustment
707- * of the recursion depth would happen for the wrong frame.
691+ /* only do recursion adjustment if there is no danger of soft-switching.
692+ * Were a soft-switch to occur, the re-adjustment of the recursion depth
693+ * would happen for the wrong frame.
708694 */
709- if (!stackless )
710- #endif
711- if (Py_EnterRecursiveCall (" while calling a Python object" )) {
695+ if (!stackless &&
696+ Py_EnterRecursiveCall (" while calling a Python object" )) {
712697 return NULL ;
713698 }
714699
@@ -819,15 +804,8 @@ _PyMethodDef_RawFastCallKeywords(PyMethodDef *method, PyObject *self,
819804 method -> ml_name );
820805
821806exit :
822- #ifdef STACKLESS
823- /* only do recursion adjustment if there is no danger
824- * of soft-switching, i.e. if we are not being called by
825- * run_cframe. Were a soft-switch to occur, the re-adjustment
826- * of the recursion depth would happen for the wrong frame.
827- */
828807 if (!stackless )
829- #endif
830- Py_LeaveRecursiveCall ();
808+ Py_LeaveRecursiveCall ();
831809 return result ;
832810}
833811
@@ -864,26 +842,21 @@ cfunction_call_varargs(PyObject *func, PyObject *args, PyObject *kwargs)
864842
865843 assert (PyCFunction_GET_FLAGS (func ) & METH_VARARGS );
866844 if (PyCFunction_GET_FLAGS (func ) & METH_KEYWORDS ) {
867- #ifdef STACKLESS
868- /* only do recursion adjustment if there is no danger
869- * of soft-switching, i.e. if we are not being called by
870- * run_cframe. Were a soft-switch to occur, the re-adjustment
871- * of the recursion depth would happen for the wrong frame.
845+ /* only do recursion adjustment if there is no danger of soft-switching.
846+ * Were a soft-switch to occur, the re-adjustment of the recursion depth
847+ * would happen for the wrong frame.
872848 */
873- if (!stackless )
874- #endif
875- if (Py_EnterRecursiveCall (" while calling a Python object" )) {
849+ if (!stackless &&
850+ Py_EnterRecursiveCall (" while calling a Python object" )) {
876851 return NULL ;
877852 }
878853
879854 STACKLESS_PROMOTE_FLAG (PyCFunction_GET_FLAGS (func ) & METH_STACKLESS );
880855 result = (* (PyCFunctionWithKeywords )(void (* )(void ))meth )(self , args , kwargs );
881856 STACKLESS_ASSERT ();
882857
883- #ifdef STACKLESS
884858 if (!stackless )
885- #endif
886- Py_LeaveRecursiveCall ();
859+ Py_LeaveRecursiveCall ();
887860 }
888861 else {
889862 if (kwargs != NULL && PyDict_GET_SIZE (kwargs ) != 0 ) {
@@ -892,26 +865,21 @@ cfunction_call_varargs(PyObject *func, PyObject *args, PyObject *kwargs)
892865 return NULL ;
893866 }
894867
895- #ifdef STACKLESS
896- /* only do recursion adjustment if there is no danger
897- * of soft-switching, i.e. if we are not being called by
898- * run_cframe. Were a soft-switch to occur, the re-adjustment
899- * of the recursion depth would happen for the wrong frame.
868+ /* only do recursion adjustment if there is no danger of soft-switching.
869+ * Were a soft-switch to occur, the re-adjustment of the recursion depth
870+ * would happen for the wrong frame.
900871 */
901- if (!stackless )
902- #endif
903- if (Py_EnterRecursiveCall (" while calling a Python object" )) {
872+ if (!stackless &&
873+ Py_EnterRecursiveCall (" while calling a Python object" )) {
904874 return NULL ;
905875 }
906876
907877 STACKLESS_PROMOTE_FLAG (PyCFunction_GET_FLAGS (func ) & METH_STACKLESS );
908878 result = (* meth )(self , args );
909879 STACKLESS_ASSERT ();
910880
911- #ifdef STACKLESS
912881 if (!stackless )
913- #endif
914- Py_LeaveRecursiveCall ();
882+ Py_LeaveRecursiveCall ();
915883 }
916884
917885 return _Py_CheckFunctionResult (func , result , NULL );
0 commit comments