3#ifndef __NUITKA_CALLING_H__
4#define __NUITKA_CALLING_H__
8#include "nuitka/prelude.h"
12extern char const *GET_CALLABLE_NAME(PyObject *
object);
13extern char const *GET_CALLABLE_DESC(PyObject *
object);
14extern char const *GET_CLASS_NAME(PyObject *class_object);
15extern char const *GET_INSTANCE_CLASS_NAME(PyThreadState *tstate, PyObject *instance);
18NUITKA_MAY_BE_UNUSED
static inline PyObject *Nuitka_CheckFunctionResult(PyThreadState *tstate, PyObject *callable,
21 if (unlikely(!HAS_ERROR_OCCURRED(tstate))) {
22#if PYTHON_VERSION < 0x3b0
23 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_SystemError,
"NULL result without error from call");
25 PyErr_Format(PyExc_SystemError,
"%R returned NULL without setting an exception", callable);
33 if (unlikely(DROP_ERROR_OCCURRED(tstate))) {
36#if PYTHON_VERSION < 0x3a0
37 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_SystemError,
"result with error set from call");
38#elif PYTHON_VERSION < 0x3b0
39 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_SystemError,
"result with exception set from call");
41 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_SystemError,
"%s() returned a result with an exception set",
42 GET_CALLABLE_NAME(callable));
51NUITKA_MAY_BE_UNUSED
static PyObject *CALL_FUNCTION(PyThreadState *tstate, PyObject *function_object,
52 PyObject *positional_args, PyObject *named_args) {
55 assert(!HAS_ERROR_OCCURRED(tstate));
57 CHECK_OBJECT(function_object);
58 CHECK_OBJECT(positional_args);
59 assert(named_args == NULL || Py_REFCNT(named_args) > 0);
61 ternaryfunc call_slot = Py_TYPE(function_object)->tp_call;
63 if (unlikely(call_slot == NULL)) {
64 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT(
"'%s' object is not callable", function_object);
69 if (unlikely(Py_EnterRecursiveCall((
char *)
" while calling a Python object"))) {
73 PyObject *result = (*call_slot)(function_object, positional_args, named_args);
75 Py_LeaveRecursiveCall();
77 return Nuitka_CheckFunctionResult(tstate, function_object, result);
81extern PyObject *CALL_FUNCTION_NO_ARGS(PyThreadState *tstate, PyObject *called);
84NUITKA_MAY_BE_UNUSED
static PyObject *CALL_FUNCTION_WITH_POS_ARGS(PyThreadState *tstate, PyObject *function_object,
85 PyObject *positional_args) {
86 return CALL_FUNCTION(tstate, function_object, positional_args, NULL);
90extern PyObject *CALL_METHOD_WITH_POS_ARGS(PyThreadState *tstate, PyObject *source, PyObject *attr_name,
91 PyObject *positional_args);
94NUITKA_MAY_BE_UNUSED
static PyObject *CALL_FUNCTION_WITH_KW_ARGS(PyThreadState *tstate, PyObject *function_object,
95 PyObject *named_args) {
96 return CALL_FUNCTION(tstate, function_object, const_tuple_empty, named_args);
100extern PyObject *CALL_BUILTIN_KW_ARGS(PyThreadState *tstate, PyObject *callable, PyObject **args,
101 char const **arg_names,
int max_args,
int kw_only_args);
104extern void formatCannotInstantiateAbstractClass(PyThreadState *tstate, PyTypeObject *type);
106#include "nuitka/helper/calling_generated.h"