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 version(Python_3_8_Or_Later) { 67 vectorcallfunc vectorcall; 68 } 69 } 70 71 /// _ 72 mixin(PyAPI_DATA!"PyTypeObject PyMethod_Type"); 73 74 // D translation of C macro: 75 int PyMethod_Check()(PyObject *op) { 76 return Py_TYPE(op) == &PyMethod_Type; 77 } 78 79 version(Python_3_0_Or_Later) { 80 /// Availability: 3.* 81 PyObject* PyMethod_New(PyObject*, PyObject*); 82 }else{ 83 /// Availability: 2.* 84 mixin(PyAPI_DATA!"PyTypeObject PyClass_Type"); 85 /// Availability: 2.* 86 mixin(PyAPI_DATA!"PyTypeObject PyInstance_Type"); 87 // D translation of C macro: 88 /// Availability: 2.* 89 int PyClass_Check()(PyObject *op) { 90 return Py_TYPE(op) == &PyClass_Type; 91 } 92 93 // D translation of C macro: 94 /// Availability: 2.* 95 int PyInstance_Check()(PyObject *op) { 96 return Py_TYPE(op) == &PyInstance_Type; 97 } 98 99 /// Availability: 2.* 100 PyObject* PyClass_New(PyObject*, PyObject*, PyObject*); 101 /// Availability: 2.* 102 PyObject* PyInstance_New(PyObject*, PyObject*, PyObject*); 103 /// Availability: 2.* 104 PyObject* PyInstance_NewRaw(PyObject*, PyObject*); 105 /// Availability: 2.* 106 PyObject* PyMethod_New(PyObject*, PyObject*, PyObject*); 107 /// Availability: 2.* 108 PyObject_BorrowedRef* PyMethod_Class(PyObject*); 109 /** Look up attribute with name (a string) on instance object pinst, using 110 * only the instance and base class dicts. If a descriptor is found in 111 * a class dict, the descriptor is returned without calling it. 112 * Returns NULL if nothing found, else a borrowed reference to the 113 * value associated with name in the dict in which name was found. 114 * The point of this routine is that it never calls arbitrary Python 115 * code, so is always "safe": all it does is dict lookups. The function 116 * can't fail, never sets an exception, and NULL is not an error (it just 117 * means "not found"). 118 */ 119 /// Availability: 2.* 120 PyObject* _PyInstance_Lookup(PyObject* pinst, PyObject* name); 121 /// Availability: 2.* 122 PyObject_BorrowedRef* PyMethod_GET_CLASS()(PyObject* meth) { 123 return borrowed((cast(PyMethodObject*)meth).im_class); 124 } 125 /// Availability: 2.* 126 int PyClass_IsSubclass(PyObject*, PyObject*); 127 } 128 129 /// _ 130 PyObject_BorrowedRef* PyMethod_Function(PyObject*); 131 /// _ 132 PyObject_BorrowedRef* PyMethod_Self(PyObject*); 133 /// _ 134 PyObject_BorrowedRef* PyMethod_GET_FUNCTION()(PyObject* meth) { 135 return (cast(PyMethodObject*)meth).im_func; 136 } 137 /// _ 138 PyObject_BorrowedRef* PyMethod_GET_SELF()(PyObject* meth) { 139 return (cast(PyMethodObject*)meth).im_self; 140 } 141 142 version(Python_2_6_Or_Later){ 143 /// Availability: >= 2.6 144 int PyMethod_ClearFreeList(); 145 } 146 147 version(Python_3_0_Or_Later) { 148 /// Availability: 3.* 149 struct PyInstanceMethodObject{ 150 mixin PyObject_HEAD; 151 PyObject *func; 152 } 153 154 /// Availability: 3.* 155 mixin(PyAPI_DATA!"PyTypeObject PyInstanceMethod_Type"); 156 157 /// Availability: 3.* 158 int PyInstanceMethod_Check()(PyObject* op) { 159 return (op.ob_type is &PyInstanceMethod_Type); 160 } 161 162 /// Availability: 3.* 163 PyObject* PyInstanceMethod_New(PyObject*); 164 /// Availability: 3.* 165 PyObject* PyInstanceMethod_Function(PyObject*); 166 167 /** Macros for direct access to these values. Type checks are *not* 168 done, so use with care. */ 169 /// Availability: 3.* 170 PyObject* PyInstanceMethod_GET_FUNCTION()(PyObject* meth) { 171 return ((cast(PyInstanceMethodObject*)meth).func); 172 } 173 } 174 175