Branch data Line data Source code
1 : : #ifndef Py_CPYTHON_METHODOBJECT_H 2 : : # error "this header file must not be included directly" 3 : : #endif 4 : : 5 : : // PyCFunctionObject structure 6 : : 7 : : typedef struct { 8 : : PyObject_HEAD 9 : : PyMethodDef *m_ml; /* Description of the C function to call */ 10 : : PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */ 11 : : PyObject *m_module; /* The __module__ attribute, can be anything */ 12 : : PyObject *m_weakreflist; /* List of weak references */ 13 : : vectorcallfunc vectorcall; 14 : : } PyCFunctionObject; 15 : : 16 : : #define _PyCFunctionObject_CAST(func) \ 17 : : (assert(PyCFunction_Check(func)), \ 18 : : _Py_CAST(PyCFunctionObject*, (func))) 19 : : 20 : : 21 : : // PyCMethodObject structure 22 : : 23 : : typedef struct { 24 : : PyCFunctionObject func; 25 : : PyTypeObject *mm_class; /* Class that defines this method */ 26 : : } PyCMethodObject; 27 : : 28 : : #define _PyCMethodObject_CAST(func) \ 29 : : (assert(PyCMethod_Check(func)), \ 30 : : _Py_CAST(PyCMethodObject*, (func))) 31 : : 32 : : PyAPI_DATA(PyTypeObject) PyCMethod_Type; 33 : : 34 : : #define PyCMethod_CheckExact(op) Py_IS_TYPE((op), &PyCMethod_Type) 35 : : #define PyCMethod_Check(op) PyObject_TypeCheck((op), &PyCMethod_Type) 36 : : 37 : : 38 : : /* Static inline functions for direct access to these values. 39 : : Type checks are *not* done, so use with care. */ 40 : 5624182 : static inline PyCFunction PyCFunction_GET_FUNCTION(PyObject *func) { 41 : 5624182 : return _PyCFunctionObject_CAST(func)->m_ml->ml_meth; 42 : : } 43 : : #define PyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(_PyObject_CAST(func)) 44 : : 45 : 5613382 : static inline PyObject* PyCFunction_GET_SELF(PyObject *func_obj) { 46 : 5613382 : PyCFunctionObject *func = _PyCFunctionObject_CAST(func_obj); 47 [ + + ]: 5613382 : if (func->m_ml->ml_flags & METH_STATIC) { 48 : 2 : return _Py_NULL; 49 : : } 50 : 5613380 : return func->m_self; 51 : : } 52 : : #define PyCFunction_GET_SELF(func) PyCFunction_GET_SELF(_PyObject_CAST(func)) 53 : : 54 : 3152129 : static inline int PyCFunction_GET_FLAGS(PyObject *func) { 55 : 3152129 : return _PyCFunctionObject_CAST(func)->m_ml->ml_flags; 56 : : } 57 : : #define PyCFunction_GET_FLAGS(func) PyCFunction_GET_FLAGS(_PyObject_CAST(func)) 58 : : 59 : 3835697 : static inline PyTypeObject* PyCFunction_GET_CLASS(PyObject *func_obj) { 60 : 3835697 : PyCFunctionObject *func = _PyCFunctionObject_CAST(func_obj); 61 [ + + ]: 3835697 : if (func->m_ml->ml_flags & METH_METHOD) { 62 : 2889565 : return _PyCMethodObject_CAST(func)->mm_class; 63 : : } 64 : 946132 : return _Py_NULL; 65 : : } 66 : : #define PyCFunction_GET_CLASS(func) PyCFunction_GET_CLASS(_PyObject_CAST(func))