Skip to content

Commit 8ac2085

Browse files
gh-109631: Allow interruption of short repeated regex matches (GH-109867)
Counting for signal checking now continues in new match from the point where it ended in the previous match instead of starting from 0.
1 parent 7c61a36 commit 8ac2085

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`re` functions such as :func:`re.findall`, :func:`re.split`,
2+
:func:`re.search` and :func:`re.sub` which perform short repeated matches
3+
can now be interrupted by user.

Modules/_sre/sre.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ typedef struct {
9595
size_t data_stack_base;
9696
/* current repeat context */
9797
SRE_REPEAT *repeat;
98+
unsigned int sigcount;
9899
} SRE_STATE;
99100

100101
typedef struct {

Modules/_sre/sre_lib.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
564564
Py_ssize_t alloc_pos, ctx_pos = -1;
565565
Py_ssize_t ret = 0;
566566
int jump;
567-
unsigned int sigcount=0;
567+
unsigned int sigcount = state->sigcount;
568568

569569
SRE(match_context)* ctx;
570570
SRE(match_context)* nextctx;
@@ -1567,8 +1567,10 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
15671567
ctx_pos = ctx->last_ctx_pos;
15681568
jump = ctx->jump;
15691569
DATA_POP_DISCARD(ctx);
1570-
if (ctx_pos == -1)
1570+
if (ctx_pos == -1) {
1571+
state->sigcount = sigcount;
15711572
return ret;
1573+
}
15721574
DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos);
15731575

15741576
switch (jump) {

0 commit comments

Comments
 (0)