[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.9,2.10 sre.h,2.8,2.9
Fredrik Lundh
python-dev@python.org
Thu, 29 Jun 2000 09:57:42 -0700
- Previous message: [Python-checkins] CVS: python/dist/src/Lib sre.py,1.11,1.12 sre_compile.py,1.9,1.10 sre_constants.py,1.9,1.10 sre_parse.py,1.9,1.10
- Next message: [Python-checkins] CVS: python/dist/src/Lib/test test_socket.py,1.13,1.14
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv8292/Modules
Modified Files:
_sre.c sre.h
Log Message:
- fixed split
(test_sre still complains about split, but that's caused by
the group reset bug, not split itself)
- added more mark slots
(should be dynamically allocated, but 100 is better than 32.
and checking for the upper limit is better than overwriting
the memory ;-)
- internal: renamed the cursor helper class
- internal: removed some bloat from sre_compile
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.9
retrieving revision 2.10
diff -C2 -r2.9 -r2.10
*** _sre.c 2000/06/29 12:48:37 2.9
--- _sre.c 2000/06/29 16:57:40 2.10
***************
*** 15,23 ****
* 00-03-14 fl removed most compatibility stuff (0.6)
* 00-05-10 fl towards third alpha (0.8.2)
! * 00-05-13 fl added experimental cursor stuff (0.8.3)
* 00-05-27 fl final bug hunt (0.8.4)
* 00-06-21 fl less bugs, more taste (0.8.5)
* 00-06-25 fl major changes to better deal with nested repeats (0.9)
* 00-06-28 fl fixed findall (0.9.1)
*
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
--- 15,24 ----
* 00-03-14 fl removed most compatibility stuff (0.6)
* 00-05-10 fl towards third alpha (0.8.2)
! * 00-05-13 fl added experimental scanner stuff (0.8.3)
* 00-05-27 fl final bug hunt (0.8.4)
* 00-06-21 fl less bugs, more taste (0.8.5)
* 00-06-25 fl major changes to better deal with nested repeats (0.9)
* 00-06-28 fl fixed findall (0.9.1)
+ * 00-06-29 fl fixed split, added more scanner features (0.9.2)
*
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
***************
*** 385,389 ****
/* FIXME: this is a hack! */
! void* mark_copy[64];
void* mark = NULL;
--- 386,390 ----
/* FIXME: this is a hack! */
! void* mark_copy[SRE_MARK_SIZE];
void* mark = NULL;
***************
*** 955,959 ****
staticforward PyTypeObject Pattern_Type;
staticforward PyTypeObject Match_Type;
! staticforward PyTypeObject Cursor_Type;
static PyObject *
--- 956,960 ----
staticforward PyTypeObject Pattern_Type;
staticforward PyTypeObject Match_Type;
! staticforward PyTypeObject Scanner_Type;
static PyObject *
***************
*** 1075,1079 ****
/* FIXME: dynamic! */
! for (i = 0; i < 64; i++)
state->mark[i] = NULL;
--- 1076,1080 ----
/* FIXME: dynamic! */
! for (i = 0; i < SRE_MARK_SIZE; i++)
state->mark[i] = NULL;
***************
*** 1177,1189 ****
static PyObject*
! pattern_cursor(PatternObject* pattern, PyObject* args)
{
/* create search state object */
! CursorObject* self;
PyObject* string;
/* create match object (with room for extra group marks) */
! self = PyObject_NEW(CursorObject, &Cursor_Type);
if (self == NULL)
return NULL;
--- 1178,1190 ----
static PyObject*
! pattern_scanner(PatternObject* pattern, PyObject* args)
{
/* create search state object */
! ScannerObject* self;
PyObject* string;
/* create match object (with room for extra group marks) */
! self = PyObject_NEW(ScannerObject, &Scanner_Type);
if (self == NULL)
return NULL;
***************
*** 1432,1436 ****
{"findall", (PyCFunction) pattern_findall, 1},
/* experimental */
! {"cursor", (PyCFunction) pattern_cursor, 1},
{NULL, NULL}
};
--- 1433,1437 ----
{"findall", (PyCFunction) pattern_findall, 1},
/* experimental */
! {"scanner", (PyCFunction) pattern_scanner, 1},
{NULL, NULL}
};
***************
*** 1468,1472 ****
statichere PyTypeObject Pattern_Type = {
PyObject_HEAD_INIT(NULL)
! 0, "Pattern", sizeof(PatternObject), 0,
(destructor)pattern_dealloc, /*tp_dealloc*/
0, /*tp_print*/
--- 1469,1473 ----
statichere PyTypeObject Pattern_Type = {
PyObject_HEAD_INIT(NULL)
! 0, "SRE_Pattern", sizeof(PatternObject), 0,
(destructor)pattern_dealloc, /*tp_dealloc*/
0, /*tp_print*/
***************
*** 1762,1766 ****
statichere PyTypeObject Match_Type = {
PyObject_HEAD_INIT(NULL)
! 0, "Match",
sizeof(MatchObject), /* size of basic object */
sizeof(int), /* space for group item */
--- 1763,1767 ----
statichere PyTypeObject Match_Type = {
PyObject_HEAD_INIT(NULL)
! 0, "SRE_Match",
sizeof(MatchObject), /* size of basic object */
sizeof(int), /* space for group item */
***************
*** 1771,1778 ****
/* -------------------------------------------------------------------- */
! /* cursor methods (experimental) */
static void
! cursor_dealloc(CursorObject* self)
{
state_fini(&self->state);
--- 1772,1779 ----
/* -------------------------------------------------------------------- */
! /* scanner methods (experimental) */
static void
! scanner_dealloc(ScannerObject* self)
{
state_fini(&self->state);
***************
*** 1783,1787 ****
static PyObject*
! cursor_match(CursorObject* self, PyObject* args)
{
SRE_STATE* state = &self->state;
--- 1784,1788 ----
static PyObject*
! scanner_match(ScannerObject* self, PyObject* args)
{
SRE_STATE* state = &self->state;
***************
*** 1812,1816 ****
static PyObject*
! cursor_search(CursorObject* self, PyObject* args)
{
SRE_STATE* state = &self->state;
--- 1813,1817 ----
static PyObject*
! scanner_search(ScannerObject* self, PyObject* args)
{
SRE_STATE* state = &self->state;
***************
*** 1831,1835 ****
state, self->string, status);
! if (status >= 0)
state->start = state->ptr;
--- 1832,1838 ----
state, self->string, status);
! if (status == 0 || state->ptr == state->start)
! state->start = (void*) ((char*) state->ptr + state->charsize);
! else
state->start = state->ptr;
***************
*** 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;
--- 1840,1855 ----
}
! static PyMethodDef scanner_methods[] = {
! {"match", (PyCFunction) scanner_match, 0},
! {"search", (PyCFunction) scanner_search, 0},
{NULL, NULL}
};
static PyObject*
! scanner_getattr(ScannerObject* self, char* name)
{
PyObject* res;
! res = Py_FindMethod(scanner_methods, (PyObject*) self, name);
if (res)
return res;
***************
*** 1860,1875 ****
}
PyErr_SetString(PyExc_AttributeError, name);
return NULL;
}
! statichere PyTypeObject Cursor_Type = {
PyObject_HEAD_INIT(NULL)
! 0, "Cursor",
! sizeof(CursorObject), /* size of basic object */
0,
! (destructor)cursor_dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc)cursor_getattr, /*tp_getattr*/
};
--- 1863,1881 ----
}
+ if (!strcmp(name, "groups"))
+ return Py_BuildValue("i", ((PatternObject*) self->pattern)->groups);
+
PyErr_SetString(PyExc_AttributeError, name);
return NULL;
}
! statichere PyTypeObject Scanner_Type = {
PyObject_HEAD_INIT(NULL)
! 0, "SRE_Scanner",
! sizeof(ScannerObject), /* size of basic object */
0,
! (destructor)scanner_dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc)scanner_getattr, /*tp_getattr*/
};
***************
*** 1889,1893 ****
/* Patch object types */
Pattern_Type.ob_type = Match_Type.ob_type =
! Cursor_Type.ob_type = &PyType_Type;
Py_InitModule("_" MODULE, _functions);
--- 1895,1899 ----
/* Patch object types */
Pattern_Type.ob_type = Match_Type.ob_type =
! Scanner_Type.ob_type = &PyType_Type;
Py_InitModule("_" MODULE, _functions);
Index: sre.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/sre.h,v
retrieving revision 2.8
retrieving revision 2.9
diff -C2 -r2.8 -r2.9
*** sre.h 2000/06/29 12:48:37 2.8
--- sre.h 2000/06/29 16:57:40 2.9
***************
*** 47,50 ****
--- 47,53 ----
} SRE_STACK;
+ /* FIXME: <fl> shouldn't be a constant, really... */
+ #define SRE_MARK_SIZE 200
+
typedef struct {
/* string pointers */
***************
*** 57,61 ****
/* registers */
int lastmark;
! void* mark[64]; /* FIXME: <fl> should be dynamically allocated! */
/* backtracking stack */
SRE_STACK* stack;
--- 60,64 ----
/* registers */
int lastmark;
! void* mark[SRE_MARK_SIZE];
/* backtracking stack */
SRE_STACK* stack;
***************
*** 67,76 ****
typedef struct {
! /* search helper */
PyObject_HEAD
PyObject* pattern;
PyObject* string;
SRE_STATE state;
! } CursorObject;
#endif
--- 70,79 ----
typedef struct {
! /* scanner (internal helper object) */
PyObject_HEAD
PyObject* pattern;
PyObject* string;
SRE_STATE state;
! } ScannerObject;
#endif
- Previous message: [Python-checkins] CVS: python/dist/src/Lib sre.py,1.11,1.12 sre_compile.py,1.9,1.10 sre_constants.py,1.9,1.10 sre_parse.py,1.9,1.10
- Next message: [Python-checkins] CVS: python/dist/src/Lib/test test_socket.py,1.13,1.14
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]