classobject.h 2.23 KB
Newer Older
1

Guido van Rossum's avatar
Guido van Rossum committed
2 3
/* Class object interface */

4
/* Revealing some structures (not for general use) */
Guido van Rossum's avatar
Guido van Rossum committed
5

6 7 8 9 10 11
#ifndef Py_CLASSOBJECT_H
#define Py_CLASSOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif

12
typedef struct {
13 14 15 16 17 18 19 20
    PyObject_HEAD
    PyObject	*cl_bases;	/* A tuple of class objects */
    PyObject	*cl_dict;	/* A dictionary */
    PyObject	*cl_name;	/* A string */
    /* The following three are functions or NULL */
    PyObject	*cl_getattr;
    PyObject	*cl_setattr;
    PyObject	*cl_delattr;
21
} PyClassObject;
22

23
typedef struct {
24 25 26
    PyObject_HEAD
    PyClassObject *in_class;	/* The class object */
    PyObject	  *in_dict;	/* A dictionary */
27
    PyObject	  *in_weakreflist; /* List of weak references */
28
} PyInstanceObject;
29

30
typedef struct {
31 32 33
    PyObject_HEAD
    PyObject *im_func;   /* The callable object implementing the method */
    PyObject *im_self;   /* The instance it is bound to, or NULL */
34
    PyObject *im_class;  /* The class that asked for the method */
35
    PyObject *im_weakreflist; /* List of weak references */
36 37
} PyMethodObject;

38
extern DL_IMPORT(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
Guido van Rossum's avatar
Guido van Rossum committed
39

40 41 42
#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
#define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)
#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
Guido van Rossum's avatar
Guido van Rossum committed
43

44 45 46
extern DL_IMPORT(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
extern DL_IMPORT(PyObject *) PyInstance_New(PyObject *, PyObject *,
                                            PyObject *);
47
extern DL_IMPORT(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
48
extern DL_IMPORT(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
Guido van Rossum's avatar
Guido van Rossum committed
49

50 51 52 53
extern DL_IMPORT(PyObject *) PyMethod_Function(PyObject *);
extern DL_IMPORT(PyObject *) PyMethod_Self(PyObject *);
extern DL_IMPORT(PyObject *) PyMethod_Class(PyObject *);

54 55 56 57 58 59 60 61 62
/* Macros for direct access to these values. Type checks are *not*
   done, so use with care. */
#define PyMethod_GET_FUNCTION(meth) \
        (((PyMethodObject *)meth) -> im_func)
#define PyMethod_GET_SELF(meth) \
	(((PyMethodObject *)meth) -> im_self)
#define PyMethod_GET_CLASS(meth) \
	(((PyMethodObject *)meth) -> im_class)

63
extern DL_IMPORT(int) PyClass_IsSubclass(PyObject *, PyObject *);
64

65

66 67 68 69
#ifdef __cplusplus
}
#endif
#endif /* !Py_CLASSOBJECT_H */