.. versionadded:: 3.9
+.. c:function:: PyObject* _PyObject_CallMethodOneArg(PyObject *obj, PyObject *name, PyObject *arg)
+
+ Call a method of the Python object *obj* with a single positional argument
+ *arg*, where the name of the method is given as a Python string object in
+ *name*.
+
+ Return the result of the call on success, or raise an exception and return
+ *NULL* on failure.
+
+ .. versionadded:: 3.9
+
+
.. c:function:: PyObject* _PyObject_Vectorcall(PyObject *callable, PyObject *const *args, size_t nargsf, PyObject *kwnames)
Call a callable Python object *callable*, using
1 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
}
+static inline PyObject *
+_PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg)
+{
+ assert(arg != NULL);
+ PyObject *args[2] = {self, arg};
+ return _PyObject_VectorcallMethod(name, args,
+ 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
+}
+
/* Like PyObject_CallMethod(), but expect a _Py_Identifier*
as the method name. */
PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj,
1 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
}
+static inline PyObject *
+_PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg)
+{
+ assert(arg != NULL);
+ PyObject *args[2] = {self, arg};
+ return _PyObject_VectorcallMethodId(name, args,
+ 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
+}
+
PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o);
/* Guess the size of object 'o' using len(o) or o.__length_hint__().
-Add fast functions for calling methods: :c:func:`_PyObject_VectorcallMethod`
-and :c:func:`_PyObject_CallMethodNoArgs`
+Add fast functions for calling methods: :c:func:`_PyObject_VectorcallMethod`,
+:c:func:`_PyObject_CallMethodNoArgs` and :c:func:`_PyObject_CallMethodOneArg`.
/*[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;
}
}
/* 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;
}
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;
}
/* 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;
}
{
_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;
}
{
_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;
}
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);
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;
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;
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;
* 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;
}
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. */
temp = (PyObject *)result;
result = (PyDateTime_DateTime *)
- _PyObject_CallMethodIdObjArgs(tzinfo, &PyId_fromutc, temp, NULL);
+ _PyObject_CallMethodIdOneArg(tzinfo, &PyId_fromutc, temp);
Py_DECREF(temp);
return result;
}
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);
{
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
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 */
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)
*/
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);
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;
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;
}
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:
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)
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)
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;
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)
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;
}
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;
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);
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 *
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
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;
return NULL;
}
if (func == NULL) {
- return _PyObject_CallMethodIdObjArgs(cls, &PyId___new__, cls, NULL);
+ return _PyObject_CallMethodIdOneArg(cls, &PyId___new__, cls);
}
Py_DECREF(func);
}
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;
}
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;
}
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;
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;
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;
if (result == NULL)
return NULL;
- tmp = _PyObject_CallMethodIdObjArgs(result, &PyId_difference_update, other, NULL);
+ tmp = _PyObject_CallMethodIdOneArg(result, &PyId_difference_update, other);
if (tmp == NULL) {
Py_DECREF(result);
return NULL;
if (result == NULL)
return NULL;
- tmp = _PyObject_CallMethodIdObjArgs(result, &PyId_intersection_update, other, NULL);
+ tmp = _PyObject_CallMethodIdOneArg(result, &PyId_intersection_update, other);
if (tmp == NULL) {
Py_DECREF(result);
return NULL;
if (result == NULL)
return NULL;
- tmp = _PyObject_CallMethodIdObjArgs(result, &PyId_update, other, NULL);
+ tmp = _PyObject_CallMethodIdOneArg(result, &PyId_update, other);
if (tmp == NULL) {
Py_DECREF(result);
return NULL;
if (result == NULL)
return NULL;
- tmp = _PyObject_CallMethodIdObjArgs(result, &PyId_symmetric_difference_update, other, NULL);
+ tmp = _PyObject_CallMethodIdOneArg(result, &PyId_symmetric_difference_update, other);
if (tmp == NULL) {
Py_DECREF(result);
return NULL;
/* Use _slotnames function from the copyreg module to find the slots
by this class and its bases. This function will cache the result
in __slotnames__. */
- slotnames = _PyObject_CallMethodIdObjArgs(copyreg, &PyId__slotnames,
- cls, NULL);
+ slotnames = _PyObject_CallMethodIdOneArg(copyreg, &PyId__slotnames,
+ (PyObject *)cls);
Py_DECREF(copyreg);
if (slotnames == NULL)
return NULL;
}
/* Otherwise assume a regex filter and call its match() method */
- result = _PyObject_CallMethodIdObjArgs(obj, &PyId_match, arg, NULL);
+ result = _PyObject_CallMethodIdOneArg(obj, &PyId_match, arg);
if (result == NULL)
return -1;
if (v == Py_None)
retval = Py_TYPE(receiver)->tp_iternext(receiver);
else
- retval = _PyObject_CallMethodIdObjArgs(receiver, &PyId_send, v, NULL);
+ retval = _PyObject_CallMethodIdOneArg(receiver, &PyId_send, v);
}
Py_DECREF(v);
if (retval == NULL) {
external= PyObject_GetAttrString(interp->importlib,
"_bootstrap_external");
if (external != NULL) {
- pathobj = _PyObject_CallMethodIdObjArgs(external,
- &PyId__get_sourcefile, cpathobj,
- NULL);
+ pathobj = _PyObject_CallMethodIdOneArg(
+ external, &PyId__get_sourcefile, cpathobj);
Py_DECREF(external);
}
if (pathobj == NULL)
*/
spec = _PyObject_GetAttrId(mod, &PyId___spec__);
if (_PyModuleSpec_IsInitializing(spec)) {
- PyObject *value = _PyObject_CallMethodIdObjArgs(interp->importlib,
- &PyId__lock_unlock_module, abs_name,
- NULL);
+ PyObject *value = _PyObject_CallMethodIdOneArg(
+ interp->importlib, &PyId__lock_unlock_module, abs_name);
if (value == NULL) {
Py_DECREF(spec);
goto error;
}
}
- reloaded_module = _PyObject_CallMethodIdObjArgs(imp, &PyId_reload, m, NULL);
+ reloaded_module = _PyObject_CallMethodIdOneArg(imp, &PyId_reload, m);
Py_DECREF(imp);
return reloaded_module;
}
s = PyMarshal_WriteObjectToString(value, version);
if (s == NULL)
return NULL;
- res = _PyObject_CallMethodIdObjArgs(file, &PyId_write, s, NULL);
+ res = _PyObject_CallMethodIdOneArg(file, &PyId_write, s);
Py_DECREF(s);
return res;
}
buffer = _PyObject_GetAttrId(outf, &PyId_buffer);
if (buffer) {
- result = _PyObject_CallMethodIdObjArgs(buffer, &PyId_write, encoded, NULL);
+ result = _PyObject_CallMethodIdOneArg(buffer, &PyId_write, encoded);
Py_DECREF(buffer);
Py_DECREF(encoded);
if (result == NULL)
if (file == NULL)
return -1;
assert(unicode != NULL);
- PyObject *margs[2] = {file, unicode};
- PyObject *result = _PyObject_VectorcallMethodId(&PyId_write, margs,
- 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
+ PyObject *result = _PyObject_CallMethodIdOneArg(file, &PyId_write, unicode);
if (result == NULL) {
return -1;
}