Use PyObject_CallFunctionObjArgs()
Issue #28915: Replace PyObject_CallFunction() with
PyObject_CallFunctionObjArgs() when the format string was only made of "O"
formats, PyObject* arguments.
PyObject_CallFunctionObjArgs() avoids the creation of a temporary tuple and
doesn't have to parse a format string.
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 8678c0a..ba827e6 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2496,11 +2496,13 @@
attrib = PyDict_New();
if (!attrib)
return NULL;
- node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
+ node = PyObject_CallFunctionObjArgs(self->element_factory,
+ tag, attrib, NULL);
Py_DECREF(attrib);
}
else {
- node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
+ node = PyObject_CallFunctionObjArgs(self->element_factory,
+ tag, attrib, NULL);
}
if (!node) {
return NULL;
@@ -2977,7 +2979,8 @@
return;
}
}
- res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib);
+ res = PyObject_CallFunctionObjArgs(self->handle_start,
+ tag, attrib, NULL);
} else
res = NULL;
@@ -3143,8 +3146,9 @@
/* If the target has a handler for doctype, call it. */
if (self->handle_doctype) {
- res = PyObject_CallFunction(self->handle_doctype, "OOO",
- doctype_name_obj, pubid_obj, sysid_obj);
+ res = PyObject_CallFunctionObjArgs(self->handle_doctype,
+ doctype_name_obj, pubid_obj,
+ sysid_obj, NULL);
Py_CLEAR(res);
}
else {
@@ -3163,8 +3167,9 @@
if (!res)
goto clear;
Py_DECREF(res);
- res = PyObject_CallFunction(parser_doctype, "OOO",
- doctype_name_obj, pubid_obj, sysid_obj);
+ res = PyObject_CallFunctionObjArgs(parser_doctype,
+ doctype_name_obj, pubid_obj,
+ sysid_obj, NULL);
Py_CLEAR(res);
}
}
@@ -3191,7 +3196,8 @@
target = PyUnicode_DecodeUTF8(target_in, strlen(target_in), "strict");
data = PyUnicode_DecodeUTF8(data_in, strlen(data_in), "strict");
if (target && data) {
- res = PyObject_CallFunction(self->handle_pi, "OO", target, data);
+ res = PyObject_CallFunctionObjArgs(self->handle_pi,
+ target, data, NULL);
Py_XDECREF(res);
Py_DECREF(data);
Py_DECREF(target);