[Python-checkins] gh-91870: Remove unsupported SRE opcode CALL (GH-91872)

serhiy-storchaka webhook-mailer at python.org
Tue Apr 26 14:07:33 EDT 2022


https://github.com/python/cpython/commit/f703c96cf08a0d65e718e7acfb043cbc49812a22
commit: f703c96cf08a0d65e718e7acfb043cbc49812a22
branch: main
author: Serhiy Storchaka <storchaka at gmail.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2022-04-26T21:07:25+03:00
summary:

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.

files:
M Lib/re/_compiler.py
M Lib/re/_constants.py
M Lib/re/_parser.py
M Modules/_sre/sre_constants.h
M Modules/_sre/sre_lib.h
M Modules/_sre/sre_targets.h

diff --git a/Lib/re/_compiler.py b/Lib/re/_compiler.py
index f621d04af123d..63d82025505b7 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 aa1a590290fd9..c45ce409e21b8 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 @@ def _makecodes(*names):
     '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 b864bf2b108a6..933d51589f46c 100644
--- a/Lib/re/_parser.py
+++ b/Lib/re/_parser.py
@@ -183,10 +183,6 @@ def getwidth(self):
                     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 b1ef27eccc839..d5de650b7025a 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 efd6fdeccce3f..1e5b50170ae76 100644
--- a/Modules/_sre/sre_lib.h
+++ b/Modules/_sre/sre_lib.h
@@ -1547,7 +1547,6 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
         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 389e7d77e949c..25b6edd436bb7 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,



More information about the Python-checkins mailing list