On making a call to a Python function we need to check if there is room for the frame in the frame buffer (_PyThreadState_HasStackSpace) and check the Python recursion limit(_Py_EnterRecursivePy).
The first checks tstate->datastack_top != NULL && size < tstate->datastack_limit - tstate->datastack_top and the second that tstate->py_recursion_remaining > 1.
Given that frames have a minimum size, we can set create a tstate->slots_remaining value, such that slots_remaining <= tstate->datastack_limit - tstate->datastack_top and slots_remaining <= py_recursion_remaining * FRAME_SPECIALS_SIZE. We set slots_remaining to -1 if the datastack is NULL.
Then the check size < tstate->slots_remaining would suffice to check that the data stack is not NULL, for data stack overflow and for the recursion limit all in a single check.
This is unlikely to make much difference overall, but it streamlines calls a bit.
On making a call to a Python function we need to check if there is room for the frame in the frame buffer (
_PyThreadState_HasStackSpace
) and check the Python recursion limit(_Py_EnterRecursivePy
).The first checks
tstate->datastack_top != NULL && size < tstate->datastack_limit - tstate->datastack_top
and the second thattstate->py_recursion_remaining > 1
.Given that frames have a minimum size, we can set create a
tstate->slots_remaining
value, such thatslots_remaining <= tstate->datastack_limit - tstate->datastack_top
andslots_remaining <= py_recursion_remaining * FRAME_SPECIALS_SIZE
. We setslots_remaining
to -1 if the datastack is NULL.Then the check
size < tstate->slots_remaining
would suffice to check that the data stack is not NULL, for data stack overflow and for the recursion limit all in a single check.This is unlikely to make much difference overall, but it streamlines calls a bit.