[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.6,2.7 sre.h,2.5,2.6
Fredrik Lundh
python-dev@python.org
Thu, 29 Jun 2000 04:34:30 -0700
- Previous message: [Python-checkins] CVS: python/dist/src/Lib sre.py,1.8,1.9 sre_compile.py,1.6,1.7 sre_constants.py,1.6,1.7 sre_parse.py,1.6,1.7
- Next message: [Python-checkins] CVS: python/dist/src/Modules _sre.c,2.7,2.8 sre.h,2.6,2.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv18748/Modules
Modified Files:
_sre.c sre.h
Log Message:
- last patch broke parse_template; fixed by changing some
tests in sre_patch back to previous version
- fixed return value from findall
- renamed a bunch of functions inside _sre (way too
many leading underscores...)
</F>
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.6
retrieving revision 2.7
diff -C2 -r2.6 -r2.7
*** _sre.c 2000/06/29 10:34:56 2.6
--- _sre.c 2000/06/29 11:34:28 2.7
***************
*** 200,204 ****
LOCAL(int)
! _stack_free(SRE_STATE* state)
{
if (state->stack) {
--- 200,204 ----
LOCAL(int)
! stack_free(SRE_STATE* state)
{
if (state->stack) {
***************
*** 212,216 ****
static int /* shouldn't be LOCAL */
! _stack_extend(SRE_STATE* state, int lo, int hi)
{
SRE_STACK* stack;
--- 212,216 ----
static int /* shouldn't be LOCAL */
! stack_extend(SRE_STATE* state, int lo, int hi)
{
SRE_STACK* stack;
***************
*** 243,247 ****
if (!stack) {
! _stack_free(state);
return SRE_ERROR_MEMORY;
}
--- 243,247 ----
if (!stack) {
! stack_free(state);
return SRE_ERROR_MEMORY;
}
***************
*** 776,780 ****
stack */
if (stack >= state->stacksize) {
! i = _stack_extend(state, stack + 1,
stackbase + pattern[2]);
if (i < 0)
--- 776,780 ----
stack */
if (stack >= state->stacksize) {
! i = stack_extend(state, stack + 1,
stackbase + pattern[2]);
if (i < 0)
***************
*** 1017,1021 ****
LOCAL(PyObject*)
! _setup(SRE_STATE* state, PatternObject* pattern, PyObject* args)
{
/* prepare state object */
--- 1017,1021 ----
LOCAL(PyObject*)
! state_init(SRE_STATE* state, PatternObject* pattern, PyObject* args)
{
/* prepare state object */
***************
*** 1094,1099 ****
}
static PyObject*
! _pattern_new_match(PatternObject* pattern, SRE_STATE* state,
PyObject* string, int status)
{
--- 1094,1124 ----
}
+ LOCAL(void)
+ state_fini(SRE_STATE* state)
+ {
+ stack_free(state);
+ }
+
+ LOCAL(PyObject*)
+ state_getslice(SRE_STATE* state, int index, PyObject* string)
+ {
+ index = (index - 1) * 2;
+
+ if (string == Py_None || !state->mark[index] || !state->mark[index+1]) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ return PySequence_GetSlice(
+ string,
+ ((char*)state->mark[index] - (char*)state->beginning) /
+ state->charsize,
+ ((char*)state->mark[index+1] - (char*)state->beginning) /
+ state->charsize
+ );
+ }
+
static PyObject*
! pattern_new_match(PatternObject* pattern, SRE_STATE* state,
PyObject* string, int status)
{
***************
*** 1152,1156 ****
static PyObject*
! _pattern_cursor(PatternObject* pattern, PyObject* args)
{
/* create search state object */
--- 1177,1181 ----
static PyObject*
! pattern_cursor(PatternObject* pattern, PyObject* args)
{
/* create search state object */
***************
*** 1164,1168 ****
return NULL;
! string = _setup(&self->state, pattern, args);
if (!string) {
PyObject_DEL(self);
--- 1189,1193 ----
return NULL;
! string = state_init(&self->state, pattern, args);
if (!string) {
PyObject_DEL(self);
***************
*** 1180,1184 ****
static void
! _pattern_dealloc(PatternObject* self)
{
Py_XDECREF(self->code);
--- 1205,1209 ----
static void
! pattern_dealloc(PatternObject* self)
{
Py_XDECREF(self->code);
***************
*** 1189,1193 ****
static PyObject*
! _pattern_match(PatternObject* self, PyObject* args)
{
SRE_STATE state;
--- 1214,1218 ----
static PyObject*
! pattern_match(PatternObject* self, PyObject* args)
{
SRE_STATE state;
***************
*** 1195,1199 ****
int status;
! string = _setup(&state, self, args);
if (!string)
return NULL;
--- 1220,1224 ----
int status;
! string = state_init(&state, self, args);
if (!string)
return NULL;
***************
*** 1209,1219 ****
}
! _stack_free(&state);
! return _pattern_new_match(self, &state, string, status);
}
static PyObject*
! _pattern_search(PatternObject* self, PyObject* args)
{
SRE_STATE state;
--- 1234,1244 ----
}
! state_fini(&state);
! return pattern_new_match(self, &state, string, status);
}
static PyObject*
! pattern_search(PatternObject* self, PyObject* args)
{
SRE_STATE state;
***************
*** 1221,1225 ****
int status;
! string = _setup(&state, self, args);
if (!string)
return NULL;
--- 1246,1250 ----
int status;
! string = state_init(&state, self, args);
if (!string)
return NULL;
***************
*** 1233,1239 ****
}
! _stack_free(&state);
! return _pattern_new_match(self, &state, string, status);
}
--- 1258,1264 ----
}
! state_fini(&state);
! return pattern_new_match(self, &state, string, status);
}
***************
*** 1264,1268 ****
static PyObject*
! _pattern_sub(PatternObject* self, PyObject* args)
{
PyObject* template;
--- 1289,1293 ----
static PyObject*
! pattern_sub(PatternObject* self, PyObject* args)
{
PyObject* template;
***************
*** 1277,1281 ****
static PyObject*
! _pattern_subn(PatternObject* self, PyObject* args)
{
PyObject* template;
--- 1302,1306 ----
static PyObject*
! pattern_subn(PatternObject* self, PyObject* args)
{
PyObject* template;
***************
*** 1290,1294 ****
static PyObject*
! _pattern_split(PatternObject* self, PyObject* args)
{
PyObject* string;
--- 1315,1319 ----
static PyObject*
! pattern_split(PatternObject* self, PyObject* args)
{
PyObject* string;
***************
*** 1302,1306 ****
static PyObject*
! _pattern_findall(PatternObject* self, PyObject* args)
{
SRE_STATE state;
--- 1327,1331 ----
static PyObject*
! pattern_findall(PatternObject* self, PyObject* args)
{
SRE_STATE state;
***************
*** 1308,1313 ****
PyObject* list;
int status;
! string = _setup(&state, self, args);
if (!string)
return NULL;
--- 1333,1339 ----
PyObject* list;
int status;
+ int i;
! string = state_init(&state, self, args);
if (!string)
return NULL;
***************
*** 1331,1342 ****
if (status > 0) {
! item = PySequence_GetSlice(
! string,
! ((char*) state.start - (char*) state.beginning) / state.charsize,
! ((char*) state.ptr - (char*) state.beginning) / state.charsize);
! if (!item)
! goto error;
! if (PyList_Append(list, item) < 0)
goto error;
if (state.ptr == state.start)
--- 1357,1396 ----
if (status > 0) {
! /* don't bother to build a match object */
! switch (self->groups) {
! case 0:
! item = PySequence_GetSlice(
! string,
! ((char*) state.start - (char*) state.beginning) /
! state.charsize,
! ((char*) state.ptr - (char*) state.beginning) /
! state.charsize);
! if (!item)
! goto error;
! break;
! case 1:
! item = state_getslice(&state, 1, string);
! if (!item)
! goto error;
! break;
! default:
! item = PyTuple_New(self->groups);
! if (!item)
! goto error;
! for (i = 0; i < self->groups; i++) {
! PyObject* o = state_getslice(&state, i+1, string);
! if (!o) {
! Py_DECREF(item);
! goto error;
! }
! PyTuple_SET_ITEM(item, i, o);
! }
! break;
! }
!
! if (PyList_Append(list, item) < 0) {
! Py_DECREF(item);
goto error;
+ }
if (state.ptr == state.start)
***************
*** 1359,1391 ****
}
}
-
- _stack_free(&state);
return list;
error:
! _stack_free(&state);
return NULL;
}
! static PyMethodDef _pattern_methods[] = {
! {"match", (PyCFunction) _pattern_match, 1},
! {"search", (PyCFunction) _pattern_search, 1},
! {"sub", (PyCFunction) _pattern_sub, 1},
! {"subn", (PyCFunction) _pattern_subn, 1},
! {"split", (PyCFunction) _pattern_split, 1},
! {"findall", (PyCFunction) _pattern_findall, 1},
/* experimental */
! {"cursor", (PyCFunction) _pattern_cursor, 1},
{NULL, NULL}
};
static PyObject*
! _pattern_getattr(PatternObject* self, char* name)
{
PyObject* res;
! res = Py_FindMethod(_pattern_methods, (PyObject*) self, name);
if (res)
--- 1413,1445 ----
}
}
+ state_fini(&state);
return list;
error:
! Py_DECREF(list);
! state_fini(&state);
return NULL;
}
! static PyMethodDef pattern_methods[] = {
! {"match", (PyCFunction) pattern_match, 1},
! {"search", (PyCFunction) pattern_search, 1},
! {"sub", (PyCFunction) pattern_sub, 1},
! {"subn", (PyCFunction) pattern_subn, 1},
! {"split", (PyCFunction) pattern_split, 1},
! {"findall", (PyCFunction) pattern_findall, 1},
/* experimental */
! {"cursor", (PyCFunction) pattern_cursor, 1},
{NULL, NULL}
};
static PyObject*
! pattern_getattr(PatternObject* self, char* name)
{
PyObject* res;
! res = Py_FindMethod(pattern_methods, (PyObject*) self, name);
if (res)
***************
*** 1415,1421 ****
PyObject_HEAD_INIT(NULL)
0, "Pattern", sizeof(PatternObject), 0,
! (destructor)_pattern_dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc)_pattern_getattr, /*tp_getattr*/
};
--- 1469,1475 ----
PyObject_HEAD_INIT(NULL)
0, "Pattern", sizeof(PatternObject), 0,
! (destructor)pattern_dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc)pattern_getattr, /*tp_getattr*/
};
***************
*** 1424,1428 ****
static void
! _match_dealloc(MatchObject* self)
{
Py_XDECREF(self->string);
--- 1478,1482 ----
static void
! match_dealloc(MatchObject* self)
{
Py_XDECREF(self->string);
***************
*** 1432,1436 ****
static PyObject*
! getslice_by_index(MatchObject* self, int index)
{
if (index < 0 || index >= self->groups) {
--- 1486,1490 ----
static PyObject*
! match_getslice_by_index(MatchObject* self, int index)
{
if (index < 0 || index >= self->groups) {
***************
*** 1455,1459 ****
static int
! getindex(MatchObject* self, PyObject* index)
{
if (!PyInt_Check(index) && self->pattern->groupindex != NULL) {
--- 1509,1513 ----
static int
! match_getindex(MatchObject* self, PyObject* index)
{
if (!PyInt_Check(index) && self->pattern->groupindex != NULL) {
***************
*** 1471,1481 ****
static PyObject*
! getslice(MatchObject* self, PyObject* index)
{
! return getslice_by_index(self, getindex(self, index));
}
static PyObject*
! _match_group(MatchObject* self, PyObject* args)
{
PyObject* result;
--- 1525,1535 ----
static PyObject*
! match_getslice(MatchObject* self, PyObject* index)
{
! return match_getslice_by_index(self, match_getindex(self, index));
}
static PyObject*
! match_group(MatchObject* self, PyObject* args)
{
PyObject* result;
***************
*** 1486,1493 ****
switch (size) {
case 0:
! result = getslice(self, Py_False); /* force error */
break;
case 1:
! result = getslice(self, PyTuple_GET_ITEM(args, 0));
break;
default:
--- 1540,1547 ----
switch (size) {
case 0:
! result = match_getslice(self, Py_False);
break;
case 1:
! result = match_getslice(self, PyTuple_GET_ITEM(args, 0));
break;
default:
***************
*** 1497,1501 ****
return NULL;
for (i = 0; i < size; i++) {
! PyObject* item = getslice(self, PyTuple_GET_ITEM(args, i));
if (!item) {
Py_DECREF(result);
--- 1551,1555 ----
return NULL;
for (i = 0; i < size; i++) {
! PyObject* item = match_getslice(self, PyTuple_GET_ITEM(args, i));
if (!item) {
Py_DECREF(result);
***************
*** 1510,1514 ****
static PyObject*
! _match_groups(MatchObject* self, PyObject* args)
{
PyObject* result;
--- 1564,1568 ----
static PyObject*
! match_groups(MatchObject* self, PyObject* args)
{
PyObject* result;
***************
*** 1524,1528 ****
PyObject* item;
/* FIXME: <fl> handle default! */
! item = getslice_by_index(self, index);
if (!item) {
Py_DECREF(result);
--- 1578,1582 ----
PyObject* item;
/* FIXME: <fl> handle default! */
! item = match_getslice_by_index(self, index);
if (!item) {
Py_DECREF(result);
***************
*** 1536,1540 ****
static PyObject*
! _match_groupdict(MatchObject* self, PyObject* args)
{
PyObject* result;
--- 1590,1594 ----
static PyObject*
! match_groupdict(MatchObject* self, PyObject* args)
{
PyObject* result;
***************
*** 1563,1567 ****
return NULL;
}
! item = getslice(self, key);
if (!item) {
Py_DECREF(key);
--- 1617,1621 ----
return NULL;
}
! item = match_getslice(self, key);
if (!item) {
Py_DECREF(key);
***************
*** 1580,1584 ****
static PyObject*
! _match_start(MatchObject* self, PyObject* args)
{
int index;
--- 1634,1638 ----
static PyObject*
! match_start(MatchObject* self, PyObject* args)
{
int index;
***************
*** 1588,1592 ****
return NULL;
! index = getindex(self, index_);
if (index < 0 || index >= self->groups) {
--- 1642,1646 ----
return NULL;
! index = match_getindex(self, index_);
if (index < 0 || index >= self->groups) {
***************
*** 1607,1611 ****
static PyObject*
! _match_end(MatchObject* self, PyObject* args)
{
int index;
--- 1661,1665 ----
static PyObject*
! match_end(MatchObject* self, PyObject* args)
{
int index;
***************
*** 1615,1619 ****
return NULL;
! index = getindex(self, index_);
if (index < 0 || index >= self->groups) {
--- 1669,1673 ----
return NULL;
! index = match_getindex(self, index_);
if (index < 0 || index >= self->groups) {
***************
*** 1634,1638 ****
static PyObject*
! _match_span(MatchObject* self, PyObject* args)
{
int index;
--- 1688,1692 ----
static PyObject*
! match_span(MatchObject* self, PyObject* args)
{
int index;
***************
*** 1642,1646 ****
return NULL;
! index = getindex(self, index_);
if (index < 0 || index >= self->groups) {
--- 1696,1700 ----
return NULL;
! index = match_getindex(self, index_);
if (index < 0 || index >= self->groups) {
***************
*** 1661,1680 ****
}
! static PyMethodDef _match_methods[] = {
! {"group", (PyCFunction) _match_group, 1},
! {"start", (PyCFunction) _match_start, 1},
! {"end", (PyCFunction) _match_end, 1},
! {"span", (PyCFunction) _match_span, 1},
! {"groups", (PyCFunction) _match_groups, 1},
! {"groupdict", (PyCFunction) _match_groupdict, 1},
{NULL, NULL}
};
static PyObject*
! _match_getattr(MatchObject* self, char* name)
{
PyObject* res;
! res = Py_FindMethod(_match_methods, (PyObject*) self, name);
if (res)
return res;
--- 1715,1734 ----
}
! static PyMethodDef match_methods[] = {
! {"group", (PyCFunction) match_group, 1},
! {"start", (PyCFunction) match_start, 1},
! {"end", (PyCFunction) match_end, 1},
! {"span", (PyCFunction) match_span, 1},
! {"groups", (PyCFunction) match_groups, 1},
! {"groupdict", (PyCFunction) match_groupdict, 1},
{NULL, NULL}
};
static PyObject*
! match_getattr(MatchObject* self, char* name)
{
PyObject* res;
! res = Py_FindMethod(match_methods, (PyObject*) self, name);
if (res)
return res;
***************
*** 1711,1717 ****
sizeof(MatchObject), /* size of basic object */
sizeof(int), /* space for group item */
! (destructor)_match_dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc)_match_getattr, /*tp_getattr*/
};
--- 1765,1771 ----
sizeof(MatchObject), /* size of basic object */
sizeof(int), /* space for group item */
! (destructor)match_dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc)match_getattr, /*tp_getattr*/
};
***************
*** 1720,1726 ****
static void
! _cursor_dealloc(CursorObject* self)
{
! _stack_free(&self->state);
Py_DECREF(self->string);
Py_DECREF(self->pattern);
--- 1774,1780 ----
static void
! cursor_dealloc(CursorObject* self)
{
! state_fini(&self->state);
Py_DECREF(self->string);
Py_DECREF(self->pattern);
***************
*** 1729,1733 ****
static PyObject*
! _cursor_match(CursorObject* self, PyObject* args)
{
SRE_STATE* state = &self->state;
--- 1783,1787 ----
static PyObject*
! cursor_match(CursorObject* self, PyObject* args)
{
SRE_STATE* state = &self->state;
***************
*** 1745,1749 ****
}
! match = _pattern_new_match((PatternObject*) self->pattern,
state, self->string, status);
--- 1799,1803 ----
}
! match = pattern_new_match((PatternObject*) self->pattern,
state, self->string, status);
***************
*** 1758,1762 ****
static PyObject*
! _cursor_search(CursorObject* self, PyObject* args)
{
SRE_STATE* state = &self->state;
--- 1812,1816 ----
static PyObject*
! cursor_search(CursorObject* self, PyObject* args)
{
SRE_STATE* state = &self->state;
***************
*** 1774,1778 ****
}
! match = _pattern_new_match((PatternObject*) self->pattern,
state, self->string, status);
--- 1828,1832 ----
}
! match = pattern_new_match((PatternObject*) self->pattern,
state, self->string, status);
***************
*** 1783,1798 ****
}
! static PyMethodDef _cursor_methods[] = {
! {"match", (PyCFunction) _cursor_match, 0},
! {"search", (PyCFunction) _cursor_search, 0},
{NULL, NULL}
};
static PyObject*
! _cursor_getattr(CursorObject* self, char* name)
{
PyObject* res;
! res = Py_FindMethod(_cursor_methods, (PyObject*) self, name);
if (res)
return res;
--- 1837,1852 ----
}
! static PyMethodDef cursor_methods[] = {
! {"match", (PyCFunction) cursor_match, 0},
! {"search", (PyCFunction) cursor_search, 0},
{NULL, NULL}
};
static PyObject*
! cursor_getattr(CursorObject* self, char* name)
{
PyObject* res;
! res = Py_FindMethod(cursor_methods, (PyObject*) self, name);
if (res)
return res;
***************
*** 1815,1821 ****
sizeof(CursorObject), /* size of basic object */
0,
! (destructor)_cursor_dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc)_cursor_getattr, /*tp_getattr*/
};
--- 1869,1875 ----
sizeof(CursorObject), /* size of basic object */
0,
! (destructor)cursor_dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc)cursor_getattr, /*tp_getattr*/
};
Index: sre.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/sre.h,v
retrieving revision 2.5
retrieving revision 2.6
diff -C2 -r2.5 -r2.6
- Previous message: [Python-checkins] CVS: python/dist/src/Lib sre.py,1.8,1.9 sre_compile.py,1.6,1.7 sre_constants.py,1.6,1.7 sre_parse.py,1.6,1.7
- Next message: [Python-checkins] CVS: python/dist/src/Modules _sre.c,2.7,2.8 sre.h,2.6,2.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]