classobject.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Former class object interface -- now only bound methods are here */
  2. /* Revealing some structures (not for general use) */
  3. #ifndef Py_LIMITED_API
  4. #ifndef Py_CLASSOBJECT_H
  5. #define Py_CLASSOBJECT_H
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. typedef struct {
  10. PyObject_HEAD
  11. PyObject *im_func; /* The callable object implementing the method */
  12. PyObject *im_self; /* The instance it is bound to */
  13. PyObject *im_weakreflist; /* List of weak references */
  14. vectorcallfunc vectorcall;
  15. } PyMethodObject;
  16. PyAPI_DATA(PyTypeObject) PyMethod_Type;
  17. #define PyMethod_Check(op) Py_IS_TYPE((op), &PyMethod_Type)
  18. PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *);
  19. PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
  20. PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
  21. #define _PyMethod_CAST(meth) \
  22. (assert(PyMethod_Check(meth)), _Py_CAST(PyMethodObject*, meth))
  23. /* Static inline functions for direct access to these values.
  24. Type checks are *not* done, so use with care. */
  25. static inline PyObject* PyMethod_GET_FUNCTION(PyObject *meth) {
  26. return _PyMethod_CAST(meth)->im_func;
  27. }
  28. #define PyMethod_GET_FUNCTION(meth) PyMethod_GET_FUNCTION(_PyObject_CAST(meth))
  29. static inline PyObject* PyMethod_GET_SELF(PyObject *meth) {
  30. return _PyMethod_CAST(meth)->im_self;
  31. }
  32. #define PyMethod_GET_SELF(meth) PyMethod_GET_SELF(_PyObject_CAST(meth))
  33. typedef struct {
  34. PyObject_HEAD
  35. PyObject *func;
  36. } PyInstanceMethodObject;
  37. PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type;
  38. #define PyInstanceMethod_Check(op) Py_IS_TYPE((op), &PyInstanceMethod_Type)
  39. PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *);
  40. PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
  41. #define _PyInstanceMethod_CAST(meth) \
  42. (assert(PyInstanceMethod_Check(meth)), \
  43. _Py_CAST(PyInstanceMethodObject*, meth))
  44. /* Static inline function for direct access to these values.
  45. Type checks are *not* done, so use with care. */
  46. static inline PyObject* PyInstanceMethod_GET_FUNCTION(PyObject *meth) {
  47. return _PyInstanceMethod_CAST(meth)->func;
  48. }
  49. #define PyInstanceMethod_GET_FUNCTION(meth) PyInstanceMethod_GET_FUNCTION(_PyObject_CAST(meth))
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif // !Py_CLASSOBJECT_H
  54. #endif // !Py_LIMITED_API