mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
GH-128682: Make PyStackRef_CLOSE
escaping. (GH-129404)
This commit is contained in:
parent
218f205f20
commit
808071b994
12 changed files with 1348 additions and 657 deletions
|
@ -2130,8 +2130,7 @@ dummy_func(
|
|||
PyStackRef_CLOSE(self_st);
|
||||
self_or_null = PyStackRef_NULL;
|
||||
}
|
||||
PyStackRef_CLOSE(class_st);
|
||||
PyStackRef_CLOSE(global_super_st);
|
||||
DECREF_INPUTS();
|
||||
|
||||
attr = PyStackRef_FromPyObjectSteal(attr_o);
|
||||
}
|
||||
|
@ -2245,7 +2244,7 @@ dummy_func(
|
|||
attr = PyStackRef_FromPyObjectNew(attr_o);
|
||||
#endif
|
||||
STAT_INC(LOAD_ATTR, hit);
|
||||
DECREF_INPUTS();
|
||||
PyStackRef_CLOSE(owner);
|
||||
}
|
||||
|
||||
macro(LOAD_ATTR_INSTANCE_VALUE) =
|
||||
|
@ -3671,15 +3670,14 @@ dummy_func(
|
|||
EXIT_IF(!PyStackRef_IsNull(null[0]));
|
||||
}
|
||||
|
||||
op(_EXPAND_METHOD, (callable[1], null[1], unused[oparg] -- method[1], self[1], unused[oparg])) {
|
||||
op(_EXPAND_METHOD, (callable[1], self_or_null[1], unused[oparg] -- callable[1], self_or_null[1], unused[oparg])) {
|
||||
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
|
||||
assert(PyStackRef_IsNull(null[0]));
|
||||
DEAD(null);
|
||||
assert(PyStackRef_IsNull(self_or_null[0]));
|
||||
assert(Py_TYPE(callable_o) == &PyMethod_Type);
|
||||
self[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_self);
|
||||
self_or_null[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_self);
|
||||
_PyStackRef temp = callable[0];
|
||||
method[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_func);
|
||||
assert(PyStackRef_FunctionCheck(method[0]));
|
||||
callable[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_func);
|
||||
assert(PyStackRef_FunctionCheck(callable[0]));
|
||||
PyStackRef_CLOSE(temp);
|
||||
}
|
||||
|
||||
|
@ -3740,13 +3738,13 @@ dummy_func(
|
|||
EXIT_IF(Py_TYPE(PyStackRef_AsPyObjectBorrow(callable[0])) != &PyMethod_Type);
|
||||
}
|
||||
|
||||
op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable[1], null[1], unused[oparg] -- func[1], self[1], unused[oparg])) {
|
||||
DEAD(null);
|
||||
op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable[1], self_or_null[1], unused[oparg] -- callable[1], self_or_null[1], unused[oparg])) {
|
||||
assert(PyStackRef_IsNull(self_or_null[0]));
|
||||
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
|
||||
STAT_INC(CALL, hit);
|
||||
self[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_self);
|
||||
self_or_null[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_self);
|
||||
_PyStackRef temp = callable[0];
|
||||
func[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_func);
|
||||
callable[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_func);
|
||||
PyStackRef_CLOSE(temp);
|
||||
}
|
||||
|
||||
|
@ -4171,8 +4169,9 @@ dummy_func(
|
|||
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
|
||||
|
||||
int total_args = oparg;
|
||||
_PyStackRef *arguments = args;
|
||||
if (!PyStackRef_IsNull(self_or_null[0])) {
|
||||
args--;
|
||||
arguments--;
|
||||
total_args++;
|
||||
}
|
||||
|
||||
|
@ -4183,8 +4182,8 @@ dummy_func(
|
|||
EXIT_IF(meth->ml_flags != METH_O);
|
||||
// CPython promises to check all non-vectorcall function calls.
|
||||
EXIT_IF(tstate->c_recursion_remaining <= 0);
|
||||
_PyStackRef arg_stackref = args[1];
|
||||
_PyStackRef self_stackref = args[0];
|
||||
_PyStackRef arg_stackref = arguments[1];
|
||||
_PyStackRef self_stackref = arguments[0];
|
||||
EXIT_IF(!Py_IS_TYPE(PyStackRef_AsPyObjectBorrow(self_stackref),
|
||||
method->d_common.d_type));
|
||||
STAT_INC(CALL, hit);
|
||||
|
@ -4195,11 +4194,7 @@ dummy_func(
|
|||
PyStackRef_AsPyObjectBorrow(arg_stackref));
|
||||
_Py_LeaveRecursiveCallTstate(tstate);
|
||||
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
|
||||
PyStackRef_CLOSE(self_stackref);
|
||||
PyStackRef_CLOSE(arg_stackref);
|
||||
DEAD(args);
|
||||
DEAD(self_or_null);
|
||||
PyStackRef_CLOSE(callable[0]);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res_o == NULL, error);
|
||||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
@ -4486,15 +4481,14 @@ dummy_func(
|
|||
EXIT_IF(!PyStackRef_IsNull(null[0]));
|
||||
}
|
||||
|
||||
op(_EXPAND_METHOD_KW, (callable[1], null[1], unused[oparg], unused -- method[1], self[1], unused[oparg], unused)) {
|
||||
op(_EXPAND_METHOD_KW, (callable[1], self_or_null[1], unused[oparg], unused -- callable[1], self_or_null[1], unused[oparg], unused)) {
|
||||
assert(PyStackRef_IsNull(self_or_null[0]));
|
||||
_PyStackRef callable_s = callable[0];
|
||||
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable_s);
|
||||
|
||||
assert(PyStackRef_IsNull(null[0]));
|
||||
assert(Py_TYPE(callable_o) == &PyMethod_Type);
|
||||
self[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_self);
|
||||
method[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_func);
|
||||
assert(PyStackRef_FunctionCheck(method[0]));
|
||||
self_or_null[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_self);
|
||||
callable[0] = PyStackRef_FromPyObjectNew(((PyMethodObject *)callable_o)->im_func);
|
||||
assert(PyStackRef_FunctionCheck(callable[0]));
|
||||
PyStackRef_CLOSE(callable_s);
|
||||
}
|
||||
|
||||
|
@ -4600,7 +4594,8 @@ dummy_func(
|
|||
}
|
||||
}
|
||||
|
||||
op(_DO_CALL_FUNCTION_EX, (func_st, unused, callargs_st, kwargs_st -- result)) {
|
||||
op(_DO_CALL_FUNCTION_EX, (func_st, null, callargs_st, kwargs_st -- result)) {
|
||||
(void)null;
|
||||
PyObject *func = PyStackRef_AsPyObjectBorrow(func_st);
|
||||
|
||||
// DICT_MERGE is called before this opcode if there are kwargs.
|
||||
|
@ -4671,8 +4666,8 @@ dummy_func(
|
|||
result_o = PyObject_Call(func, callargs, kwargs);
|
||||
}
|
||||
PyStackRef_XCLOSE(kwargs_st);
|
||||
DEAD(kwargs_st);
|
||||
PyStackRef_CLOSE(callargs_st);
|
||||
DEAD(null);
|
||||
PyStackRef_CLOSE(func_st);
|
||||
ERROR_IF(result_o == NULL, error);
|
||||
result = PyStackRef_FromPyObjectSteal(result_o);
|
||||
|
@ -4809,12 +4804,11 @@ dummy_func(
|
|||
|
||||
macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP;
|
||||
|
||||
pure inst(SWAP, (bottom_in, unused[oparg-2], top_in --
|
||||
top_out, unused[oparg-2], bottom_out)) {
|
||||
bottom_out = bottom_in;
|
||||
DEAD(bottom_in);
|
||||
top_out = top_in;
|
||||
DEAD(top_in);
|
||||
pure inst(SWAP, (bottom[1], unused[oparg-2], top[1] --
|
||||
bottom[1], unused[oparg-2], top[1])) {
|
||||
_PyStackRef temp = bottom[0];
|
||||
bottom[0] = top[0];
|
||||
top[0] = temp;
|
||||
assert(oparg >= 2);
|
||||
}
|
||||
|
||||
|
@ -5174,7 +5168,8 @@ dummy_func(
|
|||
EXIT_TO_TIER1();
|
||||
}
|
||||
|
||||
tier2 op(_ERROR_POP_N, (target/2, unused[oparg] --)) {
|
||||
tier2 op(_ERROR_POP_N, (target/2 --)) {
|
||||
assert(oparg == 0);
|
||||
frame->instr_ptr = _PyFrame_GetBytecode(frame) + target;
|
||||
SYNC_SP();
|
||||
GOTO_UNWIND();
|
||||
|
@ -5193,18 +5188,18 @@ dummy_func(
|
|||
}
|
||||
|
||||
label(pop_4_error) {
|
||||
STACK_SHRINK(1);
|
||||
goto pop_3_error;
|
||||
STACK_SHRINK(4);
|
||||
goto error;
|
||||
}
|
||||
|
||||
label(pop_3_error) {
|
||||
STACK_SHRINK(1);
|
||||
goto pop_2_error;
|
||||
STACK_SHRINK(3);
|
||||
goto error;
|
||||
}
|
||||
|
||||
label(pop_2_error) {
|
||||
STACK_SHRINK(1);
|
||||
goto pop_1_error;
|
||||
STACK_SHRINK(2);
|
||||
goto error;
|
||||
}
|
||||
|
||||
label(pop_1_error) {
|
||||
|
|
804
Python/executor_cases.c.h
generated
804
Python/executor_cases.c.h
generated
File diff suppressed because it is too large
Load diff
879
Python/generated_cases.c.h
generated
879
Python/generated_cases.c.h
generated
File diff suppressed because it is too large
Load diff
|
@ -989,7 +989,6 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length)
|
|||
current_error = next_spare;
|
||||
current_error_target = target;
|
||||
make_exit(&buffer[next_spare], _ERROR_POP_N, 0);
|
||||
buffer[next_spare].oparg = popped;
|
||||
buffer[next_spare].operand0 = target;
|
||||
next_spare++;
|
||||
}
|
||||
|
|
|
@ -512,10 +512,11 @@ dummy_func(void) {
|
|||
top = bottom;
|
||||
}
|
||||
|
||||
op(_SWAP, (bottom_in, unused[oparg-2], top_in --
|
||||
top_out, unused[oparg-2], bottom_out)) {
|
||||
bottom_out = bottom_in;
|
||||
top_out = top_in;
|
||||
op(_SWAP, (bottom[1], unused[oparg-2], top[1] -- bottom[1], unused[oparg-2], top[1])) {
|
||||
JitOptSymbol *temp = bottom[0];
|
||||
bottom[0] = top[0];
|
||||
top[0] = temp;
|
||||
assert(oparg >= 2);
|
||||
}
|
||||
|
||||
op(_LOAD_ATTR_INSTANCE_VALUE, (offset/1, owner -- attr)) {
|
||||
|
@ -629,10 +630,10 @@ dummy_func(void) {
|
|||
ctx->done = true;
|
||||
}
|
||||
|
||||
op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) {
|
||||
op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable[1], self_or_null[1], unused[oparg] -- callable[1], self_or_null[1], unused[oparg])) {
|
||||
(void)callable;
|
||||
func = sym_new_not_null(ctx);
|
||||
self = sym_new_not_null(ctx);
|
||||
callable[0] = sym_new_not_null(ctx);
|
||||
self_or_null[0] = sym_new_not_null(ctx);
|
||||
}
|
||||
|
||||
op(_CHECK_FUNCTION_VERSION, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
|
||||
|
|
46
Python/optimizer_cases.c.h
generated
46
Python/optimizer_cases.c.h
generated
|
@ -1837,12 +1837,6 @@
|
|||
}
|
||||
|
||||
case _EXPAND_METHOD: {
|
||||
JitOptSymbol **method;
|
||||
JitOptSymbol **self;
|
||||
method = &stack_pointer[-2 - oparg];
|
||||
self = &stack_pointer[-1 - oparg];
|
||||
method[0] = sym_new_not_null(ctx);
|
||||
self[0] = sym_new_not_null(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1870,15 +1864,13 @@
|
|||
}
|
||||
|
||||
case _INIT_CALL_BOUND_METHOD_EXACT_ARGS: {
|
||||
JitOptSymbol *callable;
|
||||
JitOptSymbol *func;
|
||||
JitOptSymbol *self;
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
JitOptSymbol **self_or_null;
|
||||
JitOptSymbol **callable;
|
||||
self_or_null = &stack_pointer[-1 - oparg];
|
||||
callable = &stack_pointer[-2 - oparg];
|
||||
(void)callable;
|
||||
func = sym_new_not_null(ctx);
|
||||
self = sym_new_not_null(ctx);
|
||||
stack_pointer[-2 - oparg] = func;
|
||||
stack_pointer[-1 - oparg] = self;
|
||||
callable[0] = sym_new_not_null(ctx);
|
||||
self_or_null[0] = sym_new_not_null(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2214,12 +2206,6 @@
|
|||
}
|
||||
|
||||
case _EXPAND_METHOD_KW: {
|
||||
JitOptSymbol **method;
|
||||
JitOptSymbol **self;
|
||||
method = &stack_pointer[-3 - oparg];
|
||||
self = &stack_pointer[-2 - oparg];
|
||||
method[0] = sym_new_not_null(ctx);
|
||||
self[0] = sym_new_not_null(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2410,16 +2396,14 @@
|
|||
}
|
||||
|
||||
case _SWAP: {
|
||||
JitOptSymbol *top_in;
|
||||
JitOptSymbol *bottom_in;
|
||||
JitOptSymbol *top_out;
|
||||
JitOptSymbol *bottom_out;
|
||||
top_in = stack_pointer[-1];
|
||||
bottom_in = stack_pointer[-2 - (oparg-2)];
|
||||
bottom_out = bottom_in;
|
||||
top_out = top_in;
|
||||
stack_pointer[-2 - (oparg-2)] = top_out;
|
||||
stack_pointer[-1] = bottom_out;
|
||||
JitOptSymbol **top;
|
||||
JitOptSymbol **bottom;
|
||||
top = &stack_pointer[-1];
|
||||
bottom = &stack_pointer[-2 - (oparg-2)];
|
||||
JitOptSymbol *temp = bottom[0];
|
||||
bottom[0] = top[0];
|
||||
top[0] = temp;
|
||||
assert(oparg >= 2);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2639,8 +2623,6 @@
|
|||
}
|
||||
|
||||
case _ERROR_POP_N: {
|
||||
stack_pointer += -oparg;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue