Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 65 additions & 5 deletions Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_effect_sizes(self):
stack.pop(y)
stack.pop(x)
for out in outputs:
stack.push(Local.local(out))
stack.push(Local.undefined(out))
self.assertEqual(stack.base_offset.to_c(), "-1 - oparg - oparg*2")
self.assertEqual(stack.top_offset.to_c(), "1 - oparg - oparg*2 + oparg*4")

Expand Down Expand Up @@ -281,6 +281,67 @@ def test_predictions(self):
"""
self.run_cases_test(input, output)

def test_sync_sp(self):
input = """
inst(A, (arg -- res)) {
SYNC_SP();
escaping_call();
res = Py_None;
}
inst(B, (arg -- res)) {
res = Py_None;
SYNC_SP();
escaping_call();
}
"""
output = """
TARGET(A) {
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(A);
_PyStackRef res;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
escaping_call();
res = Py_None;
stack_pointer[0] = res;
stack_pointer += 1;
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
}

TARGET(B) {
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(B);
_PyStackRef res;
res = Py_None;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
escaping_call();
stack_pointer[0] = res;
stack_pointer += 1;
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
}
"""
self.run_cases_test(input, output)


def test_pep7_condition(self):
input = """
inst(OP, (arg1 -- out)) {
if (arg1)
out = 0;
else {
out = 1;
}
}
"""
output = ""
with self.assertRaises(SyntaxError):
self.run_cases_test(input, output)

def test_error_if_plain(self):
input = """
inst(OP, (--)) {
Expand Down Expand Up @@ -810,7 +871,7 @@ def test_deopt_and_exit(self):
}
"""
output = ""
with self.assertRaises(Exception):
with self.assertRaises(SyntaxError):
self.run_cases_test(input, output)

def test_array_of_one(self):
Expand Down Expand Up @@ -1000,8 +1061,6 @@ def test_flush(self):
stack_pointer += 2;
assert(WITHIN_STACK_BOUNDS());
// SECOND
b = stack_pointer[-1];
a = stack_pointer[-2];
{
use(a, b);
}
Expand Down Expand Up @@ -1096,7 +1155,8 @@ def test_push_then_error(self):
b = 1;
if (cond) {
stack_pointer[0] = a;
stack_pointer += 1;
stack_pointer[1] = b;
stack_pointer += 2;
assert(WITHIN_STACK_BOUNDS());
goto error;
}
Expand Down
24 changes: 17 additions & 7 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,9 @@ dummy_func(
int err = _Py_call_instrumentation_arg(
tstate, PY_MONITORING_EVENT_PY_RETURN,
frame, this_instr, PyStackRef_AsPyObjectBorrow(val));
if (err) ERROR_NO_POP();
if (err) {
ERROR_NO_POP();
}
}

macro(INSTRUMENTED_RETURN_VALUE) =
Expand Down Expand Up @@ -1168,7 +1170,9 @@ dummy_func(
tstate, PY_MONITORING_EVENT_PY_YIELD,
frame, this_instr, PyStackRef_AsPyObjectBorrow(val));
LOAD_SP();
if (err) ERROR_NO_POP();
if (err) {
ERROR_NO_POP();
}
if (frame->instr_ptr != this_instr) {
next_instr = frame->instr_ptr;
DISPATCH();
Expand Down Expand Up @@ -1276,10 +1280,12 @@ dummy_func(
DECREF_INPUTS();
ERROR_IF(true, error);
}
if (PyDict_CheckExact(ns))
if (PyDict_CheckExact(ns)) {
err = PyDict_SetItem(ns, name, PyStackRef_AsPyObjectBorrow(v));
else
}
else {
err = PyObject_SetItem(ns, name, PyStackRef_AsPyObjectBorrow(v));
}
DECREF_INPUTS();
ERROR_IF(err, error);
}
Expand Down Expand Up @@ -1993,6 +1999,8 @@ dummy_func(
attr_o = PyObject_GetAttr(PyStackRef_AsPyObjectBorrow(owner), name);
DECREF_INPUTS();
ERROR_IF(attr_o == NULL, error);
/* We need to define self_or_null on all paths */
self_or_null = PyStackRef_NULL;
}
attr = PyStackRef_FromPyObjectSteal(attr_o);
}
Expand Down Expand Up @@ -3206,10 +3214,10 @@ dummy_func(
op(_MAYBE_EXPAND_METHOD, (callable, self_or_null, args[oparg] -- func, maybe_self, args[oparg])) {
if (PyStackRef_TYPE(callable) == &PyMethod_Type && PyStackRef_IsNull(self_or_null)) {
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
PyObject *self = ((PyMethodObject *)callable_o)->im_self;
maybe_self = PyStackRef_FromPyObjectNew(self);
PyObject *method = ((PyMethodObject *)callable_o)->im_func;
func = PyStackRef_FromPyObjectNew(method);
PyObject *self = ((PyMethodObject *)callable_o)->im_self;
maybe_self = PyStackRef_FromPyObjectNew(self);
/* Make sure that callable and all args are in memory */
args[-2] = func;
args[-1] = maybe_self;
Expand Down Expand Up @@ -4297,7 +4305,9 @@ dummy_func(
int err = _Py_call_instrumentation_2args(
tstate, PY_MONITORING_EVENT_CALL,
frame, this_instr, func, arg);
if (err) ERROR_NO_POP();
if (err) {
ERROR_NO_POP();
}
result = PyStackRef_FromPyObjectSteal(PyObject_Call(func, callargs, kwargs));

if (!PyFunction_Check(func) && !PyMethod_Check(func)) {
Expand Down
Loading
Loading