Skip to content

Commit 2fa0a04

Browse files
committed
Convert WITH_EXCEPT_START, fix generator to make it work
1 parent babdbf9 commit 2fa0a04

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,8 +2724,7 @@ dummy_func(
27242724
PUSH(res);
27252725
}
27262726

2727-
// stack effect: ( -- __0)
2728-
inst(WITH_EXCEPT_START) {
2727+
inst(WITH_EXCEPT_START, (exit_func, lasti, unused, val -- exit_func, lasti, unused, val, res)) {
27292728
/* At the top of the stack are 4 values:
27302729
- TOP = exc_info()
27312730
- SECOND = previous exception
@@ -2734,23 +2733,17 @@ dummy_func(
27342733
We call FOURTH(type(TOP), TOP, GetTraceback(TOP)).
27352734
Then we push the __exit__ return value.
27362735
*/
2737-
PyObject *exit_func;
2738-
PyObject *exc, *val, *tb, *res;
2736+
PyObject *exc, *tb;
27392737

2740-
val = TOP();
27412738
assert(val && PyExceptionInstance_Check(val));
27422739
exc = PyExceptionInstance_Class(val);
27432740
tb = PyException_GetTraceback(val);
27442741
Py_XDECREF(tb);
2745-
assert(PyLong_Check(PEEK(3)));
2746-
exit_func = PEEK(4);
2742+
assert(PyLong_Check(lasti));
27472743
PyObject *stack[4] = {NULL, exc, val, tb};
27482744
res = PyObject_Vectorcall(exit_func, stack + 1,
27492745
3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
2750-
if (res == NULL)
2751-
goto error;
2752-
2753-
PUSH(res);
2746+
ERROR_IF(res == NULL, error);
27542747
}
27552748

27562749
// stack effect: ( -- __0)

Python/generated_cases.c.h

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/generate_cases.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
8282
assert cache_offset == self.cache_offset
8383

8484
# Write input stack effect variable declarations and initializations
85+
input_names = [seffect.name for seffect in self.input_effects]
8586
for i, seffect in enumerate(reversed(self.input_effects), 1):
8687
if seffect.name != "unused":
8788
f.write(f"{indent} PyObject *{seffect.name} = PEEK({i});\n")
8889

8990
# Write output stack effect variable declarations
9091
for seffect in self.output_effects:
91-
if seffect.name != "unused":
92+
if seffect.name not in input_names and seffect.name != "unused":
9293
f.write(f"{indent} PyObject *{seffect.name};\n")
9394

9495
self.write_body(f, indent, dedent)
@@ -105,8 +106,8 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
105106
f.write(f"{indent} STACK_SHRINK({-diff});\n")
106107

107108
# Write output stack effect assignments
108-
input_names = [seffect.name for seffect in self.input_effects]
109109
for i, output in enumerate(reversed(self.output_effects), 1):
110+
# TODO: Only skip if output occurs at same position as input
110111
if output.name not in input_names and output.name != "unused":
111112
f.write(f"{indent} POKE({i}, {output.name});\n")
112113

0 commit comments

Comments
 (0)