From: Victor Stinner Date: Thu, 8 Dec 2016 23:36:19 +0000 (+0100) Subject: Use _PyObject_CallMethodIdObjArgs() X-Git-Tag: v3.7.0a1~1800 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7e42541d08b6cc103b892c1cb70ea68c66751078;p=python Use _PyObject_CallMethodIdObjArgs() Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() when the format string only use the format 'O' for objects, like "(O)". _PyObject_CallMethodIdObjArgs() avoids the code to parse a format string and avoids the creation of a temporary tuple. --- diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 1c7200b0ae..d28f613950 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -2435,7 +2435,7 @@ _io_TextIOWrapper_tell_impl(textio *self) } finally: - res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state); + res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL); Py_DECREF(saved_state); if (res == NULL) return NULL; @@ -2449,7 +2449,7 @@ fail: if (saved_state) { PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state); + res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL); _PyErr_ChainExceptions(type, value, traceback); Py_DECREF(saved_state); Py_XDECREF(res); diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 076e741481..ee356b1bf4 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -804,7 +804,8 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *args) if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &def)) return NULL; - return _PyObject_CallMethodId(pp->mapping, &PyId_get, "(OO)", key, def); + return _PyObject_CallMethodIdObjArgs(pp->mapping, &PyId_get, + key, def, NULL); } static PyObject * diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1537313b43..9c4d9e6a1c 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -130,7 +130,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) buffer = _PyObject_GetAttrId(outf, &PyId_buffer); if (buffer) { - result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded); + result = _PyObject_CallMethodIdObjArgs(buffer, &PyId_write, encoded, NULL); Py_DECREF(buffer); Py_DECREF(encoded); if (result == NULL)