[Python-checkins] cpython: Replace PyObject_CallFunction() with fastcall

victor.stinner python-checkins at python.org
Thu Dec 1 09:09:47 EST 2016


https://hg.python.org/cpython/rev/8f258245c391
changeset:   105404:8f258245c391
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Dec 01 14:51:04 2016 +0100
summary:
  Replace PyObject_CallFunction() with fastcall

Replace
    PyObject_CallFunction(func, "O", arg)
and
    PyObject_CallFunction(func, "O", arg, NULL)
with
    _PyObject_CallArg1(func, arg)

Replace
    PyObject_CallFunction(func, NULL)
with
    _PyObject_CallNoArg(func)

_PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate
memory on the C stack.

files:
  Modules/_collectionsmodule.c |   2 +-
  Modules/_elementtree.c       |  10 +++++-----
  Modules/pyexpat.c            |   2 +-
  Modules/readline.c           |   2 +-
  Objects/genobject.c          |   2 +-
  Python/_warnings.c           |   2 +-
  Python/codecs.c              |   4 ++--
  Python/marshal.c             |   2 +-
  8 files changed, 13 insertions(+), 13 deletions(-)


diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -538,7 +538,7 @@
         return NULL;
     }
     if (old_deque->maxlen < 0)
-        return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "O", deque, NULL);
+        return _PyObject_CallArg1((PyObject *)(Py_TYPE(deque)), deque);
     else
         return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
             deque, old_deque->maxlen, NULL);
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2831,7 +2831,7 @@
     if (errmsg == NULL)
         return;
 
-    error = PyObject_CallFunction(st->parseerror_obj, "O", errmsg);
+    error = _PyObject_CallArg1(st->parseerror_obj, errmsg);
     Py_DECREF(errmsg);
     if (!error)
         return;
@@ -2894,7 +2894,7 @@
                 (TreeBuilderObject*) self->target, value
                 );
         else if (self->handle_data)
-            res = PyObject_CallFunction(self->handle_data, "O", value);
+            res = _PyObject_CallArg1(self->handle_data, value);
         else
             res = NULL;
         Py_XDECREF(res);
@@ -3004,7 +3004,7 @@
         /* shortcut */
         res = treebuilder_handle_data((TreeBuilderObject*) self->target, data);
     else if (self->handle_data)
-        res = PyObject_CallFunction(self->handle_data, "O", data);
+        res = _PyObject_CallArg1(self->handle_data, data);
     else
         res = NULL;
 
@@ -3031,7 +3031,7 @@
     else if (self->handle_end) {
         tag = makeuniversal(self, tag_in);
         if (tag) {
-            res = PyObject_CallFunction(self->handle_end, "O", tag);
+            res = _PyObject_CallArg1(self->handle_end, tag);
             Py_DECREF(tag);
         }
     }
@@ -3090,7 +3090,7 @@
     if (self->handle_comment) {
         comment = PyUnicode_DecodeUTF8(comment_in, strlen(comment_in), "strict");
         if (comment) {
-            res = PyObject_CallFunction(self->handle_comment, "O", comment);
+            res = _PyObject_CallArg1(self->handle_comment, comment);
             Py_XDECREF(res);
             Py_DECREF(comment);
         }
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -119,7 +119,7 @@
                                   XML_ErrorString(code), lineno, column);
     if (buffer == NULL)
         return NULL;
-    err = PyObject_CallFunction(ErrorObject, "O", buffer);
+    err = _PyObject_CallArg1(ErrorObject, buffer);
     Py_DECREF(buffer);
     if (  err != NULL
           && set_error_attr(err, "code", code)
diff --git a/Modules/readline.c b/Modules/readline.c
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -868,7 +868,7 @@
     int result = 0;
     if (func != NULL) {
         PyObject *r;
-        r = PyObject_CallFunction(func, NULL);
+        r = _PyObject_CallNoArg(func);
         if (r == NULL)
             goto error;
         if (r == Py_None)
diff --git a/Objects/genobject.c b/Objects/genobject.c
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -1341,7 +1341,7 @@
         PyObject *res;
 
         Py_INCREF(firstiter);
-        res = PyObject_CallFunction(firstiter, "O", o);
+        res = _PyObject_CallArg1(firstiter, o);
         Py_DECREF(firstiter);
         if (res == NULL) {
             return 1;
diff --git a/Python/_warnings.c b/Python/_warnings.c
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -476,7 +476,7 @@
     }
     else {
         text = message;
-        message = PyObject_CallFunction(category, "O", message);
+        message = _PyObject_CallArg1(category, message);
         if (message == NULL)
             goto cleanup;
     }
diff --git a/Python/codecs.c b/Python/codecs.c
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -284,7 +284,7 @@
     if (errors)
         ret = PyObject_CallFunction(inccodec, "s", errors);
     else
-        ret = PyObject_CallFunction(inccodec, NULL);
+        ret = _PyObject_CallNoArg(inccodec);
     Py_DECREF(inccodec);
     return ret;
 }
@@ -322,7 +322,7 @@
     if (errors != NULL)
         streamcodec = PyObject_CallFunction(codeccls, "Os", stream, errors);
     else
-        streamcodec = PyObject_CallFunction(codeccls, "O", stream);
+        streamcodec = _PyObject_CallArg1(codeccls, stream);
     Py_DECREF(codecs);
     return streamcodec;
 }
diff --git a/Python/marshal.c b/Python/marshal.c
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1274,7 +1274,7 @@
 
         if (n == 0 && type == TYPE_FROZENSET) {
             /* call frozenset() to get the empty frozenset singleton */
-            v = PyObject_CallFunction((PyObject*)&PyFrozenSet_Type, NULL);
+            v = _PyObject_CallNoArg((PyObject*)&PyFrozenSet_Type);
             if (v == NULL)
                 break;
             R_REF(v);

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


More information about the Python-checkins mailing list