Kaydet (Commit) d056818e authored tarafından Oren Milman's avatar Oren Milman Kaydeden (comit) Serhiy Storchaka

bpo-31428: Prevent raising a SystemError in case the memo arg of…

bpo-31428: Prevent raising a SystemError in case the memo arg of ElementTree.Element.__deepcopy__() isn't a dictionary. (#3512)
üst 98758bc6
...@@ -733,14 +733,14 @@ LOCAL(PyObject *) deepcopy(PyObject *, PyObject *); ...@@ -733,14 +733,14 @@ LOCAL(PyObject *) deepcopy(PyObject *, PyObject *);
/*[clinic input] /*[clinic input]
_elementtree.Element.__deepcopy__ _elementtree.Element.__deepcopy__
memo: object memo: object(subclass_of="&PyDict_Type")
/ /
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
_elementtree_Element___deepcopy__(ElementObject *self, PyObject *memo) _elementtree_Element___deepcopy___impl(ElementObject *self, PyObject *memo)
/*[clinic end generated code: output=d1f19851d17bf239 input=df24c2b602430b77]*/ /*[clinic end generated code: output=eefc3df50465b642 input=a2d40348c0aade10]*/
{ {
Py_ssize_t i; Py_ssize_t i;
ElementObject* element; ElementObject* element;
...@@ -849,7 +849,8 @@ deepcopy(PyObject *object, PyObject *memo) ...@@ -849,7 +849,8 @@ deepcopy(PyObject *object, PyObject *memo)
/* Fall through to general case */ /* Fall through to general case */
} }
else if (Element_CheckExact(object)) { else if (Element_CheckExact(object)) {
return _elementtree_Element___deepcopy__((ElementObject *)object, memo); return _elementtree_Element___deepcopy___impl(
(ElementObject *)object, memo);
} }
} }
......
...@@ -70,6 +70,24 @@ PyDoc_STRVAR(_elementtree_Element___deepcopy____doc__, ...@@ -70,6 +70,24 @@ PyDoc_STRVAR(_elementtree_Element___deepcopy____doc__,
#define _ELEMENTTREE_ELEMENT___DEEPCOPY___METHODDEF \ #define _ELEMENTTREE_ELEMENT___DEEPCOPY___METHODDEF \
{"__deepcopy__", (PyCFunction)_elementtree_Element___deepcopy__, METH_O, _elementtree_Element___deepcopy____doc__}, {"__deepcopy__", (PyCFunction)_elementtree_Element___deepcopy__, METH_O, _elementtree_Element___deepcopy____doc__},
static PyObject *
_elementtree_Element___deepcopy___impl(ElementObject *self, PyObject *memo);
static PyObject *
_elementtree_Element___deepcopy__(ElementObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *memo;
if (!PyArg_Parse(arg, "O!:__deepcopy__", &PyDict_Type, &memo)) {
goto exit;
}
return_value = _elementtree_Element___deepcopy___impl(self, memo);
exit:
return return_value;
}
PyDoc_STRVAR(_elementtree_Element___sizeof____doc__, PyDoc_STRVAR(_elementtree_Element___sizeof____doc__,
"__sizeof__($self, /)\n" "__sizeof__($self, /)\n"
"--\n" "--\n"
...@@ -731,4 +749,4 @@ _elementtree_XMLParser__setevents(XMLParserObject *self, PyObject **args, Py_ssi ...@@ -731,4 +749,4 @@ _elementtree_XMLParser__setevents(XMLParserObject *self, PyObject **args, Py_ssi
exit: exit:
return return_value; return return_value;
} }
/*[clinic end generated code: output=75d0ff80e20b830f input=a9049054013a1b77]*/ /*[clinic end generated code: output=ed55bd5209c12364 input=a9049054013a1b77]*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment