diff options
Diffstat (limited to 'Modules/_sre.c')
| -rw-r--r-- | Modules/_sre.c | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index 09b5835..afa9099 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -35,7 +35,7 @@ * other compatibility work. */ -static char copyright[] = +static const char copyright[] = " SRE 2.2.2 Copyright (c) 1997-2002 by Secret Labs AB "; #define PY_SSIZE_T_CLEAN @@ -62,9 +62,6 @@ static char copyright[] = /* -------------------------------------------------------------------- */ /* optional features */ -/* enables fast searching */ -#define USE_FAST_SEARCH - /* enables copy/deepcopy handling (work in progress) */ #undef USE_BUILTIN_COPY @@ -717,7 +714,7 @@ _sre_SRE_Pattern_search_impl(PatternObject *self, PyObject *string, } static PyObject* -call(char* module, char* function, PyObject* args) +call(const char* module, const char* function, PyObject* args) { PyObject* name; PyObject* mod; @@ -1059,7 +1056,6 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string, PyObject* joiner; PyObject* item; PyObject* filter; - PyObject* args; PyObject* match; void* ptr; Py_ssize_t status; @@ -1161,13 +1157,7 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string, match = pattern_new_match(self, &state, 1); if (!match) goto error; - args = PyTuple_Pack(1, match); - if (!args) { - Py_DECREF(match); - goto error; - } - item = PyObject_CallObject(filter, args); - Py_DECREF(args); + item = _PyObject_CallArg1(filter, match); Py_DECREF(match); if (!item) goto error; @@ -1592,7 +1582,7 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags, skip = *code; \ VTRACE(("%lu (skip to %p)\n", \ (unsigned long)skip, code+skip)); \ - if (skip-adj > (Py_uintptr_t)(end - code)) \ + if (skip-adj > (uintptr_t)(end - code)) \ FAIL; \ code++; \ } while (0) @@ -1626,7 +1616,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end) case SRE_OP_CHARSET: offset = 256/SRE_CODE_BITS; /* 256-bit bitmap */ - if (offset > (Py_uintptr_t)(end - code)) + if (offset > (uintptr_t)(end - code)) FAIL; code += offset; break; @@ -1634,7 +1624,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end) case SRE_OP_BIGCHARSET: GET_ARG; /* Number of blocks */ offset = 256/sizeof(SRE_CODE); /* 256-byte table */ - if (offset > (Py_uintptr_t)(end - code)) + if (offset > (uintptr_t)(end - code)) FAIL; /* Make sure that each byte points to a valid block */ for (i = 0; i < 256; i++) { @@ -1643,7 +1633,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end) } code += offset; offset = arg * (256/SRE_CODE_BITS); /* 256-bit bitmap times arg */ - if (offset > (Py_uintptr_t)(end - code)) + if (offset > (uintptr_t)(end - code)) FAIL; code += offset; break; @@ -1794,11 +1784,11 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups) GET_ARG; prefix_len = arg; GET_ARG; /* Here comes the prefix string */ - if (prefix_len > (Py_uintptr_t)(newcode - code)) + if (prefix_len > (uintptr_t)(newcode - code)) FAIL; code += prefix_len; /* And here comes the overlap table */ - if (prefix_len > (Py_uintptr_t)(newcode - code)) + if (prefix_len > (uintptr_t)(newcode - code)) FAIL; /* Each overlap value should be < prefix_len */ for (i = 0; i < prefix_len; i++) { @@ -1927,7 +1917,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups) to allow arbitrary jumps anywhere in the code; so we just look for a JUMP opcode preceding our skip target. */ - if (skip >= 3 && skip-3 < (Py_uintptr_t)(end - code) && + if (skip >= 3 && skip-3 < (uintptr_t)(end - code) && code[skip-3] == SRE_OP_JUMP) { VTRACE(("both then and else parts present\n")); @@ -2052,8 +2042,9 @@ match_getindex(MatchObject* self, PyObject* index) /* Default value */ return 0; - if (PyLong_Check(index)) - return PyLong_AsSsize_t(index); + if (PyIndex_Check(index)) { + return PyNumber_AsSsize_t(index, NULL); + } i = -1; |
