summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2008-02-04 22:00:35 +0000
committerGuido van Rossum <guido@python.org>2008-02-04 22:00:35 +0000
commitd66e94d0e6681345c6b203e7e6bd56e5a82ceb82 (patch)
tree0320f535ba602d5c44aa83469c0ad442dfc5b21e
parent912ba54394107b16865501e8f02f424accc2da80 (diff)
downloadcpython-git-d66e94d0e6681345c6b203e7e6bd56e5a82ceb82.tar.gz
Backport r59862 (issue #712900): make long regexp matches interruptable
by signals.
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/_sre.c8
2 files changed, 10 insertions, 0 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 5f28bd3b05..5cd8e4ab7e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -212,6 +212,8 @@ Library
Extension Modules
-----------------
+- Backport r59862 (issue #712900): make long regexp matches interruptable.
+
- #1940: make it possible to use curses.filter() before curses.initscr()
as the documentation says.
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 354210064b..eb071ef591 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -99,6 +99,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
@@ -809,6 +810,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;
@@ -837,6 +839,9 @@ entrance:
}
for (;;) {
+ ++sigcount;
+ if ((0 == (sigcount & 0xfff)) && PyErr_CheckSignals())
+ RETURN_ERROR(SRE_ERROR_INTERRUPTED);
switch (*ctx->pattern++) {
@@ -1834,6 +1839,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(