summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-01-14 15:06:11 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2001-01-14 15:06:11 (GMT)
commit770617b23e286f1147f9480b5f625e88e7badd50 (patch)
tree54b35019e4189cbe24a1c1958ec448b624311706 /Modules
parent77b20f099e6cbad346b18c0e6db94b6ab7fd4d39 (diff)
downloadcpython-770617b23e286f1147f9480b5f625e88e7badd50.zip
cpython-770617b23e286f1147f9480b5f625e88e7badd50.tar.gz
cpython-770617b23e286f1147f9480b5f625e88e7badd50.tar.bz2
SRE fixes for 2.1 alpha:
-- added some more docstrings -- fixed typo in scanner class (#125531) -- the multiline flag (?m) should't affect the \Z operator (#127259) -- fixed non-greedy backtracking bug (#123769, #127259) -- added sre.DEBUG flag (currently dumps the parsed pattern structure) -- fixed a couple of glitches in groupdict (the #126587 memory leak had already been fixed by AMK)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sre.c56
-rw-r--r--Modules/sre_constants.h12
2 files changed, 40 insertions, 28 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index ccbd7b2..28ec61c 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -22,8 +22,10 @@
* 2000-09-21 fl don't use the buffer interface for unicode strings
* 2000-10-03 fl fixed assert_not primitive; support keyword arguments
* 2000-10-24 fl really fixed assert_not; reset groups in findall
+ * 2000-12-21 fl fixed memory leak in groupdict
+ * 2001-01-02 fl properly reset pointer after failed assertion in MIN_UNTIL
*
- * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
+ * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
*
* This version of the SRE library can be redistributed under CNRI's
* Python 1.6 license. For any other use, please contact Secret Labs
@@ -355,6 +357,7 @@ SRE_AT(SRE_STATE* state, SRE_CHAR* ptr, SRE_CODE at)
switch (at) {
case SRE_AT_BEGINNING:
+ case SRE_AT_BEGINNING_STRING:
return ((void*) ptr == state->beginning);
case SRE_AT_BEGINNING_LINE:
@@ -370,6 +373,9 @@ SRE_AT(SRE_STATE* state, SRE_CHAR* ptr, SRE_CODE at)
return ((void*) ptr == state->end ||
SRE_IS_LINEBREAK((int) ptr[0]));
+ case SRE_AT_END_STRING:
+ return ((void*) ptr == state->end);
+
case SRE_AT_BOUNDARY:
if (state->beginning == state->end)
return 0;
@@ -826,7 +832,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
/* this operator only works if the repeated item is
exactly one character wide, and we're not already
collecting backtracking points. for other cases,
- use the MAX_REPEAT operator instead */
+ use the MAX_REPEAT operator */
/* <REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */
@@ -900,7 +906,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
case SRE_OP_REPEAT:
/* create repeat context. all the hard work is done
- by the UNTIL operator */
+ by the UNTIL operator (MAX_UNTIL, MIN_UNTIL) */
/* <REPEAT> <skip> <1=min> <2=max> item <UNTIL> tail */
TRACE(("|%p|%p|REPEAT %d %d\n", pattern, ptr,
pattern[1], pattern[2]));
@@ -974,6 +980,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
if (i)
return i;
state->repeat = rp;
+ state->ptr = ptr;
return 0;
case SRE_OP_MIN_UNTIL:
@@ -986,7 +993,8 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
count = rp->count + 1;
- TRACE(("|%p|%p|MIN_UNTIL %d\n", pattern, ptr, count));
+ TRACE(("|%p|%p|MIN_UNTIL %d %p\n", pattern, ptr, count,
+ rp->pattern));
state->ptr = ptr;
@@ -1009,6 +1017,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
/* free(rp); */
return i;
}
+ state->ptr = ptr;
state->repeat = rp;
if (count >= rp->pattern[2] && rp->pattern[2] != 65535)
@@ -1020,6 +1029,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
if (i)
return i;
rp->count = count - 1;
+ state->ptr = ptr;
return 0;
default:
@@ -1965,7 +1975,7 @@ match_groupdict(MatchObject* self, PyObject* args, PyObject* kw)
PyObject* def = Py_None;
static char* kwlist[] = { "default", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:groups", kwlist, &def))
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:groupdict", kwlist, &def))
return NULL;
result = PyDict_New();
@@ -1973,35 +1983,35 @@ match_groupdict(MatchObject* self, PyObject* args, PyObject* kw)
return result;
keys = PyMapping_Keys(self->pattern->groupindex);
- if (!keys) {
- Py_DECREF(result);
- return NULL;
- }
+ if (!keys)
+ goto failed;
for (index = 0; index < PyList_GET_SIZE(keys); index++) {
+ int status;
PyObject* key;
- PyObject* item;
+ PyObject* value;
key = PyList_GET_ITEM(keys, index);
- if (!key) {
- Py_DECREF(keys);
- Py_DECREF(result);
- return NULL;
- }
- item = match_getslice(self, key, def);
- if (!item) {
+ if (!key)
+ goto failed;
+ value = match_getslice(self, key, def);
+ if (!value) {
Py_DECREF(key);
- Py_DECREF(keys);
- Py_DECREF(result);
- return NULL;
+ goto failed;
}
- /* FIXME: <fl> this can fail, right? */
- PyDict_SetItem(result, key, item);
- Py_DECREF(item);
+ status = PyDict_SetItem(result, key, value);
+ Py_DECREF(value);
+ if (status < 0)
+ goto failed;
}
Py_DECREF(keys);
return result;
+
+failed:
+ Py_DECREF(keys);
+ Py_DECREF(result);
+ return NULL;
}
static PyObject*
diff --git a/Modules/sre_constants.h b/Modules/sre_constants.h
index 5c55c3d..6cad089 100644
--- a/Modules/sre_constants.h
+++ b/Modules/sre_constants.h
@@ -6,7 +6,7 @@
* NOTE: This file is generated by sre_constants.py. If you need
* to change anything in here, edit sre_constants.py and run it.
*
- * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
+ * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
*
* See the _sre.c file for information on usage and redistribution.
*/
@@ -42,10 +42,12 @@
#define SRE_OP_SUBPATTERN 28
#define SRE_AT_BEGINNING 0
#define SRE_AT_BEGINNING_LINE 1
-#define SRE_AT_BOUNDARY 2
-#define SRE_AT_NON_BOUNDARY 3
-#define SRE_AT_END 4
-#define SRE_AT_END_LINE 5
+#define SRE_AT_BEGINNING_STRING 2
+#define SRE_AT_BOUNDARY 3
+#define SRE_AT_NON_BOUNDARY 4
+#define SRE_AT_END 5
+#define SRE_AT_END_LINE 6
+#define SRE_AT_END_STRING 7
#define SRE_CATEGORY_DIGIT 0
#define SRE_CATEGORY_NOT_DIGIT 1
#define SRE_CATEGORY_SPACE 2