Issue #28858: Remove _PyObject_CallArg1() macro
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 5 Dec 2016 16:04:32 +0000 (17:04 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 5 Dec 2016 16:04:32 +0000 (17:04 +0100)
Replace
   _PyObject_CallArg1(func, arg)
with
   PyObject_CallFunctionObjArgs(func, arg, NULL)

Using the _PyObject_CallArg1() macro increases the usage of the C stack, which
was unexpected and unwanted. PyObject_CallFunctionObjArgs() doesn't have this
issue.

15 files changed:
Include/abstract.h
Modules/_asynciomodule.c
Modules/_collectionsmodule.c
Modules/_elementtree.c
Modules/_pickle.c
Modules/_sre.c
Modules/pyexpat.c
Objects/abstract.c
Objects/fileobject.c
Objects/genobject.c
Objects/typeobject.c
Python/_warnings.c
Python/codecs.c
Python/errors.c
Python/sysmodule.c

index 900ef23932e7b4127df4851c85b4a5edd4c89610..3dfac6577ac0f8a39e8aa449aecdc2cdb81df492 100644 (file)
@@ -338,10 +338,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
     _PyObject_FastCallDict((func), (args), (nargs), NULL)
 
 #define _PyObject_CallNoArg(func) \
-    _PyObject_FastCall((func), NULL, 0)
-
-#define _PyObject_CallArg1(func, arg) \
-    _PyObject_FastCall((func), (PyObject **)&(arg), 1)
+    _PyObject_FastCallDict((func), NULL, 0, NULL)
 
     PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(PyObject *func,
                                                   PyObject *obj, PyObject *args,
index 4e8f74a3c94ebfc47cb638fb55d0e53caa5cc73c..ea02a5e9c092db3805acfe0e702ca682925ae38b 100644 (file)
@@ -257,7 +257,7 @@ future_get_result(FutureObj *fut, PyObject **result)
             return -1;
         }
 
-        exc = _PyObject_CallArg1(asyncio_InvalidStateError, msg);
+        exc = PyObject_CallFunctionObjArgs(asyncio_InvalidStateError, msg, NULL);
         Py_DECREF(msg);
         if (exc == NULL) {
             return -1;
@@ -835,7 +835,7 @@ FutureObj_finalize(FutureObj *fut)
 
     func = _PyObject_GetAttrId(fut->fut_loop, &PyId_call_exception_handler);
     if (func != NULL) {
-        res = _PyObject_CallArg1(func, context);
+        res = PyObject_CallFunctionObjArgs(func, context, NULL);
         if (res == NULL) {
             PyErr_WriteUnraisable(func);
         }
@@ -1731,7 +1731,7 @@ TaskObj_finalize(TaskObj *task)
 
     func = _PyObject_GetAttrId(task->task_loop, &PyId_call_exception_handler);
     if (func != NULL) {
-        res = _PyObject_CallArg1(func, context);
+        res = PyObject_CallFunctionObjArgs(func, context, NULL);
         if (res == NULL) {
             PyErr_WriteUnraisable(func);
         }
index cbf5b50cc9554cf3a989b4d8fef60caff6402115..b8b7584282ad9051ca9b148a83810f763f42d157 100644 (file)
@@ -538,7 +538,8 @@ deque_copy(PyObject *deque)
         return NULL;
     }
     if (old_deque->maxlen < 0)
-        return _PyObject_CallArg1((PyObject *)(Py_TYPE(deque)), deque);
+        return PyObject_CallFunctionObjArgs((PyObject *)(Py_TYPE(deque)),
+                                            deque, NULL);
     else
         return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
             deque, old_deque->maxlen, NULL);
index 3837ff125a143aa3f59c0b782d4ce14c01e7dc3a..2e0cda7bcbfb7ff703ad9f082aa8c899292ca3e7 100644 (file)
@@ -2831,7 +2831,7 @@ expat_set_error(enum XML_Error error_code, Py_ssize_t line, Py_ssize_t column,
     if (errmsg == NULL)
         return;
 
-    error = _PyObject_CallArg1(st->parseerror_obj, errmsg);
+    error = PyObject_CallFunctionObjArgs(st->parseerror_obj, errmsg, NULL);
     Py_DECREF(errmsg);
     if (!error)
         return;
@@ -2894,7 +2894,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
                 (TreeBuilderObject*) self->target, value
                 );
         else if (self->handle_data)
-            res = _PyObject_CallArg1(self->handle_data, value);
+            res = PyObject_CallFunctionObjArgs(self->handle_data, value, NULL);
         else
             res = NULL;
         Py_XDECREF(res);
@@ -3004,7 +3004,7 @@ expat_data_handler(XMLParserObject* self, const XML_Char* data_in,
         /* shortcut */
         res = treebuilder_handle_data((TreeBuilderObject*) self->target, data);
     else if (self->handle_data)
-        res = _PyObject_CallArg1(self->handle_data, data);
+        res = PyObject_CallFunctionObjArgs(self->handle_data, data, NULL);
     else
         res = NULL;
 
@@ -3031,7 +3031,7 @@ expat_end_handler(XMLParserObject* self, const XML_Char* tag_in)
     else if (self->handle_end) {
         tag = makeuniversal(self, tag_in);
         if (tag) {
-            res = _PyObject_CallArg1(self->handle_end, tag);
+            res = PyObject_CallFunctionObjArgs(self->handle_end, tag, NULL);
             Py_DECREF(tag);
         }
     }
@@ -3090,7 +3090,8 @@ expat_comment_handler(XMLParserObject* self, const XML_Char* comment_in)
     if (self->handle_comment) {
         comment = PyUnicode_DecodeUTF8(comment_in, strlen(comment_in), "strict");
         if (comment) {
-            res = _PyObject_CallArg1(self->handle_comment, comment);
+            res = PyObject_CallFunctionObjArgs(self->handle_comment,
+                                               comment, NULL);
             Py_XDECREF(res);
             Py_DECREF(comment);
         }
index d6d5cca10fa426a1d5216f82e625994d0d759c3e..78c206e814d4679e71b9705b5d7f3da6094931ae 100644 (file)
@@ -346,7 +346,7 @@ _Pickle_FastCall(PyObject *func, PyObject *obj)
 {
     PyObject *result;
 
-    result = _PyObject_CallArg1(func, obj);
+    result = PyObject_CallFunctionObjArgs(func, obj, NULL);
     Py_DECREF(obj);
     return result;
 }
index 6e149011017ea36c8d122480d8ad0b784d7fc36b..438849483f3cd753ad8796963dbcbe997acc6c5a 100644 (file)
@@ -1157,7 +1157,7 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
             match = pattern_new_match(self, &state, 1);
             if (!match)
                 goto error;
-            item = _PyObject_CallArg1(filter, match);
+            item = PyObject_CallFunctionObjArgs(filter, match, NULL);
             Py_DECREF(match);
             if (!item)
                 goto error;
index 541eee7beb00e7f1380c7e59111f85bc5698b705..ece4d160eb4bcd05d4584983a70e4e757f026af3 100644 (file)
@@ -119,7 +119,7 @@ set_error(xmlparseobject *self, enum XML_Error code)
                                   XML_ErrorString(code), lineno, column);
     if (buffer == NULL)
         return NULL;
-    err = _PyObject_CallArg1(ErrorObject, buffer);
+    err = PyObject_CallFunctionObjArgs(ErrorObject, buffer, NULL);
     Py_DECREF(buffer);
     if (  err != NULL
           && set_error_attr(err, "code", code)
index beb12c98f6a11f690440cfc893cb85403cd623ba..a6a58db59104e3b756ee93bf6c72ce61f1cb429b 100644 (file)
@@ -2496,7 +2496,7 @@ call_function_tail(PyObject *callable, PyObject *args)
     assert(args != NULL);
 
     if (!PyTuple_Check(args)) {
-        result = _PyObject_CallArg1(callable, args);
+        result = PyObject_CallFunctionObjArgs(callable, args, NULL);
     }
     else {
         result = PyObject_Call(callable, args, NULL);
index 32f8a8983ef54705385f0356e59811056a9476cc..fcdb5fd0a44e0e085a0a0007f635aa3f4b72abc6 100644 (file)
@@ -146,7 +146,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
         Py_DECREF(writer);
         return -1;
     }
-    result = _PyObject_CallArg1(writer, value);
+    result = PyObject_CallFunctionObjArgs(writer, value, NULL);
     Py_DECREF(value);
     Py_DECREF(writer);
     if (result == NULL)
index bd7873bceb7e0fdad4f33d6d5a3aaaf9da760978..59f53cefcb35093d5695f27a3a39e558a1befc56 100644 (file)
@@ -1341,7 +1341,7 @@ async_gen_init_hooks(PyAsyncGenObject *o)
         PyObject *res;
 
         Py_INCREF(firstiter);
-        res = _PyObject_CallArg1(firstiter, o);
+        res = PyObject_CallFunctionObjArgs(firstiter, o, NULL);
         Py_DECREF(firstiter);
         if (res == NULL) {
             return 1;
index 0af153481a67025f0773fc7812700cba45e5cbf8..d9699ef1ba05c40d30bd7737b8cbe5032f499a67 100644 (file)
@@ -5873,7 +5873,7 @@ slot_sq_item(PyObject *self, Py_ssize_t i)
         goto error;
     }
 
-    retval = _PyObject_CallArg1(func, ival);
+    retval = PyObject_CallFunctionObjArgs(func, ival, NULL);
     Py_DECREF(func);
     Py_DECREF(ival);
     return retval;
@@ -5914,7 +5914,7 @@ slot_sq_contains(PyObject *self, PyObject *value)
         return -1;
     }
     if (func != NULL) {
-        res = _PyObject_CallArg1(func, value);
+        res = PyObject_CallFunctionObjArgs(func, value, NULL);
         Py_DECREF(func);
         if (res != NULL) {
             result = PyObject_IsTrue(res);
@@ -6284,7 +6284,7 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op)
         PyErr_Clear();
         Py_RETURN_NOTIMPLEMENTED;
     }
-    res = _PyObject_CallArg1(func, other);
+    res = PyObject_CallFunctionObjArgs(func, other, NULL);
     Py_DECREF(func);
     return res;
 }
index cecc8ad5881c7e9bfd518d73574a2655c3317343..189bf704317c62eb365903759d4ca8c434ffec35 100644 (file)
@@ -476,7 +476,7 @@ warn_explicit(PyObject *category, PyObject *message,
     }
     else {
         text = message;
-        message = _PyObject_CallArg1(category, message);
+        message = PyObject_CallFunctionObjArgs(category, message, NULL);
         if (message == NULL)
             goto cleanup;
     }
index 55f6ca85e3cd1e6ea96f665d0bd079aafbbc2f25..688a40bd6ff418b6ec1010bd15a99805a16b5022 100644 (file)
@@ -322,7 +322,7 @@ PyObject *codec_getstreamcodec(const char *encoding,
     if (errors != NULL)
         streamcodec = PyObject_CallFunction(codeccls, "Os", stream, errors);
     else
-        streamcodec = _PyObject_CallArg1(codeccls, stream);
+        streamcodec = PyObject_CallFunctionObjArgs(codeccls, stream, NULL);
     Py_DECREF(codecs);
     return streamcodec;
 }
index 01304d25a1a87206a9637348e5b24fe8aa9e417f..74283c9be3343fcfd6dc37af62bba2ebdde4ef5d 100644 (file)
@@ -62,7 +62,7 @@ _PyErr_CreateException(PyObject *exception, PyObject *value)
         return PyObject_Call(exception, value, NULL);
     }
     else {
-        return _PyObject_CallArg1(exception, value);
+        return PyObject_CallFunctionObjArgs(exception, value, NULL);
     }
 }
 
index 98a66741f597ac2e27e9bb64ab6eff37299f37ae..416a02b5466f44a9ab1bf6b8985539ba8444d5f3 100644 (file)
@@ -2325,7 +2325,7 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file)
     if (writer == NULL)
         goto error;
 
-    result = _PyObject_CallArg1(writer, unicode);
+    result = PyObject_CallFunctionObjArgs(writer, unicode, NULL);
     if (result == NULL) {
         goto error;
     } else {