From 7fe8f02094bec21755faaaef929e5f20da3efa32 Mon Sep 17 00:00:00 2001 From: Anselm Kruis Date: Sun, 29 Oct 2017 14:47:46 +0100 Subject: [PATCH] Stackless issue #133: fix Python/ceval.c Ensure, that frame->f_lasti is >= -1. This invariant was broken by the switch to wordcode. --- Python/ceval.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index 3cde8bedf83bb3..09f83827f30bfa 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3887,9 +3887,12 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) */ f->f_stacktop = stack_pointer; - /* the -1 is to adjust for the f_lasti change. - (look for the word 'Promise' above) */ - f->f_lasti = INSTR_OFFSET() - 2; + /* Set f->f_lasti to the instruction before the current one or to the + * first instruction (-1). See "f->f_lasti refers to ..." above. + */ + f->f_lasti = INSTR_OFFSET() ? + assert(INSTR_OFFSET() >= sizeof(_Py_CODEUNIT)), + (int)(INSTR_OFFSET() - sizeof(_Py_CODEUNIT)) : -1; if (SLP_PEEK_NEXT_FRAME(tstate)->f_back != f) return retval; STACKLESS_UNPACK(tstate, retval); @@ -3935,9 +3938,12 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) f->f_execute = slp_eval_frame_noval; f->f_stacktop = stack_pointer; - /* the -1 is to adjust for the f_lasti change. - (look for the word 'Promise' above) */ - f->f_lasti = INSTR_OFFSET() - 2; + /* Set f->f_lasti to the instruction before the current one or to the + * first instruction (-1). See "f->f_lasti refers to ..." above. + */ + f->f_lasti = INSTR_OFFSET() ? + assert(INSTR_OFFSET() >= sizeof(_Py_CODEUNIT)), + (int)(INSTR_OFFSET() - sizeof(_Py_CODEUNIT)) : -1; return (PyObject *) Py_UnwindToken; #endif }