Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:53

0001 
0002 /* Method object interface */
0003 
0004 #ifndef Py_METHODOBJECT_H
0005 #define Py_METHODOBJECT_H
0006 #ifdef __cplusplus
0007 extern "C" {
0008 #endif
0009 
0010 /* This is about the type 'builtin_function_or_method',
0011    not Python methods in user-defined classes.  See classobject.h
0012    for the latter. */
0013 
0014 PyAPI_DATA(PyTypeObject) PyCFunction_Type;
0015 
0016 #define PyCFunction_CheckExact(op) Py_IS_TYPE((op), &PyCFunction_Type)
0017 #define PyCFunction_Check(op) PyObject_TypeCheck((op), &PyCFunction_Type)
0018 
0019 typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
0020 typedef PyObject *(*PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t);
0021 typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
0022                                              PyObject *);
0023 typedef PyObject *(*PyCFunctionFastWithKeywords) (PyObject *,
0024                                                   PyObject *const *, Py_ssize_t,
0025                                                   PyObject *);
0026 typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,
0027                                size_t, PyObject *);
0028 
0029 // For backwards compatibility. `METH_FASTCALL` was added to the stable API in
0030 // 3.10 alongside `_PyCFunctionFastWithKeywords` and `_PyCFunctionFast`.
0031 // Note that the underscore-prefixed names were documented in public docs;
0032 // people may be using them.
0033 typedef PyCFunctionFast _PyCFunctionFast;
0034 typedef PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords;
0035 
0036 // Cast an function to the PyCFunction type to use it with PyMethodDef.
0037 //
0038 // This macro can be used to prevent compiler warnings if the first parameter
0039 // uses a different pointer type than PyObject* (ex: METH_VARARGS and METH_O
0040 // calling conventions).
0041 //
0042 // The macro can also be used for METH_FASTCALL and METH_VARARGS|METH_KEYWORDS
0043 // calling conventions to avoid compiler warnings because the function has more
0044 // than 2 parameters. The macro first casts the function to the
0045 // "void func(void)" type to prevent compiler warnings.
0046 //
0047 // If a function is declared with the METH_NOARGS calling convention, it must
0048 // have 2 parameters. Since the second parameter is unused, Py_UNUSED() can be
0049 // used to prevent a compiler warning. If the function has a single parameter,
0050 // it triggers an undefined behavior when Python calls it with 2 parameters
0051 // (bpo-33012).
0052 #define _PyCFunction_CAST(func) \
0053     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
0054 
0055 PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
0056 PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
0057 PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
0058 
0059 struct PyMethodDef {
0060     const char  *ml_name;   /* The name of the built-in function/method */
0061     PyCFunction ml_meth;    /* The C function that implements it */
0062     int         ml_flags;   /* Combination of METH_xxx flags, which mostly
0063                                describe the args expected by the C func */
0064     const char  *ml_doc;    /* The __doc__ attribute, or NULL */
0065 };
0066 
0067 /* PyCFunction_New is declared as a function for stable ABI (declaration is
0068  * needed for e.g. GCC with -fvisibility=hidden), but redefined as a macro
0069  * that calls PyCFunction_NewEx. */
0070 PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
0071 #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
0072 
0073 /* PyCFunction_NewEx is similar: on 3.9+, this calls PyCMethod_New. */
0074 PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
0075                                          PyObject *);
0076 
0077 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
0078 #define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL)
0079 PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *,
0080                                      PyObject *, PyTypeObject *);
0081 #endif
0082 
0083 
0084 /* Flag passed to newmethodobject */
0085 /* #define METH_OLDARGS  0x0000   -- unsupported now */
0086 #define METH_VARARGS  0x0001
0087 #define METH_KEYWORDS 0x0002
0088 /* METH_NOARGS and METH_O must not be combined with the flags above. */
0089 #define METH_NOARGS   0x0004
0090 #define METH_O        0x0008
0091 
0092 /* METH_CLASS and METH_STATIC are a little different; these control
0093    the construction of methods for a class.  These cannot be used for
0094    functions in modules. */
0095 #define METH_CLASS    0x0010
0096 #define METH_STATIC   0x0020
0097 
0098 /* METH_COEXIST allows a method to be entered even though a slot has
0099    already filled the entry.  When defined, the flag allows a separate
0100    method, "__contains__" for example, to coexist with a defined
0101    slot like sq_contains. */
0102 
0103 #define METH_COEXIST   0x0040
0104 
0105 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a0000
0106 #  define METH_FASTCALL  0x0080
0107 #endif
0108 
0109 /* This bit is preserved for Stackless Python */
0110 #ifdef STACKLESS
0111 #  define METH_STACKLESS 0x0100
0112 #else
0113 #  define METH_STACKLESS 0x0000
0114 #endif
0115 
0116 /* METH_METHOD means the function stores an
0117  * additional reference to the class that defines it;
0118  * both self and class are passed to it.
0119  * It uses PyCMethodObject instead of PyCFunctionObject.
0120  * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC.
0121  */
0122 
0123 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
0124 #define METH_METHOD 0x0200
0125 #endif
0126 
0127 
0128 #ifndef Py_LIMITED_API
0129 #  define Py_CPYTHON_METHODOBJECT_H
0130 #  include "cpython/methodobject.h"
0131 #  undef Py_CPYTHON_METHODOBJECT_H
0132 #endif
0133 
0134 #ifdef __cplusplus
0135 }
0136 #endif
0137 #endif /* !Py_METHODOBJECT_H */