mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
GH-128682: Mark two more macros as escaping. (GH-129645)
Expand out SETLOCAL so that code generator can see the decref. Mark Py_CLEAR as escaping
This commit is contained in:
parent
2effea4dab
commit
96ff4c2486
6 changed files with 127 additions and 46 deletions
|
@ -272,7 +272,6 @@ dummy_func(
|
|||
|
||||
inst(LOAD_FAST_AND_CLEAR, (-- value)) {
|
||||
value = GETLOCAL(oparg);
|
||||
// do not use SETLOCAL here, it decrefs the old value
|
||||
GETLOCAL(oparg) = PyStackRef_NULL;
|
||||
}
|
||||
|
||||
|
@ -328,8 +327,10 @@ dummy_func(
|
|||
}
|
||||
|
||||
replicate(8) inst(STORE_FAST, (value --)) {
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
DEAD(value);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
}
|
||||
|
||||
pseudo(STORE_FAST_MAYBE_NULL, (unused --)) = {
|
||||
|
@ -339,18 +340,24 @@ dummy_func(
|
|||
inst(STORE_FAST_LOAD_FAST, (value1 -- value2)) {
|
||||
uint32_t oparg1 = oparg >> 4;
|
||||
uint32_t oparg2 = oparg & 15;
|
||||
SETLOCAL(oparg1, value1);
|
||||
_PyStackRef tmp = GETLOCAL(oparg1);
|
||||
GETLOCAL(oparg1) = value1;
|
||||
DEAD(value1);
|
||||
value2 = PyStackRef_DUP(GETLOCAL(oparg2));
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
}
|
||||
|
||||
inst(STORE_FAST_STORE_FAST, (value2, value1 --)) {
|
||||
uint32_t oparg1 = oparg >> 4;
|
||||
uint32_t oparg2 = oparg & 15;
|
||||
SETLOCAL(oparg1, value1);
|
||||
_PyStackRef tmp = GETLOCAL(oparg1);
|
||||
GETLOCAL(oparg1) = value1;
|
||||
DEAD(value1);
|
||||
SETLOCAL(oparg2, value2);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
tmp = GETLOCAL(oparg2);
|
||||
GETLOCAL(oparg2) = value2;
|
||||
DEAD(value2);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
}
|
||||
|
||||
pure inst(POP_TOP, (value --)) {
|
||||
|
@ -1775,7 +1782,9 @@ dummy_func(
|
|||
);
|
||||
ERROR_IF(1, error);
|
||||
}
|
||||
SETLOCAL(oparg, PyStackRef_NULL);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = PyStackRef_NULL;
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
}
|
||||
|
||||
inst(MAKE_CELL, (--)) {
|
||||
|
@ -1786,7 +1795,9 @@ dummy_func(
|
|||
if (cell == NULL) {
|
||||
ERROR_NO_POP();
|
||||
}
|
||||
SETLOCAL(oparg, PyStackRef_FromPyObjectSteal(cell));
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = PyStackRef_FromPyObjectSteal(cell);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
}
|
||||
|
||||
inst(DELETE_DEREF, (--)) {
|
||||
|
|
|
@ -194,6 +194,7 @@ lltrace_instruction(_PyInterpreterFrame *frame,
|
|||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void
|
||||
lltrace_resume_frame(_PyInterpreterFrame *frame)
|
||||
{
|
||||
|
|
|
@ -221,15 +221,6 @@ GETITEM(PyObject *v, Py_ssize_t i) {
|
|||
#define LOCALS_ARRAY (frame->localsplus)
|
||||
#define GETLOCAL(i) (frame->localsplus[i])
|
||||
|
||||
/* The SETLOCAL() macro must not DECREF the local variable in-place and
|
||||
then store the new value; it must copy the old value to a temporary
|
||||
value, then store the new value, and then DECREF the temporary value.
|
||||
This is because it is possible that during the DECREF the frame is
|
||||
accessed by other code (e.g. a __del__ method or gc.collect()) and the
|
||||
variable would be pointing to already-freed memory. */
|
||||
#define SETLOCAL(i, value) do { _PyStackRef tmp = GETLOCAL(i); \
|
||||
GETLOCAL(i) = value; \
|
||||
PyStackRef_XCLOSE(tmp); } while (0)
|
||||
|
||||
#ifdef Py_STATS
|
||||
#define UPDATE_MISS_STATS(INSTNAME) \
|
||||
|
|
69
Python/executor_cases.c.h
generated
69
Python/executor_cases.c.h
generated
|
@ -205,7 +205,6 @@
|
|||
_PyStackRef value;
|
||||
oparg = CURRENT_OPARG();
|
||||
value = GETLOCAL(oparg);
|
||||
// do not use SETLOCAL here, it decrefs the old value
|
||||
GETLOCAL(oparg) = PyStackRef_NULL;
|
||||
stack_pointer[0] = value;
|
||||
stack_pointer += 1;
|
||||
|
@ -307,9 +306,13 @@
|
|||
oparg = 0;
|
||||
assert(oparg == CURRENT_OPARG());
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -318,9 +321,13 @@
|
|||
oparg = 1;
|
||||
assert(oparg == CURRENT_OPARG());
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -329,9 +336,13 @@
|
|||
oparg = 2;
|
||||
assert(oparg == CURRENT_OPARG());
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -340,9 +351,13 @@
|
|||
oparg = 3;
|
||||
assert(oparg == CURRENT_OPARG());
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -351,9 +366,13 @@
|
|||
oparg = 4;
|
||||
assert(oparg == CURRENT_OPARG());
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -362,9 +381,13 @@
|
|||
oparg = 5;
|
||||
assert(oparg == CURRENT_OPARG());
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -373,9 +396,13 @@
|
|||
oparg = 6;
|
||||
assert(oparg == CURRENT_OPARG());
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -384,9 +411,13 @@
|
|||
oparg = 7;
|
||||
assert(oparg == CURRENT_OPARG());
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -394,9 +425,13 @@
|
|||
_PyStackRef value;
|
||||
oparg = CURRENT_OPARG();
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2255,7 +2290,11 @@
|
|||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
JUMP_TO_ERROR();
|
||||
}
|
||||
SETLOCAL(oparg, PyStackRef_NULL);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = PyStackRef_NULL;
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2268,7 +2307,11 @@
|
|||
if (cell == NULL) {
|
||||
JUMP_TO_ERROR();
|
||||
}
|
||||
SETLOCAL(oparg, PyStackRef_FromPyObjectSteal(cell));
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = PyStackRef_FromPyObjectSteal(cell);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -6314,7 +6357,9 @@
|
|||
#endif
|
||||
if (exit->executor && !exit->executor->vm_data.valid) {
|
||||
exit->temperature = initial_temperature_backoff_counter();
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(exit->executor);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
if (exit->executor == NULL) {
|
||||
_Py_BackoffCounter temperature = exit->temperature;
|
||||
|
|
57
Python/generated_cases.c.h
generated
57
Python/generated_cases.c.h
generated
|
@ -1082,7 +1082,9 @@
|
|||
frame, this_instr, callable_o, arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (err < 0) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(res_o);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1842,7 +1844,9 @@
|
|||
frame, this_instr, func, arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (err < 0) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(result_o);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2163,7 +2167,9 @@
|
|||
frame, this_instr, callable_o, arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (err < 0) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(res_o);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3837,7 +3843,11 @@
|
|||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
goto error;
|
||||
}
|
||||
SETLOCAL(oparg, PyStackRef_NULL);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = PyStackRef_NULL;
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -4781,7 +4791,9 @@
|
|||
frame, this_instr, callable_o, arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (err < 0) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(res_o);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4920,7 +4932,9 @@
|
|||
frame, this_instr, func, arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (err < 0) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(result_o);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5155,7 +5169,9 @@
|
|||
frame, this_instr, callable_o, arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (err < 0) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(res_o);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5421,7 +5437,9 @@
|
|||
frame, this_instr, global_super, arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (err < 0) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(super);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6858,7 +6876,6 @@
|
|||
INSTRUCTION_STATS(LOAD_FAST_AND_CLEAR);
|
||||
_PyStackRef value;
|
||||
value = GETLOCAL(oparg);
|
||||
// do not use SETLOCAL here, it decrefs the old value
|
||||
GETLOCAL(oparg) = PyStackRef_NULL;
|
||||
stack_pointer[0] = value;
|
||||
stack_pointer += 1;
|
||||
|
@ -7338,7 +7355,9 @@
|
|||
frame, this_instr, global_super, arg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (err < 0) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
Py_CLEAR(super);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7472,7 +7491,11 @@
|
|||
if (cell == NULL) {
|
||||
goto error;
|
||||
}
|
||||
SETLOCAL(oparg, PyStackRef_FromPyObjectSteal(cell));
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = PyStackRef_FromPyObjectSteal(cell);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -8545,9 +8568,13 @@
|
|||
INSTRUCTION_STATS(STORE_FAST);
|
||||
_PyStackRef value;
|
||||
value = stack_pointer[-1];
|
||||
SETLOCAL(oparg, value);
|
||||
_PyStackRef tmp = GETLOCAL(oparg);
|
||||
GETLOCAL(oparg) = value;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -8560,9 +8587,13 @@
|
|||
value1 = stack_pointer[-1];
|
||||
uint32_t oparg1 = oparg >> 4;
|
||||
uint32_t oparg2 = oparg & 15;
|
||||
SETLOCAL(oparg1, value1);
|
||||
_PyStackRef tmp = GETLOCAL(oparg1);
|
||||
GETLOCAL(oparg1) = value1;
|
||||
value2 = PyStackRef_DUP(GETLOCAL(oparg2));
|
||||
stack_pointer[-1] = value2;
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -8576,10 +8607,20 @@
|
|||
value2 = stack_pointer[-2];
|
||||
uint32_t oparg1 = oparg >> 4;
|
||||
uint32_t oparg2 = oparg & 15;
|
||||
SETLOCAL(oparg1, value1);
|
||||
SETLOCAL(oparg2, value2);
|
||||
stack_pointer += -2;
|
||||
_PyStackRef tmp = GETLOCAL(oparg1);
|
||||
GETLOCAL(oparg1) = value1;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
tmp = GETLOCAL(oparg2);
|
||||
GETLOCAL(oparg2) = value2;
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyStackRef_XCLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue