@@ -13,7 +13,7 @@ extern "C" {
1313
1414PyAPI_DATA (PyTypeObject ) PyCFunction_Type ;
1515
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)) )
1717
1818typedef  PyObject  * (* PyCFunction )(PyObject  * , PyObject  * );
1919typedef  PyObject  * (* _PyCFunctionFast ) (PyObject  * , PyObject  * const  * , Py_ssize_t );
@@ -22,21 +22,13 @@ typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
2222typedef  PyObject  * (* _PyCFunctionFastWithKeywords ) (PyObject  * ,
2323 PyObject  * const  * , Py_ssize_t ,
2424 PyObject  * );
25+ typedef  PyObject  * (* PyCMethod )(PyObject  * , PyTypeObject  * , PyObject  * const  * ,
26+  size_t , PyObject  * );
27+ 
2528PyAPI_FUNC (PyCFunction ) PyCFunction_GetFunction (PyObject  * );
2629PyAPI_FUNC (PyObject  * ) PyCFunction_GetSelf (PyObject  * );
2730PyAPI_FUNC (int ) PyCFunction_GetFlags (PyObject  * );
2831
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 
4032Py_DEPRECATED (3.9 ) PyAPI_FUNC (PyObject  * ) PyCFunction_Call (PyObject  * , PyObject  * , PyObject  * );
4133
4234struct  PyMethodDef  {
@@ -52,6 +44,13 @@ typedef struct PyMethodDef PyMethodDef;
5244PyAPI_FUNC (PyObject  * ) PyCFunction_NewEx (PyMethodDef  * , PyObject  * ,
5345 PyObject  * );
5446
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+ 
5554/* Flag passed to newmethodobject */ 
5655/* #define METH_OLDARGS 0x0000 -- unsupported now */ 
5756#define  METH_VARARGS  0x0001
@@ -84,15 +83,24 @@ PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
8483#define  METH_STACKLESS  0x0000
8584#endif 
8685
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+ 
8798#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+ 
96104#endif 
97105
98106#ifdef  __cplusplus 
0 commit comments