Skip to content
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
Merge branch 'main' into frame-stack-api
  • Loading branch information
markshannon committed Sep 7, 2022
commit b21d1982ba8b1f4d7714aec1498ccb7750aba684
8 changes: 7 additions & 1 deletion Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ _PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear);
static inline bool
_PyThreadState_HasStackSpace(PyThreadState *tstate, int size)
{
return tstate->frame_stack.top + size < tstate->frame_stack.limit;
assert(
(tstate->frame_stack.top == NULL && tstate->frame_stack.limit == NULL)
||
(tstate->frame_stack.top != NULL && tstate->frame_stack.limit != NULL)
);
return tstate->frame_stack.top != NULL &&
size < tstate->frame_stack.limit - tstate->frame_stack.top;
}

extern _PyInterpreterFrame *
Expand Down
13 changes: 5 additions & 8 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2187,15 +2187,12 @@ _PyInterpreterFrame *
_PyThreadState_PushFrame(PyThreadState *tstate, size_t size)
{
assert(size < INT_MAX/sizeof(PyObject *));
PyObject **base = tstate->frame_stack.top;
PyObject **top = base + size;
if (top >= tstate->frame_stack.limit) {
base = push_chunk(&tstate->frame_stack, (int)size);
if (_PyThreadState_HasStackSpace(tstate, (int)size)) {
_PyInterpreterFrame *res = (_PyInterpreterFrame *)tstate->frame_stack.top;
tstate->frame_stack.top += size;
return res;
}
else {
tstate->frame_stack.top = top;
}
return (_PyInterpreterFrame *)base;
return (_PyInterpreterFrame *)push_chunk(&tstate->frame_stack, (int)size);
}

void
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.