Use _PyObject_CallMethodIdObjArgs()
Issue #28915: Replace _PyObject_CallMethodId() with
_PyObject_CallMethodIdObjArgs() in various modules when the format string was
only made of "O" formats, PyObject* arguments.
_PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and
doesn't have to parse a format string.
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 78c206e..46ea276 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4571,8 +4571,8 @@
{
_Py_IDENTIFIER(find_class);
- return _PyObject_CallMethodId((PyObject *)self, &PyId_find_class, "OO",
- module_name, global_name);
+ return _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId_find_class,
+ module_name, global_name, NULL);
}
static Py_ssize_t
@@ -5184,7 +5184,7 @@
else {
_Py_IDENTIFIER(__new__);
- result = _PyObject_CallMethodId(cls, &PyId___new__, "O", cls);
+ result = _PyObject_CallMethodIdObjArgs(cls, &PyId___new__, cls, NULL);
}
return result;
}
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index a68db18..f1469df 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1445,7 +1445,7 @@
bytes = PyBytes_FromStringAndSize(ptr, size);
if (bytes == NULL)
return NULL;
- res = _PyObject_CallMethodId(f, &PyId_write, "O", bytes);
+ res = _PyObject_CallMethodIdObjArgs(f, &PyId_write, bytes, NULL);
Py_DECREF(bytes);
if (res == NULL)
return NULL;
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index d1da189..15c8969 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -1611,7 +1611,7 @@
if (str == NULL)
return -1;
- wr = _PyObject_CallMethodId(self->stream, &PyId_write, "O", str);
+ wr = _PyObject_CallMethodIdObjArgs(self->stream, &PyId_write, str, NULL);
Py_DECREF(str);
if (wr == NULL)
return -1;
@@ -1702,7 +1702,7 @@
if (PyBytes_Size(pwrt) > 0) {
PyObject *wr;
- wr = _PyObject_CallMethodId(self->stream, &PyId_write, "O", pwrt);
+ wr = _PyObject_CallMethodIdObjArgs(self->stream, &PyId_write, pwrt);
if (wr == NULL) {
Py_DECREF(pwrt);
return NULL;