diff options
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r-- | Modules/_sre.c | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index 5bcc387..99c3cd5 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -70,10 +70,6 @@ static char copyright[] = /* enables copy/deepcopy handling (work in progress) */ #undef USE_BUILTIN_COPY -#if PY_VERSION_HEX < 0x01060000 -#define PyObject_DEL(op) PyMem_DEL((op)) -#endif - /* -------------------------------------------------------------------- */ #if defined(_MSC_VER) @@ -804,7 +800,7 @@ entrance: if (ctx->pattern[0] == SRE_OP_INFO) { /* optimization info block */ /* <INFO> <1=skip> <2=flags> <3=min> ... */ - if (ctx->pattern[3] && (end - ctx->ptr)/state->charsize < ctx->pattern[3]) { + if (ctx->pattern[3] && (Py_uintptr_t)(end - ctx->ptr)/state->charsize < ctx->pattern[3]) { TRACE(("reject (got %" PY_FORMAT_SIZE_T "d chars, " "need %" PY_FORMAT_SIZE_T "d)\n", (end - ctx->ptr)/state->charsize, @@ -1880,7 +1876,7 @@ static PyObject* pattern_match(PatternObject* self, PyObject* args, PyObject* kw) { SRE_STATE state; - int status; + Py_ssize_t status; PyObject* string; Py_ssize_t start = 0; @@ -2002,10 +1998,8 @@ join_list(PyObject* list, PyObject* string) /* join list elements */ PyObject* joiner; -#if PY_VERSION_HEX >= 0x01060000 PyObject* function; PyObject* args; -#endif PyObject* result; joiner = PySequence_GetSlice(string, 0, 0); @@ -2017,7 +2011,6 @@ join_list(PyObject* list, PyObject* string) return joiner; } -#if PY_VERSION_HEX >= 0x01060000 function = PyObject_GetAttrString(joiner, "join"); if (!function) { Py_DECREF(joiner); @@ -2033,12 +2026,6 @@ join_list(PyObject* list, PyObject* string) result = PyObject_CallObject(function, args); Py_DECREF(args); /* also removes list */ Py_DECREF(function); -#else - result = call( - "string", "join", - PyTuple_Pack(2, list, joiner) - ); -#endif Py_DECREF(joiner); return result; @@ -2049,7 +2036,7 @@ pattern_findall(PatternObject* self, PyObject* args, PyObject* kw) { SRE_STATE state; PyObject* list; - int status; + Py_ssize_t status; Py_ssize_t i, b, e; PyObject* string; @@ -2145,7 +2132,6 @@ error: } -#if PY_VERSION_HEX >= 0x02020000 static PyObject* pattern_finditer(PatternObject* pattern, PyObject* args, PyObject* kw) { @@ -2167,7 +2153,6 @@ pattern_finditer(PatternObject* pattern, PyObject* args, PyObject* kw) return iterator; } -#endif static PyObject* pattern_split(PatternObject* self, PyObject* args, PyObject* kw) @@ -2175,7 +2160,7 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw) SRE_STATE state; PyObject* list; PyObject* item; - int status; + Py_ssize_t status; Py_ssize_t n; Py_ssize_t i; void* last; @@ -2291,7 +2276,7 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string, PyObject* args; PyObject* match; void* ptr; - int status; + Py_ssize_t status; Py_ssize_t n; Py_ssize_t i, b, e; int logical_charsize, charsize; @@ -2310,7 +2295,7 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string, ptr = getstring(ptemplate, &n, &logical_charsize, &charsize, &view); b = charsize; if (ptr) { - literal = sre_literal_template(b, ptr, n); + literal = sre_literal_template(charsize, ptr, n); } else { PyErr_Clear(); literal = 0; @@ -2590,10 +2575,8 @@ static PyMethodDef pattern_methods[] = { pattern_split_doc}, {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS, pattern_findall_doc}, -#if PY_VERSION_HEX >= 0x02020000 {"finditer", (PyCFunction) pattern_finditer, METH_VARARGS|METH_KEYWORDS, pattern_finditer_doc}, -#endif {"scanner", (PyCFunction) pattern_scanner, METH_VARARGS|METH_KEYWORDS}, {"__copy__", (PyCFunction) pattern_copy, METH_NOARGS}, {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O}, @@ -2788,7 +2771,7 @@ _compile(PyObject* self_, PyObject* args) skip = *code; \ VTRACE(("%lu (skip to %p)\n", \ (unsigned long)skip, code+skip)); \ - if (skip-adj > end-code) \ + if (skip-adj > (Py_uintptr_t)(end - code)) \ FAIL; \ code++; \ } while (0) @@ -2821,7 +2804,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end) case SRE_OP_CHARSET: offset = 32/sizeof(SRE_CODE); /* 32-byte bitmap */ - if (offset > end-code) + if (offset > (Py_uintptr_t)(end - code)) FAIL; code += offset; break; @@ -2829,7 +2812,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 > end-code) + if (offset > (Py_uintptr_t)(end - code)) FAIL; /* Make sure that each byte points to a valid block */ for (i = 0; i < 256; i++) { @@ -2838,7 +2821,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end) } code += offset; offset = arg * 32/sizeof(SRE_CODE); /* 32-byte bitmap times arg */ - if (offset > end-code) + if (offset > (Py_uintptr_t)(end - code)) FAIL; code += offset; break; @@ -2901,7 +2884,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups) sre_match() code is robust even if they don't, and the worst you can get is nonsensical match results. */ GET_ARG; - if (arg > 2*groups+1) { + if (arg > 2 * (size_t)groups + 1) { VTRACE(("arg=%d, groups=%d\n", (int)arg, (int)groups)); FAIL; } @@ -2989,11 +2972,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 > newcode-code) + if (prefix_len > (Py_uintptr_t)(newcode - code)) FAIL; code += prefix_len; /* And here comes the overlap table */ - if (prefix_len > newcode-code) + if (prefix_len > (Py_uintptr_t)(newcode - code)) FAIL; /* Each overlap value should be < prefix_len */ for (i = 0; i < prefix_len; i++) { @@ -3084,7 +3067,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups) case SRE_OP_GROUPREF: case SRE_OP_GROUPREF_IGNORE: GET_ARG; - if (arg >= groups) + if (arg >= (size_t)groups) FAIL; break; @@ -3093,7 +3076,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups) 'group' is either an integer group number or a group name, 'then' and 'else' are sub-regexes, and 'else' is optional. */ GET_ARG; - if (arg >= groups) + if (arg >= (size_t)groups) FAIL; GET_SKIP_ADJ(1); code--; /* The skip is relative to the first arg! */ @@ -3122,7 +3105,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 < end-code && + if (skip >= 3 && skip-3 < (Py_uintptr_t)(end - code) && code[skip-3] == SRE_OP_JUMP) { VTRACE(("both then and else parts present\n")); @@ -3776,7 +3759,7 @@ scanner_match(ScannerObject* self, PyObject *unused) { SRE_STATE* state = &self->state; PyObject* match; - int status; + Py_ssize_t status; state_reset(state); @@ -3807,7 +3790,7 @@ scanner_search(ScannerObject* self, PyObject *unused) { SRE_STATE* state = &self->state; PyObject* match; - int status; + Py_ssize_t status; state_reset(state); |