1 /**
2   Mirror _classobject.h
3   */
4 module deimos.python.classobject;
5 
6 import deimos.python.pyport;
7 import deimos.python.object;
8 
9 extern(C):
10 // Python-header-file: Include/classobject.h:
11 
12 version(Python_3_0_Or_Later) {
13 }else{
14     /** 
15 subclasses PyObject
16 
17 Availability: 2.*
18     */
19     struct PyClassObject {
20         mixin PyObject_HEAD;
21 
22         /** A tuple of class objects */
23         PyObject*	cl_bases;	
24         /** A dictionary */
25         PyObject*	cl_dict;	
26         /** A string */
27         PyObject*	cl_name;	
28         /** The following three are functions or null */
29         PyObject*	cl_getattr;
30         /// ditto
31         PyObject*	cl_setattr;
32         /// ditto
33         PyObject*	cl_delattr;
34     }
35 
36     /// subclass of PyObject.
37     /// Availability: 2.*
38     struct PyInstanceObject {
39         mixin PyObject_HEAD;
40 
41         /** The class object */
42         PyClassObject* in_class;
43         /** A dictionary */
44         PyObject*	  in_dict;
45         /** List of weak references */
46         PyObject*	  in_weakreflist;
47     }
48 }
49 
50 /// subclasses PyObject.
51 struct PyMethodObject {
52     mixin PyObject_HEAD;
53     /** The callable object implementing the method */
54     PyObject* im_func;
55     /** The instance it is bound to, or NULL */
56     PyObject* im_self;
57     version(Python_3_0_Or_Later) {
58     }else{
59         /** The class that asked for the method 
60         Availability: 2.*
61          */
62         PyObject* im_class;
63     }
64     /** List of weak references */
65     PyObject* im_weakreflist;
66 }
67 
68 /// _
69 mixin(PyAPI_DATA!"PyTypeObject PyMethod_Type");
70 
71 // D translation of C macro:
72 int PyMethod_Check()(PyObject *op) {
73     return Py_TYPE(op) == &PyMethod_Type;
74 }
75 
76 version(Python_3_0_Or_Later) {
77     /// Availability: 3.*
78     PyObject* PyMethod_New(PyObject*, PyObject*);
79 }else{
80     /// Availability: 2.*
81     mixin(PyAPI_DATA!"PyTypeObject PyClass_Type");
82     /// Availability: 2.*
83     mixin(PyAPI_DATA!"PyTypeObject PyInstance_Type");
84     // D translation of C macro:
85     /// Availability: 2.*
86     int PyClass_Check()(PyObject *op) {
87         return Py_TYPE(op) == &PyClass_Type;
88     }
89 
90     // D translation of C macro:
91     /// Availability: 2.*
92     int PyInstance_Check()(PyObject *op) {
93         return Py_TYPE(op) == &PyInstance_Type;
94     }
95 
96     /// Availability: 2.*
97     PyObject* PyClass_New(PyObject*, PyObject*, PyObject*);
98     /// Availability: 2.*
99     PyObject* PyInstance_New(PyObject*, PyObject*, PyObject*);
100     /// Availability: 2.*
101     PyObject* PyInstance_NewRaw(PyObject*, PyObject*);
102     /// Availability: 2.*
103     PyObject* PyMethod_New(PyObject*, PyObject*, PyObject*);
104     /// Availability: 2.*
105     PyObject_BorrowedRef* PyMethod_Class(PyObject*);
106 /** Look up attribute with name (a string) on instance object pinst, using
107  * only the instance and base class dicts.  If a descriptor is found in
108  * a class dict, the descriptor is returned without calling it.
109  * Returns NULL if nothing found, else a borrowed reference to the
110  * value associated with name in the dict in which name was found.
111  * The point of this routine is that it never calls arbitrary Python
112  * code, so is always "safe":  all it does is dict lookups.  The function
113  * can't fail, never sets an exception, and NULL is not an error (it just
114  * means "not found").
115  */
116     /// Availability: 2.*
117     PyObject* _PyInstance_Lookup(PyObject* pinst, PyObject* name);
118     /// Availability: 2.*
119     PyObject_BorrowedRef* PyMethod_GET_CLASS()(PyObject* meth) {
120         return borrowed((cast(PyMethodObject*)meth).im_class);
121     }
122     /// Availability: 2.*
123     int PyClass_IsSubclass(PyObject*, PyObject*);
124 }
125 
126 /// _
127 PyObject_BorrowedRef* PyMethod_Function(PyObject*);
128 /// _
129 PyObject_BorrowedRef* PyMethod_Self(PyObject*);
130 /// _
131 PyObject_BorrowedRef* PyMethod_GET_FUNCTION()(PyObject* meth) {
132     return (cast(PyMethodObject*)meth).im_func;
133 }
134 /// _
135 PyObject_BorrowedRef* PyMethod_GET_SELF()(PyObject* meth) {
136     return (cast(PyMethodObject*)meth).im_self;
137 }
138 
139 version(Python_2_6_Or_Later){
140     /// Availability: >= 2.6
141     int PyMethod_ClearFreeList();
142 }
143 
144 version(Python_3_0_Or_Later) {
145     /// Availability: 3.*
146     struct PyInstanceMethodObject{
147         mixin PyObject_HEAD;
148         PyObject *func;
149     }
150 
151     /// Availability: 3.*
152     mixin(PyAPI_DATA!"PyTypeObject PyInstanceMethod_Type");
153 
154     /// Availability: 3.*
155     int PyInstanceMethod_Check()(PyObject* op) {
156         return (op.ob_type is &PyInstanceMethod_Type);
157     }
158 
159     /// Availability: 3.*
160     PyObject* PyInstanceMethod_New(PyObject*);
161     /// Availability: 3.*
162     PyObject* PyInstanceMethod_Function(PyObject*);
163 
164     /** Macros for direct access to these values. Type checks are *not*
165        done, so use with care. */
166     /// Availability: 3.*
167     PyObject* PyInstanceMethod_GET_FUNCTION()(PyObject* meth) {
168         return ((cast(PyInstanceMethodObject*)meth).func);
169     }
170 }
171 
172