Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:49

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 // Cast an function to the PyCFunction type to use it with PyMethodDef.
0030 //
0031 // This macro can be used to prevent compiler warnings if the first parameter
0032 // uses a different pointer type than PyObject* (ex: METH_VARARGS and METH_O
0033 // calling conventions).
0034 //
0035 // The macro can also be used for METH_FASTCALL and METH_VARARGS|METH_KEYWORDS
0036 // calling conventions to avoid compiler warnings because the function has more
0037 // than 2 parameters. The macro first casts the function to the
0038 // "void func(void)" type to prevent compiler warnings.
0039 //
0040 // If a function is declared with the METH_NOARGS calling convention, it must
0041 // have 2 parameters. Since the second parameter is unused, Py_UNUSED() can be
0042 // used to prevent a compiler warning. If the function has a single parameter,
0043 // it triggers an undefined behavior when Python calls it with 2 parameters
0044 // (bpo-33012).
0045 #define _PyCFunction_CAST(func) \
0046     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
0047 
0048 PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
0049 PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
0050 PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
0051 
0052 Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
0053 
0054 struct PyMethodDef {
0055     const char  *ml_name;   /* The name of the built-in function/method */
0056     PyCFunction ml_meth;    /* The C function that implements it */
0057     int         ml_flags;   /* Combination of METH_xxx flags, which mostly
0058                                describe the args expected by the C func */
0059     const char  *ml_doc;    /* The __doc__ attribute, or NULL */
0060 };
0061 
0062 /* PyCFunction_New is declared as a function for stable ABI (declaration is
0063  * needed for e.g. GCC with -fvisibility=hidden), but redefined as a macro
0064  * that calls PyCFunction_NewEx. */
0065 PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
0066 #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
0067 
0068 /* PyCFunction_NewEx is similar: on 3.9+, this calls PyCMethod_New. */
0069 PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
0070                                          PyObject *);
0071 
0072 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
0073 #define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL)
0074 PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *,
0075                                      PyObject *, PyTypeObject *);
0076 #endif
0077 
0078 
0079 /* Flag passed to newmethodobject */
0080 /* #define METH_OLDARGS  0x0000   -- unsupported now */
0081 #define METH_VARARGS  0x0001
0082 #define METH_KEYWORDS 0x0002
0083 /* METH_NOARGS and METH_O must not be combined with the flags above. */
0084 #define METH_NOARGS   0x0004
0085 #define METH_O        0x0008
0086 
0087 /* METH_CLASS and METH_STATIC are a little different; these control
0088    the construction of methods for a class.  These cannot be used for
0089    functions in modules. */
0090 #define METH_CLASS    0x0010
0091 #define METH_STATIC   0x0020
0092 
0093 /* METH_COEXIST allows a method to be entered even though a slot has
0094    already filled the entry.  When defined, the flag allows a separate
0095    method, "__contains__" for example, to coexist with a defined
0096    slot like sq_contains. */
0097 
0098 #define METH_COEXIST   0x0040
0099 
0100 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a0000
0101 #  define METH_FASTCALL  0x0080
0102 #endif
0103 
0104 /* This bit is preserved for Stackless Python */
0105 #ifdef STACKLESS
0106 #  define METH_STACKLESS 0x0100
0107 #else
0108 #  define METH_STACKLESS 0x0000
0109 #endif
0110 
0111 /* METH_METHOD means the function stores an
0112  * additional reference to the class that defines it;
0113  * both self and class are passed to it.
0114  * It uses PyCMethodObject instead of PyCFunctionObject.
0115  * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC.
0116  */
0117 
0118 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
0119 #define METH_METHOD 0x0200
0120 #endif
0121 
0122 
0123 #ifndef Py_LIMITED_API
0124 #  define Py_CPYTHON_METHODOBJECT_H
0125 #  include "cpython/methodobject.h"
0126 #  undef Py_CPYTHON_METHODOBJECT_H
0127 #endif
0128 
0129 #ifdef __cplusplus
0130 }
0131 #endif
0132 #endif /* !Py_METHODOBJECT_H */