File indexing completed on 2025-01-30 10:18:05
0001 #ifndef Py_INTERNAL_CALL_H
0002 #define Py_INTERNAL_CALL_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007 #ifndef Py_BUILD_CORE
0008 # error "this header requires Py_BUILD_CORE define"
0009 #endif
0010
0011 #include "pycore_pystate.h" // _PyThreadState_GET()
0012
0013 PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(
0014 PyThreadState *tstate,
0015 PyObject *callable,
0016 PyObject *obj,
0017 PyObject *args,
0018 PyObject *kwargs);
0019
0020 PyAPI_FUNC(PyObject *) _PyObject_FastCallDictTstate(
0021 PyThreadState *tstate,
0022 PyObject *callable,
0023 PyObject *const *args,
0024 size_t nargsf,
0025 PyObject *kwargs);
0026
0027 PyAPI_FUNC(PyObject *) _PyObject_Call(
0028 PyThreadState *tstate,
0029 PyObject *callable,
0030 PyObject *args,
0031 PyObject *kwargs);
0032
0033 extern PyObject * _PyObject_CallMethodFormat(
0034 PyThreadState *tstate, PyObject *callable, const char *format, ...);
0035
0036
0037
0038 static inline vectorcallfunc
0039 _PyVectorcall_FunctionInline(PyObject *callable)
0040 {
0041 assert(callable != NULL);
0042
0043 PyTypeObject *tp = Py_TYPE(callable);
0044 if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_VECTORCALL)) {
0045 return NULL;
0046 }
0047 assert(PyCallable_Check(callable));
0048
0049 Py_ssize_t offset = tp->tp_vectorcall_offset;
0050 assert(offset > 0);
0051
0052 vectorcallfunc ptr;
0053 memcpy(&ptr, (char *) callable + offset, sizeof(ptr));
0054 return ptr;
0055 }
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 static inline PyObject *
0077 _PyObject_VectorcallTstate(PyThreadState *tstate, PyObject *callable,
0078 PyObject *const *args, size_t nargsf,
0079 PyObject *kwnames)
0080 {
0081 vectorcallfunc func;
0082 PyObject *res;
0083
0084 assert(kwnames == NULL || PyTuple_Check(kwnames));
0085 assert(args != NULL || PyVectorcall_NARGS(nargsf) == 0);
0086
0087 func = _PyVectorcall_FunctionInline(callable);
0088 if (func == NULL) {
0089 Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
0090 return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwnames);
0091 }
0092 res = func(callable, args, nargsf, kwnames);
0093 return _Py_CheckFunctionResult(tstate, callable, res, NULL);
0094 }
0095
0096
0097 static inline PyObject *
0098 _PyObject_CallNoArgsTstate(PyThreadState *tstate, PyObject *func) {
0099 return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
0100 }
0101
0102
0103
0104 static inline PyObject *
0105 _PyObject_CallNoArgs(PyObject *func) {
0106 EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
0107 PyThreadState *tstate = _PyThreadState_GET();
0108 return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
0109 }
0110
0111
0112 static inline PyObject *
0113 _PyObject_FastCallTstate(PyThreadState *tstate, PyObject *func, PyObject *const *args, Py_ssize_t nargs)
0114 {
0115 EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
0116 return _PyObject_VectorcallTstate(tstate, func, args, (size_t)nargs, NULL);
0117 }
0118
0119 PyObject *const *
0120 _PyStack_UnpackDict(PyThreadState *tstate,
0121 PyObject *const *args, Py_ssize_t nargs,
0122 PyObject *kwargs, PyObject **p_kwnames);
0123
0124 void
0125 _PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs,
0126 PyObject *kwnames);
0127
0128 void _PyStack_UnpackDict_FreeNoDecRef(PyObject *const *stack, PyObject *kwnames);
0129
0130 #ifdef __cplusplus
0131 }
0132 #endif
0133 #endif