@@ -13,7 +13,7 @@ extern "C" {
13
13
14
14
PyAPI_DATA (PyTypeObject ) PyCFunction_Type ;
15
15
16
- #define PyCFunction_Check (op ) Py_IS_TYPE(op, &PyCFunction_Type)
16
+ #define PyCFunction_Check (op ) ( Py_IS_TYPE(op, &PyCFunction_Type) || (PyType_IsSubtype(Py_TYPE(op), &PyCFunction_Type)) )
17
17
18
18
typedef PyObject * (* PyCFunction )(PyObject * , PyObject * );
19
19
typedef PyObject * (* _PyCFunctionFast ) (PyObject * , PyObject * const * , Py_ssize_t );
@@ -22,21 +22,13 @@ typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
22
22
typedef PyObject * (* _PyCFunctionFastWithKeywords ) (PyObject * ,
23
23
PyObject * const * , Py_ssize_t ,
24
24
PyObject * );
25
+ typedef PyObject * (* PyCMethod )(PyObject * , PyTypeObject * , PyObject * const * ,
26
+ size_t , PyObject * );
27
+
25
28
PyAPI_FUNC (PyCFunction ) PyCFunction_GetFunction (PyObject * );
26
29
PyAPI_FUNC (PyObject * ) PyCFunction_GetSelf (PyObject * );
27
30
PyAPI_FUNC (int ) PyCFunction_GetFlags (PyObject * );
28
31
29
- /* Macros for direct access to these values. Type checks are *not*
30
- done, so use with care. */
31
- #ifndef Py_LIMITED_API
32
- #define PyCFunction_GET_FUNCTION (func ) \
33
- (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
34
- #define PyCFunction_GET_SELF (func ) \
35
- (((PyCFunctionObject *)func) -> m_ml -> ml_flags & METH_STATIC ? \
36
- NULL : ((PyCFunctionObject *)func) -> m_self)
37
- #define PyCFunction_GET_FLAGS (func ) \
38
- (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
39
- #endif
40
32
Py_DEPRECATED (3.9 ) PyAPI_FUNC (PyObject * ) PyCFunction_Call (PyObject * , PyObject * , PyObject * );
41
33
42
34
struct PyMethodDef {
@@ -52,6 +44,13 @@ typedef struct PyMethodDef PyMethodDef;
52
44
PyAPI_FUNC (PyObject * ) PyCFunction_NewEx (PyMethodDef * , PyObject * ,
53
45
PyObject * );
54
46
47
+ #if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 >= 0x03090000
48
+ #define PyCFunction_NewEx (ML , SELF , MOD ) PyCMethod_New((ML), (SELF), (MOD), NULL)
49
+ PyAPI_FUNC (PyObject * ) PyCMethod_New (PyMethodDef * , PyObject * ,
50
+ PyObject * , PyTypeObject * );
51
+ #endif
52
+
53
+
55
54
/* Flag passed to newmethodobject */
56
55
/* #define METH_OLDARGS 0x0000 -- unsupported now */
57
56
#define METH_VARARGS 0x0001
@@ -84,15 +83,24 @@ PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
84
83
#define METH_STACKLESS 0x0000
85
84
#endif
86
85
86
+ /* METH_METHOD means the function stores an
87
+ * additional reference to the class that defines it;
88
+ * both self and class are passed to it.
89
+ * It uses PyCMethodObject instead of PyCFunctionObject.
90
+ * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC.
91
+ */
92
+
93
+ #if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 >= 0x03090000
94
+ #define METH_METHOD 0x0200
95
+ #endif
96
+
97
+
87
98
#ifndef Py_LIMITED_API
88
- typedef struct {
89
- PyObject_HEAD
90
- PyMethodDef * m_ml ; /* Description of the C function to call */
91
- PyObject * m_self ; /* Passed as 'self' arg to the C func, can be NULL */
92
- PyObject * m_module ; /* The __module__ attribute, can be anything */
93
- PyObject * m_weakreflist ; /* List of weak references */
94
- vectorcallfunc vectorcall ;
95
- } PyCFunctionObject ;
99
+
100
+ #define Py_CPYTHON_METHODOBJECT_H
101
+ #include "cpython/methodobject.h"
102
+ #undef Py_CPYTHON_METHODOBJECT_H
103
+
96
104
#endif
97
105
98
106
#ifdef __cplusplus
0 commit comments