Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
abstract.h105 linesDownload Raw Back to cpython
1#ifndef Py_CPYTHON_ABSTRACTOBJECT_H2#  error "this header file must not be included directly"3#endif4 5/* === Object Protocol ================================================== */6 7/* Like PyObject_CallMethod(), but expect a _Py_Identifier*8   as the method name. */9PyAPI_FUNC(PyObject*) _PyObject_CallMethodId(10    PyObject *obj,11    _Py_Identifier *name,12    const char *format, ...);13 14/* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple)15   format to a Python dictionary ("kwargs" dict).16 17   The type of kwnames keys is not checked. The final function getting18   arguments is responsible to check if all keys are strings, for example using19   PyArg_ParseTupleAndKeywords() or PyArg_ValidateKeywordArguments().20 21   Duplicate keys are merged using the last value. If duplicate keys must raise22   an exception, the caller is responsible to implement an explicit keys on23   kwnames. */24PyAPI_FUNC(PyObject*) _PyStack_AsDict(PyObject *const *values, PyObject *kwnames);25 26 27/* === Vectorcall protocol (PEP 590) ============================= */28 29// PyVectorcall_NARGS() is exported as a function for the stable ABI.30// Here (when we are not using the stable ABI), the name is overridden to31// call a static inline function for best performance.32static inline Py_ssize_t33_PyVectorcall_NARGS(size_t n)34{35    return n & ~PY_VECTORCALL_ARGUMENTS_OFFSET;36}37#define PyVectorcall_NARGS(n) _PyVectorcall_NARGS(n)38 39PyAPI_FUNC(vectorcallfunc) PyVectorcall_Function(PyObject *callable);40 41// Backwards compatibility aliases (PEP 590) for API that was provisional42// in Python 3.843#define _PyObject_Vectorcall PyObject_Vectorcall44#define _PyObject_VectorcallMethod PyObject_VectorcallMethod45#define _PyObject_FastCallDict PyObject_VectorcallDict46#define _PyVectorcall_Function PyVectorcall_Function47#define _PyObject_CallOneArg PyObject_CallOneArg48#define _PyObject_CallMethodNoArgs PyObject_CallMethodNoArgs49#define _PyObject_CallMethodOneArg PyObject_CallMethodOneArg50 51/* Same as PyObject_Vectorcall except that keyword arguments are passed as52   dict, which may be NULL if there are no keyword arguments. */53PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(54    PyObject *callable,55    PyObject *const *args,56    size_t nargsf,57    PyObject *kwargs);58 59PyAPI_FUNC(PyObject *) PyObject_CallOneArg(PyObject *func, PyObject *arg);60 61static inline PyObject *62PyObject_CallMethodNoArgs(PyObject *self, PyObject *name)63{64    size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;65    return PyObject_VectorcallMethod(name, &self, nargsf, _Py_NULL);66}67 68static inline PyObject *69PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg)70{71    PyObject *args[2] = {self, arg};72    size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;73    assert(arg != NULL);74    return PyObject_VectorcallMethod(name, args, nargsf, _Py_NULL);75}76 77/* Guess the size of object 'o' using len(o) or o.__length_hint__().78   If neither of those return a non-negative value, then return the default79   value.  If one of the calls fails, this function returns -1. */80PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);81 82/* === Sequence protocol ================================================ */83 84/* Assume tp_as_sequence and sq_item exist and that 'i' does not85   need to be corrected for a negative index. */86#define PySequence_ITEM(o, i)\87    ( Py_TYPE(o)->tp_as_sequence->sq_item((o), (i)) )88 89/* Return the size of the sequence 'o', assuming that 'o' was returned by90   PySequence_Fast and is not NULL. */91#define PySequence_Fast_GET_SIZE(o) \92    (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))93 94/* Return the 'i'-th element of the sequence 'o', assuming that o was returned95   by PySequence_Fast, and that i is within bounds. */96#define PySequence_Fast_GET_ITEM(o, i)\97     (PyList_Check(o) ? PyList_GET_ITEM((o), (i)) : PyTuple_GET_ITEM((o), (i)))98 99/* Return a pointer to the underlying item array for100   an object returned by PySequence_Fast */101#define PySequence_Fast_ITEMS(sf) \102    (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \103                      : ((PyTupleObject *)(sf))->ob_item)104 105 
codekingpro/portable-devtools · Team Ai