/Include/classobject.h

http://unladen-swallow.googlecode.com/ · C Header · 84 lines · 53 code · 15 blank · 16 comment · 3 complexity · 8595b37bbfbbda172fa013c590a5bd91 MD5 · raw file

  1. /* Class object interface */
  2. /* Revealing some structures (not for general use) */
  3. #ifndef Py_CLASSOBJECT_H
  4. #define Py_CLASSOBJECT_H
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef struct {
  9. PyObject_HEAD
  10. PyObject *cl_bases; /* A tuple of class objects */
  11. PyObject *cl_dict; /* A dictionary */
  12. PyObject *cl_name; /* A string */
  13. /* The following three are functions or NULL */
  14. PyObject *cl_getattr;
  15. PyObject *cl_setattr;
  16. PyObject *cl_delattr;
  17. } PyClassObject;
  18. typedef struct {
  19. PyObject_HEAD
  20. PyClassObject *in_class; /* The class object */
  21. PyObject *in_dict; /* A dictionary */
  22. PyObject *in_weakreflist; /* List of weak references */
  23. } PyInstanceObject;
  24. /* If you change this, update Util/PyTypeBuilder.h accordingly. */
  25. typedef struct PyMethodObject {
  26. PyObject_HEAD
  27. PyObject *im_func; /* The callable object implementing the method */
  28. PyObject *im_self; /* The instance it is bound to, or NULL */
  29. PyObject *im_class; /* The class that asked for the method */
  30. PyObject *im_weakreflist; /* List of weak references */
  31. } PyMethodObject;
  32. PyAPI_DATA(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
  33. #define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
  34. #define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)
  35. #define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
  36. PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
  37. PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
  38. PyObject *);
  39. PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
  40. PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
  41. PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
  42. PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
  43. PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);
  44. PyAPI_FUNC(int) _PyMethod_ShouldBind(PyObject *, PyObject *);
  45. /* Look up attribute with name (a string) on instance object pinst, using
  46. * only the instance and base class dicts. If a descriptor is found in
  47. * a class dict, the descriptor is returned without calling it.
  48. * Returns NULL if nothing found, else a borrowed reference to the
  49. * value associated with name in the dict in which name was found.
  50. * The point of this routine is that it never calls arbitrary Python
  51. * code, so is always "safe": all it does is dict lookups. The function
  52. * can't fail, never sets an exception, and NULL is not an error (it just
  53. * means "not found").
  54. */
  55. PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);
  56. /* Macros for direct access to these values. Type checks are *not*
  57. done, so use with care. */
  58. #define PyMethod_GET_FUNCTION(meth) \
  59. (((PyMethodObject *)meth) -> im_func)
  60. #define PyMethod_GET_SELF(meth) \
  61. (((PyMethodObject *)meth) -> im_self)
  62. #define PyMethod_GET_CLASS(meth) \
  63. (((PyMethodObject *)meth) -> im_class)
  64. PyAPI_FUNC(int) PyClass_IsSubclass(PyObject *, PyObject *);
  65. PyAPI_FUNC(int) PyMethod_ClearFreeList(void);
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* !Py_CLASSOBJECT_H */