blob: 059730b4095c101ecebe69d0645cda55961012a8 [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 */
Guido van Rossumcaa63801995-01-12 11:45:45 +000027} PyInstanceObject;
Guido van Rossumb3f72581993-05-21 19:56:10 +000028
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000029typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000030 PyObject_HEAD
31 PyObject *im_func; /* The callable object implementing the method */
32 PyObject *im_self; /* The instance it is bound to, or NULL */
33 PyObject *im_class; /* The class that defined the method */
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000034} PyMethodObject;
35
Guido van Rossum051ab121995-02-27 10:17:52 +000036extern DL_IMPORT(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000037
Guido van Rossumcaa63801995-01-12 11:45:45 +000038#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
39#define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)
40#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000041
Fred Drakeea9cb5a2000-07-09 00:20:36 +000042extern DL_IMPORT(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
43extern DL_IMPORT(PyObject *) PyInstance_New(PyObject *, PyObject *,
44 PyObject *);
45extern DL_IMPORT(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000046
Fred Drakeea9cb5a2000-07-09 00:20:36 +000047extern DL_IMPORT(PyObject *) PyMethod_Function(PyObject *);
48extern DL_IMPORT(PyObject *) PyMethod_Self(PyObject *);
49extern DL_IMPORT(PyObject *) PyMethod_Class(PyObject *);
Guido van Rossum04691fc1992-08-12 15:35:34 +000050
Guido van Rossumd4ba73c1998-07-10 15:46:33 +000051/* Macros for direct access to these values. Type checks are *not*
52 done, so use with care. */
53#define PyMethod_GET_FUNCTION(meth) \
54 (((PyMethodObject *)meth) -> im_func)
55#define PyMethod_GET_SELF(meth) \
56 (((PyMethodObject *)meth) -> im_self)
57#define PyMethod_GET_CLASS(meth) \
58 (((PyMethodObject *)meth) -> im_class)
59
Fred Drakeea9cb5a2000-07-09 00:20:36 +000060extern DL_IMPORT(int) PyClass_IsSubclass(PyObject *, PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000061
Fred Drakeea9cb5a2000-07-09 00:20:36 +000062extern DL_IMPORT(PyObject *) PyInstance_DoBinOp(PyObject *, PyObject *,
63 char *, char *,
64 PyObject * (*)(PyObject *,
65 PyObject *));
Guido van Rossumc5d92e11994-09-28 15:44:39 +000066
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000067extern DL_IMPORT(int)
68PyInstance_HalfBinOp(PyObject *, PyObject *, char *, PyObject **,
69 PyObject * (*)(PyObject *, PyObject *), int);
70
Guido van Rossuma3309961993-07-28 09:05:47 +000071#ifdef __cplusplus
72}
73#endif
74#endif /* !Py_CLASSOBJECT_H */