blob: 8f8db7d813031a7bde3c60355fbe26359cb453aa [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
Tim Petersdf875b92003-04-07 17:51:59 +000054/* Look up attribute with name (a string) on instance object pinst, using
55 * only the instance and base class dicts. If a descriptor is found in
56 * a class dict, the descriptor is returned without calling it.
57 * Returns NULL if nothing found, else a borrowed reference to the
58 * value associated with name in the dict in which name was found.
59 * The point of this routine is that it never calls arbitrary Python
60 * code, so is always "safe": all it does is dict lookups. The function
Tim Petersf995cce2003-04-08 18:47:21 +000061 * can't fail, never sets an exception, and NULL is not an error (it just
Tim Petersdf875b92003-04-07 17:51:59 +000062 * means "not found").
63 */
Tim Petersf995cce2003-04-08 18:47:21 +000064PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);
Tim Petersdf875b92003-04-07 17:51:59 +000065
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000066/* Macros for direct access to these values. Type checks are *not*
67 done, so use with care. */
68#define PyMethod_GET_FUNCTION(meth) \
69 (((PyMethodObject *)meth) -> im_func)
70#define PyMethod_GET_SELF(meth) \
71 (((PyMethodObject *)meth) -> im_self)
72#define PyMethod_GET_CLASS(meth) \
73 (((PyMethodObject *)meth) -> im_class)
74
Mark Hammond91a681d2002-08-12 07:21:58 +000075PyAPI_FUNC(int) PyClass_IsSubclass(PyObject *, PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000076
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000077
Guido van Rossuma3309961993-07-28 09:05:47 +000078#ifdef __cplusplus
79}
80#endif
81#endif /* !Py_CLASSOBJECT_H */