Back to home page

EIC code displayed by LXR

 
 

    


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 // Static inline variant of public PyVectorcall_Function().
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 /* Call the callable object 'callable' with the "vectorcall" calling
0059    convention.
0060 
0061    args is a C array for positional arguments.
0062 
0063    nargsf is the number of positional arguments plus optionally the flag
0064    PY_VECTORCALL_ARGUMENTS_OFFSET which means that the caller is allowed to
0065    modify args[-1].
0066 
0067    kwnames is a tuple of keyword names. The values of the keyword arguments
0068    are stored in "args" after the positional arguments (note that the number
0069    of keyword arguments does not change nargsf). kwnames can also be NULL if
0070    there are no keyword arguments.
0071 
0072    keywords must only contain strings and all keys must be unique.
0073 
0074    Return the result on success. Raise an exception and return NULL on
0075    error. */
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 // Private static inline function variant of public PyObject_CallNoArgs()
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 /* !Py_INTERNAL_CALL_H */