backed out of broken minimal repeat patch from July

also fixed a couple of minor potential resource leaks in pattern_subx
(Guido had already fixed the big one)
This commit is contained in:
Fredrik Lundh 2001-12-09 16:13:15 +00:00
parent ed69aeedb9
commit 82b230732f
4 changed files with 22 additions and 24 deletions

View File

@ -83,8 +83,8 @@ class Pattern:
if name:
ogid = self.groupdict.get(name, None)
if ogid is not None:
raise error, ("redefinition of group name %s as group %d; " +
"was group %d") % (`name`, gid, ogid)
raise error, ("redefinition of group name %s as group %d; "
"was group %d" % (repr(name), gid, ogid))
self.groupdict[name] = gid
self.open.append(gid)
return gid

View File

@ -638,8 +638,14 @@ xyzabc
(r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'),
# bug 130748: ^* should be an error (nothing to repeat)
(r'^*', '', SYNTAX_ERROR),
# bug 133283: minimizing repeat bug
(r'"(?:\\"|[^"])*?"', r'"\""', SUCCEED, 'found', r'"\"'),
# bug 133283: minimizing repeat problem
(r'"(?:\\"|[^"])*?"', r'"\""', SUCCEED, 'found', r'"\""'),
# bug 477728: minimizing repeat problem
(r'^.*?$', 'one\ntwo\nthree\n', FAIL),
# bug 483789: minimizing repeat problem
(r'a[^>]*?b', 'a>b', FAIL),
# bug 490573: minimizing repeat problem
(r'^a*?$', 'foo', FAIL),
]
try:

View File

@ -296,7 +296,7 @@ if verbose:
# implementation of repeated groups.
test("sre.match('(x)*', 50000*'x').span()", (0, 50000), RuntimeError)
test("sre.match(r'(x)*y', 50000*'x'+'y').span()", (0, 50001), RuntimeError)
test("sre.match(r'(x)*?y', 50000*'x'+'y').span()", (0, 50001))
test("sre.match(r'(x)*?y', 50000*'x'+'y').span()", (0, 50001), RuntimeError)
from re_tests import *

View File

@ -36,6 +36,7 @@
* 2001-10-21 fl added sub/subn primitive
* 2001-10-22 fl check for literal sub/subn templates
* 2001-10-24 fl added finditer primitive (for 2.2 only)
* 2001-12-07 fl fixed memory leak in sub/subn (Guido van Rossum)
*
* Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
*
@ -1116,21 +1117,9 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
/* see if the tail matches */
state->repeat = rp->prev;
/* FIXME: the following fix doesn't always work (#133283) */
if (rp->pattern[2] == 65535) {
/* unbounded repeat */
for (;;) {
i = SRE_MATCH(state, pattern, level + 1);
if (i || ptr >= end)
break;
state->ptr = ++ptr;
}
} else
i = SRE_MATCH(state, pattern, level + 1);
if (i) {
/* free(rp); */
i = SRE_MATCH(state, pattern, level + 1);
if (i)
return i;
}
state->ptr = ptr;
state->repeat = rp;
@ -2143,11 +2132,14 @@ pattern_subx(PatternObject* self, PyObject* template, PyObject* string,
}
string = state_init(&state, self, string, 0, INT_MAX);
if (!string)
if (!string) {
Py_DECREF(filter);
return NULL;
}
list = PyList_New(0);
if (!list) {
Py_DECREF(filter);
state_fini(&state);
return NULL;
}
@ -2260,9 +2252,9 @@ next:
return item;
error:
Py_DECREF(filter);
Py_DECREF(list);
state_fini(&state);
Py_DECREF(filter);
return NULL;
}
@ -2403,7 +2395,7 @@ pattern_getattr(PatternObject* self, char* name)
statichere PyTypeObject Pattern_Type = {
PyObject_HEAD_INIT(NULL)
0, "_sre.SRE_Pattern",
0, "_" SRE_MODULE ".SRE_Pattern",
sizeof(PatternObject), sizeof(SRE_CODE),
(destructor)pattern_dealloc, /*tp_dealloc*/
0, /*tp_print*/
@ -2866,7 +2858,7 @@ match_getattr(MatchObject* self, char* name)
statichere PyTypeObject Match_Type = {
PyObject_HEAD_INIT(NULL)
0, "_sre.SRE_Match",
0, "_" SRE_MODULE ".SRE_Match",
sizeof(MatchObject), sizeof(int),
(destructor)match_dealloc, /*tp_dealloc*/
0, /*tp_print*/
@ -2974,7 +2966,7 @@ scanner_getattr(ScannerObject* self, char* name)
statichere PyTypeObject Scanner_Type = {
PyObject_HEAD_INIT(NULL)
0, "_sre.SRE_Scanner",
0, "_" SRE_MODULE ".SRE_Scanner",
sizeof(ScannerObject), 0,
(destructor)scanner_dealloc, /*tp_dealloc*/
0, /*tp_print*/