summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 19e7bdc..b81a8e2 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -95,6 +95,7 @@ static char copyright[] =
#define SRE_ERROR_STATE -2 /* illegal state */
#define SRE_ERROR_RECURSION_LIMIT -3 /* runaway recursion */
#define SRE_ERROR_MEMORY -9 /* out of memory */
+#define SRE_ERROR_INTERRUPTED -10 /* signal handler raised exception */
#if defined(VERBOSE)
#define TRACE(v) printf v
@@ -805,6 +806,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
Py_ssize_t alloc_pos, ctx_pos = -1;
Py_ssize_t i, ret = 0;
Py_ssize_t jump;
+ unsigned int sigcount=0;
SRE_MATCH_CONTEXT* ctx;
SRE_MATCH_CONTEXT* nextctx;
@@ -833,6 +835,9 @@ entrance:
}
for (;;) {
+ ++sigcount;
+ if ((0 == (sigcount & 0xfff)) && PyErr_CheckSignals())
+ RETURN_ERROR(SRE_ERROR_INTERRUPTED);
switch (*ctx->pattern++) {
@@ -1833,6 +1838,9 @@ pattern_error(int status)
case SRE_ERROR_MEMORY:
PyErr_NoMemory();
break;
+ case SRE_ERROR_INTERRUPTED:
+ /* An exception has already been raised, so let it fly */
+ break;
default:
/* other error codes indicate compiler/engine bugs */
PyErr_SetString(