Get rid of ERROR_IF's "label" parameter (GH-132654)

This commit is contained in:
Brandt Bucher 2025-04-29 17:21:53 -07:00 committed by GitHub
parent b329096cfb
commit 732d1b0241
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 155 additions and 162 deletions

View File

@ -419,7 +419,7 @@ def test_pep7_condition(self):
def test_error_if_plain(self):
input = """
inst(OP, (--)) {
ERROR_IF(cond, label);
ERROR_IF(cond);
}
"""
output = """
@ -432,7 +432,7 @@ def test_error_if_plain(self):
next_instr += 1;
INSTRUCTION_STATS(OP);
if (cond) {
JUMP_TO_LABEL(label);
JUMP_TO_LABEL(error);
}
DISPATCH();
}
@ -442,7 +442,7 @@ def test_error_if_plain(self):
def test_error_if_plain_with_comment(self):
input = """
inst(OP, (--)) {
ERROR_IF(cond, label); // Comment is ok
ERROR_IF(cond); // Comment is ok
}
"""
output = """
@ -455,7 +455,7 @@ def test_error_if_plain_with_comment(self):
next_instr += 1;
INSTRUCTION_STATS(OP);
if (cond) {
JUMP_TO_LABEL(label);
JUMP_TO_LABEL(error);
}
DISPATCH();
}
@ -467,7 +467,7 @@ def test_error_if_pop(self):
inst(OP, (left, right -- res)) {
SPAM(left, right);
INPUTS_DEAD();
ERROR_IF(cond, label);
ERROR_IF(cond);
res = 0;
}
"""
@ -487,7 +487,7 @@ def test_error_if_pop(self):
left = stack_pointer[-2];
SPAM(left, right);
if (cond) {
JUMP_TO_LABEL(pop_2_label);
JUMP_TO_LABEL(pop_2_error);
}
res = 0;
stack_pointer[-2] = res;
@ -503,7 +503,7 @@ def test_error_if_pop_with_result(self):
inst(OP, (left, right -- res)) {
res = SPAM(left, right);
INPUTS_DEAD();
ERROR_IF(cond, label);
ERROR_IF(cond);
}
"""
output = """
@ -522,7 +522,7 @@ def test_error_if_pop_with_result(self):
left = stack_pointer[-2];
res = SPAM(left, right);
if (cond) {
JUMP_TO_LABEL(pop_2_label);
JUMP_TO_LABEL(pop_2_error);
}
stack_pointer[-2] = res;
stack_pointer += -1;
@ -903,7 +903,7 @@ def test_array_error_if(self):
inst(OP, (extra, values[oparg] --)) {
DEAD(extra);
DEAD(values);
ERROR_IF(oparg == 0, somewhere);
ERROR_IF(oparg == 0);
}
"""
output = """
@ -922,7 +922,7 @@ def test_array_error_if(self):
if (oparg == 0) {
stack_pointer += -1 - oparg;
assert(WITHIN_STACK_BOUNDS());
JUMP_TO_LABEL(somewhere);
JUMP_TO_LABEL(error);
}
stack_pointer += -1 - oparg;
assert(WITHIN_STACK_BOUNDS());
@ -1319,7 +1319,7 @@ def test_pop_on_error_peeks(self):
op(THIRD, (j, k --)) {
INPUTS_DEAD(); // Mark j and k as used
ERROR_IF(cond, error);
ERROR_IF(cond);
}
macro(TEST) = FIRST + SECOND + THIRD;
@ -1369,7 +1369,7 @@ def test_push_then_error(self):
op(SECOND, (a -- a, b)) {
b = 1;
ERROR_IF(cond, error);
ERROR_IF(cond);
}
macro(TEST) = FIRST + SECOND;
@ -1414,10 +1414,10 @@ def test_error_if_true(self):
input = """
inst(OP1, ( --)) {
ERROR_IF(true, here);
ERROR_IF(true);
}
inst(OP2, ( --)) {
ERROR_IF(1, there);
ERROR_IF(1);
}
"""
output = """
@ -1429,7 +1429,7 @@ def test_error_if_true(self):
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP1);
JUMP_TO_LABEL(here);
JUMP_TO_LABEL(error);
}
TARGET(OP2) {
@ -1440,7 +1440,7 @@ def test_error_if_true(self):
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP2);
JUMP_TO_LABEL(there);
JUMP_TO_LABEL(error);
}
"""
self.run_cases_test(input, output)
@ -1716,7 +1716,7 @@ def test_no_escaping_calls_in_branching_macros(self):
input = """
inst(OP, ( -- )) {
ERROR_IF(escaping_call(), error);
ERROR_IF(escaping_call());
}
"""
with self.assertRaises(SyntaxError):

View File

@ -156,7 +156,7 @@ dummy_func(
QSBR_QUIESCENT_STATE(tstate);
if (_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & _PY_EVAL_EVENTS_MASK) {
int err = _Py_HandlePending(tstate);
ERROR_IF(err != 0, error);
ERROR_IF(err != 0);
}
}
@ -166,7 +166,7 @@ dummy_func(
QSBR_QUIESCENT_STATE(tstate);
if (_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & _PY_EVAL_EVENTS_MASK) {
int err = _Py_HandlePending(tstate);
ERROR_IF(err != 0, error);
ERROR_IF(err != 0);
}
}
}
@ -200,7 +200,7 @@ dummy_func(
((_PyThreadStateImpl *)tstate)->tlbc_index) {
_Py_CODEUNIT *bytecode =
_PyEval_GetExecutableCode(tstate, _PyFrame_GetCode(frame));
ERROR_IF(bytecode == NULL, error);
ERROR_IF(bytecode == NULL);
ptrdiff_t off = this_instr - _PyFrame_GetBytecode(frame);
frame->tlbc_index = ((_PyThreadStateImpl *)tstate)->tlbc_index;
frame->instr_ptr = bytecode + off;
@ -236,7 +236,7 @@ dummy_func(
op(_MONITOR_RESUME, (--)) {
int err = _Py_call_instrumentation(
tstate, oparg > 0, frame, this_instr);
ERROR_IF(err, error);
ERROR_IF(err);
if (frame->instr_ptr != this_instr) {
/* Instrumentation has jumped */
next_instr = frame->instr_ptr;
@ -260,7 +260,7 @@ dummy_func(
UNBOUNDLOCAL_ERROR_MSG,
PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, oparg)
);
ERROR_IF(1, error);
ERROR_IF(true);
}
value = PyStackRef_DUP(value_s);
}
@ -446,7 +446,7 @@ dummy_func(
inst(UNARY_NEGATIVE, (value -- res)) {
PyObject *res_o = PyNumber_Negative(PyStackRef_AsPyObjectBorrow(value));
PyStackRef_CLOSE(value);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -481,7 +481,7 @@ dummy_func(
op(_TO_BOOL, (value -- res)) {
int err = PyObject_IsTrue(PyStackRef_AsPyObjectBorrow(value));
PyStackRef_CLOSE(value);
ERROR_IF(err < 0, error);
ERROR_IF(err < 0);
res = err ? PyStackRef_True : PyStackRef_False;
}
@ -576,7 +576,7 @@ dummy_func(
inst(UNARY_INVERT, (value -- res)) {
PyObject *res_o = PyNumber_Invert(PyStackRef_AsPyObjectBorrow(value));
PyStackRef_CLOSE(value);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -618,7 +618,7 @@ dummy_func(
PyStackRef_CLOSE_SPECIALIZED(right, _PyLong_ExactDealloc);
PyStackRef_CLOSE_SPECIALIZED(left, _PyLong_ExactDealloc);
INPUTS_DEAD();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -633,7 +633,7 @@ dummy_func(
PyStackRef_CLOSE_SPECIALIZED(right, _PyLong_ExactDealloc);
PyStackRef_CLOSE_SPECIALIZED(left, _PyLong_ExactDealloc);
INPUTS_DEAD();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -648,7 +648,7 @@ dummy_func(
PyStackRef_CLOSE_SPECIALIZED(right, _PyLong_ExactDealloc);
PyStackRef_CLOSE_SPECIALIZED(left, _PyLong_ExactDealloc);
INPUTS_DEAD();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -681,7 +681,7 @@ dummy_func(
((PyFloatObject *)right_o)->ob_fval;
res = _PyFloat_FromDouble_ConsumeInputs(left, right, dres);
INPUTS_DEAD();
ERROR_IF(PyStackRef_IsNull(res), error);
ERROR_IF(PyStackRef_IsNull(res));
}
pure op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) {
@ -696,7 +696,7 @@ dummy_func(
((PyFloatObject *)right_o)->ob_fval;
res = _PyFloat_FromDouble_ConsumeInputs(left, right, dres);
INPUTS_DEAD();
ERROR_IF(PyStackRef_IsNull(res), error);
ERROR_IF(PyStackRef_IsNull(res));
}
pure op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res)) {
@ -711,7 +711,7 @@ dummy_func(
((PyFloatObject *)right_o)->ob_fval;
res = _PyFloat_FromDouble_ConsumeInputs(left, right, dres);
INPUTS_DEAD();
ERROR_IF(PyStackRef_IsNull(res), error);
ERROR_IF(PyStackRef_IsNull(res));
}
macro(BINARY_OP_MULTIPLY_FLOAT) =
@ -732,7 +732,7 @@ dummy_func(
PyStackRef_CLOSE_SPECIALIZED(right, _PyUnicode_ExactDealloc);
PyStackRef_CLOSE_SPECIALIZED(left, _PyUnicode_ExactDealloc);
INPUTS_DEAD();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -780,7 +780,7 @@ dummy_func(
PyUnicode_Append(&temp, right_o);
*target_local = PyStackRef_FromPyObjectSteal(temp);
Py_DECREF(right_o);
ERROR_IF(PyStackRef_IsNull(*target_local), error);
ERROR_IF(PyStackRef_IsNull(*target_local));
#if TIER_ONE
// The STORE_FAST is already done. This is done here in tier one,
// and during trace projection in tier two:
@ -839,7 +839,7 @@ dummy_func(
Py_DECREF(slice);
}
PyStackRef_CLOSE(container);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -864,7 +864,7 @@ dummy_func(
Py_DECREF(slice);
}
DECREF_INPUTS();
ERROR_IF(err, error);
ERROR_IF(err);
}
macro(STORE_SLICE) = _SPECIALIZE_STORE_SLICE + _STORE_SLICE;
@ -978,7 +978,7 @@ dummy_func(
_PyErr_SetKeyError(sub);
}
DECREF_INPUTS();
ERROR_IF(rc <= 0, error); // not found or error
ERROR_IF(rc <= 0); // not found or error
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -1016,13 +1016,13 @@ dummy_func(
inst(LIST_APPEND, (list, unused[oparg-1], v -- list, unused[oparg-1])) {
int err = _PyList_AppendTakeRef((PyListObject *)PyStackRef_AsPyObjectBorrow(list),
PyStackRef_AsPyObjectSteal(v));
ERROR_IF(err < 0, error);
ERROR_IF(err < 0);
}
inst(SET_ADD, (set, unused[oparg-1], v -- set, unused[oparg-1])) {
int err = _PySet_AddTakeRef((PySetObject *)PyStackRef_AsPyObjectBorrow(set),
PyStackRef_AsPyObjectSteal(v));
ERROR_IF(err, error);
ERROR_IF(err);
}
family(STORE_SUBSCR, INLINE_CACHE_ENTRIES_STORE_SUBSCR) = {
@ -1046,7 +1046,7 @@ dummy_func(
/* container[sub] = v */
int err = PyObject_SetItem(PyStackRef_AsPyObjectBorrow(container), PyStackRef_AsPyObjectBorrow(sub), PyStackRef_AsPyObjectBorrow(v));
DECREF_INPUTS();
ERROR_IF(err, error);
ERROR_IF(err);
}
macro(STORE_SUBSCR) = _SPECIALIZE_STORE_SUBSCR + _STORE_SUBSCR;
@ -1095,7 +1095,7 @@ dummy_func(
PyStackRef_AsPyObjectSteal(sub),
PyStackRef_AsPyObjectSteal(value));
PyStackRef_CLOSE(dict_st);
ERROR_IF(err, error);
ERROR_IF(err);
}
inst(DELETE_SUBSCR, (container, sub --)) {
@ -1103,14 +1103,14 @@ dummy_func(
int err = PyObject_DelItem(PyStackRef_AsPyObjectBorrow(container),
PyStackRef_AsPyObjectBorrow(sub));
DECREF_INPUTS();
ERROR_IF(err, error);
ERROR_IF(err);
}
inst(CALL_INTRINSIC_1, (value -- res)) {
assert(oparg <= MAX_INTRINSIC_1);
PyObject *res_o = _PyIntrinsics_UnaryFunctions[oparg].func(tstate, PyStackRef_AsPyObjectBorrow(value));
PyStackRef_CLOSE(value);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -1121,7 +1121,7 @@ dummy_func(
PyObject *res_o = _PyIntrinsics_BinaryFunctions[oparg].func(tstate, value2, value1);
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -1135,7 +1135,7 @@ dummy_func(
monitor_reraise(tstate, frame, this_instr);
goto exception_unwind;
}
ERROR_IF(true, error);
ERROR_IF(true);
}
tier1 inst(INTERPRETER_EXIT, (retval --)) {
@ -1173,7 +1173,7 @@ dummy_func(
int err = _Py_call_instrumentation_arg(
tstate, PY_MONITORING_EVENT_PY_RETURN,
frame, this_instr, PyStackRef_AsPyObjectBorrow(val));
ERROR_IF(err, error);
ERROR_IF(err);
}
macro(INSTRUMENTED_RETURN_VALUE) =
@ -1196,12 +1196,12 @@ dummy_func(
"__aiter__ method, got %.100s",
type->tp_name);
PyStackRef_CLOSE(obj);
ERROR_IF(true, error);
ERROR_IF(true);
}
iter_o = (*getter)(obj_o);
PyStackRef_CLOSE(obj);
ERROR_IF(iter_o == NULL, error);
ERROR_IF(iter_o == NULL);
if (Py_TYPE(iter_o)->tp_as_async == NULL ||
Py_TYPE(iter_o)->tp_as_async->am_anext == NULL) {
@ -1211,7 +1211,7 @@ dummy_func(
"that does not implement __anext__: %.100s",
Py_TYPE(iter_o)->tp_name);
Py_DECREF(iter_o);
ERROR_IF(true, error);
ERROR_IF(true);
}
iter = PyStackRef_FromPyObjectSteal(iter_o);
}
@ -1227,7 +1227,7 @@ dummy_func(
inst(GET_AWAITABLE, (iterable -- iter)) {
PyObject *iter_o = _PyEval_GetAwaitable(PyStackRef_AsPyObjectBorrow(iterable), oparg);
PyStackRef_CLOSE(iterable);
ERROR_IF(iter_o == NULL, error);
ERROR_IF(iter_o == NULL);
iter = PyStackRef_FromPyObjectSteal(iter_o);
}
@ -1289,7 +1289,7 @@ dummy_func(
}
else {
PyStackRef_CLOSE(v);
ERROR_IF(true, error);
ERROR_IF(true);
}
}
PyStackRef_CLOSE(v);
@ -1450,11 +1450,11 @@ dummy_func(
inst(LOAD_BUILD_CLASS, ( -- bc)) {
PyObject *bc_o;
int err = PyMapping_GetOptionalItem(BUILTINS(), &_Py_ID(__build_class__), &bc_o);
ERROR_IF(err < 0, error);
ERROR_IF(err < 0);
if (bc_o == NULL) {
_PyErr_SetString(tstate, PyExc_NameError,
"__build_class__ not found");
ERROR_IF(true, error);
ERROR_IF(true);
}
bc = PyStackRef_FromPyObjectSteal(bc_o);
}
@ -1467,7 +1467,7 @@ dummy_func(
_PyErr_Format(tstate, PyExc_SystemError,
"no locals found when storing %R", name);
PyStackRef_CLOSE(v);
ERROR_IF(true, error);
ERROR_IF(true);
}
if (PyDict_CheckExact(ns)) {
err = PyDict_SetItem(ns, name, PyStackRef_AsPyObjectBorrow(v));
@ -1476,7 +1476,7 @@ dummy_func(
err = PyObject_SetItem(ns, name, PyStackRef_AsPyObjectBorrow(v));
}
PyStackRef_CLOSE(v);
ERROR_IF(err, error);
ERROR_IF(err);
}
inst(DELETE_NAME, (--)) {
@ -1522,7 +1522,7 @@ dummy_func(
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
int res = _PyEval_UnpackIterableStackRef(tstate, seq_o, oparg, -1, top);
Py_DECREF(seq_o);
ERROR_IF(res == 0, error);
ERROR_IF(res == 0);
}
macro(UNPACK_SEQUENCE) = _SPECIALIZE_UNPACK_SEQUENCE + _UNPACK_SEQUENCE;
@ -1580,7 +1580,7 @@ dummy_func(
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
int res = _PyEval_UnpackIterableStackRef(tstate, seq_o, oparg & 0xFF, oparg >> 8, top);
Py_DECREF(seq_o);
ERROR_IF(res == 0, error);
ERROR_IF(res == 0);
}
family(STORE_ATTR, INLINE_CACHE_ENTRIES_STORE_ATTR) = {
@ -1607,7 +1607,7 @@ dummy_func(
int err = PyObject_SetAttr(PyStackRef_AsPyObjectBorrow(owner),
name, PyStackRef_AsPyObjectBorrow(v));
DECREF_INPUTS();
ERROR_IF(err, error);
ERROR_IF(err);
}
macro(STORE_ATTR) = _SPECIALIZE_STORE_ATTR + unused/3 + _STORE_ATTR;
@ -1616,14 +1616,14 @@ dummy_func(
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyObject_DelAttr(PyStackRef_AsPyObjectBorrow(owner), name);
PyStackRef_CLOSE(owner);
ERROR_IF(err, error);
ERROR_IF(err);
}
inst(STORE_GLOBAL, (v --)) {
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyDict_SetItem(GLOBALS(), name, PyStackRef_AsPyObjectBorrow(v));
PyStackRef_CLOSE(v);
ERROR_IF(err, error);
ERROR_IF(err);
}
inst(DELETE_GLOBAL, (--)) {
@ -1645,7 +1645,7 @@ dummy_func(
if (l == NULL) {
_PyErr_SetString(tstate, PyExc_SystemError,
"no locals found");
ERROR_IF(true, error);
ERROR_IF(true);
}
locals = PyStackRef_FromPyObjectNew(l);
}
@ -1655,7 +1655,7 @@ dummy_func(
PyObject *v_o;
int err = PyMapping_GetOptionalItem(PyStackRef_AsPyObjectBorrow(mod_or_class_dict), name, &v_o);
PyStackRef_CLOSE(mod_or_class_dict);
ERROR_IF(err < 0, error);
ERROR_IF(err < 0);
if (v_o == NULL) {
if (PyDict_CheckExact(GLOBALS())
&& PyDict_CheckExact(BUILTINS()))
@ -1677,16 +1677,16 @@ dummy_func(
/* Slow-path if globals or builtins is not a dict */
/* namespace 1: globals */
int err = PyMapping_GetOptionalItem(GLOBALS(), name, &v_o);
ERROR_IF(err < 0, error);
ERROR_IF(err < 0);
if (v_o == NULL) {
/* namespace 2: builtins */
int err = PyMapping_GetOptionalItem(BUILTINS(), name, &v_o);
ERROR_IF(err < 0, error);
ERROR_IF(err < 0);
if (v_o == NULL) {
_PyEval_FormatExcCheckArg(
tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
ERROR_IF(true, error);
ERROR_IF(true);
}
}
}
@ -1697,7 +1697,7 @@ dummy_func(
inst(LOAD_NAME, (-- v)) {
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
PyObject *v_o = _PyEval_LoadName(tstate, frame, name);
ERROR_IF(v_o == NULL, error);
ERROR_IF(v_o == NULL);
v = PyStackRef_FromPyObjectSteal(v_o);
}
@ -1723,7 +1723,7 @@ dummy_func(
op(_LOAD_GLOBAL, ( -- res[1])) {
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
_PyEval_LoadGlobalStackRef(GLOBALS(), BUILTINS(), name, res);
ERROR_IF(PyStackRef_IsNull(*res), error);
ERROR_IF(PyStackRef_IsNull(*res));
}
op(_PUSH_NULL_CONDITIONAL, ( -- null[oparg & 1])) {
@ -1806,7 +1806,7 @@ dummy_func(
UNBOUNDLOCAL_ERROR_MSG,
PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, oparg)
);
ERROR_IF(1, error);
ERROR_IF(true);
}
_PyStackRef tmp = GETLOCAL(oparg);
GETLOCAL(oparg) = PyStackRef_NULL;
@ -1867,7 +1867,7 @@ dummy_func(
value = _PyCell_GetStackRef(cell);
if (PyStackRef_IsNull(value)) {
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
ERROR_IF(true, error);
ERROR_IF(true);
}
}
@ -1894,12 +1894,12 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(pieces, oparg, pieces_o);
if (CONVERSION_FAILED(pieces_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *str_o = _PyUnicode_JoinArray(&_Py_STR(empty), pieces_o, oparg);
STACKREFS_TO_PYOBJECTS_CLEANUP(pieces_o);
DECREF_INPUTS();
ERROR_IF(str_o == NULL, error);
ERROR_IF(str_o == NULL);
str = PyStackRef_FromPyObjectSteal(str_o);
}
@ -1937,7 +1937,7 @@ dummy_func(
Py_TYPE(iterable)->tp_name);
}
PyStackRef_CLOSE(iterable_st);
ERROR_IF(true, error);
ERROR_IF(true);
}
assert(Py_IsNone(none_val));
PyStackRef_CLOSE(iterable_st);
@ -1947,14 +1947,14 @@ dummy_func(
int err = _PySet_Update(PyStackRef_AsPyObjectBorrow(set),
PyStackRef_AsPyObjectBorrow(iterable));
PyStackRef_CLOSE(iterable);
ERROR_IF(err < 0, error);
ERROR_IF(err < 0);
}
inst(BUILD_SET, (values[oparg] -- set)) {
PyObject *set_o = PySet_New(NULL);
if (set_o == NULL) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
int err = 0;
@ -1971,7 +1971,7 @@ dummy_func(
DEAD(values);
if (err) {
Py_DECREF(set_o);
ERROR_IF(true, error);
ERROR_IF(true);
}
INPUTS_DEAD();
@ -1982,7 +1982,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(values, oparg*2, values_o);
if (CONVERSION_FAILED(values_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *map_o = _PyDict_FromItems(
values_o, 2,
@ -1990,7 +1990,7 @@ dummy_func(
oparg);
STACKREFS_TO_PYOBJECTS_CLEANUP(values_o);
DECREF_INPUTS();
ERROR_IF(map_o == NULL, error);
ERROR_IF(map_o == NULL);
map = PyStackRef_FromPyObjectStealMortal(map_o);
}
@ -1999,18 +1999,18 @@ dummy_func(
if (LOCALS() == NULL) {
_PyErr_Format(tstate, PyExc_SystemError,
"no locals found when setting up annotations");
ERROR_IF(true, error);
ERROR_IF(true);
}
/* check if __annotations__ in locals()... */
int err = PyMapping_GetOptionalItem(LOCALS(), &_Py_ID(__annotations__), &ann_dict);
ERROR_IF(err < 0, error);
ERROR_IF(err < 0);
if (ann_dict == NULL) {
ann_dict = PyDict_New();
ERROR_IF(ann_dict == NULL, error);
ERROR_IF(ann_dict == NULL);
err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__),
ann_dict);
Py_DECREF(ann_dict);
ERROR_IF(err, error);
ERROR_IF(err);
}
else {
Py_DECREF(ann_dict);
@ -2034,7 +2034,7 @@ dummy_func(
Py_TYPE(update_o)->tp_name);
}
PyStackRef_CLOSE(update);
ERROR_IF(true, error);
ERROR_IF(true);
}
PyStackRef_CLOSE(update);
}
@ -2048,7 +2048,7 @@ dummy_func(
if (err < 0) {
_PyEval_FormatKwargsError(tstate, callable_o, update_o);
PyStackRef_CLOSE(update);
ERROR_IF(true, error);
ERROR_IF(true);
}
PyStackRef_CLOSE(update);
}
@ -2063,7 +2063,7 @@ dummy_func(
PyStackRef_AsPyObjectSteal(key),
PyStackRef_AsPyObjectSteal(value)
);
ERROR_IF(err != 0, error);
ERROR_IF(err != 0);
}
macro(INSTRUMENTED_LOAD_SUPER_ATTR) =
@ -2101,7 +2101,7 @@ dummy_func(
frame, this_instr, global_super, arg);
if (err) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
}
// we make no attempt to optimize here; specializations should
@ -2125,11 +2125,11 @@ dummy_func(
}
}
DECREF_INPUTS();
ERROR_IF(super == NULL, error);
ERROR_IF(super == NULL);
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
PyObject *attr_o = PyObject_GetAttr(super, name);
Py_DECREF(super);
ERROR_IF(attr_o == NULL, error);
ERROR_IF(attr_o == NULL);
attr = PyStackRef_FromPyObjectSteal(attr_o);
}
@ -2150,7 +2150,7 @@ dummy_func(
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
PyObject *attr = _PySuper_Lookup((PyTypeObject *)class, self, name, NULL);
DECREF_INPUTS();
ERROR_IF(attr == NULL, error);
ERROR_IF(attr == NULL);
attr_st = PyStackRef_FromPyObjectSteal(attr);
}
@ -2236,7 +2236,7 @@ dummy_func(
meth | NULL | arg1 | ... | argN
*/
PyStackRef_CLOSE(owner);
ERROR_IF(attr_o == NULL, error);
ERROR_IF(attr_o == NULL);
self_or_null[0] = PyStackRef_NULL;
}
}
@ -2244,7 +2244,7 @@ dummy_func(
/* Classic, pushes one value. */
attr_o = PyObject_GetAttr(PyStackRef_AsPyObjectBorrow(owner), name);
PyStackRef_CLOSE(owner);
ERROR_IF(attr_o == NULL, error);
ERROR_IF(attr_o == NULL);
}
attr = PyStackRef_FromPyObjectSteal(attr_o);
}
@ -2608,11 +2608,11 @@ dummy_func(
assert((oparg >> 5) <= Py_GE);
PyObject *res_o = PyObject_RichCompare(left_o, right_o, oparg >> 5);
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
if (oparg & 16) {
int res_bool = PyObject_IsTrue(res_o);
Py_DECREF(res_o);
ERROR_IF(res_bool < 0, error);
ERROR_IF(res_bool < 0);
res = res_bool ? PyStackRef_True : PyStackRef_False;
}
else {
@ -2706,7 +2706,7 @@ dummy_func(
int res = PySequence_Contains(right_o, left_o);
DECREF_INPUTS();
ERROR_IF(res < 0, error);
ERROR_IF(res < 0);
b = (res ^ oparg) ? PyStackRef_True : PyStackRef_False;
}
@ -2740,7 +2740,7 @@ dummy_func(
// Note: both set and frozenset use the same seq_contains method!
int res = _PySet_Contains((PySetObject *)right_o, left_o);
DECREF_INPUTS();
ERROR_IF(res < 0, error);
ERROR_IF(res < 0);
b = (res ^ oparg) ? PyStackRef_True : PyStackRef_False;
}
@ -2754,7 +2754,7 @@ dummy_func(
STAT_INC(CONTAINS_OP, hit);
int res = PyDict_Contains(right_o, left_o);
DECREF_INPUTS();
ERROR_IF(res < 0, error);
ERROR_IF(res < 0);
b = (res ^ oparg) ? PyStackRef_True : PyStackRef_False;
}
@ -2764,7 +2764,7 @@ dummy_func(
int err = _PyEval_CheckExceptStarTypeValid(tstate, match_type);
if (err < 0) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *match_o = NULL;
@ -2772,10 +2772,10 @@ dummy_func(
int res = _PyEval_ExceptionGroupMatch(frame, exc_value, match_type,
&match_o, &rest_o);
DECREF_INPUTS();
ERROR_IF(res < 0, error);
ERROR_IF(res < 0);
assert((match_o == NULL) == (rest_o == NULL));
ERROR_IF(match_o == NULL, error);
ERROR_IF(match_o == NULL);
if (!Py_IsNone(match_o)) {
PyErr_SetHandledException(match_o);
@ -2805,14 +2805,14 @@ dummy_func(
PyStackRef_AsPyObjectBorrow(fromlist),
PyStackRef_AsPyObjectBorrow(level));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
inst(IMPORT_FROM, (from -- from, res)) {
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
PyObject *res_o = _PyEval_ImportFrom(tstate, PyStackRef_AsPyObjectBorrow(from), name);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -2850,7 +2850,7 @@ dummy_func(
int optimized = _PyOptimizer_Optimize(frame, start, &executor, 0);
if (optimized <= 0) {
this_instr[1].counter = restart_backoff_counter(counter);
ERROR_IF(optimized < 0, error);
ERROR_IF(optimized < 0);
}
else {
this_instr[1].counter = initial_jump_backoff_counter();
@ -2976,9 +2976,9 @@ dummy_func(
inst(GET_LEN, (obj -- obj, len)) {
// PUSH(len(TOS))
Py_ssize_t len_i = PyObject_Length(PyStackRef_AsPyObjectBorrow(obj));
ERROR_IF(len_i < 0, error);
ERROR_IF(len_i < 0);
PyObject *len_o = PyLong_FromSsize_t(len_i);
ERROR_IF(len_o == NULL, error);
ERROR_IF(len_o == NULL);
len = PyStackRef_FromPyObjectSteal(len_o);
}
@ -2996,7 +2996,7 @@ dummy_func(
attrs = PyStackRef_FromPyObjectSteal(attrs_o);
}
else {
ERROR_IF(_PyErr_Occurred(tstate), error); // Error!
ERROR_IF(_PyErr_Occurred(tstate)); // Error!
attrs = PyStackRef_None; // Failure!
}
}
@ -3015,7 +3015,7 @@ dummy_func(
// On successful match, PUSH(values). Otherwise, PUSH(None).
PyObject *values_or_none_o = _PyEval_MatchKeys(tstate,
PyStackRef_AsPyObjectBorrow(subject), PyStackRef_AsPyObjectBorrow(keys));
ERROR_IF(values_or_none_o == NULL, error);
ERROR_IF(values_or_none_o == NULL);
values_or_none = PyStackRef_FromPyObjectSteal(values_or_none_o);
}
@ -3026,7 +3026,7 @@ dummy_func(
/* before: [obj]; after [getiter(obj)] */
PyObject *iter_o = PyObject_GetIter(PyStackRef_AsPyObjectBorrow(iterable));
PyStackRef_CLOSE(iterable);
ERROR_IF(iter_o == NULL, error);
ERROR_IF(iter_o == NULL);
iter = PyStackRef_FromPyObjectSteal(iter_o);
}
@ -3377,7 +3377,7 @@ dummy_func(
r->start = value + r->step;
r->len--;
PyObject *res = PyLong_FromLong(value);
ERROR_IF(res == NULL, error);
ERROR_IF(res == NULL);
next = PyStackRef_FromPyObjectSteal(res);
}
@ -3470,7 +3470,7 @@ dummy_func(
PyObject *res_o = PyObject_Vectorcall(exit_func_o, stack + 2 - has_self,
(3 + has_self) | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
Py_XDECREF(original_tb);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -3704,7 +3704,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *res_o = PyObject_Vectorcall(
callable_o, args_o,
@ -3730,7 +3730,7 @@ dummy_func(
}
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -3752,7 +3752,7 @@ dummy_func(
tstate, PY_MONITORING_EVENT_CALL,
frame, this_instr, function, arg0
);
ERROR_IF(err, error);
ERROR_IF(err);
}
macro(CALL) = _SPECIALIZE_CALL + unused/2 + _MAYBE_EXPAND_METHOD + _DO_CALL + _CHECK_PERIODIC;
@ -3857,7 +3857,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *res_o = PyObject_Vectorcall(
callable_o, args_o,
@ -3866,7 +3866,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4009,7 +4009,7 @@ dummy_func(
(void)callable; // Silence compiler warnings about unused variables
(void)null;
PyStackRef_CLOSE(arg);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4037,7 +4037,7 @@ dummy_func(
(void)callable; // Silence compiler warnings about unused variables
(void)null;
PyStackRef_CLOSE(arg);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4130,12 +4130,12 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *res_o = tp->tp_vectorcall((PyObject *)tp, args_o, total_args, NULL);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4170,7 +4170,7 @@ dummy_func(
DEAD(args);
DEAD(self_or_null);
PyStackRef_CLOSE(callable);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4198,7 +4198,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *res_o = _PyCFunctionFast_CAST(cfunc)(
PyCFunction_GET_SELF(callable_o),
@ -4207,7 +4207,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4237,13 +4237,13 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *res_o = cfunc(PyCFunction_GET_SELF(callable_o), args_o, total_args, NULL);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4325,7 +4325,7 @@ dummy_func(
UNLOCK_OBJECT(self_o);
PyStackRef_CLOSE(self);
PyStackRef_CLOSE(callable);
ERROR_IF(err, error);
ERROR_IF(err);
#if TIER_ONE
// Skip the following POP_TOP. This is done here in tier one, and
// during trace projection in tier two:
@ -4363,7 +4363,7 @@ dummy_func(
_Py_LeaveRecursiveCallTstate(tstate);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4397,7 +4397,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyCFunctionFastWithKeywords cfunc =
_PyCFunctionFastWithKeywords_CAST(meth->ml_meth);
@ -4405,7 +4405,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4443,7 +4443,7 @@ dummy_func(
DEAD(args);
DEAD(self_or_null);
PyStackRef_CLOSE(callable);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4477,14 +4477,14 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyCFunctionFast cfunc = _PyCFunctionFast_CAST(meth->ml_meth);
PyObject *res_o = cfunc(self, (args_o + 1), nargs);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4517,7 +4517,7 @@ dummy_func(
int err = _Py_call_instrumentation_2args(
tstate, PY_MONITORING_EVENT_CALL,
frame, this_instr, function, arg);
ERROR_IF(err, error);
ERROR_IF(err);
}
op(_MAYBE_EXPAND_METHOD_KW, (callable, self_or_null, unused[oparg], unused -- callable, self_or_null, unused[oparg], unused)) {
@ -4574,7 +4574,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *res_o = PyObject_Vectorcall(
callable_o, args_o,
@ -4599,7 +4599,7 @@ dummy_func(
}
}
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4629,7 +4629,7 @@ dummy_func(
DEAD(self_or_null);
DEAD(callable);
SYNC_SP();
ERROR_IF(temp == NULL, error);
ERROR_IF(temp == NULL);
new_frame = temp;
}
@ -4727,7 +4727,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames);
int positional_args = total_args - (int)PyTuple_GET_SIZE(kwnames_o);
@ -4739,7 +4739,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4842,7 +4842,7 @@ dummy_func(
PyStackRef_CLOSE(callargs_st);
DEAD(null);
PyStackRef_CLOSE(func_st);
ERROR_IF(result_o == NULL, error);
ERROR_IF(result_o == NULL);
result = PyStackRef_FromPyObjectSteal(result_o);
}
@ -4863,7 +4863,7 @@ dummy_func(
PyFunction_New(codeobj, GLOBALS());
PyStackRef_CLOSE(codeobj_st);
ERROR_IF(func_obj == NULL, error);
ERROR_IF(func_obj == NULL);
_PyFunction_SetVersion(
func_obj, ((PyCodeObject *)codeobj)->co_version);
@ -4887,7 +4887,7 @@ dummy_func(
assert(PyStackRef_FunctionCheck(frame->f_funcobj));
PyFunctionObject *func = (PyFunctionObject *)PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(func);
ERROR_IF(gen == NULL, error);
ERROR_IF(gen == NULL);
assert(STACK_LEVEL() == 0);
SAVE_STACK();
_PyInterpreterFrame *gen_frame = &gen->gi_iframe;
@ -4912,7 +4912,7 @@ dummy_func(
PyObject *step_o = oparg == 3 ? PyStackRef_AsPyObjectBorrow(args[2]) : NULL;
PyObject *slice_o = PySlice_New(start_o, stop_o, step_o);
DECREF_INPUTS();
ERROR_IF(slice_o == NULL, error);
ERROR_IF(slice_o == NULL);
slice = PyStackRef_FromPyObjectStealMortal(slice_o);
}
@ -4922,7 +4922,7 @@ dummy_func(
conv_fn = _PyEval_ConversionFuncs[oparg];
PyObject *result_o = conv_fn(PyStackRef_AsPyObjectBorrow(value));
PyStackRef_CLOSE(value);
ERROR_IF(result_o == NULL, error);
ERROR_IF(result_o == NULL);
result = PyStackRef_FromPyObjectSteal(result_o);
}
@ -4933,7 +4933,7 @@ dummy_func(
if (!PyUnicode_CheckExact(value_o)) {
PyObject *res_o = PyObject_Format(value_o, NULL);
PyStackRef_CLOSE(value);
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
else {
@ -4945,7 +4945,7 @@ dummy_func(
inst(FORMAT_WITH_SPEC, (value, fmt_spec -- res)) {
PyObject *res_o = PyObject_Format(PyStackRef_AsPyObjectBorrow(value), PyStackRef_AsPyObjectBorrow(fmt_spec));
DECREF_INPUTS();
ERROR_IF(res_o == NULL, error);
ERROR_IF(res_o == NULL);
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -5024,7 +5024,7 @@ dummy_func(
inst(INSTRUMENTED_INSTRUCTION, ( -- )) {
int next_opcode = _Py_call_instrumentation_instruction(
tstate, frame, this_instr);
ERROR_IF(next_opcode < 0, error);
ERROR_IF(next_opcode < 0);
next_instr = this_instr;
if (_PyOpcode_Caches[next_opcode]) {
PAUSE_ADAPTIVE_COUNTER(next_instr[1].counter);

View File

@ -28,7 +28,6 @@ static PyObject *
print_expr(PyThreadState* Py_UNUSED(ignored), PyObject *value)
{
PyObject *hook = _PySys_GetRequiredAttr(&_Py_ID(displayhook));
// Can't use ERROR_IF here.
if (hook == NULL) {
return NULL;
}

View File

@ -543,7 +543,6 @@ def tier_variable(node: parser.CodeDef) -> int | None:
def has_error_with_pop(op: parser.CodeDef) -> bool:
return (
variable_used(op, "ERROR_IF")
or variable_used(op, "pop_1_error")
or variable_used(op, "exception_unwind")
)
@ -551,7 +550,6 @@ def has_error_with_pop(op: parser.CodeDef) -> bool:
def has_error_without_pop(op: parser.CodeDef) -> bool:
return (
variable_used(op, "ERROR_NO_POP")
or variable_used(op, "pop_1_error")
or variable_used(op, "exception_unwind")
)

View File

@ -170,12 +170,12 @@ def deopt_if(
exit_if = deopt_if
def goto_error(self, offset: int, label: str, storage: Storage) -> str:
def goto_error(self, offset: int, storage: Storage) -> str:
if offset > 0:
return f"JUMP_TO_LABEL(pop_{offset}_{label});"
return f"JUMP_TO_LABEL(pop_{offset}_error);"
if offset < 0:
storage.copy().flush(self.out)
return f"JUMP_TO_LABEL({label});"
return f"JUMP_TO_LABEL(error);"
def error_if(
self,
@ -191,17 +191,13 @@ def error_if(
unconditional = always_true(first_tkn)
if unconditional:
next(tkn_iter)
comma = next(tkn_iter)
if comma.kind != "COMMA":
raise analysis_error(f"Expected comma, got '{comma.text}'", comma)
next(tkn_iter) # RPAREN
self.out.start_line()
else:
self.out.emit_at("if ", tkn)
self.emit(lparen)
emit_to(self.out, tkn_iter, "COMMA")
emit_to(self.out, tkn_iter, "RPAREN")
self.out.emit(") {\n")
label = next(tkn_iter).text
next(tkn_iter) # RPAREN
next(tkn_iter) # Semi colon
storage.clear_inputs("at ERROR_IF")
@ -210,7 +206,7 @@ def error_if(
offset = int(c_offset)
except ValueError:
offset = -1
self.out.emit(self.goto_error(offset, label, storage))
self.out.emit(self.goto_error(offset, storage))
self.out.emit("\n")
if not unconditional:
self.out.emit("}\n")
@ -227,7 +223,7 @@ def error_no_pop(
next(tkn_iter) # LPAREN
next(tkn_iter) # RPAREN
next(tkn_iter) # Semi colon
self.out.emit_at(self.goto_error(0, "error", storage), tkn)
self.out.emit_at(self.goto_error(0, storage), tkn)
return False
def decref_inputs(

View File

@ -184,7 +184,7 @@ ### Special functions/macros
Those include:
* `DEOPT_IF(cond, instruction)`. Deoptimize if `cond` is met.
* `ERROR_IF(cond, label)`. Jump to error handler at `label` if `cond` is true.
* `ERROR_IF(cond)`. Jump to error handler if `cond` is true.
* `DECREF_INPUTS()`. Generate `Py_DECREF()` calls for the input stack effects.
* `SYNC_SP()`. Synchronizes the physical stack pointer with the stack effects.
* `INSTRUCTION_SIZE`. Replaced with the size of the instruction which is equal
@ -209,7 +209,7 @@ ### Special functions/macros
2. Before the first `ERROR_IF`, all input values must be `DECREF`ed,
and no objects may be allocated or `INCREF`ed, with the exception
of attempting to create an object and checking for success using
`ERROR_IF(result == NULL, label)`. (TODO: Unclear what to do with
`ERROR_IF(result == NULL)`. (TODO: Unclear what to do with
intermediate results.)
3. No `DEOPT_IF` may follow an `ERROR_IF` in the same block.
@ -221,14 +221,14 @@ ### Special functions/macros
- Use `goto error`.
- Use a block containing the appropriate `DECREF` calls ending in
`ERROR_IF(true, error)`.
`ERROR_IF(true)`.
An example of the latter would be:
```cc
res = PyObject_Add(left, right);
if (res == NULL) {
DECREF_INPUTS();
ERROR_IF(true, error);
ERROR_IF(true);
}
```
@ -346,7 +346,7 @@ ### More examples
```C
inst ( BUILD_TUPLE, (items[oparg] -- tuple) ) {
tuple = _PyTuple_FromArraySteal(items, oparg);
ERROR_IF(tuple == NULL, error);
ERROR_IF(tuple == NULL);
}
```
```C

View File

@ -64,7 +64,7 @@ def __init__(self, out: CWriter, labels: dict[str, Label]):
super().__init__(out, labels)
self._replacers["oparg"] = self.oparg
def goto_error(self, offset: int, label: str, storage: Storage) -> str:
def goto_error(self, offset: int, storage: Storage) -> str:
# To do: Add jump targets for popping values.
if offset != 0:
storage.copy().flush(self.out)