From afea0dcf6e688f8edf68387c1516a9275d948a57 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 22 Nov 2016 23:04:39 +0100 Subject: Issue #28765: _sre.compile() now checks the type of groupindex and indexgroup groupindex must a dictionary and indexgroup must be a tuple. Previously, indexgroup was a list. Use a tuple to reduce the memory usage. --- Modules/_sre.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Modules/_sre.c') diff --git a/Modules/_sre.c b/Modules/_sre.c index 979e61fb53..6e14901101 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1438,8 +1438,8 @@ _sre.compile flags: int code: object(subclass_of='&PyList_Type') groups: Py_ssize_t - groupindex: object - indexgroup: object + groupindex: object(subclass_of='&PyDict_Type') + indexgroup: object(subclass_of='&PyTuple_Type') [clinic start generated code]*/ @@ -1447,7 +1447,7 @@ static PyObject * _sre_compile_impl(PyObject *module, PyObject *pattern, int flags, PyObject *code, Py_ssize_t groups, PyObject *groupindex, PyObject *indexgroup) -/*[clinic end generated code: output=ef9c2b3693776404 input=7d059ec8ae1edb85]*/ +/*[clinic end generated code: output=ef9c2b3693776404 input=0a68476dbbe5db30]*/ { /* "compile" pattern descriptor to pattern object */ -- cgit v1.2.1 From 40273ec4f37c65c13a09d0ac23b08c99ebe2f1a3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 5 Dec 2016 17:04:32 +0100 Subject: Issue #28858: Remove _PyObject_CallArg1() macro Replace _PyObject_CallArg1(func, arg) with PyObject_CallFunctionObjArgs(func, arg, NULL) Using the _PyObject_CallArg1() macro increases the usage of the C stack, which was unexpected and unwanted. PyObject_CallFunctionObjArgs() doesn't have this issue. --- Modules/_sre.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Modules/_sre.c') diff --git a/Modules/_sre.c b/Modules/_sre.c index 6e14901101..438849483f 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1157,7 +1157,7 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string, match = pattern_new_match(self, &state, 1); if (!match) goto error; - item = _PyObject_CallArg1(filter, match); + item = PyObject_CallFunctionObjArgs(filter, match, NULL); Py_DECREF(match); if (!item) goto error; -- cgit v1.2.1 From 2146dbe89d873bf5661fd2cb18303aa9162d48fe Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 13 Jan 2017 08:53:58 +0200 Subject: Issue #29195: Removed support of deprecated undocumented keyword arguments in methods of regular expression objects. --- Modules/_sre.c | 87 ++++++++++------------------------------------------------ 1 file changed, 15 insertions(+), 72 deletions(-) (limited to 'Modules/_sre.c') diff --git a/Modules/_sre.c b/Modules/_sre.c index 438849483f..1cef7d02d2 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -551,55 +551,25 @@ sre_search(SRE_STATE* state, SRE_CODE* pattern) return sre_ucs4_search(state, pattern); } -static PyObject * -fix_string_param(PyObject *string, PyObject *string2, const char *oldname) -{ - if (string2 != NULL) { - if (string != NULL) { - PyErr_Format(PyExc_TypeError, - "Argument given by name ('%s') and position (1)", - oldname); - return NULL; - } - if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, - "The '%s' keyword parameter name is deprecated. " - "Use 'string' instead.", oldname) < 0) - return NULL; - return string2; - } - if (string == NULL) { - PyErr_SetString(PyExc_TypeError, - "Required argument 'string' (pos 1) not found"); - return NULL; - } - return string; -} - /*[clinic input] _sre.SRE_Pattern.match - string: object = NULL + string: object pos: Py_ssize_t = 0 endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize - * - pattern: object = NULL Matches zero or more characters at the beginning of the string. [clinic start generated code]*/ static PyObject * _sre_SRE_Pattern_match_impl(PatternObject *self, PyObject *string, - Py_ssize_t pos, Py_ssize_t endpos, - PyObject *pattern) -/*[clinic end generated code: output=74b4b1da3bb2d84e input=3d079aa99979b81d]*/ + Py_ssize_t pos, Py_ssize_t endpos) +/*[clinic end generated code: output=ea2d838888510661 input=a2ba191647abebe5]*/ { SRE_STATE state; Py_ssize_t status; PyObject *match; - string = fix_string_param(string, pattern, "pattern"); - if (!string) - return NULL; if (!state_init(&state, (PatternObject *)self, string, pos, endpos)) return NULL; @@ -623,29 +593,22 @@ _sre_SRE_Pattern_match_impl(PatternObject *self, PyObject *string, /*[clinic input] _sre.SRE_Pattern.fullmatch - string: object = NULL + string: object pos: Py_ssize_t = 0 endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize - * - pattern: object = NULL Matches against all of the string [clinic start generated code]*/ static PyObject * _sre_SRE_Pattern_fullmatch_impl(PatternObject *self, PyObject *string, - Py_ssize_t pos, Py_ssize_t endpos, - PyObject *pattern) -/*[clinic end generated code: output=1c98bc5da744ea94 input=d4228606cc12580f]*/ + Py_ssize_t pos, Py_ssize_t endpos) +/*[clinic end generated code: output=5833c47782a35f4a input=a6f640614aaefceb]*/ { SRE_STATE state; Py_ssize_t status; PyObject *match; - string = fix_string_param(string, pattern, "pattern"); - if (!string) - return NULL; - if (!state_init(&state, self, string, pos, endpos)) return NULL; @@ -669,11 +632,9 @@ _sre_SRE_Pattern_fullmatch_impl(PatternObject *self, PyObject *string, /*[clinic input] _sre.SRE_Pattern.search - string: object = NULL + string: object pos: Py_ssize_t = 0 endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize - * - pattern: object = NULL Scan through string looking for a match, and return a corresponding match object instance. @@ -682,18 +643,13 @@ Return None if no position in the string matches. static PyObject * _sre_SRE_Pattern_search_impl(PatternObject *self, PyObject *string, - Py_ssize_t pos, Py_ssize_t endpos, - PyObject *pattern) -/*[clinic end generated code: output=3839394a18e5ea4f input=dab42720f4be3a4b]*/ + Py_ssize_t pos, Py_ssize_t endpos) +/*[clinic end generated code: output=25f302a644e951e8 input=4ae5cb7dc38fed1b]*/ { SRE_STATE state; Py_ssize_t status; PyObject *match; - string = fix_string_param(string, pattern, "pattern"); - if (!string) - return NULL; - if (!state_init(&state, self, string, pos, endpos)) return NULL; @@ -762,30 +718,23 @@ deepcopy(PyObject** object, PyObject* memo) /*[clinic input] _sre.SRE_Pattern.findall - string: object = NULL + string: object pos: Py_ssize_t = 0 endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize - * - source: object = NULL Return a list of all non-overlapping matches of pattern in string. [clinic start generated code]*/ static PyObject * _sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string, - Py_ssize_t pos, Py_ssize_t endpos, - PyObject *source) -/*[clinic end generated code: output=51295498b300639d input=df688355c056b9de]*/ + Py_ssize_t pos, Py_ssize_t endpos) +/*[clinic end generated code: output=f4966baceea60aca input=5b6a4ee799741563]*/ { SRE_STATE state; PyObject* list; Py_ssize_t status; Py_ssize_t i, b, e; - string = fix_string_param(string, source, "source"); - if (!string) - return NULL; - if (!state_init(&state, self, string, pos, endpos)) return NULL; @@ -922,18 +871,16 @@ _sre_SRE_Pattern_scanner_impl(PatternObject *self, PyObject *string, /*[clinic input] _sre.SRE_Pattern.split - string: object = NULL + string: object maxsplit: Py_ssize_t = 0 - * - source: object = NULL Split string by the occurrences of pattern. [clinic start generated code]*/ static PyObject * _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string, - Py_ssize_t maxsplit, PyObject *source) -/*[clinic end generated code: output=20bac2ff55b9f84c input=41e0b2e35e599d7b]*/ + Py_ssize_t maxsplit) +/*[clinic end generated code: output=7ac66f381c45e0be input=1eeeb10dafc9947a]*/ { SRE_STATE state; PyObject* list; @@ -943,10 +890,6 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string, Py_ssize_t i; void* last; - string = fix_string_param(string, source, "source"); - if (!string) - return NULL; - assert(self->codesize != 0); if (self->code[0] != SRE_OP_INFO || self->code[3] == 0) { if (self->code[0] == SRE_OP_INFO && self->code[4] == 0) { -- cgit v1.2.1 From bfeec6d871e3db2e0ddfdef01387913bc19cadd4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 23 Jan 2017 09:47:21 +0200 Subject: Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever possible. Patch is writen with Coccinelle. --- Modules/_sre.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'Modules/_sre.c') diff --git a/Modules/_sre.c b/Modules/_sre.c index 1cef7d02d2..061af39ef5 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -481,8 +481,7 @@ state_getslice(SRE_STATE* state, Py_ssize_t index, PyObject* string, int empty) /* want empty string */ i = j = 0; else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } else { i = STATE_OFFSET(state, state->mark[index]); @@ -2368,8 +2367,7 @@ match_lastindex_get(MatchObject *self) { if (self->lastindex >= 0) return PyLong_FromSsize_t(self->lastindex); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2383,8 +2381,7 @@ match_lastgroup_get(MatchObject *self) return result; PyErr_Clear(); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2466,8 +2463,7 @@ pattern_new_match(PatternObject* pattern, SRE_STATE* state, Py_ssize_t status) } else if (status == 0) { /* no match */ - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } -- cgit v1.2.1