Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Leave receiver on stack when exiting SEND loop.
  • Loading branch information
markshannon committed Feb 10, 2023
commit f2dbcf9528e83ef322083ed03b01b95ec75b1fa9
3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.12a5 3516 (Add COMPARE_AND_BRANCH instruction)
# Python 3.12a5 3517 (Change YIELD_VALUE oparg to exception block depth)
# Python 3.12a5 3518 (Add RETURN_CONST instruction)
# Python 3.12a5 3519 (Modify SEND instruction)

# Python 3.13 will start with 3550

Expand All @@ -444,7 +445,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3518).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3519).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

Expand Down
21 changes: 13 additions & 8 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ async def _asyncwith(c):
YIELD_VALUE 2
RESUME 3
JUMP_BACKWARD_NO_INTERRUPT 4 (to 14)
>> POP_TOP
>> SWAP 2
POP_TOP
POP_TOP

%3d LOAD_CONST 1 (1)
STORE_FAST 1 (x)
Expand All @@ -490,30 +492,33 @@ async def _asyncwith(c):
CALL 2
GET_AWAITABLE 2
LOAD_CONST 0 (None)
>> SEND 3 (to 56)
>> SEND 3 (to 60)
YIELD_VALUE 2
RESUME 3
JUMP_BACKWARD_NO_INTERRUPT 4 (to 48)
JUMP_BACKWARD_NO_INTERRUPT 4 (to 52)
>> POP_TOP
POP_TOP

%3d LOAD_CONST 2 (2)
STORE_FAST 2 (y)
RETURN_CONST 0 (None)

%3d >> CLEANUP_THROW
JUMP_BACKWARD 23 (to 22)
JUMP_BACKWARD 26 (to 22)
>> CLEANUP_THROW
JUMP_BACKWARD 8 (to 56)
JUMP_BACKWARD 9 (to 60)
>> PUSH_EXC_INFO
WITH_EXCEPT_START
GET_AWAITABLE 2
LOAD_CONST 0 (None)
>> SEND 4 (to 90)
>> SEND 4 (to 96)
YIELD_VALUE 3
RESUME 3
JUMP_BACKWARD_NO_INTERRUPT 4 (to 80)
JUMP_BACKWARD_NO_INTERRUPT 4 (to 86)
>> CLEANUP_THROW
>> POP_JUMP_IF_TRUE 1 (to 94)
>> SWAP 2
POP_TOP
POP_JUMP_IF_TRUE 1 (to 104)
RERAISE 2
>> POP_TOP
POP_EXCEPT
Expand Down
4 changes: 2 additions & 2 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ mark_stacks(PyCodeObject *code_obj, int len)
case SEND:
j = get_arg(code, i) + i + 1;
assert(j < len);
assert(stacks[j] == UNINITIALIZED || stacks[j] == pop_value(next_stack));
stacks[j] = pop_value(next_stack);
assert(stacks[j] == UNINITIALIZED || stacks[j] == next_stack);
stacks[j] = next_stack;
stacks[i+1] = next_stack;
break;
case JUMP_FORWARD:
Expand Down
8 changes: 3 additions & 5 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,8 @@ dummy_func(
PREDICT(LOAD_CONST);
}

inst(SEND, (receiver, v -- receiver if (!jump), retval)) {
inst(SEND, (receiver, v -- receiver, retval)) {
assert(frame != &entry_frame);
bool jump = false;
PySendResult gen_status;
if (tstate->c_tracefunc == NULL) {
gen_status = PyIter_Send(receiver, v, &retval);
Expand Down Expand Up @@ -715,9 +714,7 @@ dummy_func(
Py_DECREF(v);
if (gen_status == PYGEN_RETURN) {
assert(retval != NULL);
Py_DECREF(receiver);
JUMPBY(oparg);
jump = true;
}
else {
assert(gen_status == PYGEN_NEXT);
Expand Down Expand Up @@ -796,12 +793,13 @@ dummy_func(
}
}

inst(CLEANUP_THROW, (sub_iter, last_sent_val, exc_value -- value)) {
inst(CLEANUP_THROW, (sub_iter, last_sent_val, exc_value -- none, value)) {
assert(throwflag);
assert(exc_value && PyExceptionInstance_Check(exc_value));
if (PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration)) {
value = Py_NewRef(((PyStopIterationObject *)exc_value)->value);
DECREF_INPUTS();
none = Py_NewRef(Py_None);
}
else {
_PyErr_SetRaisedException(tstate, Py_NewRef(exc_value));
Expand Down
2 changes: 2 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,8 @@ compiler_add_yield_from(struct compiler *c, location loc, int await)
ADDOP(c, loc, CLEANUP_THROW);

USE_LABEL(c, exit);
ADDOP_I(c, loc, SWAP, 2);
ADDOP(c, loc, POP_TOP);
return SUCCESS;
}

Expand Down
10 changes: 4 additions & 6 deletions Python/generated_cases.c.h

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

4 changes: 2 additions & 2 deletions Python/opcode_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
case GET_AWAITABLE:
return 1;
case SEND:
return ((!jump) ? 1 : 0) + 1;
return 2;
case YIELD_VALUE:
return 1;
case POP_EXCEPT:
Expand All @@ -465,7 +465,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
case END_ASYNC_FOR:
return 0;
case CLEANUP_THROW:
return 1;
return 2;
case LOAD_ASSERTION_ERROR:
return 1;
case LOAD_BUILD_CLASS:
Expand Down