Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
methodobject.h147 linesDownload Raw Back to include
1 2/* Method object interface */3 4#ifndef Py_METHODOBJECT_H5#define Py_METHODOBJECT_H6#ifdef __cplusplus7extern "C" {8#endif9 10/* This is about the type 'builtin_function_or_method',11   not Python methods in user-defined classes.  See classobject.h12   for the latter. */13 14PyAPI_DATA(PyTypeObject) PyCFunction_Type;15 16#define PyCFunction_CheckExact(op) Py_IS_TYPE((op), &PyCFunction_Type)17#define PyCFunction_Check(op) PyObject_TypeCheck((op), &PyCFunction_Type)18 19typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);20typedef PyObject *(*PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t);21typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,22                                             PyObject *);23typedef PyObject *(*PyCFunctionFastWithKeywords) (PyObject *,24                                                  PyObject *const *, Py_ssize_t,25                                                  PyObject *);26typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,27                               Py_ssize_t, PyObject *);28 29// For backwards compatibility. `METH_FASTCALL` was added to the stable API in30// 3.10 alongside `_PyCFunctionFastWithKeywords` and `_PyCFunctionFast`.31// Note that the underscore-prefixed names were documented in public docs;32// people may be using them.33typedef PyCFunctionFast _PyCFunctionFast;34typedef PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords;35 36// Cast a function to the PyCFunction type to use it with PyMethodDef.37//38// This macro can be used to prevent compiler warnings if the first parameter39// uses a different pointer type than PyObject* (ex: METH_VARARGS and METH_O40// calling conventions).41//42// The macro can also be used for METH_FASTCALL and METH_VARARGS|METH_KEYWORDS43// calling conventions to avoid compiler warnings because the function has more44// than 2 parameters. The macro first casts the function to the45// "void func(void)" type to prevent compiler warnings.46//47// If a function is declared with the METH_NOARGS calling convention, it must48// have 2 parameters. Since the second parameter is unused, Py_UNUSED() can be49// used to prevent a compiler warning. If the function has a single parameter,50// it triggers an undefined behavior when Python calls it with 2 parameters51// (bpo-33012).52#define _PyCFunction_CAST(func)                         \53    _Py_FUNC_CAST(PyCFunction, func)54// The macros below are given for semantic convenience, allowing users55// to see whether a cast to suppress an undefined behavior is necessary.56// Note: At runtime, the original function signature must be respected.57#define _PyCFunctionFast_CAST(func)                     \58    _Py_FUNC_CAST(PyCFunctionFast, func)59#define _PyCFunctionWithKeywords_CAST(func)             \60    _Py_FUNC_CAST(PyCFunctionWithKeywords, func)61#define _PyCFunctionFastWithKeywords_CAST(func)         \62    _Py_FUNC_CAST(PyCFunctionFastWithKeywords, func)63 64PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);65PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);66PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);67 68struct PyMethodDef {69    const char  *ml_name;   /* The name of the built-in function/method */70    PyCFunction ml_meth;    /* The C function that implements it */71    int         ml_flags;   /* Combination of METH_xxx flags, which mostly72                               describe the args expected by the C func */73    const char  *ml_doc;    /* The __doc__ attribute, or NULL */74};75 76/* PyCFunction_New is declared as a function for stable ABI (declaration is77 * needed for e.g. GCC with -fvisibility=hidden), but redefined as a macro78 * that calls PyCFunction_NewEx. */79PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);80#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)81 82/* PyCFunction_NewEx is similar: on 3.9+, this calls PyCMethod_New. */83PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,84                                         PyObject *);85 86#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x0309000087#define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL)88PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *,89                                     PyObject *, PyTypeObject *);90#endif91 92 93/* Flag passed to newmethodobject */94/* #define METH_OLDARGS  0x0000   -- unsupported now */95#define METH_VARARGS  0x000196#define METH_KEYWORDS 0x000297/* METH_NOARGS and METH_O must not be combined with the flags above. */98#define METH_NOARGS   0x000499#define METH_O        0x0008100 101/* METH_CLASS and METH_STATIC are a little different; these control102   the construction of methods for a class.  These cannot be used for103   functions in modules. */104#define METH_CLASS    0x0010105#define METH_STATIC   0x0020106 107/* METH_COEXIST allows a method to be entered even though a slot has108   already filled the entry.  When defined, the flag allows a separate109   method, "__contains__" for example, to coexist with a defined110   slot like sq_contains. */111 112#define METH_COEXIST   0x0040113 114#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a0000115#  define METH_FASTCALL  0x0080116#endif117 118/* This bit is preserved for Stackless Python */119#ifdef STACKLESS120#  define METH_STACKLESS 0x0100121#else122#  define METH_STACKLESS 0x0000123#endif124 125/* METH_METHOD means the function stores an126 * additional reference to the class that defines it;127 * both self and class are passed to it.128 * It uses PyCMethodObject instead of PyCFunctionObject.129 * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC.130 */131 132#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000133#define METH_METHOD 0x0200134#endif135 136 137#ifndef Py_LIMITED_API138#  define Py_CPYTHON_METHODOBJECT_H139#  include "cpython/methodobject.h"140#  undef Py_CPYTHON_METHODOBJECT_H141#endif142 143#ifdef __cplusplus144}145#endif146#endif /* !Py_METHODOBJECT_H */147 
codekingpro/portable-devtools · Team Ai