bpo-37483: add _PyObject_CallOneArg() function (#14558)
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 4caf3a4..443acc5 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -141,8 +141,7 @@
Do this check after 'future_init()'; in case we need to raise
an error, __del__ needs a properly initialized object.
*/
- PyObject *res = PyObject_CallFunctionObjArgs(
- asyncio_iscoroutine_func, coro, NULL);
+ PyObject *res = _PyObject_CallOneArg(asyncio_iscoroutine_func, coro);
if (res == NULL) {
return -1;
}
@@ -1286,8 +1285,7 @@
_asyncio_Future__repr_info_impl(FutureObj *self)
/*[clinic end generated code: output=fa69e901bd176cfb input=f21504d8e2ae1ca2]*/
{
- return PyObject_CallFunctionObjArgs(
- asyncio_future_repr_info_func, self, NULL);
+ return _PyObject_CallOneArg(asyncio_future_repr_info_func, (PyObject *)self);
}
static PyObject *
@@ -1364,7 +1362,7 @@
func = _PyObject_GetAttrId(fut->fut_loop, &PyId_call_exception_handler);
if (func != NULL) {
- PyObject *res = PyObject_CallFunctionObjArgs(func, context, NULL);
+ PyObject *res = _PyObject_CallOneArg(func, context);
if (res == NULL) {
PyErr_WriteUnraisable(func);
}
@@ -2104,13 +2102,13 @@
Py_DECREF(current_task_func);
return NULL;
}
- ret = PyObject_CallFunctionObjArgs(current_task_func, loop, NULL);
+ ret = _PyObject_CallOneArg(current_task_func, loop);
Py_DECREF(current_task_func);
Py_DECREF(loop);
return ret;
}
else {
- ret = PyObject_CallFunctionObjArgs(current_task_func, loop, NULL);
+ ret = _PyObject_CallOneArg(current_task_func, loop);
Py_DECREF(current_task_func);
return ret;
}
@@ -2146,7 +2144,7 @@
return NULL;
}
- res = PyObject_CallFunctionObjArgs(all_tasks_func, loop, NULL);
+ res = _PyObject_CallOneArg(all_tasks_func, loop);
Py_DECREF(all_tasks_func);
return res;
}
@@ -2159,8 +2157,7 @@
_asyncio_Task__repr_info_impl(TaskObj *self)
/*[clinic end generated code: output=6a490eb66d5ba34b input=3c6d051ed3ddec8b]*/
{
- return PyObject_CallFunctionObjArgs(
- asyncio_task_repr_info_func, self, NULL);
+ return _PyObject_CallOneArg(asyncio_task_repr_info_func, (PyObject *)self);
}
/*[clinic input]
@@ -2411,7 +2408,7 @@
func = _PyObject_GetAttrId(task->task_loop, &PyId_call_exception_handler);
if (func != NULL) {
- PyObject *res = PyObject_CallFunctionObjArgs(func, context, NULL);
+ PyObject *res = _PyObject_CallOneArg(func, context);
if (res == NULL) {
PyErr_WriteUnraisable(func);
}
@@ -2543,7 +2540,7 @@
return NULL;
}
- PyObject *e = PyObject_CallFunctionObjArgs(et, msg, NULL);
+ PyObject *e = _PyObject_CallOneArg(et, msg);
Py_DECREF(msg);
if (e == NULL) {
return NULL;
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 45169ec..cc7d3cf 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -512,8 +512,7 @@
return NULL;
}
if (old_deque->maxlen < 0)
- result = PyObject_CallFunctionObjArgs((PyObject *)(Py_TYPE(deque)),
- deque, NULL);
+ result = _PyObject_CallOneArg((PyObject *)(Py_TYPE(deque)), deque);
else
result = PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
deque, old_deque->maxlen, NULL);
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 014cbb4..9653ff9 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -1240,7 +1240,7 @@
if (line == NULL) {
return NULL;
}
- result = PyObject_CallFunctionObjArgs(self->write, line, NULL);
+ result = _PyObject_CallOneArg(self->write, line);
Py_DECREF(line);
return result;
}
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 6766524..973a654 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -925,7 +925,7 @@
if (!checker || !retval)
return retval;
- v = PyObject_CallFunctionObjArgs(checker, retval, NULL);
+ v = _PyObject_CallOneArg(checker, retval);
if (v == NULL)
_PyTraceback_Add("GetResult", "_ctypes/callproc.c", __LINE__-2);
Py_DECREF(retval);
@@ -1118,7 +1118,7 @@
if (argtypes && argtype_count > i) {
PyObject *v;
converter = PyTuple_GET_ITEM(argtypes, i);
- v = PyObject_CallFunctionObjArgs(converter, arg, NULL);
+ v = _PyObject_CallOneArg(converter, arg);
if (v == NULL) {
_ctypes_extend_error(PyExc_ArgError, "argument %zd: ", i+1);
goto cleanup;
@@ -1795,7 +1795,7 @@
typ = PyDict_GetItemWithError(_ctypes_ptrtype_cache, (PyObject *)Py_TYPE(arg));
if (typ) {
- return PyObject_CallFunctionObjArgs(typ, arg, NULL);
+ return _PyObject_CallOneArg(typ, arg);
}
else if (PyErr_Occurred()) {
return NULL;
@@ -1803,7 +1803,7 @@
typ = POINTER(NULL, (PyObject *)Py_TYPE(arg));
if (typ == NULL)
return NULL;
- result = PyObject_CallFunctionObjArgs(typ, arg, NULL);
+ result = _PyObject_CallOneArg(typ, arg);
Py_DECREF(typ);
return result;
}
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index ee1b5e5..b93ec3d 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2696,7 +2696,7 @@
PyObject *event = PyTuple_Pack(2, action, node);
if (event == NULL)
return -1;
- res = _PyObject_FastCall(self->events_append, &event, 1);
+ res = _PyObject_CallOneArg(self->events_append, event);
Py_DECREF(event);
if (res == NULL)
return -1;
@@ -2859,7 +2859,7 @@
}
if (self->comment_factory) {
- comment = _PyObject_FastCall(self->comment_factory, &text, 1);
+ comment = _PyObject_CallOneArg(self->comment_factory, text);
if (!comment)
return NULL;
@@ -3197,7 +3197,7 @@
if (errmsg == NULL)
return;
- error = _PyObject_FastCall(st->parseerror_obj, &errmsg, 1);
+ error = _PyObject_CallOneArg(st->parseerror_obj, errmsg);
Py_DECREF(errmsg);
if (!error)
return;
@@ -3260,7 +3260,7 @@
(TreeBuilderObject*) self->target, value
);
else if (self->handle_data)
- res = _PyObject_FastCall(self->handle_data, &value, 1);
+ res = _PyObject_CallOneArg(self->handle_data, value);
else
res = NULL;
Py_XDECREF(res);
@@ -3371,7 +3371,7 @@
/* shortcut */
res = treebuilder_handle_data((TreeBuilderObject*) self->target, data);
else if (self->handle_data)
- res = _PyObject_FastCall(self->handle_data, &data, 1);
+ res = _PyObject_CallOneArg(self->handle_data, data);
else
res = NULL;
@@ -3398,7 +3398,7 @@
else if (self->handle_end) {
tag = makeuniversal(self, tag_in);
if (tag) {
- res = _PyObject_FastCall(self->handle_end, &tag, 1);
+ res = _PyObject_CallOneArg(self->handle_end, tag);
Py_DECREF(tag);
}
}
@@ -3485,7 +3485,7 @@
if (!prefix)
return;
- res = _PyObject_FastCall(self->handle_end_ns, &prefix, 1);
+ res = _PyObject_CallOneArg(self->handle_end_ns, prefix);
Py_DECREF(prefix);
}
@@ -3515,7 +3515,7 @@
if (!comment)
return;
- res = _PyObject_FastCall(self->handle_comment, &comment, 1);
+ res = _PyObject_CallOneArg(self->handle_comment, comment);
}
Py_XDECREF(res);
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index fab4509..82cc776 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -557,7 +557,7 @@
PyObject *b;
if (peek != NULL) {
- PyObject *readahead = PyObject_CallFunctionObjArgs(peek, _PyLong_One, NULL);
+ PyObject *readahead = _PyObject_CallOneArg(peek, _PyLong_One);
if (readahead == NULL) {
/* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals()
when EINTR occurs so we needn't do it ourselves. */
diff --git a/Modules/_json.c b/Modules/_json.c
index e3aa997..38beb6f 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -818,14 +818,14 @@
*next_idx_ptr = idx + 1;
if (has_pairs_hook) {
- val = PyObject_CallFunctionObjArgs(s->object_pairs_hook, rval, NULL);
+ val = _PyObject_CallOneArg(s->object_pairs_hook, rval);
Py_DECREF(rval);
return val;
}
/* if object_hook is not None: rval = object_hook(rval) */
if (s->object_hook != Py_None) {
- val = PyObject_CallFunctionObjArgs(s->object_hook, rval, NULL);
+ val = _PyObject_CallOneArg(s->object_hook, rval);
Py_DECREF(rval);
return val;
}
@@ -931,7 +931,7 @@
return NULL;
/* rval = parse_constant(constant) */
- rval = PyObject_CallFunctionObjArgs(s->parse_constant, cstr, NULL);
+ rval = _PyObject_CallOneArg(s->parse_constant, cstr);
idx += PyUnicode_GET_LENGTH(cstr);
Py_DECREF(cstr);
*next_idx_ptr = idx;
@@ -1030,7 +1030,7 @@
idx - start);
if (numstr == NULL)
return NULL;
- rval = PyObject_CallFunctionObjArgs(custom_func, numstr, NULL);
+ rval = _PyObject_CallOneArg(custom_func, numstr);
}
else {
Py_ssize_t i, n;
@@ -1440,7 +1440,7 @@
if (s->fast_encode) {
return s->fast_encode(NULL, obj);
}
- encoded = PyObject_CallFunctionObjArgs(s->encoder, obj, NULL);
+ encoded = _PyObject_CallOneArg(s->encoder, obj);
if (encoded != NULL && !PyUnicode_Check(encoded)) {
PyErr_Format(PyExc_TypeError,
"encoder() must return a string, not %.80s",
@@ -1526,7 +1526,7 @@
return -1;
}
}
- newobj = PyObject_CallFunctionObjArgs(s->defaultfn, obj, NULL);
+ newobj = _PyObject_CallOneArg(s->defaultfn, obj);
if (newobj == NULL) {
Py_XDECREF(ident);
return -1;
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 3adece0..d6d1250 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -359,7 +359,7 @@
{
PyObject *result;
- result = PyObject_CallFunctionObjArgs(func, obj, NULL);
+ result = _PyObject_CallOneArg(func, obj);
Py_DECREF(obj);
return result;
}
@@ -420,7 +420,7 @@
return PyObject_CallFunctionObjArgs(func, self, obj, NULL);
}
else {
- return PyObject_CallFunctionObjArgs(func, obj, NULL);
+ return _PyObject_CallOneArg(func, obj);
}
}
@@ -2296,7 +2296,7 @@
return -1;
}
}
- result = PyObject_CallFunctionObjArgs(self->write, payload, NULL);
+ result = _PyObject_CallOneArg(self->write, payload);
Py_XDECREF(mem);
if (result == NULL) {
return -1;
@@ -2504,8 +2504,7 @@
}
int in_band = 1;
if (self->buffer_callback != NULL) {
- PyObject *ret = PyObject_CallFunctionObjArgs(self->buffer_callback,
- obj, NULL);
+ PyObject *ret = _PyObject_CallOneArg(self->buffer_callback, obj);
if (ret == NULL) {
return -1;
}
@@ -4322,8 +4321,7 @@
* regular reduction mechanism.
*/
if (self->reducer_override != NULL) {
- reduce_value = PyObject_CallFunctionObjArgs(self->reducer_override,
- obj, NULL);
+ reduce_value = _PyObject_CallOneArg(self->reducer_override, obj);
if (reduce_value == NULL) {
goto error;
}
diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c
index 4d41804..7552d1b 100644
--- a/Modules/_sqlite/cache.c
+++ b/Modules/_sqlite/cache.c
@@ -112,9 +112,8 @@
Py_TYPE(self)->tp_free((PyObject*)self);
}
-PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
+PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* key)
{
- PyObject* key = args;
pysqlite_Node* node;
pysqlite_Node* ptr;
PyObject* data;
@@ -184,6 +183,9 @@
}
}
+ /* We cannot replace this by _PyObject_CallOneArg() since
+ * PyObject_CallFunction() has a special case when using a
+ * single tuple as argument. */
data = PyObject_CallFunction(self->factory, "O", key);
if (!data) {
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 5ceeaf9..08604b9 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -310,7 +310,7 @@
factory = (PyObject*)&pysqlite_CursorType;
}
- cursor = PyObject_CallFunctionObjArgs(factory, (PyObject *)self, NULL);
+ cursor = _PyObject_CallOneArg(factory, (PyObject *)self);
if (cursor == NULL)
return NULL;
if (!PyObject_TypeCheck(cursor, &pysqlite_CursorType)) {
@@ -970,7 +970,7 @@
py_statement = PyUnicode_DecodeUTF8(statement_string,
strlen(statement_string), "replace");
if (py_statement) {
- ret = PyObject_CallFunctionObjArgs((PyObject*)user_arg, py_statement, NULL);
+ ret = _PyObject_CallOneArg((PyObject*)user_arg, py_statement);
Py_DECREF(py_statement);
}
@@ -1465,16 +1465,9 @@
goto finally;
}
- args = PyTuple_New(1);
- if (!args) {
- goto finally;
- }
- Py_INCREF(self);
- PyTuple_SetItem(args, 0, (PyObject*)self);
- retval = PyObject_CallObject(pyfn_iterdump, args);
+ retval = _PyObject_CallOneArg(pyfn_iterdump, (PyObject *)self);
finally:
- Py_XDECREF(args);
Py_XDECREF(module);
return retval;
}
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 38d94b2..e6fcac8 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -266,7 +266,7 @@
item = PyBytes_FromStringAndSize(val_str, nbytes);
if (!item)
goto error;
- converted = PyObject_CallFunction(converter, "O", item);
+ converted = _PyObject_CallOneArg(converter, item);
Py_DECREF(item);
}
} else {
diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c
index c23b09f..59a5e22 100644
--- a/Modules/_sqlite/microprotocols.c
+++ b/Modules/_sqlite/microprotocols.c
@@ -92,7 +92,7 @@
Py_DECREF(key);
if (adapter) {
Py_INCREF(adapter);
- adapted = PyObject_CallFunctionObjArgs(adapter, obj, NULL);
+ adapted = _PyObject_CallOneArg(adapter, obj);
Py_DECREF(adapter);
return adapted;
}
@@ -105,7 +105,7 @@
return NULL;
}
if (adapter) {
- adapted = PyObject_CallFunctionObjArgs(adapter, obj, NULL);
+ adapted = _PyObject_CallOneArg(adapter, obj);
Py_DECREF(adapter);
if (adapted == Py_None) {
@@ -124,7 +124,7 @@
return NULL;
}
if (adapter) {
- adapted = PyObject_CallFunctionObjArgs(adapter, proto, NULL);
+ adapted = _PyObject_CallOneArg(adapter, proto);
Py_DECREF(adapter);
if (adapted == Py_None) {
diff --git a/Modules/_sre.c b/Modules/_sre.c
index d4fe588..f4f9d01 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1082,7 +1082,7 @@
match = pattern_new_match(self, &state, 1);
if (!match)
goto error;
- item = PyObject_CallFunctionObjArgs(filter, match, NULL);
+ item = _PyObject_CallOneArg(filter, match);
Py_DECREF(match);
if (!item)
goto error;
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 9281c68..d1c635a 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -2098,7 +2098,7 @@
return 0;
}
- s_object = PyObject_CallFunctionObjArgs((PyObject *)(&PyStructType), fmt, NULL);
+ s_object = _PyObject_CallOneArg((PyObject *)(&PyStructType), fmt);
if (s_object != NULL) {
if (PyDict_GET_SIZE(cache) >= MAXCACHE)
PyDict_Clear(cache);
diff --git a/Modules/_xxtestfuzz/fuzzer.c b/Modules/_xxtestfuzz/fuzzer.c
index 16104e4..2446e71 100644
--- a/Modules/_xxtestfuzz/fuzzer.c
+++ b/Modules/_xxtestfuzz/fuzzer.c
@@ -104,7 +104,7 @@
if (input_bytes == NULL) {
return 0;
}
- PyObject* parsed = PyObject_CallFunctionObjArgs(json_loads_method, input_bytes, NULL);
+ PyObject* parsed = _PyObject_CallOneArg(json_loads_method, input_bytes);
if (parsed == NULL) {
/* Ignore ValueError as the fuzzer will more than likely
generate some invalid json and values */
@@ -263,7 +263,7 @@
PyObject* pattern = compiled_patterns[idx];
PyObject* match_callable = PyObject_GetAttrString(pattern, "match");
- PyObject* matches = PyObject_CallFunctionObjArgs(match_callable, to_match, NULL);
+ PyObject* matches = _PyObject_CallOneArg(match_callable, to_match);
Py_XDECREF(matches);
Py_DECREF(match_callable);
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index b67f348..7ed8365 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -291,7 +291,7 @@
if (codecobj == NULL)
return NULL;
- r = PyObject_CallFunctionObjArgs(cofunc, codecobj, NULL);
+ r = _PyObject_CallOneArg(cofunc, codecobj);
Py_DECREF(codecobj);
return r;
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index c01a0e5..052ed88 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -81,7 +81,7 @@
static PyObject *
call_error_callback(PyObject *errors, PyObject *exc)
{
- PyObject *args, *cb, *r;
+ PyObject *cb, *r;
const char *str;
assert(PyUnicode_Check(errors));
@@ -92,17 +92,7 @@
if (cb == NULL)
return NULL;
- args = PyTuple_New(1);
- if (args == NULL) {
- Py_DECREF(cb);
- return NULL;
- }
-
- PyTuple_SET_ITEM(args, 0, exc);
- Py_INCREF(exc);
-
- r = PyObject_CallObject(cb, args);
- Py_DECREF(args);
+ r = _PyObject_CallOneArg(cb, exc);
Py_DECREF(cb);
return r;
}
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 0cf00e8..2ee7651 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -763,7 +763,7 @@
_PyObject_ASSERT(op, callback != NULL);
/* copy-paste of weakrefobject.c's handle_callback() */
- temp = PyObject_CallFunctionObjArgs(callback, wr, NULL);
+ temp = _PyObject_CallOneArg(callback, (PyObject *)wr);
if (temp == NULL)
PyErr_WriteUnraisable(callback);
else
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 00e3cbb..781d0cc 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -134,7 +134,7 @@
newkey = newvalue;
Py_INCREF(newvalue);
} else {
- newkey = PyObject_CallFunctionObjArgs(gbo->keyfunc, newvalue, NULL);
+ newkey = _PyObject_CallOneArg(gbo->keyfunc, newvalue);
if (newkey == NULL) {
Py_DECREF(newvalue);
return -1;
@@ -1210,7 +1210,7 @@
if (lz->start == 1)
return item;
- good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
+ good = _PyObject_CallOneArg(lz->func, item);
if (good == NULL) {
Py_DECREF(item);
return NULL;
@@ -1373,7 +1373,7 @@
if (item == NULL)
return NULL;
- good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
+ good = _PyObject_CallOneArg(lz->func, item);
if (good == NULL) {
Py_DECREF(item);
return NULL;
@@ -3906,7 +3906,7 @@
ok = PyObject_IsTrue(item);
} else {
PyObject *good;
- good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
+ good = _PyObject_CallOneArg(lz->func, item);
if (good == NULL) {
Py_DECREF(item);
return NULL;
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 45a1e68..3d193e7 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -119,7 +119,7 @@
XML_ErrorString(code), lineno, column);
if (buffer == NULL)
return NULL;
- err = PyObject_CallFunctionObjArgs(ErrorObject, buffer, NULL);
+ err = _PyObject_CallOneArg(ErrorObject, buffer);
Py_DECREF(buffer);
if ( err != NULL
&& set_error_attr(err, "code", code)