From f703c96cf08a0d65e718e7acfb043cbc49812a22 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 26 Apr 2022 21:07:25 +0300 Subject: gh-91870: Remove unsupported SRE opcode CALL (GH-91872) It was initially added to support atomic groups, but that support was never fully implemented, and CALL was only left in the compiler, but not interpreter and parser. ATOMIC_GROUP is now used to support atomic groups. --- Lib/re/_compiler.py | 6 ---- Lib/re/_constants.py | 3 +- Lib/re/_parser.py | 4 --- Modules/_sre/sre_constants.h | 73 ++++++++++++++++++++++---------------------- Modules/_sre/sre_lib.h | 1 - Modules/_sre/sre_targets.h | 3 +- 6 files changed, 38 insertions(+), 52 deletions(-) diff --git a/Lib/re/_compiler.py b/Lib/re/_compiler.py index f621d04..63d8202 100644 --- a/Lib/re/_compiler.py +++ b/Lib/re/_compiler.py @@ -164,12 +164,6 @@ def _compile(data, pattern, flags): _compile(data, av[1], flags) emit(SUCCESS) code[skip] = _len(code) - skip - elif op is CALL: - emit(op) - skip = _len(code); emit(0) - _compile(data, av, flags) - emit(SUCCESS) - code[skip] = _len(code) - skip elif op is AT: emit(op) if flags & SRE_FLAG_MULTILINE: diff --git a/Lib/re/_constants.py b/Lib/re/_constants.py index aa1a590..c45ce40 100644 --- a/Lib/re/_constants.py +++ b/Lib/re/_constants.py @@ -13,7 +13,7 @@ # update when constants are added or removed -MAGIC = 20220402 +MAGIC = 20220423 from _sre import MAXREPEAT, MAXGROUPS @@ -78,7 +78,6 @@ OPCODES = _makecodes( 'ASSERT', 'ASSERT_NOT', 'AT', 'BRANCH', - 'CALL', 'CATEGORY', 'CHARSET', 'BIGCHARSET', 'GROUPREF', 'GROUPREF_EXISTS', diff --git a/Lib/re/_parser.py b/Lib/re/_parser.py index b864bf2..933d515 100644 --- a/Lib/re/_parser.py +++ b/Lib/re/_parser.py @@ -183,10 +183,6 @@ class SubPattern: j = max(j, h) lo = lo + i hi = hi + j - elif op is CALL: - i, j = av.getwidth() - lo = lo + i - hi = hi + j elif op is ATOMIC_GROUP: i, j = av.getwidth() lo = lo + i diff --git a/Modules/_sre/sre_constants.h b/Modules/_sre/sre_constants.h index b1ef27e..d5de650 100644 --- a/Modules/_sre/sre_constants.h +++ b/Modules/_sre/sre_constants.h @@ -11,7 +11,7 @@ * See the sre.c file for information on usage and redistribution. */ -#define SRE_MAGIC 20220402 +#define SRE_MAGIC 20220423 #define SRE_OP_FAILURE 0 #define SRE_OP_SUCCESS 1 #define SRE_OP_ANY 2 @@ -20,42 +20,41 @@ #define SRE_OP_ASSERT_NOT 5 #define SRE_OP_AT 6 #define SRE_OP_BRANCH 7 -#define SRE_OP_CALL 8 -#define SRE_OP_CATEGORY 9 -#define SRE_OP_CHARSET 10 -#define SRE_OP_BIGCHARSET 11 -#define SRE_OP_GROUPREF 12 -#define SRE_OP_GROUPREF_EXISTS 13 -#define SRE_OP_IN 14 -#define SRE_OP_INFO 15 -#define SRE_OP_JUMP 16 -#define SRE_OP_LITERAL 17 -#define SRE_OP_MARK 18 -#define SRE_OP_MAX_UNTIL 19 -#define SRE_OP_MIN_UNTIL 20 -#define SRE_OP_NOT_LITERAL 21 -#define SRE_OP_NEGATE 22 -#define SRE_OP_RANGE 23 -#define SRE_OP_REPEAT 24 -#define SRE_OP_REPEAT_ONE 25 -#define SRE_OP_SUBPATTERN 26 -#define SRE_OP_MIN_REPEAT_ONE 27 -#define SRE_OP_ATOMIC_GROUP 28 -#define SRE_OP_POSSESSIVE_REPEAT 29 -#define SRE_OP_POSSESSIVE_REPEAT_ONE 30 -#define SRE_OP_GROUPREF_IGNORE 31 -#define SRE_OP_IN_IGNORE 32 -#define SRE_OP_LITERAL_IGNORE 33 -#define SRE_OP_NOT_LITERAL_IGNORE 34 -#define SRE_OP_GROUPREF_LOC_IGNORE 35 -#define SRE_OP_IN_LOC_IGNORE 36 -#define SRE_OP_LITERAL_LOC_IGNORE 37 -#define SRE_OP_NOT_LITERAL_LOC_IGNORE 38 -#define SRE_OP_GROUPREF_UNI_IGNORE 39 -#define SRE_OP_IN_UNI_IGNORE 40 -#define SRE_OP_LITERAL_UNI_IGNORE 41 -#define SRE_OP_NOT_LITERAL_UNI_IGNORE 42 -#define SRE_OP_RANGE_UNI_IGNORE 43 +#define SRE_OP_CATEGORY 8 +#define SRE_OP_CHARSET 9 +#define SRE_OP_BIGCHARSET 10 +#define SRE_OP_GROUPREF 11 +#define SRE_OP_GROUPREF_EXISTS 12 +#define SRE_OP_IN 13 +#define SRE_OP_INFO 14 +#define SRE_OP_JUMP 15 +#define SRE_OP_LITERAL 16 +#define SRE_OP_MARK 17 +#define SRE_OP_MAX_UNTIL 18 +#define SRE_OP_MIN_UNTIL 19 +#define SRE_OP_NOT_LITERAL 20 +#define SRE_OP_NEGATE 21 +#define SRE_OP_RANGE 22 +#define SRE_OP_REPEAT 23 +#define SRE_OP_REPEAT_ONE 24 +#define SRE_OP_SUBPATTERN 25 +#define SRE_OP_MIN_REPEAT_ONE 26 +#define SRE_OP_ATOMIC_GROUP 27 +#define SRE_OP_POSSESSIVE_REPEAT 28 +#define SRE_OP_POSSESSIVE_REPEAT_ONE 29 +#define SRE_OP_GROUPREF_IGNORE 30 +#define SRE_OP_IN_IGNORE 31 +#define SRE_OP_LITERAL_IGNORE 32 +#define SRE_OP_NOT_LITERAL_IGNORE 33 +#define SRE_OP_GROUPREF_LOC_IGNORE 34 +#define SRE_OP_IN_LOC_IGNORE 35 +#define SRE_OP_LITERAL_LOC_IGNORE 36 +#define SRE_OP_NOT_LITERAL_LOC_IGNORE 37 +#define SRE_OP_GROUPREF_UNI_IGNORE 38 +#define SRE_OP_IN_UNI_IGNORE 39 +#define SRE_OP_LITERAL_UNI_IGNORE 40 +#define SRE_OP_NOT_LITERAL_UNI_IGNORE 41 +#define SRE_OP_RANGE_UNI_IGNORE 42 #define SRE_AT_BEGINNING 0 #define SRE_AT_BEGINNING_LINE 1 #define SRE_AT_BEGINNING_STRING 2 diff --git a/Modules/_sre/sre_lib.h b/Modules/_sre/sre_lib.h index efd6fde..1e5b501 100644 --- a/Modules/_sre/sre_lib.h +++ b/Modules/_sre/sre_lib.h @@ -1547,7 +1547,6 @@ dispatch: TARGET(SRE_OP_NEGATE): TARGET(SRE_OP_BIGCHARSET): TARGET(SRE_OP_CHARSET): - TARGET(SRE_OP_CALL): TRACE(("|%p|%p|UNKNOWN %d\n", pattern, ptr, pattern[-1])); RETURN_ERROR(SRE_ERROR_ILLEGAL); diff --git a/Modules/_sre/sre_targets.h b/Modules/_sre/sre_targets.h index 389e7d7..25b6edd 100644 --- a/Modules/_sre/sre_targets.h +++ b/Modules/_sre/sre_targets.h @@ -11,7 +11,7 @@ * See the sre.c file for information on usage and redistribution. */ -static void *sre_targets[44] = { +static void *sre_targets[43] = { &&TARGET_SRE_OP_FAILURE, &&TARGET_SRE_OP_SUCCESS, &&TARGET_SRE_OP_ANY, @@ -20,7 +20,6 @@ static void *sre_targets[44] = { &&TARGET_SRE_OP_ASSERT_NOT, &&TARGET_SRE_OP_AT, &&TARGET_SRE_OP_BRANCH, - &&TARGET_SRE_OP_CALL, &&TARGET_SRE_OP_CATEGORY, &&TARGET_SRE_OP_CHARSET, &&TARGET_SRE_OP_BIGCHARSET, -- cgit v0.12