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

Commit 26584ad

Browse files
author
Anselm Kruis
committed
Stackless issue #133: fix wordcode.
Fix the wordcode processing.
1 parent e120d73 commit 26584ad

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Python/ceval.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
12661266
oparg = NEXTARG();
12671267
if (opcode == EXTENDED_ARG) {
12681268
opcode = NEXTOP();
1269-
oparg = oparg<<16 | NEXTARG();
1269+
oparg = oparg<<8 | NEXTARG();
12701270
}
12711271
assert(opcode == FOR_ITER);
12721272

@@ -1301,7 +1301,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
13011301
oparg = NEXTARG();
13021302
if (opcode == EXTENDED_ARG) {
13031303
opcode = NEXTOP();
1304-
oparg = oparg<<16 | NEXTARG();
1304+
oparg = oparg<<8 | NEXTARG();
13051305
}
13061306
assert(opcode == SETUP_WITH);
13071307

@@ -3872,7 +3872,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
38723872
/* restore this opcode and enable frame to handle it */
38733873
f->f_execute = slp_eval_frame_iter;
38743874
stackless_call_with_opcode:
3875-
next_instr -= (oparg >> 16) ? 6 : 3;
3875+
3876+
#define EXTENDED_ARG_OFFSET(x) \
3877+
(assert(sizeof(x) == 4), \
3878+
(!((x) >> 8) ? 0 : \
3879+
(!((x) >> 16) ? 2 : \
3880+
(!((x) >> 24) ? 4 : 6 ))))
3881+
3882+
next_instr -= 2 + EXTENDED_ARG_OFFSET(oparg);
38763883

38773884
stackless_call:
38783885
/*
@@ -3882,7 +3889,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
38823889

38833890
/* the -1 is to adjust for the f_lasti change.
38843891
(look for the word 'Promise' above) */
3885-
f->f_lasti = INSTR_OFFSET() - 1;
3892+
f->f_lasti = INSTR_OFFSET() - 2;
38863893
if (SLP_PEEK_NEXT_FRAME(tstate)->f_back != f)
38873894
return retval;
38883895
STACKLESS_UNPACK(tstate, retval);
@@ -3906,12 +3913,12 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
39063913

39073914
f->f_stacktop = NULL;
39083915
if (f->f_execute == slp_eval_frame_iter) {
3909-
next_instr += (oparg >> 16) ? 6 : 3;
3916+
next_instr += 2 + EXTENDED_ARG_OFFSET(oparg);;
39103917
f->f_execute = slp_eval_frame_value;
39113918
goto stackless_iter_return;
39123919
}
39133920
else if (f->f_execute == slp_eval_frame_setup_with) {
3914-
next_instr += (oparg >> 16) ? 6 : 3;
3921+
next_instr += 2 + EXTENDED_ARG_OFFSET(oparg);
39153922
f->f_execute = slp_eval_frame_value;
39163923
goto stackless_setup_with_return;
39173924
}
@@ -3930,7 +3937,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
39303937

39313938
/* the -1 is to adjust for the f_lasti change.
39323939
(look for the word 'Promise' above) */
3933-
f->f_lasti = INSTR_OFFSET() - 1;
3940+
f->f_lasti = INSTR_OFFSET() - 2;
39343941
return (PyObject *) Py_UnwindToken;
39353942
#endif
39363943
}

0 commit comments

Comments
 (0)