bpo-37547: add _PyObject_CallMethodOneArg (GH-14685)
diff --git a/Modules/_abc.c b/Modules/_abc.c
index 219ea0d..7b5d418 100644
--- a/Modules/_abc.c
+++ b/Modules/_abc.c
@@ -480,7 +480,6 @@
/*[clinic end generated code: output=b8b5148f63b6b56f input=a4f4525679261084]*/
{
PyObject *subtype, *result = NULL, *subclass = NULL;
- PyObject *margs[2];
_abc_data *impl = _get_impl(self);
if (impl == NULL) {
return NULL;
@@ -515,16 +514,12 @@
}
}
/* Fall back to the subclass check. */
- margs[0] = self;
- margs[1] = subclass;
- result = _PyObject_VectorcallMethodId(&PyId___subclasscheck__, margs,
- 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
+ result = _PyObject_CallMethodIdOneArg(self, &PyId___subclasscheck__,
+ subclass);
goto end;
}
- margs[0] = self;
- margs[1] = subclass;
- result = _PyObject_VectorcallMethodId(&PyId___subclasscheck__, margs,
- 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
+ result = _PyObject_CallMethodIdOneArg(self, &PyId___subclasscheck__,
+ subclass);
if (result == NULL) {
goto end;
}
@@ -536,10 +531,8 @@
break;
case 0:
Py_DECREF(result);
- margs[0] = self;
- margs[1] = subtype;
- result = _PyObject_VectorcallMethodId(&PyId___subclasscheck__, margs,
- 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
+ result = _PyObject_CallMethodIdOneArg(self, &PyId___subclasscheck__,
+ subtype);
break;
case 1: // Nothing to do.
break;
@@ -620,8 +613,8 @@
}
/* 3. Check the subclass hook. */
- ok = _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId___subclasshook__,
- subclass, NULL);
+ ok = _PyObject_CallMethodIdOneArg((PyObject *)self, &PyId___subclasshook__,
+ subclass);
if (ok == NULL) {
goto end;
}
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 6c469d2..e9e6c56 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -1842,8 +1842,8 @@
{
_Py_IDENTIFIER(add);
- PyObject *res = _PyObject_CallMethodIdObjArgs(
- all_tasks, &PyId_add, task, NULL);
+ PyObject *res = _PyObject_CallMethodIdOneArg(all_tasks,
+ &PyId_add, task);
if (res == NULL) {
return -1;
}
@@ -1857,8 +1857,8 @@
{
_Py_IDENTIFIER(discard);
- PyObject *res = _PyObject_CallMethodIdObjArgs(
- all_tasks, &PyId_discard, task, NULL);
+ PyObject *res = _PyObject_CallMethodIdOneArg(all_tasks,
+ &PyId_discard, task);
if (res == NULL) {
return -1;
}
@@ -2611,13 +2611,11 @@
result = _PyGen_Send((PyGenObject*)coro, Py_None);
}
else {
- result = _PyObject_CallMethodIdObjArgs(coro, &PyId_send,
- Py_None, NULL);
+ result = _PyObject_CallMethodIdOneArg(coro, &PyId_send, Py_None);
}
}
else {
- result = _PyObject_CallMethodIdObjArgs(coro, &PyId_throw,
- exc, NULL);
+ result = _PyObject_CallMethodIdOneArg(coro, &PyId_throw, exc);
if (clear_exc) {
/* We created 'exc' during this call */
Py_DECREF(exc);
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 973a654..bd67c6e 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -1699,7 +1699,7 @@
if (!PyArg_ParseTuple(args, "OO!", &typ, &PyTuple_Type, &state))
return NULL;
- obj = _PyObject_CallMethodIdObjArgs(typ, &PyId___new__, typ, NULL);
+ obj = _PyObject_CallMethodIdOneArg(typ, &PyId___new__, typ);
if (obj == NULL)
return NULL;
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 0546368..19d3d7e 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1237,8 +1237,7 @@
if (tzinfo == Py_None)
Py_RETURN_NONE;
- result = _PyObject_CallMethodIdObjArgs(tzinfo, &PyId_tzname,
- tzinfoarg, NULL);
+ result = _PyObject_CallMethodIdOneArg(tzinfo, &PyId_tzname, tzinfoarg);
if (result == NULL || result == Py_None)
return result;
@@ -1693,8 +1692,7 @@
return NULL;
}
- result = _PyObject_CallMethodIdObjArgs(time, &PyId_struct_time,
- args, NULL);
+ result = _PyObject_CallMethodIdOneArg(time, &PyId_struct_time, args);
Py_DECREF(time);
Py_DECREF(args);
return result;
@@ -2894,8 +2892,7 @@
* time.time() delivers; if someone were gonzo about optimization,
* date.today() could get away with plain C time().
*/
- result = _PyObject_CallMethodIdObjArgs(cls, &PyId_fromtimestamp,
- time, NULL);
+ result = _PyObject_CallMethodIdOneArg(cls, &PyId_fromtimestamp, time);
Py_DECREF(time);
return result;
}
@@ -3209,8 +3206,8 @@
if (PyUnicode_GetLength(format) == 0)
return PyObject_Str((PyObject *)self);
- return _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId_strftime,
- format, NULL);
+ return _PyObject_CallMethodIdOneArg((PyObject *)self, &PyId_strftime,
+ format);
}
/* ISO methods. */
@@ -5960,7 +5957,7 @@
temp = (PyObject *)result;
result = (PyDateTime_DateTime *)
- _PyObject_CallMethodIdObjArgs(tzinfo, &PyId_fromutc, temp, NULL);
+ _PyObject_CallMethodIdOneArg(tzinfo, &PyId_fromutc, temp);
Py_DECREF(temp);
return result;
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index b93ec3d..b9b5016 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2679,7 +2679,7 @@
}
else {
PyObject *res;
- res = _PyObject_CallMethodIdObjArgs(element, &PyId_append, child, NULL);
+ res = _PyObject_CallMethodIdOneArg(element, &PyId_append, child);
if (res == NULL)
return -1;
Py_DECREF(res);
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 9e7e5f3..86dd277 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -439,8 +439,8 @@
{
if (self->ok && self->raw) {
PyObject *r;
- r = _PyObject_CallMethodIdObjArgs(self->raw, &PyId__dealloc_warn,
- source, NULL);
+ r = _PyObject_CallMethodIdOneArg(self->raw, &PyId__dealloc_warn,
+ source);
if (r)
Py_DECREF(r);
else
@@ -1323,7 +1323,7 @@
goto end;
Py_CLEAR(res);
}
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_truncate, pos, NULL);
+ res = _PyObject_CallMethodOneArg(self->raw, _PyIO_str_truncate, pos);
if (res == NULL)
goto end;
/* Reset cached position */
@@ -1467,7 +1467,7 @@
raised (see issue #10956).
*/
do {
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_readinto, memobj, NULL);
+ res = _PyObject_CallMethodOneArg(self->raw, _PyIO_str_readinto, memobj);
} while (res == NULL && _PyIO_trap_eintr());
Py_DECREF(memobj);
if (res == NULL)
@@ -1815,7 +1815,7 @@
*/
do {
errno = 0;
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_write, memobj, NULL);
+ res = _PyObject_CallMethodOneArg(self->raw, _PyIO_str_write, memobj);
errnum = errno;
} while (res == NULL && _PyIO_trap_eintr());
Py_DECREF(memobj);
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 7f784a3..e4cbbfa 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -145,8 +145,8 @@
PyObject *exc, *val, *tb;
int rc;
_Py_IDENTIFIER(close);
- res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type,
- &PyId_close, self, NULL);
+ res = _PyObject_CallMethodIdOneArg((PyObject*)&PyRawIOBase_Type,
+ &PyId_close, (PyObject *)self);
if (!self->closefd) {
self->fd = -1;
return res;
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index ed1dc00..05911d9 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -977,8 +977,8 @@
if (cmp == 0) {
self->encoding_start_of_stream = 0;
- PyObject *res = PyObject_CallMethodObjArgs(
- self->encoder, _PyIO_str_setstate, _PyLong_Zero, NULL);
+ PyObject *res = _PyObject_CallMethodOneArg(
+ self->encoder, _PyIO_str_setstate, _PyLong_Zero);
if (res == NULL) {
return -1;
}
@@ -1155,8 +1155,8 @@
PyObject *locale_module = _PyIO_get_locale_module(state);
if (locale_module == NULL)
goto catch_ImportError;
- self->encoding = _PyObject_CallMethodIdObjArgs(
- locale_module, &PyId_getpreferredencoding, Py_False, NULL);
+ self->encoding = _PyObject_CallMethodIdOneArg(
+ locale_module, &PyId_getpreferredencoding, Py_False);
Py_DECREF(locale_module);
if (self->encoding == NULL) {
catch_ImportError:
@@ -1597,8 +1597,7 @@
PyObject *ret;
do {
- ret = PyObject_CallMethodObjArgs(self->buffer,
- _PyIO_str_write, b, NULL);
+ ret = _PyObject_CallMethodOneArg(self->buffer, _PyIO_str_write, b);
} while (ret == NULL && _PyIO_trap_eintr());
Py_DECREF(b);
if (ret == NULL)
@@ -1668,8 +1667,7 @@
self->encoding_start_of_stream = 0;
}
else
- b = PyObject_CallMethodObjArgs(self->encoder,
- _PyIO_str_encode, text, NULL);
+ b = _PyObject_CallMethodOneArg(self->encoder, _PyIO_str_encode, text);
Py_DECREF(text);
if (b == NULL)
@@ -1851,9 +1849,9 @@
if (chunk_size == NULL)
goto fail;
- input_chunk = PyObject_CallMethodObjArgs(self->buffer,
+ input_chunk = _PyObject_CallMethodOneArg(self->buffer,
(self->has_read1 ? _PyIO_str_read1: _PyIO_str_read),
- chunk_size, NULL);
+ chunk_size);
Py_DECREF(chunk_size);
if (input_chunk == NULL)
goto fail;
@@ -2414,8 +2412,8 @@
self->encoding_start_of_stream = 1;
}
else {
- res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate,
- _PyLong_Zero, NULL);
+ res = _PyObject_CallMethodOneArg(self->encoder, _PyIO_str_setstate,
+ _PyLong_Zero);
self->encoding_start_of_stream = 0;
}
if (res == NULL)
@@ -2554,8 +2552,7 @@
posobj = PyLong_FromOff_t(cookie.start_pos);
if (posobj == NULL)
goto fail;
- res = PyObject_CallMethodObjArgs(self->buffer,
- _PyIO_str_seek, posobj, NULL);
+ res = _PyObject_CallMethodOneArg(self->buffer, _PyIO_str_seek, posobj);
Py_DECREF(posobj);
if (res == NULL)
goto fail;
@@ -2837,7 +2834,7 @@
}
finally:
- res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL);
+ res = _PyObject_CallMethodIdOneArg(self->decoder, &PyId_setstate, saved_state);
Py_DECREF(saved_state);
if (res == NULL)
return NULL;
@@ -2851,7 +2848,7 @@
if (saved_state) {
PyObject *type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback);
- res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL);
+ res = _PyObject_CallMethodIdOneArg(self->decoder, &PyId_setstate, saved_state);
_PyErr_ChainExceptions(type, value, traceback);
Py_DECREF(saved_state);
Py_XDECREF(res);
@@ -2878,7 +2875,7 @@
return NULL;
Py_DECREF(res);
- return PyObject_CallMethodObjArgs(self->buffer, _PyIO_str_truncate, pos, NULL);
+ return _PyObject_CallMethodOneArg(self->buffer, _PyIO_str_truncate, pos);
}
static PyObject *
@@ -3055,9 +3052,9 @@
else {
PyObject *exc = NULL, *val, *tb;
if (self->finalizing) {
- res = _PyObject_CallMethodIdObjArgs(self->buffer,
- &PyId__dealloc_warn,
- self, NULL);
+ res = _PyObject_CallMethodIdOneArg(self->buffer,
+ &PyId__dealloc_warn,
+ (PyObject *)self);
if (res)
Py_DECREF(res);
else
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index ea5d24f..f27a6dc 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -204,8 +204,8 @@
PyObject *exc, *val, *tb;
int rc;
_Py_IDENTIFIER(close);
- res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type,
- &PyId_close, self, NULL);
+ res = _PyObject_CallMethodIdOneArg((PyObject*)&PyRawIOBase_Type,
+ &PyId_close, self);
if (!self->closehandle) {
self->handle = INVALID_HANDLE_VALUE;
return res;
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 0b0928f..735c13d 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -5773,7 +5773,7 @@
return NULL;
}
if (func == NULL) {
- return _PyObject_CallMethodIdObjArgs(cls, &PyId___new__, cls, NULL);
+ return _PyObject_CallMethodIdOneArg(cls, &PyId___new__, cls);
}
Py_DECREF(func);
}
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 30a9b88..47b8b62 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -1185,9 +1185,9 @@
return -1;
}
- uppercase_level = _PyObject_CallMethodIdObjArgs(
+ uppercase_level = _PyObject_CallMethodIdOneArg(
(PyObject *)&PyUnicode_Type, &PyId_upper,
- isolation_level, NULL);
+ isolation_level);
if (!uppercase_level) {
return -1;
}
@@ -1648,8 +1648,8 @@
goto finally;
}
- uppercase_name = _PyObject_CallMethodIdObjArgs((PyObject *)&PyUnicode_Type,
- &PyId_upper, name, NULL);
+ uppercase_name = _PyObject_CallMethodIdOneArg((PyObject *)&PyUnicode_Type,
+ &PyId_upper, name);
if (!uppercase_name) {
goto finally;
}
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 26c90a8..48986c4 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1507,7 +1507,7 @@
bytes = PyBytes_FromStringAndSize(ptr, size);
if (bytes == NULL)
return NULL;
- res = _PyObject_CallMethodIdObjArgs(f, &PyId_write, bytes, NULL);
+ res = _PyObject_CallMethodIdOneArg(f, &PyId_write, bytes);
Py_DECREF(bytes);
if (res == NULL)
return NULL;
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 052ed88..4de6787 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -1776,7 +1776,7 @@
if (str == NULL)
return -1;
- wr = _PyObject_CallMethodIdObjArgs(self->stream, &PyId_write, str, NULL);
+ wr = _PyObject_CallMethodIdOneArg(self->stream, &PyId_write, str);
Py_DECREF(str);
if (wr == NULL)
return -1;
@@ -1870,7 +1870,7 @@
if (PyBytes_Size(pwrt) > 0) {
PyObject *wr;
- wr = _PyObject_CallMethodIdObjArgs(self->stream, &PyId_write, pwrt);
+ wr = _PyObject_CallMethodIdOneArg(self->stream, &PyId_write, pwrt);
if (wr == NULL) {
Py_DECREF(pwrt);
return NULL;