diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-10-02 15:36:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 15:36:29 (GMT) |
commit | 65c845e065d6ff7abc1abdc9c24bc7612a665161 (patch) | |
tree | c4b253cbbf3537e4f5c76df21250a8e87a51e130 /Modules/_sre | |
parent | d09a3145b596810078d0b24e1a9cbebc117f804d (diff) | |
download | cpython-65c845e065d6ff7abc1abdc9c24bc7612a665161.zip cpython-65c845e065d6ff7abc1abdc9c24bc7612a665161.tar.gz cpython-65c845e065d6ff7abc1abdc9c24bc7612a665161.tar.bz2 |
[3.12] gh-109631: Allow interruption of short repeated regex matches (GH-109867) (#109886)
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.
(cherry picked from commit 8ac2085b80eca4d9b2a1093d0a7da020fd12e11a)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Modules/_sre')
-rw-r--r-- | Modules/_sre/sre.h | 1 | ||||
-rw-r--r-- | Modules/_sre/sre_lib.h | 6 |
2 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_sre/sre.h b/Modules/_sre/sre.h index d967d9e..a0f2356 100644 --- a/Modules/_sre/sre.h +++ b/Modules/_sre/sre.h @@ -94,6 +94,7 @@ typedef struct { size_t data_stack_base; /* current repeat context */ SRE_REPEAT *repeat; + unsigned int sigcount; } SRE_STATE; typedef struct { diff --git a/Modules/_sre/sre_lib.h b/Modules/_sre/sre_lib.h index e831498..f8d556b 100644 --- a/Modules/_sre/sre_lib.h +++ b/Modules/_sre/sre_lib.h @@ -563,7 +563,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel) Py_ssize_t alloc_pos, ctx_pos = -1; Py_ssize_t ret = 0; int jump; - unsigned int sigcount=0; + unsigned int sigcount = state->sigcount; SRE(match_context)* ctx; SRE(match_context)* nextctx; @@ -1565,8 +1565,10 @@ exit: ctx_pos = ctx->last_ctx_pos; jump = ctx->jump; DATA_POP_DISCARD(ctx); - if (ctx_pos == -1) + if (ctx_pos == -1) { + state->sigcount = sigcount; return ret; + } DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); switch (jump) { |