Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | /* Class object interface */ |
| 3 | |
Guido van Rossum | b3f7258 | 1993-05-21 19:56:10 +0000 | [diff] [blame] | 4 | /* Revealing some structures (not for general use) */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 5 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 6 | #ifndef Py_CLASSOBJECT_H |
| 7 | #define Py_CLASSOBJECT_H |
| 8 | #ifdef __cplusplus |
| 9 | extern "C" { |
| 10 | #endif |
| 11 | |
Guido van Rossum | 81daa32 | 1993-05-20 14:24:46 +0000 | [diff] [blame] | 12 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 13 | 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 Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 21 | } PyClassObject; |
Guido van Rossum | 81daa32 | 1993-05-20 14:24:46 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | b3f7258 | 1993-05-21 19:56:10 +0000 | [diff] [blame] | 23 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 24 | PyObject_HEAD |
| 25 | PyClassObject *in_class; /* The class object */ |
| 26 | PyObject *in_dict; /* A dictionary */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 27 | } PyInstanceObject; |
Guido van Rossum | b3f7258 | 1993-05-21 19:56:10 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | d4ba73c | 1998-07-10 15:46:33 +0000 | [diff] [blame] | 29 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 30 | 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 Rossum | d4ba73c | 1998-07-10 15:46:33 +0000 | [diff] [blame] | 34 | } PyMethodObject; |
| 35 | |
Guido van Rossum | 051ab12 | 1995-02-27 10:17:52 +0000 | [diff] [blame] | 36 | extern DL_IMPORT(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 37 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 38 | #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 Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 41 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 42 | extern DL_IMPORT(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *); |
| 43 | extern DL_IMPORT(PyObject *) PyInstance_New(PyObject *, PyObject *, |
| 44 | PyObject *); |
| 45 | extern DL_IMPORT(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 46 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 47 | extern DL_IMPORT(PyObject *) PyMethod_Function(PyObject *); |
| 48 | extern DL_IMPORT(PyObject *) PyMethod_Self(PyObject *); |
| 49 | extern DL_IMPORT(PyObject *) PyMethod_Class(PyObject *); |
Guido van Rossum | 04691fc | 1992-08-12 15:35:34 +0000 | [diff] [blame] | 50 | |
Guido van Rossum | d4ba73c | 1998-07-10 15:46:33 +0000 | [diff] [blame] | 51 | /* 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 Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 60 | extern DL_IMPORT(int) PyClass_IsSubclass(PyObject *, PyObject *); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 61 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 62 | extern DL_IMPORT(PyObject *) PyInstance_DoBinOp(PyObject *, PyObject *, |
| 63 | char *, char *, |
| 64 | PyObject * (*)(PyObject *, |
| 65 | PyObject *)); |
Guido van Rossum | c5d92e1 | 1994-09-28 15:44:39 +0000 | [diff] [blame] | 66 | |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 67 | extern DL_IMPORT(int) |
| 68 | PyInstance_HalfBinOp(PyObject *, PyObject *, char *, PyObject **, |
| 69 | PyObject * (*)(PyObject *, PyObject *), int); |
| 70 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 71 | #ifdef __cplusplus |
| 72 | } |
| 73 | #endif |
| 74 | #endif /* !Py_CLASSOBJECT_H */ |