Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 7fe8f02

Browse files
author
Anselm Kruis
committed
Stackless issue #133: fix Python/ceval.c
Ensure, that frame->f_lasti is >= -1. This invariant was broken by the switch to wordcode.
1 parent 3a234aa commit 7fe8f02

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Python/ceval.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,9 +3887,12 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
38873887
*/
38883888
f->f_stacktop = stack_pointer;
38893889

3890-
/* the -1 is to adjust for the f_lasti change.
3891-
(look for the word 'Promise' above) */
3892-
f->f_lasti = INSTR_OFFSET() - 2;
3890+
/* Set f->f_lasti to the instruction before the current one or to the
3891+
* first instruction (-1). See "f->f_lasti refers to ..." above.
3892+
*/
3893+
f->f_lasti = INSTR_OFFSET() ?
3894+
assert(INSTR_OFFSET() >= sizeof(_Py_CODEUNIT)),
3895+
(int)(INSTR_OFFSET() - sizeof(_Py_CODEUNIT)) : -1;
38933896
if (SLP_PEEK_NEXT_FRAME(tstate)->f_back != f)
38943897
return retval;
38953898
STACKLESS_UNPACK(tstate, retval);
@@ -3935,9 +3938,12 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
39353938
f->f_execute = slp_eval_frame_noval;
39363939
f->f_stacktop = stack_pointer;
39373940

3938-
/* the -1 is to adjust for the f_lasti change.
3939-
(look for the word 'Promise' above) */
3940-
f->f_lasti = INSTR_OFFSET() - 2;
3941+
/* Set f->f_lasti to the instruction before the current one or to the
3942+
* first instruction (-1). See "f->f_lasti refers to ..." above.
3943+
*/
3944+
f->f_lasti = INSTR_OFFSET() ?
3945+
assert(INSTR_OFFSET() >= sizeof(_Py_CODEUNIT)),
3946+
(int)(INSTR_OFFSET() - sizeof(_Py_CODEUNIT)) : -1;
39413947
return (PyObject *) Py_UnwindToken;
39423948
#endif
39433949
}

0 commit comments

Comments
 (0)