| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3231893 commit 1896793
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,21 +93,19 @@ PyAPI_FUNC(int) Py_GetRecursionLimit(void); | |||
| 93 | 93 | PyThreadState_GET()->overflowed = 0; \ | |
| 94 | 94 | } while(0) | |
| 95 | 95 | PyAPI_FUNC(int) _Py_CheckRecursiveCall(const char *where); | |
| 96 | - /* XXX _Py_CheckRecursionLimit should be changed to | ||
| 97 | - _PyRuntime.ceval.check_recursion_limit. However, due to the macros | ||
| 98 | - in which it's used, _Py_CheckRecursionLimit is stuck in the stable | ||
| 99 | - ABI. It should be removed therefrom when possible. | ||
| 96 | + | ||
| 97 | + /* Due to the macros in which it's used, _Py_CheckRecursionLimit is in | ||
| 98 | + the stable ABI. It should be removed therefrom when possible. | ||
| 100 | 99 | */ | |
| 101 | 100 | PyAPI_DATA(int) _Py_CheckRecursionLimit; | |
| 102 | 101 | ||
| 103 | 102 | #ifdef USE_STACKCHECK | |
| 104 | - /* With USE_STACKCHECK, we artificially decrement the recursion limit in order | ||
| 105 | - to trigger regular stack checks in _Py_CheckRecursiveCall(), except if | ||
| 106 | - the "overflowed" flag is set, in which case we need the true value | ||
| 107 | - of _Py_CheckRecursionLimit for _Py_MakeEndRecCheck() to function properly. | ||
| 103 | + /* With USE_STACKCHECK, trigger stack checks in _Py_CheckRecursiveCall() | ||
| 104 | + on every 64th call to Py_EnterRecursiveCall. | ||
| 108 | 105 | */ | |
| 109 | 106 | # define _Py_MakeRecCheck(x) \ | |
| 110 | - (++(x) > (_Py_CheckRecursionLimit += PyThreadState_GET()->overflowed - 1)) | ||
| 107 | + (++(x) > _Py_CheckRecursionLimit || \ | ||
| 108 | + ++(PyThreadState_GET()->stackcheck_counter) > 64) | ||
| 111 | 109 | #else | |
| 112 | 110 | # define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit) | |
| 113 | 111 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,6 @@ struct _pending_calls { | |||
| 29 | 29 | ||
| 30 | 30 | struct _ceval_runtime_state { | |
| 31 | 31 | int recursion_limit; | |
| 32 | - int check_recursion_limit; | ||
| 33 | 32 | /* Records whether tracing is on for any thread. Counts the number | |
| 34 | 33 | of threads for which tstate->c_tracefunc is non-NULL, so if the | |
| 35 | 34 | value is 0, we know we don't have to check this thread's | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -151,6 +151,8 @@ typedef struct _ts { | |||
| 151 | 151 | to handle the runtime error. */ | |
| 152 | 152 | char recursion_critical; /* The current calls must not cause | |
| 153 | 153 | a stack overflow. */ | |
| 154 | + int stackcheck_counter; | ||
| 155 | + | ||
| 154 | 156 | /* 'tracing' keeps track of the execution depth when tracing/profiling. | |
| 155 | 157 | This is to prevent the actual trace/profile code from being recorded in | |
| 156 | 158 | the trace/profile. */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Make the behavior of USE_STACKCHECK deterministic in a multi-threaded | ||
| 2 | + environment. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -469,13 +469,15 @@ _Py_CheckRecursiveCall(const char *where) | |||
| 469 | 469 | int recursion_limit = _PyRuntime.ceval.recursion_limit; | |
| 470 | 470 | ||
| 471 | 471 | #ifdef USE_STACKCHECK | |
| 472 | + tstate->stackcheck_counter = 0; | ||
| 472 | 473 | if (PyOS_CheckStack()) { | |
| 473 | 474 | --tstate->recursion_depth; | |
| 474 | 475 | PyErr_SetString(PyExc_MemoryError, "Stack overflow"); | |
| 475 | 476 | return -1; | |
| 476 | 477 | } | |
| 477 | - #endif | ||
| 478 | + /* Needed for ABI backwards-compatibility (see bpo-31857) */ | ||
| 478 | 479 | _Py_CheckRecursionLimit = recursion_limit; | |
| 480 | + #endif | ||
| 479 | 481 | if (tstate->recursion_critical) | |
| 480 | 482 | /* Somebody asked that we don't check for recursion. */ | |
| 481 | 483 | return 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,6 +245,7 @@ new_threadstate(PyInterpreterState *interp, int init) | |||
| 245 | 245 | tstate->recursion_depth = 0; | |
| 246 | 246 | tstate->overflowed = 0; | |
| 247 | 247 | tstate->recursion_critical = 0; | |
| 248 | + tstate->stackcheck_counter = 0; | ||
| 248 | 249 | tstate->tracing = 0; | |
| 249 | 250 | tstate->use_tracing = 0; | |
| 250 | 251 | tstate->gilstate_counter = 0; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments