blob: b071e98f04ec6e749c6e5820257020f990a0303e [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/* Class object interface */
3
Guido van Rossumb3f72581993-05-21 19:56:10 +00004/* Revealing some structures (not for general use) */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00005
Fred Drakeea9cb5a2000-07-09 00:20:36 +00006#ifndef Py_CLASSOBJECT_H
7#define Py_CLASSOBJECT_H
8#ifdef __cplusplus
9extern "C" {
10#endif
11
Guido van Rossum81daa321993-05-20 14:24:46 +000012typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000013 PyObject_HEAD
14 PyObject *cl_bases; /* A tuple of class objects */
15 PyObject *cl_dict; /* A dictionary */
16 PyObject *cl_name; /* A string */
17 /* The following three are functions or NULL */
18 PyObject *cl_getattr;
19 PyObject *cl_setattr;
20 PyObject *cl_delattr;
Guido van Rossumcaa63801995-01-12 11:45:45 +000021} PyClassObject;
Guido van Rossum81daa321993-05-20 14:24:46 +000022
Guido van Rossumb3f72581993-05-21 19:56:10 +000023typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000024 PyObject_HEAD
25 PyClassObject *in_class; /* The class object */
26 PyObject *in_dict; /* A dictionary */
Fred Drake41deb1e2001-02-01 05:27:45 +000027 PyObject *in_weakreflist; /* List of weak references */
Guido van Rossumcaa63801995-01-12 11:45:45 +000028} PyInstanceObject;
Guido van Rossumb3f72581993-05-21 19:56:10 +000029
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000030typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000031 PyObject_HEAD
32 PyObject *im_func; /* The callable object implementing the method */
33 PyObject *im_self; /* The instance it is bound to, or NULL */
Guido van Rossum301d0f82001-12-07 21:54:33 +000034 PyObject *im_class; /* The class that asked for the method */
Fred Drake6a1c87d2001-03-23 04:17:58 +000035 PyObject *im_weakreflist; /* List of weak references */
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000036} PyMethodObject;
37
Mark Hammond91a681d2002-08-12 07:21:58 +000038PyAPI_DATA(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000039
Guido van Rossumcaa63801995-01-12 11:45:45 +000040#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
41#define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)
42#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000043
Mark Hammond91a681d2002-08-12 07:21:58 +000044PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
45PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000046 PyObject *);
Mark Hammond91a681d2002-08-12 07:21:58 +000047PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
48PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000049
Mark Hammond91a681d2002-08-12 07:21:58 +000050PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
51PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
52PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);
Guido van Rossumb479dc52001-09-05 22:52:50 +000053
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000054/* Macros for direct access to these values. Type checks are *not*
55 done, so use with care. */
56#define PyMethod_GET_FUNCTION(meth) \
57 (((PyMethodObject *)meth) -> im_func)
58#define PyMethod_GET_SELF(meth) \
59 (((PyMethodObject *)meth) -> im_self)
60#define PyMethod_GET_CLASS(meth) \
61 (((PyMethodObject *)meth) -> im_class)
62
Mark Hammond91a681d2002-08-12 07:21:58 +000063PyAPI_FUNC(int) PyClass_IsSubclass(PyObject *, PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000064
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000065
Guido van Rossuma3309961993-07-28 09:05:47 +000066#ifdef __cplusplus
67}
68#endif
69#endif /* !Py_CLASSOBJECT_H */