blob: bc03e0d0270dc32fe4e03418355a0c558fd901a0 [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;
Antoine Pitroua57df2c2010-03-31 21:32:15 +000021 PyObject *cl_weakreflist; /* List of weak references */
Guido van Rossumcaa63801995-01-12 11:45:45 +000022} PyClassObject;
Guido van Rossum81daa321993-05-20 14:24:46 +000023
Guido van Rossumb3f72581993-05-21 19:56:10 +000024typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000025 PyObject_HEAD
26 PyClassObject *in_class; /* The class object */
27 PyObject *in_dict; /* A dictionary */
Fred Drake41deb1e2001-02-01 05:27:45 +000028 PyObject *in_weakreflist; /* List of weak references */
Guido van Rossumcaa63801995-01-12 11:45:45 +000029} PyInstanceObject;
Guido van Rossumb3f72581993-05-21 19:56:10 +000030
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000031typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000032 PyObject_HEAD
33 PyObject *im_func; /* The callable object implementing the method */
34 PyObject *im_self; /* The instance it is bound to, or NULL */
Guido van Rossum301d0f82001-12-07 21:54:33 +000035 PyObject *im_class; /* The class that asked for the method */
Fred Drake6a1c87d2001-03-23 04:17:58 +000036 PyObject *im_weakreflist; /* List of weak references */
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000037} PyMethodObject;
38
Mark Hammond91a681d2002-08-12 07:21:58 +000039PyAPI_DATA(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000040
Guido van Rossumcaa63801995-01-12 11:45:45 +000041#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
42#define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)
43#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000044
Mark Hammond91a681d2002-08-12 07:21:58 +000045PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
46PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000047 PyObject *);
Mark Hammond91a681d2002-08-12 07:21:58 +000048PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
49PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000050
Mark Hammond91a681d2002-08-12 07:21:58 +000051PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
52PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
53PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);
Guido van Rossumb479dc52001-09-05 22:52:50 +000054
Tim Petersdf875b92003-04-07 17:51:59 +000055/* Look up attribute with name (a string) on instance object pinst, using
56 * only the instance and base class dicts. If a descriptor is found in
57 * a class dict, the descriptor is returned without calling it.
58 * Returns NULL if nothing found, else a borrowed reference to the
59 * value associated with name in the dict in which name was found.
60 * The point of this routine is that it never calls arbitrary Python
61 * code, so is always "safe": all it does is dict lookups. The function
Tim Petersf995cce2003-04-08 18:47:21 +000062 * can't fail, never sets an exception, and NULL is not an error (it just
Tim Petersdf875b92003-04-07 17:51:59 +000063 * means "not found").
64 */
Tim Petersf995cce2003-04-08 18:47:21 +000065PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);
Tim Petersdf875b92003-04-07 17:51:59 +000066
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000067/* Macros for direct access to these values. Type checks are *not*
68 done, so use with care. */
69#define PyMethod_GET_FUNCTION(meth) \
70 (((PyMethodObject *)meth) -> im_func)
71#define PyMethod_GET_SELF(meth) \
72 (((PyMethodObject *)meth) -> im_self)
73#define PyMethod_GET_CLASS(meth) \
74 (((PyMethodObject *)meth) -> im_class)
75
Mark Hammond91a681d2002-08-12 07:21:58 +000076PyAPI_FUNC(int) PyClass_IsSubclass(PyObject *, PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000077
Christian Heimes3b718a72008-02-14 12:47:33 +000078PyAPI_FUNC(int) PyMethod_ClearFreeList(void);
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000079
Guido van Rossuma3309961993-07-28 09:05:47 +000080#ifdef __cplusplus
81}
82#endif
83#endif /* !Py_CLASSOBJECT_H */