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.
This commit is contained in:
parent
55ba38a480
commit
5abaa2b139
|
@ -2496,11 +2496,13 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
|
||||||
attrib = PyDict_New();
|
attrib = PyDict_New();
|
||||||
if (!attrib)
|
if (!attrib)
|
||||||
return NULL;
|
return NULL;
|
||||||
node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
|
node = PyObject_CallFunctionObjArgs(self->element_factory,
|
||||||
|
tag, attrib, NULL);
|
||||||
Py_DECREF(attrib);
|
Py_DECREF(attrib);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
|
node = PyObject_CallFunctionObjArgs(self->element_factory,
|
||||||
|
tag, attrib, NULL);
|
||||||
}
|
}
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2977,7 +2979,8 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib);
|
res = PyObject_CallFunctionObjArgs(self->handle_start,
|
||||||
|
tag, attrib, NULL);
|
||||||
} else
|
} else
|
||||||
res = NULL;
|
res = NULL;
|
||||||
|
|
||||||
|
@ -3143,8 +3146,9 @@ expat_start_doctype_handler(XMLParserObject *self,
|
||||||
|
|
||||||
/* If the target has a handler for doctype, call it. */
|
/* If the target has a handler for doctype, call it. */
|
||||||
if (self->handle_doctype) {
|
if (self->handle_doctype) {
|
||||||
res = PyObject_CallFunction(self->handle_doctype, "OOO",
|
res = PyObject_CallFunctionObjArgs(self->handle_doctype,
|
||||||
doctype_name_obj, pubid_obj, sysid_obj);
|
doctype_name_obj, pubid_obj,
|
||||||
|
sysid_obj, NULL);
|
||||||
Py_CLEAR(res);
|
Py_CLEAR(res);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3163,8 +3167,9 @@ expat_start_doctype_handler(XMLParserObject *self,
|
||||||
if (!res)
|
if (!res)
|
||||||
goto clear;
|
goto clear;
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
res = PyObject_CallFunction(parser_doctype, "OOO",
|
res = PyObject_CallFunctionObjArgs(parser_doctype,
|
||||||
doctype_name_obj, pubid_obj, sysid_obj);
|
doctype_name_obj, pubid_obj,
|
||||||
|
sysid_obj, NULL);
|
||||||
Py_CLEAR(res);
|
Py_CLEAR(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3191,7 +3196,8 @@ expat_pi_handler(XMLParserObject* self, const XML_Char* target_in,
|
||||||
target = PyUnicode_DecodeUTF8(target_in, strlen(target_in), "strict");
|
target = PyUnicode_DecodeUTF8(target_in, strlen(target_in), "strict");
|
||||||
data = PyUnicode_DecodeUTF8(data_in, strlen(data_in), "strict");
|
data = PyUnicode_DecodeUTF8(data_in, strlen(data_in), "strict");
|
||||||
if (target && data) {
|
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_XDECREF(res);
|
||||||
Py_DECREF(data);
|
Py_DECREF(data);
|
||||||
Py_DECREF(target);
|
Py_DECREF(target);
|
||||||
|
|
|
@ -2549,7 +2549,7 @@ _PyObject_CallFunctionVa(PyObject *callable, const char *format,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nargs == 1 && PyTuple_Check(stack[0])) {
|
if (nargs == 1 && PyTuple_Check(stack[0])) {
|
||||||
/* Special cases:
|
/* Special cases for backward compatibility:
|
||||||
- PyObject_CallFunction(func, "O", tuple) calls func(*tuple)
|
- PyObject_CallFunction(func, "O", tuple) calls func(*tuple)
|
||||||
- PyObject_CallFunction(func, "(OOO)", arg1, arg2, arg3) calls
|
- PyObject_CallFunction(func, "(OOO)", arg1, arg2, arg3) calls
|
||||||
func(*(arg1, arg2, arg3)): func(arg1, arg2, arg3) */
|
func(*(arg1, arg2, arg3)): func(arg1, arg2, arg3) */
|
||||||
|
|
|
@ -1454,7 +1454,7 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del)
|
||||||
doc = pold->prop_doc ? pold->prop_doc : Py_None;
|
doc = pold->prop_doc ? pold->prop_doc : Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
new = PyObject_CallFunction(type, "OOOO", get, set, del, doc);
|
new = PyObject_CallFunctionObjArgs(type, get, set, del, doc, NULL);
|
||||||
Py_DECREF(type);
|
Py_DECREF(type);
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue