Skip to content

bpo-45711: Do not push/pop traceback on stack as part of exc_info #29968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 16 additions & 9 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,15 @@ the original TOS1.
.. opcode:: END_ASYNC_FOR

Terminates an :keyword:`async for` loop. Handles an exception raised
when awaiting a next item. If TOS is :exc:`StopAsyncIteration` pop 7
when awaiting a next item. If TOS is :exc:`StopAsyncIteration` pop 5
values from the stack and restore the exception state using the second
three of them. Otherwise re-raise the exception using the three values
two of them. Otherwise re-raise the exception using the two values
from the stack. An exception handler block is removed from the block stack.

.. versionadded:: 3.8

.. versionchanged:: 3.11
Exception representation on the stack now consist of two, not three, items.

.. opcode:: BEFORE_ASYNC_WITH

Expand Down Expand Up @@ -561,8 +563,10 @@ iterations of the loop.

.. opcode:: POP_EXCEPT

Pops three values from the stack, which are used to restore the exception state.
Pops two values from the stack, which are used to restore the exception state.

.. versionchanged:: 3.11
Exception representation on the stack now consist of two, not three, items.

.. opcode:: RERAISE

Expand All @@ -572,27 +576,30 @@ iterations of the loop.

.. versionadded:: 3.9

.. versionchanged:: 3.11
Exception representation on the stack now consist of two, not three, items.

.. opcode:: PUSH_EXC_INFO

Pops the three values from the stack. Pushes the current exception to the top of the stack.
Pushes the three values originally popped back to the stack.
Pops two values from the stack. Pushes the current exception to the top of the stack.
Pushes the two values originally popped back to the stack.
Used in exception handlers.

.. versionadded:: 3.11


.. opcode:: WITH_EXCEPT_START

Calls the function in position 8 on the stack with the top three
items on the stack as arguments.
Calls the function in position 6 on the stack with the top two
items on the stack, as well as a traceback derived from the second item,
as arguments.
Used to implement the call ``context_manager.__exit__(*exc_info())`` when an exception
has occurred in a :keyword:`with` statement.

.. versionadded:: 3.9
.. versionchanged:: 3.11
The ``__exit__`` function is in position 8 of the stack rather than 7.

The ``__exit__`` function is in position 6 of the stack rather than 7.
Exception representation on the stack now consist of two, not three, items.

.. opcode:: POP_EXCEPT_AND_RERAISE

Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(

#define _Py_FatalRefcountError(message) _Py_FatalRefcountErrorFunc(__func__, message)


/* number of items stored in the stack for each exception */
#define PY_EXC_INFO_STACK_SIZE 2

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.11a3 3464 (bpo-45636: Merge numeric BINARY_*/INPLACE_* into
# BINARY_OP)
# Python 3.11a3 3465 (Add COPY_FREE_VARS opcode)
# Python 3.11a3 3466 (bpo-45711: exc_info on the stack does not include traceback)

#
# MAGIC must change whenever the bytecode emitted by the compiler may no
Expand All @@ -380,7 +381,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 = (3465).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3466).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
Loading