diff options
author | Mark Shannon <mark@hotpy.org> | 2022-07-01 14:44:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-01 14:44:30 (GMT) |
commit | 02b30a8ef8fe591e7f5ebc00a885811a98f1d357 (patch) | |
tree | 4728c82eaaca7bb2e556c5a850b7c50d0794696e /Objects | |
parent | 9fa966136fd026ecb74a21b4d63b699d3d40b977 (diff) | |
download | cpython-02b30a8ef8fe591e7f5ebc00a885811a98f1d357.zip cpython-02b30a8ef8fe591e7f5ebc00a885811a98f1d357.tar.gz cpython-02b30a8ef8fe591e7f5ebc00a885811a98f1d357.tar.bz2 |
[3.11] GH-94438: Backport GH-94444 (#94486)
* Account for NULLs on evaluation stack when jumping lines.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/frameobject.c | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 8be41d4..85cc4a2 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -137,9 +137,24 @@ typedef enum kind { Iterator = 1, Except = 2, Object = 3, + Null = 4, } Kind; -#define BITS_PER_BLOCK 2 +static int +compatible_kind(Kind from, Kind to) { + if (to == 0) { + return 0; + } + if (to == Object) { + return from != Null; + } + if (to == Null) { + return 1; + } + return from == to; +} + +#define BITS_PER_BLOCK 3 #define UNINITIALIZED -2 #define OVERFLOWED -1 @@ -298,6 +313,23 @@ mark_stacks(PyCodeObject *code_obj, int len) case RERAISE: /* End of block */ break; + case PUSH_NULL: + next_stack = push_value(next_stack, Null); + stacks[i+1] = next_stack; + break; + case LOAD_GLOBAL: + if (_Py_OPARG(code[i]) & 1) { + next_stack = push_value(next_stack, Null); + } + next_stack = push_value(next_stack, Object); + stacks[i+1] = next_stack; + break; + case LOAD_METHOD: + next_stack = pop_value(next_stack); + next_stack = push_value(next_stack, Null); + next_stack = push_value(next_stack, Object); + stacks[i+1] = next_stack; + break; default: { int delta = PyCompile_OpcodeStackEffect(opcode, _Py_OPARG(code[i])); @@ -319,17 +351,6 @@ mark_stacks(PyCodeObject *code_obj, int len) } static int -compatible_kind(Kind from, Kind to) { - if (to == 0) { - return 0; - } - if (to == Object) { - return 1; - } - return from == to; -} - -static int compatible_stack(int64_t from_stack, int64_t to_stack) { if (from_stack < 0 || to_stack < 0) { @@ -365,7 +386,8 @@ explain_incompatible_stack(int64_t to_stack) case Except: return "can't jump into an 'except' block as there's no exception"; case Object: - return "differing stack depth"; + case Null: + return "incompatible stacks"; case Iterator: return "can't jump into the body of a for loop"; default: |