Skip to content

Commit 1560a0c

Browse files
committed
8. support code in sre_lib.h
1 parent a43cb6e commit 1560a0c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

Modules/sre_lib.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,16 +1032,14 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
10321032
case SRE_OP_REPEAT:
10331033
/* create repeat context. all the hard work is done
10341034
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]];
10381042

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-
}
10451043
ctx->u.rep->count = -1;
10461044
ctx->u.rep->pattern = ctx->pattern;
10471045
ctx->u.rep->prev = state->repeat;
@@ -1051,7 +1049,6 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
10511049
state->ptr = ctx->ptr;
10521050
DO_JUMP(JUMP_REPEAT, jump_repeat, ctx->pattern+ctx->pattern[0]);
10531051
state->repeat = ctx->u.rep->prev;
1054-
PyObject_Free(ctx->u.rep);
10551052

10561053
if (ret) {
10571054
RETURN_ON_ERROR(ret);
@@ -1061,7 +1058,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
10611058

10621059
case SRE_OP_MAX_UNTIL:
10631060
/* 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 */
10651063

10661064
/* FIXME: we probably need to deal with zero-width
10671065
matches in here... */
@@ -1081,7 +1079,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
10811079
/* not enough matches */
10821080
ctx->u.rep->count = ctx->count;
10831081
DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1,
1084-
ctx->u.rep->pattern+3);
1082+
ctx->u.rep->pattern+4);
10851083
if (ret) {
10861084
RETURN_ON_ERROR(ret);
10871085
RETURN_SUCCESS;
@@ -1103,7 +1101,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
11031101
DATA_PUSH(&ctx->u.rep->last_ptr);
11041102
ctx->u.rep->last_ptr = state->ptr;
11051103
DO_JUMP(JUMP_MAX_UNTIL_2, jump_max_until_2,
1106-
ctx->u.rep->pattern+3);
1104+
ctx->u.rep->pattern+4);
11071105
DATA_POP(&ctx->u.rep->last_ptr);
11081106
if (ret) {
11091107
MARK_POP_DISCARD(ctx->lastmark);
@@ -1128,7 +1126,8 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
11281126

11291127
case SRE_OP_MIN_UNTIL:
11301128
/* 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 */
11321131

11331132
ctx->u.rep = state->repeat;
11341133
if (!ctx->u.rep)
@@ -1145,7 +1144,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
11451144
/* not enough matches */
11461145
ctx->u.rep->count = ctx->count;
11471146
DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1,
1148-
ctx->u.rep->pattern+3);
1147+
ctx->u.rep->pattern+4);
11491148
if (ret) {
11501149
RETURN_ON_ERROR(ret);
11511150
RETURN_SUCCESS;
@@ -1188,7 +1187,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
11881187
DATA_PUSH(&ctx->u.rep->last_ptr);
11891188
ctx->u.rep->last_ptr = state->ptr;
11901189
DO_JUMP(JUMP_MIN_UNTIL_3,jump_min_until_3,
1191-
ctx->u.rep->pattern+3);
1190+
ctx->u.rep->pattern+4);
11921191
DATA_POP(&ctx->u.rep->last_ptr);
11931192
if (ret) {
11941193
RETURN_ON_ERROR(ret);

0 commit comments

Comments
 (0)