Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(149300)

Side by Side Diff: Modules/_sre.c

Issue 10076: Regex objects became uncopyable in 2.5
Patch Set: Created 9 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Misc/NEWS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Secret Labs' Regular Expression Engine 2 * Secret Labs' Regular Expression Engine
3 * 3 *
4 * regular expression matching engine 4 * regular expression matching engine
5 * 5 *
6 * partial history: 6 * partial history:
7 * 1999-10-24 fl created (based on existing template matcher code) 7 * 1999-10-24 fl created (based on existing template matcher code)
8 * 2000-03-06 fl first alpha, sort of 8 * 2000-03-06 fl first alpha, sort of
9 * 2000-08-01 fl fixes for 1.6b1 9 * 2000-08-01 fl fixes for 1.6b1
10 * 2000-08-07 fl use PyOS_CheckStack() if available 10 * 2000-08-07 fl use PyOS_CheckStack() if available
(...skipping 2470 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 PyObject* string; 2481 PyObject* string;
2482 Py_ssize_t count = 0; 2482 Py_ssize_t count = 0;
2483 static char* kwlist[] = { "repl", "string", "count", NULL }; 2483 static char* kwlist[] = { "repl", "string", "count", NULL };
2484 if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|n:subn", kwlist, 2484 if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|n:subn", kwlist,
2485 &ptemplate, &string, &count)) 2485 &ptemplate, &string, &count))
2486 return NULL; 2486 return NULL;
2487 2487
2488 return pattern_subx(self, ptemplate, string, count, 1); 2488 return pattern_subx(self, ptemplate, string, count, 1);
2489 } 2489 }
2490 2490
2491 #ifdef USE_BUILTIN_COPY
2491 static PyObject* 2492 static PyObject*
2492 pattern_copy(PatternObject* self, PyObject *unused) 2493 pattern_copy(PatternObject* self, PyObject *unused)
2493 { 2494 {
2494 #ifdef USE_BUILTIN_COPY
2495 PatternObject* copy; 2495 PatternObject* copy;
2496 int offset; 2496 int offset;
2497 2497
2498 copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize); 2498 copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize);
2499 if (!copy) 2499 if (!copy)
2500 return NULL; 2500 return NULL;
2501 2501
2502 offset = offsetof(PatternObject, groups); 2502 offset = offsetof(PatternObject, groups);
2503 2503
2504 Py_XINCREF(self->groupindex); 2504 Py_XINCREF(self->groupindex);
2505 Py_XINCREF(self->indexgroup); 2505 Py_XINCREF(self->indexgroup);
2506 Py_XINCREF(self->pattern); 2506 Py_XINCREF(self->pattern);
2507 2507
2508 memcpy((char*) copy + offset, (char*) self + offset, 2508 memcpy((char*) copy + offset, (char*) self + offset,
2509 sizeof(PatternObject) + self->codesize * sizeof(SRE_CODE) - offset); 2509 sizeof(PatternObject) + self->codesize * sizeof(SRE_CODE) - offset);
2510 copy->weakreflist = NULL; 2510 copy->weakreflist = NULL;
2511 2511
2512 return (PyObject*) copy; 2512 return (PyObject*) copy;
2513 #else 2513 }
2514 PyErr_SetString(PyExc_TypeError, "cannot copy this pattern object");
2515 return NULL;
2516 #endif 2514 #endif
2517 }
2518 2515
2516 #ifdef USE_BUILTIN_COPY
2519 static PyObject* 2517 static PyObject*
2520 pattern_deepcopy(PatternObject* self, PyObject* memo) 2518 pattern_deepcopy(PatternObject* self, PyObject* memo)
2521 { 2519 {
2522 #ifdef USE_BUILTIN_COPY
2523 PatternObject* copy; 2520 PatternObject* copy;
2524 2521
2525 copy = (PatternObject*) pattern_copy(self); 2522 copy = (PatternObject*) pattern_copy(self);
2526 if (!copy) 2523 if (!copy)
2527 return NULL; 2524 return NULL;
2528 2525
2529 if (!deepcopy(&copy->groupindex, memo) || 2526 if (!deepcopy(&copy->groupindex, memo) ||
2530 !deepcopy(&copy->indexgroup, memo) || 2527 !deepcopy(&copy->indexgroup, memo) ||
2531 !deepcopy(&copy->pattern, memo)) { 2528 !deepcopy(&copy->pattern, memo)) {
2532 Py_DECREF(copy); 2529 Py_DECREF(copy);
2533 return NULL; 2530 return NULL;
2534 } 2531 }
2535 2532 }
2536 #else
2537 PyErr_SetString(PyExc_TypeError, "cannot deepcopy this pattern object");
2538 return NULL;
2539 #endif 2533 #endif
2540 }
2541 2534
2542 PyDoc_STRVAR(pattern_match_doc, 2535 PyDoc_STRVAR(pattern_match_doc,
2543 "match(string[, pos[, endpos]]) --> match object or None.\n\ 2536 "match(string[, pos[, endpos]]) --> match object or None.\n\
2544 Matches zero or more characters at the beginning of the string"); 2537 Matches zero or more characters at the beginning of the string");
2545 2538
2546 PyDoc_STRVAR(pattern_search_doc, 2539 PyDoc_STRVAR(pattern_search_doc,
2547 "search(string[, pos[, endpos]]) --> match object or None.\n\ 2540 "search(string[, pos[, endpos]]) --> match object or None.\n\
2548 Scan through string looking for a match, and return a corresponding\n\ 2541 Scan through string looking for a match, and return a corresponding\n\
2549 MatchObject instance. Return None if no position in the string matches."); 2542 MatchObject instance. Return None if no position in the string matches.");
2550 2543
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 pattern_subn_doc}, 2579 pattern_subn_doc},
2587 {"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS, 2580 {"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS,
2588 pattern_split_doc}, 2581 pattern_split_doc},
2589 {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS, 2582 {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS,
2590 pattern_findall_doc}, 2583 pattern_findall_doc},
2591 #if PY_VERSION_HEX >= 0x02020000 2584 #if PY_VERSION_HEX >= 0x02020000
2592 {"finditer", (PyCFunction) pattern_finditer, METH_VARARGS, 2585 {"finditer", (PyCFunction) pattern_finditer, METH_VARARGS,
2593 pattern_finditer_doc}, 2586 pattern_finditer_doc},
2594 #endif 2587 #endif
2595 {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS}, 2588 {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
2589 #ifdef USE_BUILTIN_COPY
2596 {"__copy__", (PyCFunction) pattern_copy, METH_NOARGS}, 2590 {"__copy__", (PyCFunction) pattern_copy, METH_NOARGS},
2597 {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O}, 2591 {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O},
2592 #endif
2598 {NULL, NULL} 2593 {NULL, NULL}
2599 }; 2594 };
2600 2595
2601 static PyObject* 2596 static PyObject*
2602 pattern_getattr(PatternObject* self, char* name) 2597 pattern_getattr(PatternObject* self, char* name)
2603 { 2598 {
2604 PyObject* res; 2599 PyObject* res;
2605 2600
2606 res = Py_FindMethod(pattern_methods, (PyObject*) self, name); 2601 res = Py_FindMethod(pattern_methods, (PyObject*) self, name);
2607 2602
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after
3901 if (x) { 3896 if (x) {
3902 PyDict_SetItemString(d, "copyright", x); 3897 PyDict_SetItemString(d, "copyright", x);
3903 Py_DECREF(x); 3898 Py_DECREF(x);
3904 } 3899 }
3905 } 3900 }
3906 3901
3907 #endif /* !defined(SRE_RECURSIVE) */ 3902 #endif /* !defined(SRE_RECURSIVE) */
3908 3903
3909 /* vim:ts=4:sw=4:et 3904 /* vim:ts=4:sw=4:et
3910 */ 3905 */
OLDNEW
« no previous file with comments | « Misc/NEWS ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+