@@ -510,29 +510,6 @@ Py_SetRecursionLimit(int new_limit)
510510 recursion_limit = new_limit ;
511511}
512512
513- int
514- _Py_CheckRecursiveCall (char * where )
515- {
516- PyThreadState * tstate = PyThreadState_GET ();
517-
518- #ifdef USE_STACKCHECK
519- if (PyOS_CheckStack ()) {
520- -- tstate -> recursion_depth ;
521- PyErr_SetString (PyExc_MemoryError , "Stack overflow" );
522- return -1 ;
523- }
524- #endif
525- if (tstate -> recursion_depth > recursion_limit ) {
526- -- tstate -> recursion_depth ;
527- PyErr_Format (PyExc_RuntimeError ,
528- "maximum recursion depth exceeded%s" ,
529- where );
530- return -1 ;
531- }
532- return 0 ;
533- }
534-
535-
536513/* Status code for main loop (reason for stack unwind) */
537514
538515enum why_code {
@@ -697,9 +674,21 @@ eval_frame(PyFrameObject *f)
697674 if (f == NULL )
698675 return NULL ;
699676
677+ #ifdef USE_STACKCHECK
678+ if (tstate -> recursion_depth %10 == 0 && PyOS_CheckStack ()) {
679+ PyErr_SetString (PyExc_MemoryError , "Stack overflow" );
680+ return NULL ;
681+ }
682+ #endif
683+
700684 /* push frame */
701- if (Py_EnterRecursiveCall ("" ))
685+ if (++ tstate -> recursion_depth > recursion_limit ) {
686+ -- tstate -> recursion_depth ;
687+ PyErr_SetString (PyExc_RuntimeError ,
688+ "maximum recursion depth exceeded" );
689+ tstate -> frame = f -> f_back ;
702690 return NULL ;
691+ }
703692
704693 tstate -> frame = f ;
705694
@@ -721,7 +710,9 @@ eval_frame(PyFrameObject *f)
721710 if (call_trace (tstate -> c_tracefunc , tstate -> c_traceobj ,
722711 f , PyTrace_CALL , Py_None )) {
723712 /* Trace function raised an error */
724- goto exit_eval_frame ;
713+ -- tstate -> recursion_depth ;
714+ tstate -> frame = f -> f_back ;
715+ return NULL ;
725716 }
726717 }
727718 if (tstate -> c_profilefunc != NULL ) {
@@ -731,7 +722,9 @@ eval_frame(PyFrameObject *f)
731722 tstate -> c_profileobj ,
732723 f , PyTrace_CALL , Py_None )) {
733724 /* Profile function raised an error */
734- goto exit_eval_frame ;
725+ -- tstate -> recursion_depth ;
726+ tstate -> frame = f -> f_back ;
727+ return NULL ;
735728 }
736729 }
737730 }
@@ -2435,8 +2428,7 @@ eval_frame(PyFrameObject *f)
24352428 reset_exc_info (tstate );
24362429
24372430 /* pop frame */
2438- exit_eval_frame :
2439- Py_LeaveRecursiveCall ();
2431+ -- tstate -> recursion_depth ;
24402432 tstate -> frame = f -> f_back ;
24412433
24422434 return retval ;
0 commit comments