@@ -1032,16 +1032,14 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1032
1032
case SRE_OP_REPEAT :
1033
1033
/* create repeat context. all the hard work is done
1034
1034
by the UNTIL operator (MAX_UNTIL, MIN_UNTIL) */
1035
- /* <REPEAT> <skip> <1=min> <2=max> item <UNTIL> tail */
1036
- TRACE (("|%p|%p|REPEAT %d %d\n" , ctx -> pattern , ctx -> ptr ,
1037
- ctx -> pattern [1 ], ctx -> pattern [2 ]));
1035
+ /* <REPEAT> <skip> <1=min> <2=max>
1036
+ <3=repeat_index> item <UNTIL> tail */
1037
+ TRACE (("|%p|%p|REPEAT %d %d %d\n" , ctx -> pattern , ctx -> ptr ,
1038
+ ctx -> pattern [1 ], ctx -> pattern [2 ], ctx -> pattern [3 ]));
1039
+
1040
+ /* install repeat context */
1041
+ ctx -> u .rep = & state -> repeats_array [ctx -> pattern [3 ]];
1038
1042
1039
- /* install new repeat context */
1040
- ctx -> u .rep = (SRE_REPEAT * ) PyObject_Malloc (sizeof (* ctx -> u .rep ));
1041
- if (!ctx -> u .rep ) {
1042
- PyErr_NoMemory ();
1043
- RETURN_FAILURE ;
1044
- }
1045
1043
ctx -> u .rep -> count = -1 ;
1046
1044
ctx -> u .rep -> pattern = ctx -> pattern ;
1047
1045
ctx -> u .rep -> prev = state -> repeat ;
@@ -1051,7 +1049,6 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1051
1049
state -> ptr = ctx -> ptr ;
1052
1050
DO_JUMP (JUMP_REPEAT , jump_repeat , ctx -> pattern + ctx -> pattern [0 ]);
1053
1051
state -> repeat = ctx -> u .rep -> prev ;
1054
- PyObject_Free (ctx -> u .rep );
1055
1052
1056
1053
if (ret ) {
1057
1054
RETURN_ON_ERROR (ret );
@@ -1061,7 +1058,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1061
1058
1062
1059
case SRE_OP_MAX_UNTIL :
1063
1060
/* maximizing repeat */
1064
- /* <REPEAT> <skip> <1=min> <2=max> item <MAX_UNTIL> tail */
1061
+ /* <REPEAT> <skip> <1=min> <2=max>
1062
+ <3=repeat_index> item <MAX_UNTIL> tail */
1065
1063
1066
1064
/* FIXME: we probably need to deal with zero-width
1067
1065
matches in here... */
@@ -1081,7 +1079,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1081
1079
/* not enough matches */
1082
1080
ctx -> u .rep -> count = ctx -> count ;
1083
1081
DO_JUMP (JUMP_MAX_UNTIL_1 , jump_max_until_1 ,
1084
- ctx -> u .rep -> pattern + 3 );
1082
+ ctx -> u .rep -> pattern + 4 );
1085
1083
if (ret ) {
1086
1084
RETURN_ON_ERROR (ret );
1087
1085
RETURN_SUCCESS ;
@@ -1103,7 +1101,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1103
1101
DATA_PUSH (& ctx -> u .rep -> last_ptr );
1104
1102
ctx -> u .rep -> last_ptr = state -> ptr ;
1105
1103
DO_JUMP (JUMP_MAX_UNTIL_2 , jump_max_until_2 ,
1106
- ctx -> u .rep -> pattern + 3 );
1104
+ ctx -> u .rep -> pattern + 4 );
1107
1105
DATA_POP (& ctx -> u .rep -> last_ptr );
1108
1106
if (ret ) {
1109
1107
MARK_POP_DISCARD (ctx -> lastmark );
@@ -1128,7 +1126,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1128
1126
1129
1127
case SRE_OP_MIN_UNTIL :
1130
1128
/* minimizing repeat */
1131
- /* <REPEAT> <skip> <1=min> <2=max> item <MIN_UNTIL> tail */
1129
+ /* <REPEAT> <skip> <1=min> <2=max>
1130
+ <3=repeat_index> item <MIN_UNTIL> tail */
1132
1131
1133
1132
ctx -> u .rep = state -> repeat ;
1134
1133
if (!ctx -> u .rep )
@@ -1145,7 +1144,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1145
1144
/* not enough matches */
1146
1145
ctx -> u .rep -> count = ctx -> count ;
1147
1146
DO_JUMP (JUMP_MIN_UNTIL_1 , jump_min_until_1 ,
1148
- ctx -> u .rep -> pattern + 3 );
1147
+ ctx -> u .rep -> pattern + 4 );
1149
1148
if (ret ) {
1150
1149
RETURN_ON_ERROR (ret );
1151
1150
RETURN_SUCCESS ;
@@ -1188,7 +1187,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
1188
1187
DATA_PUSH (& ctx -> u .rep -> last_ptr );
1189
1188
ctx -> u .rep -> last_ptr = state -> ptr ;
1190
1189
DO_JUMP (JUMP_MIN_UNTIL_3 ,jump_min_until_3 ,
1191
- ctx -> u .rep -> pattern + 3 );
1190
+ ctx -> u .rep -> pattern + 4 );
1192
1191
DATA_POP (& ctx -> u .rep -> last_ptr );
1193
1192
if (ret ) {
1194
1193
RETURN_ON_ERROR (ret );
0 commit comments