8000 Do fewer probes when growing stack limit · python/cpython@afac1e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit afac1e6

Browse files
committed
Do fewer probes when growing stack limit
1 parent 03fc52e commit afac1e6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate) {
223223
}
224224

225225
static inline int _Py_ReachedRecursionLimit(PyThreadState *tstate, int margin_count) {
226+
assert(tstate->c_stack_soft_limit != UINTPTR_MAX);
226227
char here;
227228
uintptr_t here_addr = (uintptr_t)&here;
228229
return here_addr <= tstate->c_stack_soft_limit + margin_count * PYOS_STACK_MARGIN_BYTES;

Python/ceval.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,15 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
332332
tstate->c_stack_soft_limit = here_addr - PYOS_STACK_MARGIN_BYTES;
333333
return 0;
334334
}
335+
int margin = PYOS_STACK_MARGIN;
335336
assert(tstate->c_stack_soft_limit != UINTPTR_MAX);
336-
int margin = PYOS_STACK_MARGIN*3/2;
337-
while (margin > 0 && _PyOS_CheckStack(margin)) {
338-
margin -= PYOS_STACK_MARGIN/2;
337+
if (_PyOS_CheckStack(margin)) {
338+
margin = PYOS_STACK_MARGIN/2;
339+
}
340+
else {
341+
if (_PyOS_CheckStack(PYOS_STACK_MARGIN*3/2) == 0) {
342+
margin = PYOS_STACK_MARGIN*3/2;
343+
}
339344
}
340345
tstate->c_stack_hard_limit = here_addr - margin * sizeof(void *);
341346
tstate->c_stack_soft_limit = tstate->c_stack_hard_limit + PYOS_STACK_MARGIN_BYTES;

0 commit comments

Comments
 (0)
0