[Python-checkins] cpython: Use _PyObject_CallMethodIdObjArgs()

victor.stinner python-checkins at python.org
Thu Dec 8 20:16:59 EST 2016


https://hg.python.org/cpython/rev/67302e6caa29
changeset:   105539:67302e6caa29
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Dec 09 00:36:19 2016 +0100
summary:
  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.

files:
  Modules/_io/textio.c  |  4 ++--
  Objects/descrobject.c |  3 ++-
  Python/sysmodule.c    |  2 +-
  3 files changed, 5 insertions(+), 4 deletions(-)


diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -2435,7 +2435,7 @@
     }
 
 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 @@
     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
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -804,7 +804,8 @@
 
     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
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -130,7 +130,7 @@
 
     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)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list