diff options
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r-- | Modules/_sre.c | 107 |
1 files changed, 23 insertions, 84 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index d09249672f..2a2fd272c4 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]); @@ -551,55 +550,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 +592,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 +631,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 +642,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 +717,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 +870,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 +889,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) { @@ -1157,7 +1099,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; @@ -1438,8 +1380,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 +1389,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 */ @@ -2430,8 +2372,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 * @@ -2445,8 +2386,7 @@ match_lastgroup_get(MatchObject *self) return result; PyErr_Clear(); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2528,8 +2468,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; } |