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.
This commit is contained in:
parent
e3d75c63cd
commit
726a57d45f
|
@ -576,5 +576,5 @@ def compile(p, flags=0):
|
||||||
return _sre.compile(
|
return _sre.compile(
|
||||||
pattern, flags | p.pattern.flags, code,
|
pattern, flags | p.pattern.flags, code,
|
||||||
p.pattern.groups-1,
|
p.pattern.groups-1,
|
||||||
groupindex, indexgroup
|
groupindex, tuple(indexgroup)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1506,7 +1506,7 @@ class ReTests(unittest.TestCase):
|
||||||
long_overflow = 2**128
|
long_overflow = 2**128
|
||||||
self.assertRaises(TypeError, re.finditer, "a", {})
|
self.assertRaises(TypeError, re.finditer, "a", {})
|
||||||
with self.assertRaises(OverflowError):
|
with self.assertRaises(OverflowError):
|
||||||
_sre.compile("abc", 0, [long_overflow], 0, [], [])
|
_sre.compile("abc", 0, [long_overflow], 0, {}, ())
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
_sre.compile({}, 0, [], 0, [], [])
|
_sre.compile({}, 0, [], 0, [], [])
|
||||||
|
|
||||||
|
|
|
@ -1438,8 +1438,8 @@ _sre.compile
|
||||||
flags: int
|
flags: int
|
||||||
code: object(subclass_of='&PyList_Type')
|
code: object(subclass_of='&PyList_Type')
|
||||||
groups: Py_ssize_t
|
groups: Py_ssize_t
|
||||||
groupindex: object
|
groupindex: object(subclass_of='&PyDict_Type')
|
||||||
indexgroup: object
|
indexgroup: object(subclass_of='&PyTuple_Type')
|
||||||
|
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
@ -1447,7 +1447,7 @@ static PyObject *
|
||||||
_sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
|
_sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
|
||||||
PyObject *code, Py_ssize_t groups, PyObject *groupindex,
|
PyObject *code, Py_ssize_t groups, PyObject *groupindex,
|
||||||
PyObject *indexgroup)
|
PyObject *indexgroup)
|
||||||
/*[clinic end generated code: output=ef9c2b3693776404 input=7d059ec8ae1edb85]*/
|
/*[clinic end generated code: output=ef9c2b3693776404 input=0a68476dbbe5db30]*/
|
||||||
{
|
{
|
||||||
/* "compile" pattern descriptor to pattern object */
|
/* "compile" pattern descriptor to pattern object */
|
||||||
|
|
||||||
|
|
|
@ -438,7 +438,7 @@ _sre_compile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwna
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
static const char * const _keywords[] = {"pattern", "flags", "code", "groups", "groupindex", "indexgroup", NULL};
|
static const char * const _keywords[] = {"pattern", "flags", "code", "groups", "groupindex", "indexgroup", NULL};
|
||||||
static _PyArg_Parser _parser = {"OiO!nOO:compile", _keywords, 0};
|
static _PyArg_Parser _parser = {"OiO!nO!O!:compile", _keywords, 0};
|
||||||
PyObject *pattern;
|
PyObject *pattern;
|
||||||
int flags;
|
int flags;
|
||||||
PyObject *code;
|
PyObject *code;
|
||||||
|
@ -447,7 +447,7 @@ _sre_compile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwna
|
||||||
PyObject *indexgroup;
|
PyObject *indexgroup;
|
||||||
|
|
||||||
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
|
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
|
||||||
&pattern, &flags, &PyList_Type, &code, &groups, &groupindex, &indexgroup)) {
|
&pattern, &flags, &PyList_Type, &code, &groups, &PyDict_Type, &groupindex, &PyTuple_Type, &indexgroup)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
return_value = _sre_compile_impl(module, pattern, flags, code, groups, groupindex, indexgroup);
|
return_value = _sre_compile_impl(module, pattern, flags, code, groups, groupindex, indexgroup);
|
||||||
|
@ -728,4 +728,4 @@ _sre_SRE_Scanner_search(ScannerObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
{
|
{
|
||||||
return _sre_SRE_Scanner_search_impl(self);
|
return _sre_SRE_Scanner_search_impl(self);
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=a4a246bca1963bc9 input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=b74b16d90f207358 input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_VAR_HEAD
|
PyObject_VAR_HEAD
|
||||||
Py_ssize_t groups; /* must be first! */
|
Py_ssize_t groups; /* must be first! */
|
||||||
PyObject* groupindex;
|
PyObject* groupindex; /* dict */
|
||||||
PyObject* indexgroup;
|
PyObject* indexgroup; /* tuple */
|
||||||
/* compatibility */
|
/* compatibility */
|
||||||
PyObject* pattern; /* pattern source (or None) */
|
PyObject* pattern; /* pattern source (or None) */
|
||||||
int flags; /* flags used when compiling pattern source */
|
int flags; /* flags used when compiling pattern source */
|
||||||
|
|
Loading…
Reference in New Issue