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:
parent
ed69aeedb9
commit
82b230732f
|
@ -83,8 +83,8 @@ class Pattern:
|
||||||
if name:
|
if name:
|
||||||
ogid = self.groupdict.get(name, None)
|
ogid = self.groupdict.get(name, None)
|
||||||
if ogid is not None:
|
if ogid is not None:
|
||||||
raise error, ("redefinition of group name %s as group %d; " +
|
raise error, ("redefinition of group name %s as group %d; "
|
||||||
"was group %d") % (`name`, gid, ogid)
|
"was group %d" % (repr(name), gid, ogid))
|
||||||
self.groupdict[name] = gid
|
self.groupdict[name] = gid
|
||||||
self.open.append(gid)
|
self.open.append(gid)
|
||||||
return gid
|
return gid
|
||||||
|
|
|
@ -638,8 +638,14 @@ xyzabc
|
||||||
(r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'),
|
(r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'),
|
||||||
# bug 130748: ^* should be an error (nothing to repeat)
|
# bug 130748: ^* should be an error (nothing to repeat)
|
||||||
(r'^*', '', SYNTAX_ERROR),
|
(r'^*', '', SYNTAX_ERROR),
|
||||||
# bug 133283: minimizing repeat bug
|
# bug 133283: minimizing repeat problem
|
||||||
(r'"(?:\\"|[^"])*?"', r'"\""', SUCCEED, 'found', r'"\"'),
|
(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:
|
try:
|
||||||
|
|
|
@ -296,7 +296,7 @@ if verbose:
|
||||||
# implementation of repeated groups.
|
# implementation of repeated groups.
|
||||||
test("sre.match('(x)*', 50000*'x').span()", (0, 50000), RuntimeError)
|
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), 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 *
|
from re_tests import *
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
* 2001-10-21 fl added sub/subn primitive
|
* 2001-10-21 fl added sub/subn primitive
|
||||||
* 2001-10-22 fl check for literal sub/subn templates
|
* 2001-10-22 fl check for literal sub/subn templates
|
||||||
* 2001-10-24 fl added finditer primitive (for 2.2 only)
|
* 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.
|
* 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 */
|
/* see if the tail matches */
|
||||||
state->repeat = rp->prev;
|
state->repeat = rp->prev;
|
||||||
/* FIXME: the following fix doesn't always work (#133283) */
|
i = SRE_MATCH(state, pattern, level + 1);
|
||||||
if (rp->pattern[2] == 65535) {
|
if (i)
|
||||||
/* 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); */
|
|
||||||
return i;
|
return i;
|
||||||
}
|
|
||||||
|
|
||||||
state->ptr = ptr;
|
state->ptr = ptr;
|
||||||
state->repeat = rp;
|
state->repeat = rp;
|
||||||
|
@ -2143,11 +2132,14 @@ pattern_subx(PatternObject* self, PyObject* template, PyObject* string,
|
||||||
}
|
}
|
||||||
|
|
||||||
string = state_init(&state, self, string, 0, INT_MAX);
|
string = state_init(&state, self, string, 0, INT_MAX);
|
||||||
if (!string)
|
if (!string) {
|
||||||
|
Py_DECREF(filter);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
list = PyList_New(0);
|
list = PyList_New(0);
|
||||||
if (!list) {
|
if (!list) {
|
||||||
|
Py_DECREF(filter);
|
||||||
state_fini(&state);
|
state_fini(&state);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2260,9 +2252,9 @@ next:
|
||||||
return item;
|
return item;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
Py_DECREF(filter);
|
|
||||||
Py_DECREF(list);
|
Py_DECREF(list);
|
||||||
state_fini(&state);
|
state_fini(&state);
|
||||||
|
Py_DECREF(filter);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2403,7 +2395,7 @@ pattern_getattr(PatternObject* self, char* name)
|
||||||
|
|
||||||
statichere PyTypeObject Pattern_Type = {
|
statichere PyTypeObject Pattern_Type = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, "_sre.SRE_Pattern",
|
0, "_" SRE_MODULE ".SRE_Pattern",
|
||||||
sizeof(PatternObject), sizeof(SRE_CODE),
|
sizeof(PatternObject), sizeof(SRE_CODE),
|
||||||
(destructor)pattern_dealloc, /*tp_dealloc*/
|
(destructor)pattern_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
|
@ -2866,7 +2858,7 @@ match_getattr(MatchObject* self, char* name)
|
||||||
|
|
||||||
statichere PyTypeObject Match_Type = {
|
statichere PyTypeObject Match_Type = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, "_sre.SRE_Match",
|
0, "_" SRE_MODULE ".SRE_Match",
|
||||||
sizeof(MatchObject), sizeof(int),
|
sizeof(MatchObject), sizeof(int),
|
||||||
(destructor)match_dealloc, /*tp_dealloc*/
|
(destructor)match_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
|
@ -2974,7 +2966,7 @@ scanner_getattr(ScannerObject* self, char* name)
|
||||||
|
|
||||||
statichere PyTypeObject Scanner_Type = {
|
statichere PyTypeObject Scanner_Type = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, "_sre.SRE_Scanner",
|
0, "_" SRE_MODULE ".SRE_Scanner",
|
||||||
sizeof(ScannerObject), 0,
|
sizeof(ScannerObject), 0,
|
||||||
(destructor)scanner_dealloc, /*tp_dealloc*/
|
(destructor)scanner_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
|
|
Loading…
Reference in New Issue