mirror of
https://github.com/python/cpython.git
synced 2025-09-14 20:56:06 +00:00
[3.11] GH-94438: Backport GH-94444 (#94486)
* Account for NULLs on evaluation stack when jumping lines.
This commit is contained in:
parent
9fa966136f
commit
02b30a8ef8
3 changed files with 98 additions and 17 deletions
|
@ -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]));
|
||||
|
@ -318,17 +350,6 @@ mark_stacks(PyCodeObject *code_obj, int len)
|
|||
return stacks;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue