Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55ba38a

Browse files
committed
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.
1 parent 61bdb0d commit 55ba38a

6 files changed

Lines changed: 9 additions & 9 deletions

File tree

Modules/_pickle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,8 +4571,8 @@ find_class(UnpicklerObject *self, PyObject *module_name, PyObject *global_name)
45714571
{
45724572
_Py_IDENTIFIER(find_class);
45734573

4574-
return _PyObject_CallMethodId((PyObject *)self, &PyId_find_class, "OO",
4575-
module_name, global_name);
4574+
return _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId_find_class,
4575+
module_name, global_name, NULL);
45764576
}
45774577

45784578
static Py_ssize_t
@@ -5184,7 +5184,7 @@ instantiate(PyObject *cls, PyObject *args)
51845184
else {
51855185
_Py_IDENTIFIER(__new__);
51865186

5187-
result = _PyObject_CallMethodId(cls, &PyId___new__, "O", cls);
5187+
result = _PyObject_CallMethodIdObjArgs(cls, &PyId___new__, cls, NULL);
51885188
}
51895189
return result;
51905190
}

Modules/arraymodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ array_array_tofile(arrayobject *self, PyObject *f)
14451445
bytes = PyBytes_FromStringAndSize(ptr, size);
14461446
if (bytes == NULL)
14471447
return NULL;
1448-
res = _PyObject_CallMethodId(f, &PyId_write, "O", bytes);
1448+
res = _PyObject_CallMethodIdObjArgs(f, &PyId_write, bytes, NULL);
14491449
Py_DECREF(bytes);
14501450
if (res == NULL)
14511451
return NULL;

Modules/cjkcodecs/multibytecodec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ mbstreamwriter_iwrite(MultibyteStreamWriterObject *self,
16111611
if (str == NULL)
16121612
return -1;
16131613

1614-
wr = _PyObject_CallMethodId(self->stream, &PyId_write, "O", str);
1614+
wr = _PyObject_CallMethodIdObjArgs(self->stream, &PyId_write, str, NULL);
16151615
Py_DECREF(str);
16161616
if (wr == NULL)
16171617
return -1;
@@ -1702,7 +1702,7 @@ _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *se
17021702
if (PyBytes_Size(pwrt) > 0) {
17031703
PyObject *wr;
17041704

1705-
wr = _PyObject_CallMethodId(self->stream, &PyId_write, "O", pwrt);
1705+
wr = _PyObject_CallMethodIdObjArgs(self->stream, &PyId_write, pwrt);
17061706
if (wr == NULL) {
17071707
Py_DECREF(pwrt);
17081708
return NULL;

Python/_warnings.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ check_matched(PyObject *obj, PyObject *arg)
2626

2727
if (obj == Py_None)
2828
return 1;
29-
result = _PyObject_CallMethodId(obj, &PyId_match, "O", arg);
29+
result = _PyObject_CallMethodIdObjArgs(obj, &PyId_match, arg, NULL);
3030
if (result == NULL)
3131
return -1;
3232

Python/import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ PyImport_ReloadModule(PyObject *m)
17051705
Py_INCREF(imp);
17061706
}
17071707

1708-
reloaded_module = _PyObject_CallMethodId(imp, &PyId_reload, "O", m);
1708+
reloaded_module = _PyObject_CallMethodIdObjArgs(imp, &PyId_reload, m, NULL);
17091709
Py_DECREF(imp);
17101710
return reloaded_module;
17111711
}

Python/marshal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ marshal_dump(PyObject *self, PyObject *args)
16491649
s = PyMarshal_WriteObjectToString(x, version);
16501650
if (s == NULL)
16511651
return NULL;
1652-
res = _PyObject_CallMethodId(f, &PyId_write, "O", s);
1652+
res = _PyObject_CallMethodIdObjArgs(f, &PyId_write, s, NULL);
16531653
Py_DECREF(s);
16541654
return res;
16551655
}

0 commit comments

Comments
 (0)