#include "frameobject.h"
-static PyObject *
-cfunction_call_varargs(PyObject *func, PyObject *args, PyObject *kwargs);
-
static PyObject *const *
_PyStack_UnpackDict(PyObject *const *args, Py_ssize_t nargs, PyObject *kwargs,
PyObject **p_kwnames);
if (_PyVectorcall_Function(callable) != NULL) {
return PyVectorcall_Call(callable, args, kwargs);
}
- else if (PyCFunction_Check(callable)) {
- /* This must be a METH_VARARGS function, otherwise we would be
- * in the previous case */
- return cfunction_call_varargs(callable, args, kwargs);
- }
else {
call = callable->ob_type->tp_call;
if (call == NULL) {
}
+PyObject *
+PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
+{
+ return PyObject_Call(callable, args, kwargs);
+}
+
+
/* --- PyFunction call functions ---------------------------------- */
static PyObject* _Py_HOT_FUNCTION
}
-/* --- PyCFunction call functions --------------------------------- */
-
-static PyObject *
-cfunction_call_varargs(PyObject *func, PyObject *args, PyObject *kwargs)
-{
- assert(!PyErr_Occurred());
- assert(kwargs == NULL || PyDict_Check(kwargs));
-
- PyCFunction meth = PyCFunction_GET_FUNCTION(func);
- PyObject *self = PyCFunction_GET_SELF(func);
- PyObject *result;
-
- assert(PyCFunction_GET_FLAGS(func) & METH_VARARGS);
- if (PyCFunction_GET_FLAGS(func) & METH_KEYWORDS) {
- if (Py_EnterRecursiveCall(" while calling a Python object")) {
- return NULL;
- }
-
- result = (*(PyCFunctionWithKeywords)(void(*)(void))meth)(self, args, kwargs);
-
- Py_LeaveRecursiveCall();
- }
- else {
- if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
- PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
- ((PyCFunctionObject*)func)->m_ml->ml_name);
- return NULL;
- }
-
- if (Py_EnterRecursiveCall(" while calling a Python object")) {
- return NULL;
- }
-
- result = (*meth)(self, args);
-
- Py_LeaveRecursiveCall();
- }
-
- return _Py_CheckFunctionResult(func, result, NULL);
-}
-
-
-PyObject *
-PyCFunction_Call(PyObject *func, PyObject *args, PyObject *kwargs)
-{
- /* For METH_VARARGS, we cannot use vectorcall as the vectorcall pointer
- * is NULL. This is intentional, since vectorcall would be slower. */
- if (PyCFunction_GET_FLAGS(func) & METH_VARARGS) {
- return cfunction_call_varargs(func, args, kwargs);
- }
- return PyVectorcall_Call(func, args, kwargs);
-}
-
-
/* --- More complex call functions -------------------------------- */
/* External interface to call any callable object.
PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
static PyObject * cfunction_vectorcall_O(
PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
+static PyObject * cfunction_call(
+ PyObject *func, PyObject *args, PyObject *kwargs);
PyObject *
0, /* tp_as_sequence */
0, /* tp_as_mapping */
(hashfunc)meth_hash, /* tp_hash */
- PyCFunction_Call, /* tp_call */
+ cfunction_call, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
Py_LeaveRecursiveCall();
return result;
}
+
+
+static PyObject *
+cfunction_call(PyObject *func, PyObject *args, PyObject *kwargs)
+{
+ assert(!PyErr_Occurred());
+ assert(kwargs == NULL || PyDict_Check(kwargs));
+
+ int flags = PyCFunction_GET_FLAGS(func);
+ if (!(flags & METH_VARARGS)) {
+ /* If this is not a METH_VARARGS function, delegate to vectorcall */
+ return PyVectorcall_Call(func, args, kwargs);
+ }
+
+ /* For METH_VARARGS, we cannot use vectorcall as the vectorcall pointer
+ * is NULL. This is intentional, since vectorcall would be slower. */
+ PyCFunction meth = PyCFunction_GET_FUNCTION(func);
+ PyObject *self = PyCFunction_GET_SELF(func);
+
+ PyObject *result;
+ if (flags & METH_KEYWORDS) {
+ result = (*(PyCFunctionWithKeywords)(void(*)(void))meth)(self, args, kwargs);
+ }
+ else {
+ if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
+ PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
+ ((PyCFunctionObject*)func)->m_ml->ml_name);
+ return NULL;
+ }
+ result = meth(self, args);
+ }
+ return _Py_CheckFunctionResult(func, result, NULL);
+}