[Python-checkins] CVS: python/dist/src/Modules _sre.c,2.55,2.56 sre.h,2.20,2.21

Fredrik Lundh effbot@users.sourceforge.net
2001年7月02日 09:42:52 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv29536/Modules
Modified Files:
	_sre.c sre.h 
Log Message:
merged with pythonware's SRE 2.1.1 codebase
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.55
retrieving revision 2.56
diff -C2 -r2.55 -r2.56
*** _sre.c	2001年04月15日 19:00:58	2.55
--- _sre.c	2001年07月02日 16:42:49	2.56
***************
*** 29,32 ****
--- 29,34 ----
 * 2001年03月20日 fl lots of fixes for 2.1b2
 * 2001年04月15日 fl export copyright as Python attribute, not global
+ * 2001年04月28日 fl added __copy__ methods (work in progress)
+ * 2001年05月14日 fl fixes for 1.5.2
 *
 * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
***************
*** 44,50 ****
 
 static char copyright[] =
! " SRE 2.1b2 Copyright (c) 1997-2001 by Secret Labs AB ";
 
 #include "Python.h"
 
 #include "sre.h"
--- 46,53 ----
 
 static char copyright[] =
! " SRE 2.1.1 Copyright (c) 1997-2001 by Secret Labs AB ";
 
 #include "Python.h"
+ #include "structmember.h" /* offsetof */
 
 #include "sre.h"
***************
*** 87,90 ****
--- 90,96 ----
 #undef USE_INLINE
 
+ /* enables copy/deepcopy handling (work in progress) */
+ #undef USE_BUILTIN_COPY
+ 
 #if PY_VERSION_HEX < 0x01060000
 #define PyObject_DEL(op) PyMem_DEL((op))
***************
*** 445,448 ****
--- 451,455 ----
 return this == that;
 
+ #if defined(HAVE_UNICODE)
 case SRE_AT_UNI_BOUNDARY:
 if (state->beginning == state->end)
***************
*** 462,465 ****
--- 469,474 ----
 SRE_UNI_IS_WORD((int) ptr[0]) : 0;
 return this == that;
+ #endif
+ 
 }
 
***************
*** 1287,1290 ****
--- 1296,1301 ----
 return NULL;
 
+ self->codesize = n;
+ 
 for (i = 0; i < n; i++) {
 PyObject *o = PyList_GET_ITEM(code, i);
***************
*** 1845,1848 ****
--- 1856,1895 ----
 }
 
+ static PyObject*
+ pattern_copy(PatternObject* self, PyObject* args)
+ {
+ #if USE_BUILTIN_COPY
+ PatternObject* copy;
+ int offset;
+ 
+ /* work in progress */
+ 
+ copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize);
+ if (!copy)
+ return NULL;
+ 
+ offset = offsetof(PatternObject, groups);
+ 
+ Py_XINCREF(self->groupindex);
+ Py_XINCREF(self->indexgroup);
+ Py_XINCREF(self->pattern);
+ 
+ memcpy((char*) copy + offset, (char*) self + offset,
+ sizeof(PatternObject) + self->codesize * sizeof(SRE_CODE) - offset);
+ 
+ return (PyObject*) copy;
+ #else
+ PyErr_SetString(PyExc_TypeError, "cannot copy this pattern object");
+ return NULL;
+ #endif
+ }
+ 
+ static PyObject*
+ pattern_deepcopy(PatternObject* self, PyObject* args)
+ {
+ PyErr_SetString(PyExc_TypeError, "cannot deepcopy this pattern object");
+ return NULL;
+ }
+ 
 static PyMethodDef pattern_methods[] = {
 {"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS},
***************
*** 1852,1857 ****
 {"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS},
 {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS},
- /* experimental */
 {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
 {NULL, NULL}
 };
--- 1899,1905 ----
 {"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS},
 {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS},
 {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
+ {"__copy__", (PyCFunction) pattern_copy, METH_VARARGS},
+ {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_VARARGS},
 {NULL, NULL}
 };
***************
*** 2212,2215 ****
--- 2260,2303 ----
 }
 
+ static PyObject*
+ match_copy(MatchObject* self, PyObject* args)
+ {
+ #if USE_BUILTIN_COPY
+ MatchObject* copy;
+ int slots, offset;
+ 
+ /* works in progress */
+ 
+ slots = 2 * (self->pattern->groups+1);
+ 
+ copy = PyObject_NEW_VAR(MatchObject, &Match_Type, slots);
+ if (!copy)
+ return NULL;
+ 
+ /* this value a constant, but any compiler should be able to
+ figure that out all by itself */
+ offset = offsetof(MatchObject, string);
+ 
+ Py_XINCREF(self->pattern);
+ Py_XINCREF(self->string);
+ Py_XINCREF(self->regs);
+ 
+ memcpy((char*) copy + offset, (char*) self + offset,
+ sizeof(MatchObject) + slots * sizeof(int) - offset);
+ 
+ return (PyObject*) copy;
+ #else
+ PyErr_SetString(PyExc_TypeError, "cannot deepcopy this match object");
+ return NULL;
+ #endif
+ }
+ 
+ static PyObject*
+ match_deepcopy(MatchObject* self, PyObject* args)
+ {
+ PyErr_SetString(PyExc_TypeError, "cannot deepcopy this match object");
+ return NULL;
+ }
+ 
 static PyMethodDef match_methods[] = {
 {"group", (PyCFunction) match_group, METH_VARARGS},
***************
*** 2220,2223 ****
--- 2308,2313 ----
 {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS},
 {"expand", (PyCFunction) match_expand, METH_VARARGS},
+ {"__copy__", (PyCFunction) match_copy, METH_VARARGS},
+ {"__deepcopy__", (PyCFunction) match_deepcopy, METH_VARARGS},
 {NULL, NULL}
 };
Index: sre.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/sre.h,v
retrieving revision 2.20
retrieving revision 2.21
diff -C2 -r2.20 -r2.21
*** sre.h	2001年06月27日 18:59:43	2.20
--- sre.h	2001年07月02日 16:42:49	2.21
***************
*** 4,8 ****
 * regular expression matching engine
 *
! * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
 *
 * See the _sre.c file for information on usage and redistribution.
--- 4,8 ----
 * regular expression matching engine
 *
! * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
 *
 * See the _sre.c file for information on usage and redistribution.
***************
*** 22,28 ****
 #endif
 
 typedef struct {
 PyObject_VAR_HEAD
! int groups;
 PyObject* groupindex;
 PyObject* indexgroup;
--- 22,30 ----
 #endif
 
+ #define SRE_CODE unsigned short
+ 
 typedef struct {
 PyObject_VAR_HEAD
! int groups; /* must be first! */
 PyObject* groupindex;
 PyObject* indexgroup;
***************
*** 31,34 ****
--- 33,37 ----
 int flags; /* flags used when compiling pattern source */
 /* pattern code */
+ int codesize;
 SRE_CODE code[1];
 } PatternObject;
***************
*** 38,42 ****
 typedef struct {
 PyObject_VAR_HEAD
! PyObject* string; /* link to the target string */
 PyObject* regs; /* cached list of matching spans */
 PatternObject* pattern; /* link to the regex (pattern) object */
--- 41,45 ----
 typedef struct {
 PyObject_VAR_HEAD
! PyObject* string; /* link to the target string (must be first) */
 PyObject* regs; /* cached list of matching spans */
 PatternObject* pattern; /* link to the regex (pattern) object */

AltStyle によって変換されたページ (->オリジナル) /