Skip to content

Commit 04e07c2

Browse files
authored
bpo-47186: Replace JUMP_IF_NOT_EXC_MATCH by CHECK_EXC_MATCH + jump (GH-32231)
1 parent ae9de82 commit 04e07c2

File tree

11 files changed

+107
-111
lines changed

11 files changed

+107
-111
lines changed

Doc/library/dis.rst

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,12 @@ iterations of the loop.
628628

629629
.. versionadded:: 3.11
630630

631+
.. opcode:: CHECK_EXC_MATCH
632+
633+
Performs exception matching for ``except``. Tests whether the TOS1 is an exception
634+
matching TOS. Pops TOS and pushes the boolean result of the test.
635+
636+
.. versionadded:: 3.11
631637

632638
.. opcode:: WITH_EXCEPT_START
633639

@@ -916,18 +922,6 @@ iterations of the loop.
916922
.. versionadded:: 3.1
917923

918924

919-
.. opcode:: JUMP_IF_NOT_EXC_MATCH (target)
920-
921-
Performs exception matching for ``except``.
922-
Tests whether the second value on the stack is an exception matching TOS,
923-
and jumps if it is not. Pops one value from the stack.
924-
925-
.. versionadded:: 3.9
926-
927-
.. versionchanged:: 3.11
928-
This opcode no longer pops the active exception.
929-
930-
931925
.. opcode:: JUMP_IF_NOT_EG_MATCH (target)
932926

933927
Performs exception matching for ``except*``. Applies ``split(TOS)`` on

Doc/whatsnew/3.11.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ CPython bytecode changes
520520
* Add :opcode:`POP_JUMP_IF_NOT_NONE` and :opcode:`POP_JUMP_IF_NONE` opcodes to
521521
speed up conditional jumps.
522522

523-
* :opcode:`JUMP_IF_NOT_EXC_MATCH` no longer pops the active exception.
523+
* Replaced :opcode:`JUMP_IF_NOT_EXC_MATCH` by :opcode:`CHECK_EXC_MATCH` which
524+
performs the check but does not jump.
524525

525526
* Replaced :opcode:`JUMP_ABSOLUTE` by the relative :opcode:`JUMP_BACKWARD`.
526527

Include/opcode.h

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

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ def _write_atomic(path, data, mode=0o666):
397397
# Python 3.11a6 3487 (Remove the adaptive "oparg counter" mechanism)
398398
# Python 3.11a6 3488 (LOAD_GLOBAL can push additional NULL)
399399
# Python 3.11a6 3489 (Add JUMP_BACKWARD, remove JUMP_ABSOLUTE)
400+
# Python 3.11a6 3490 (remove JUMP_IF_NOT_EXC_MATCH, add CHECK_EXC_MATCH)
400401

401402
# Python 3.12 will start with magic number 3500
402403

@@ -411,7 +412,7 @@ def _write_atomic(path, data, mode=0o666):
411412
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
412413
# in PC/launcher.c must also be updated.
413414

414-
MAGIC_NUMBER = (3489).to_bytes(2, 'little') + b'\r\n'
415+
MAGIC_NUMBER = (3490).to_bytes(2, 'little') + b'\r\n'
415416
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
416417

417418
_PYCACHE = '__pycache__'

Lib/opcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def jabs_op(name, op, entries=0):
7676
def_op('MATCH_KEYS', 33)
7777

7878
def_op('PUSH_EXC_INFO', 35)
79+
def_op('CHECK_EXC_MATCH', 36)
7980

8081
def_op('WITH_EXCEPT_START', 49)
8182
def_op('GET_AITER', 50)
@@ -138,7 +139,6 @@ def jabs_op(name, op, entries=0):
138139
def_op('CONTAINS_OP', 118)
139140
def_op('RERAISE', 119)
140141
def_op('COPY', 120)
141-
jabs_op('JUMP_IF_NOT_EXC_MATCH', 121)
142142
def_op('BINARY_OP', 122, 1)
143143
jrel_op('SEND', 123) # Number of bytes to skip
144144
def_op('LOAD_FAST', 124) # Local variable number

0 commit comments

Comments
 (0)