mirror of
https://github.com/python/cpython
synced 2026-09-29 10:35:30 +03:00
bpo-37483: add _PyObject_CallOneArg() function (#14558)
This commit is contained in:
parent
9d40554e0d
commit
196a530e00
44 changed files with 128 additions and 146 deletions
|
|
@ -172,13 +172,13 @@ PyObject_GetItem(PyObject *o, PyObject *key)
|
|||
}
|
||||
|
||||
if (PyType_Check(o)) {
|
||||
PyObject *meth, *result, *stack[1] = {key};
|
||||
PyObject *meth, *result;
|
||||
_Py_IDENTIFIER(__class_getitem__);
|
||||
if (_PyObject_LookupAttrId(o, &PyId___class_getitem__, &meth) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (meth) {
|
||||
result = _PyObject_FastCall(meth, stack, 1);
|
||||
result = _PyObject_CallOneArg(meth, key);
|
||||
Py_DECREF(meth);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -737,7 +737,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
|
|||
}
|
||||
|
||||
/* And call it. */
|
||||
result = PyObject_CallFunctionObjArgs(meth, format_spec, NULL);
|
||||
result = _PyObject_CallOneArg(meth, format_spec);
|
||||
Py_DECREF(meth);
|
||||
|
||||
if (result && !PyUnicode_Check(result)) {
|
||||
|
|
@ -2459,7 +2459,7 @@ PyObject_IsInstance(PyObject *inst, PyObject *cls)
|
|||
Py_DECREF(checker);
|
||||
return ok;
|
||||
}
|
||||
res = PyObject_CallFunctionObjArgs(checker, inst, NULL);
|
||||
res = _PyObject_CallOneArg(checker, inst);
|
||||
Py_LeaveRecursiveCall();
|
||||
Py_DECREF(checker);
|
||||
if (res != NULL) {
|
||||
|
|
@ -2533,7 +2533,7 @@ PyObject_IsSubclass(PyObject *derived, PyObject *cls)
|
|||
Py_DECREF(checker);
|
||||
return ok;
|
||||
}
|
||||
res = PyObject_CallFunctionObjArgs(checker, derived, NULL);
|
||||
res = _PyObject_CallOneArg(checker, derived);
|
||||
Py_LeaveRecursiveCall();
|
||||
Py_DECREF(checker);
|
||||
if (res != NULL) {
|
||||
|
|
|
|||
|
|
@ -89,8 +89,7 @@ _canresize(PyByteArrayObject *self)
|
|||
PyObject *
|
||||
PyByteArray_FromObject(PyObject *input)
|
||||
{
|
||||
return PyObject_CallFunctionObjArgs((PyObject *)&PyByteArray_Type,
|
||||
input, NULL);
|
||||
return _PyObject_CallOneArg((PyObject *)&PyByteArray_Type, input);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
@ -2018,8 +2017,7 @@ bytearray_fromhex_impl(PyTypeObject *type, PyObject *string)
|
|||
{
|
||||
PyObject *result = _PyBytes_FromHex(string, type == &PyByteArray_Type);
|
||||
if (type != &PyByteArray_Type && result != NULL) {
|
||||
Py_SETREF(result, PyObject_CallFunctionObjArgs((PyObject *)type,
|
||||
result, NULL));
|
||||
Py_SETREF(result, _PyObject_CallOneArg((PyObject *)type, result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2333,8 +2333,7 @@ bytes_fromhex_impl(PyTypeObject *type, PyObject *string)
|
|||
{
|
||||
PyObject *result = _PyBytes_FromHex(string, 0);
|
||||
if (type != &PyBytes_Type && result != NULL) {
|
||||
Py_SETREF(result, PyObject_CallFunctionObjArgs((PyObject *)type,
|
||||
result, NULL));
|
||||
Py_SETREF(result, _PyObject_CallOneArg((PyObject *)type, result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1340,8 +1340,7 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *args[1] = {obj};
|
||||
return _PyObject_FastCall(gs->prop_get, args, 1);
|
||||
return _PyObject_CallOneArg(gs->prop_get, obj);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -1362,7 +1361,7 @@ property_descr_set(PyObject *self, PyObject *obj, PyObject *value)
|
|||
return -1;
|
||||
}
|
||||
if (value == NULL)
|
||||
res = PyObject_CallFunctionObjArgs(func, obj, NULL);
|
||||
res = _PyObject_CallOneArg(func, obj);
|
||||
else
|
||||
res = PyObject_CallFunctionObjArgs(func, obj, value, NULL);
|
||||
if (res == NULL)
|
||||
|
|
|
|||
|
|
@ -2113,8 +2113,7 @@ dict_subscript(PyDictObject *mp, PyObject *key)
|
|||
_Py_IDENTIFIER(__missing__);
|
||||
missing = _PyObject_LookupSpecial((PyObject *)mp, &PyId___missing__);
|
||||
if (missing != NULL) {
|
||||
res = PyObject_CallFunctionObjArgs(missing,
|
||||
key, NULL);
|
||||
res = _PyObject_CallOneArg(missing, key);
|
||||
Py_DECREF(missing);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
|
|||
Py_DECREF(writer);
|
||||
return -1;
|
||||
}
|
||||
result = PyObject_CallFunctionObjArgs(writer, value, NULL);
|
||||
result = _PyObject_CallOneArg(writer, value);
|
||||
Py_DECREF(value);
|
||||
Py_DECREF(writer);
|
||||
if (result == NULL)
|
||||
|
|
|
|||
|
|
@ -1501,7 +1501,7 @@ float_fromhex(PyTypeObject *type, PyObject *string)
|
|||
goto parse_error;
|
||||
result = PyFloat_FromDouble(negate ? -x : x);
|
||||
if (type != &PyFloat_Type && result != NULL) {
|
||||
Py_SETREF(result, PyObject_CallFunctionObjArgs((PyObject *)type, result, NULL));
|
||||
Py_SETREF(result, _PyObject_CallOneArg((PyObject *)type, result));
|
||||
}
|
||||
return result;
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ _PyGen_Finalize(PyObject *self)
|
|||
/* Save the current exception, if any. */
|
||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||
|
||||
res = PyObject_CallFunctionObjArgs(finalizer, self, NULL);
|
||||
res = _PyObject_CallOneArg(finalizer, self);
|
||||
|
||||
if (res == NULL) {
|
||||
PyErr_WriteUnraisable(self);
|
||||
|
|
@ -562,7 +562,7 @@ _PyGen_SetStopIterationValue(PyObject *value)
|
|||
return 0;
|
||||
}
|
||||
/* Construct an exception instance manually with
|
||||
* PyObject_CallFunctionObjArgs and pass it to PyErr_SetObject.
|
||||
* _PyObject_CallOneArg and pass it to PyErr_SetObject.
|
||||
*
|
||||
* We do this to handle a situation when "value" is a tuple, in which
|
||||
* case PyErr_SetObject would set the value of StopIteration to
|
||||
|
|
@ -570,7 +570,7 @@ _PyGen_SetStopIterationValue(PyObject *value)
|
|||
*
|
||||
* (See PyErr_SetObject/_PyErr_CreateException code for details.)
|
||||
*/
|
||||
e = PyObject_CallFunctionObjArgs(PyExc_StopIteration, value, NULL);
|
||||
e = _PyObject_CallOneArg(PyExc_StopIteration, value);
|
||||
if (e == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1279,7 +1279,7 @@ async_gen_init_hooks(PyAsyncGenObject *o)
|
|||
PyObject *res;
|
||||
|
||||
Py_INCREF(firstiter);
|
||||
res = PyObject_CallFunctionObjArgs(firstiter, o, NULL);
|
||||
res = _PyObject_CallOneArg(firstiter, (PyObject *)o);
|
||||
Py_DECREF(firstiter);
|
||||
if (res == NULL) {
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -2258,8 +2258,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
|
|||
}
|
||||
|
||||
for (i = 0; i < saved_ob_size ; i++) {
|
||||
keys[i] = PyObject_CallFunctionObjArgs(keyfunc, saved_ob_item[i],
|
||||
NULL);
|
||||
keys[i] = _PyObject_CallOneArg(keyfunc, saved_ob_item[i]);
|
||||
if (keys[i] == NULL) {
|
||||
for (i=i-1 ; i>=0 ; i--)
|
||||
Py_DECREF(keys[i]);
|
||||
|
|
|
|||
|
|
@ -5611,8 +5611,7 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
|
|||
Py_DECREF(bytes);
|
||||
|
||||
if (long_obj != NULL && type != &PyLong_Type) {
|
||||
Py_SETREF(long_obj, PyObject_CallFunctionObjArgs((PyObject *)type,
|
||||
long_obj, NULL));
|
||||
Py_SETREF(long_obj, _PyObject_CallOneArg((PyObject *)type, long_obj));
|
||||
}
|
||||
|
||||
return long_obj;
|
||||
|
|
|
|||
|
|
@ -1962,7 +1962,7 @@ struct_get_unpacker(const char *fmt, Py_ssize_t itemsize)
|
|||
if (format == NULL)
|
||||
goto error;
|
||||
|
||||
structobj = PyObject_CallFunctionObjArgs(Struct, format, NULL);
|
||||
structobj = _PyObject_CallOneArg(Struct, format);
|
||||
if (structobj == NULL)
|
||||
goto error;
|
||||
|
||||
|
|
@ -2001,7 +2001,7 @@ struct_unpack_single(const char *ptr, struct unpacker *x)
|
|||
PyObject *v;
|
||||
|
||||
memcpy(x->item, ptr, x->itemsize);
|
||||
v = PyObject_CallFunctionObjArgs(x->unpack_from, x->mview, NULL);
|
||||
v = _PyObject_CallOneArg(x->unpack_from, x->mview);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -736,8 +736,7 @@ module_getattro(PyModuleObject *m, PyObject *name)
|
|||
_Py_IDENTIFIER(__getattr__);
|
||||
getattr = _PyDict_GetItemId(m->md_dict, &PyId___getattr__);
|
||||
if (getattr) {
|
||||
PyObject* stack[1] = {name};
|
||||
return _PyObject_FastCall(getattr, stack, 1);
|
||||
return _PyObject_CallOneArg(getattr, name);
|
||||
}
|
||||
_Py_IDENTIFIER(__name__);
|
||||
mod_name = _PyDict_GetItemId(m->md_dict, &PyId___name__);
|
||||
|
|
|
|||
|
|
@ -1459,8 +1459,7 @@ static PyObject*
|
|||
call_unbound_noarg(int unbound, PyObject *func, PyObject *self)
|
||||
{
|
||||
if (unbound) {
|
||||
PyObject *args[1] = {self};
|
||||
return _PyObject_FastCall(func, args, 1);
|
||||
return _PyObject_CallOneArg(func, self);
|
||||
}
|
||||
else {
|
||||
return _PyObject_CallNoArg(func);
|
||||
|
|
@ -6561,7 +6560,7 @@ call_attribute(PyObject *self, PyObject *attr, PyObject *name)
|
|||
else
|
||||
attr = descr;
|
||||
}
|
||||
res = PyObject_CallFunctionObjArgs(attr, name, NULL);
|
||||
res = _PyObject_CallOneArg(attr, name);
|
||||
Py_XDECREF(descr);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4248,7 +4248,7 @@ unicode_decode_call_errorhandler_wchar(
|
|||
if (*exceptionObject == NULL)
|
||||
goto onError;
|
||||
|
||||
restuple = PyObject_CallFunctionObjArgs(*errorHandler, *exceptionObject, NULL);
|
||||
restuple = _PyObject_CallOneArg(*errorHandler, *exceptionObject);
|
||||
if (restuple == NULL)
|
||||
goto onError;
|
||||
if (!PyTuple_Check(restuple)) {
|
||||
|
|
@ -4352,7 +4352,7 @@ unicode_decode_call_errorhandler_writer(
|
|||
if (*exceptionObject == NULL)
|
||||
goto onError;
|
||||
|
||||
restuple = PyObject_CallFunctionObjArgs(*errorHandler, *exceptionObject, NULL);
|
||||
restuple = _PyObject_CallOneArg(*errorHandler, *exceptionObject);
|
||||
if (restuple == NULL)
|
||||
goto onError;
|
||||
if (!PyTuple_Check(restuple)) {
|
||||
|
|
@ -6799,8 +6799,7 @@ unicode_encode_call_errorhandler(const char *errors,
|
|||
if (*exceptionObject == NULL)
|
||||
return NULL;
|
||||
|
||||
restuple = PyObject_CallFunctionObjArgs(
|
||||
*errorHandler, *exceptionObject, NULL);
|
||||
restuple = _PyObject_CallOneArg(*errorHandler, *exceptionObject);
|
||||
if (restuple == NULL)
|
||||
return NULL;
|
||||
if (!PyTuple_Check(restuple)) {
|
||||
|
|
@ -8778,8 +8777,7 @@ unicode_translate_call_errorhandler(const char *errors,
|
|||
if (*exceptionObject == NULL)
|
||||
return NULL;
|
||||
|
||||
restuple = PyObject_CallFunctionObjArgs(
|
||||
*errorHandler, *exceptionObject, NULL);
|
||||
restuple = _PyObject_CallOneArg(*errorHandler, *exceptionObject);
|
||||
if (restuple == NULL)
|
||||
return NULL;
|
||||
if (!PyTuple_Check(restuple)) {
|
||||
|
|
|
|||
|
|
@ -874,7 +874,7 @@ PyWeakref_GetObject(PyObject *ref)
|
|||
static void
|
||||
handle_callback(PyWeakReference *ref, PyObject *callback)
|
||||
{
|
||||
PyObject *cbresult = PyObject_CallFunctionObjArgs(callback, ref, NULL);
|
||||
PyObject *cbresult = _PyObject_CallOneArg(callback, (PyObject *)ref);
|
||||
|
||||
if (cbresult == NULL)
|
||||
PyErr_WriteUnraisable(callback);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue