8000 GH-91079: Decouple C stack overflow checks from Python recursion checks. by markshannon · Pull Request #96507 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-91079: Decouple C stack overflow checks from Python recursion checks. #96507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reduce amount of C stack available. Should make things more robust.
  • Loading branch information
markshannon committed Sep 2, 2022
commit a6ccf957dd8fedabe27d05c295c02fa9d7408d81
4 changes: 2 additions & 2 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,
static inline int _Py_EnterRecursiveCallN(PyThreadState *tstate, int n,
const char *where) {
tstate->c_recursion_remaining -= n;
if (tstate->c_recursion_remaining < 0) {
if (tstate->c_recursion_remaining >= 0) {
return 0;
}
return _Py_CheckRecursiveCallN(tstate, n, where);
Expand Down Expand Up @@ -160,7 +160,7 @@ extern PyObject* _Py_MakeCoro(PyFunctionObject *func);

extern int _Py_HandlePending(PyThreadState *tstate);

#define C_RECURSION_LIMT 3000
#define C_RECURSION_LIMT 2500

#ifdef __cplusplus
}
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def __getitem__(self, key):

@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
def test_extended_arg(self):
# default: 1000 * 2.5 = 2500 repetitions
repeat = int(sys.getrecursionlimit() * 2.5)
repeat = 2000
longexpr = 'x = x or ' + '-x' * repeat
g = {}
code = '''
Expand Down
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Py_SetRecursionLimit(int new_limit)
int
_Py_CheckRecursiveCallN(PyThreadState *tstate, int n, const char *where)
{
assert(tstate->c_recursion_remaining < n);
assert(tstate->c_recursion_remaining < 0);
if (tstate->c_recursion_headroom) {
if (tstate->c_recursion_remaining < -50) {
/* Overflowing while handling an overflow. Give up. */
Expand Down
0