| 8 | | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 9 | | |
| 10 | | struct _object { |
| 11 | | int ob_refcnt; |
| 12 | | _typeobject *ob_type; |
| 13 | | } |
| 14 | | alias _object PyObject; |
| 15 | | |
| 16 | | struct PyVarObject { |
| 17 | | int ob_refcnt; |
| 18 | | _typeobject *ob_type; |
| 19 | | int ob_size; |
| 20 | | } |
| 21 | | |
| 22 | | alias PyObject * (*unaryfunc)(PyObject *); |
| 23 | | alias PyObject * (*binaryfunc)(PyObject *, PyObject *); |
| 24 | | alias PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *); |
| 25 | | alias int (*inquiry)(PyObject *); |
| 26 | | alias int (*coercion)(PyObject **, PyObject **); |
| 27 | | alias PyObject *(*intargfunc)(PyObject *, int); |
| 28 | | alias PyObject *(*intintargfunc)(PyObject *, int, int); |
| 29 | | alias int(*intobjargproc)(PyObject *, int, PyObject *); |
| 30 | | alias int(*intintobjargproc)(PyObject *, int, int, PyObject *); |
| 31 | | alias int(*objobjargproc)(PyObject *, PyObject *, PyObject *); |
| 32 | | alias int (*getreadbufferproc)(PyObject *, int, void **); |
| 33 | | alias int (*getwritebufferproc)(PyObject *, int, void **); |
| 34 | | alias int (*getsegcountproc)(PyObject *, int *); |
| 35 | | alias int (*getcharbufferproc)(PyObject *, int, char **); |
| 36 | | alias int (*objobjproc)(PyObject *, PyObject *); |
| 37 | | alias int (*visitproc)(PyObject *, void *); |
| 38 | | alias int (*traverseproc)(PyObject *, visitproc, void *); |
| 39 | | |
| 40 | | struct PyMemberDef { |
| 41 | | char *name; |
| 42 | | int type; |
| 43 | | int offset; |
| 44 | | int flags; |
| 45 | | char *doc; |
| 46 | | } |
| 47 | | |
| 48 | | struct PyNumberMethods { |
| 49 | | binaryfunc nb_add; |
| 50 | | binaryfunc nb_subtract; |
| 51 | | binaryfunc nb_multiply; |
| 52 | | binaryfunc nb_divide; |
| 53 | | binaryfunc nb_remainder; |
| 54 | | binaryfunc nb_divmod; |
| 55 | | ternaryfunc nb_power; |
| 56 | | unaryfunc nb_negative; |
| 57 | | unaryfunc nb_positive; |
| 58 | | unaryfunc nb_absolute; |
| 59 | | inquiry nb_nonzero; |
| 60 | | unaryfunc nb_invert; |
| 61 | | binaryfunc nb_lshift; |
| 62 | | binaryfunc nb_rshift; |
| 63 | | binaryfunc nb_and; |
| 64 | | binaryfunc nb_xor; |
| 65 | | binaryfunc nb_or; |
| 66 | | coercion nb_coerce; |
| 67 | | unaryfunc nb_int; |
| 68 | | unaryfunc nb_long; |
| 69 | | unaryfunc nb_float; |
| 70 | | unaryfunc nb_oct; |
| 71 | | unaryfunc nb_hex; |
| 72 | | |
| 73 | | binaryfunc nb_inplace_add; |
| 74 | | binaryfunc nb_inplace_subtract; |
| 75 | | binaryfunc nb_inplace_multiply; |
| 76 | | binaryfunc nb_inplace_divide; |
| 77 | | binaryfunc nb_inplace_remainder; |
| 78 | | ternaryfunc nb_inplace_power; |
| 79 | | binaryfunc nb_inplace_lshift; |
| 80 | | binaryfunc nb_inplace_rshift; |
| 81 | | binaryfunc nb_inplace_and; |
| 82 | | binaryfunc nb_inplace_xor; |
| 83 | | binaryfunc nb_inplace_or; |
| 84 | | |
| 85 | | |
| 86 | | binaryfunc nb_floor_divide; |
| 87 | | binaryfunc nb_true_divide; |
| 88 | | binaryfunc nb_inplace_floor_divide; |
| 89 | | binaryfunc nb_inplace_true_divide; |
| 90 | | }; |
| 91 | | |
| 92 | | struct PySequenceMethods { |
| 93 | | inquiry sq_length; |
| 94 | | binaryfunc sq_concat; |
| 95 | | intargfunc sq_repeat; |
| 96 | | intargfunc sq_item; |
| 97 | | intintargfunc sq_slice; |
| 98 | | intobjargproc sq_ass_item; |
| 99 | | intintobjargproc sq_ass_slice; |
| 100 | | objobjproc sq_contains; |
| 101 | | binaryfunc sq_inplace_concat; |
| 102 | | intargfunc sq_inplace_repeat; |
| 103 | | }; |
| 104 | | |
| 105 | | struct PyMappingMethods { |
| 106 | | inquiry mp_length; |
| 107 | | binaryfunc mp_subscript; |
| 108 | | objobjargproc mp_ass_subscript; |
| 109 | | }; |
| 110 | | |
| 111 | | struct PyBufferProcs { |
| 112 | | getreadbufferproc bf_getreadbuffer; |
| 113 | | getwritebufferproc bf_getwritebuffer; |
| 114 | | getsegcountproc bf_getsegcount; |
| 115 | | getcharbufferproc bf_getcharbuffer; |
| 116 | | }; |
| 117 | | |
| 118 | | |
| 119 | | alias void (*freefunc)(void *); |
| 120 | | alias void (*destructor)(PyObject *); |
| 121 | | alias int (*printfunc)(PyObject *, FILE *, int); |
| 122 | | alias PyObject *(*getattrfunc)(PyObject *, char *); |
| 123 | | alias PyObject *(*getattrofunc)(PyObject *, PyObject *); |
| 124 | | alias int (*setattrfunc)(PyObject *, char *, PyObject *); |
| 125 | | alias int (*setattrofunc)(PyObject *, PyObject *, PyObject *); |
| 126 | | alias int (*cmpfunc)(PyObject *, PyObject *); |
| 127 | | alias PyObject *(*reprfunc)(PyObject *); |
| 128 | | alias long (*hashfunc)(PyObject *); |
| 129 | | alias PyObject *(*richcmpfunc) (PyObject *, PyObject *, int); |
| 130 | | alias PyObject *(*getiterfunc) (PyObject *); |
| 131 | | alias PyObject *(*iternextfunc) (PyObject *); |
| 132 | | alias PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *); |
| 133 | | alias int (*descrsetfunc) (PyObject *, PyObject *, PyObject *); |
| 134 | | alias int (*initproc)(PyObject *, PyObject *, PyObject *); |
| 135 | | alias PyObject *(*newfunc)(_typeobject *, PyObject *, PyObject *); |
| 136 | | alias PyObject *(*allocfunc)(_typeobject *, int); |
| 137 | | |
| 138 | | struct _typeobject { |
| 139 | | int ob_refcnt; |
| 140 | | _typeobject *ob_type; |
| 141 | | int ob_size; |
| 142 | | char *tp_name; |
| 143 | | int tp_basicsize, tp_itemsize; |
| 144 | | |
| 145 | | destructor tp_dealloc; |
| 146 | | printfunc tp_print; |
| 147 | | getattrfunc tp_getattr; |
| 148 | | setattrfunc tp_setattr; |
| 149 | | cmpfunc tp_compare; |
| 150 | | reprfunc tp_repr; |
| 151 | | |
| 152 | | PyNumberMethods *tp_as_number; |
| 153 | | PySequenceMethods *tp_as_sequence; |
| 154 | | PyMappingMethods *tp_as_mapping; |
| 155 | | |
| 156 | | hashfunc tp_hash; |
| 157 | | ternaryfunc tp_call; |
| 158 | | reprfunc tp_str; |
| 159 | | getattrofunc tp_getattro; |
| 160 | | setattrofunc tp_setattro; |
| 161 | | |
| 162 | | PyBufferProcs *tp_as_buffer; |
| 163 | | |
| 164 | | long tp_flags; |
| 165 | | |
| 166 | | char *tp_doc; |
| 167 | | |
| 168 | | traverseproc tp_traverse; |
| 169 | | |
| 170 | | inquiry tp_clear; |
| 171 | | |
| 172 | | richcmpfunc tp_richcompare; |
| 173 | | |
| 174 | | long tp_weaklistoffset; |
| 175 | | |
| 176 | | getiterfunc tp_iter; |
| 177 | | iternextfunc tp_iternext; |
| 178 | | |
| 179 | | PyMethodDef *tp_methods; |
| 180 | | PyMemberDef *tp_members; |
| 181 | | PyGetSetDef *tp_getset; |
| 182 | | _typeobject *tp_base; |
| 183 | | PyObject *tp_dict; |
| 184 | | descrgetfunc tp_descr_get; |
| 185 | | descrsetfunc tp_descr_set; |
| 186 | | long tp_dictoffset; |
| 187 | | initproc tp_init; |
| 188 | | allocfunc tp_alloc; |
| 189 | | newfunc tp_new; |
| 190 | | freefunc tp_free; |
| 191 | | inquiry tp_is_gc; |
| 192 | | PyObject *tp_bases; |
| 193 | | PyObject *tp_mro; |
| 194 | | PyObject *tp_cache; |
| 195 | | PyObject *tp_subclasses; |
| 196 | | PyObject *tp_weaklist; |
| 197 | | destructor tp_del; |
| 198 | | } |
| 199 | | |
| 200 | | alias _typeobject PyTypeObject; |
| 201 | | |
| 202 | | struct _heaptypeobject { |
| 203 | | PyTypeObject type; |
| 204 | | PyNumberMethods as_number; |
| 205 | | PyMappingMethods as_mapping; |
| 206 | | PySequenceMethods as_sequence; |
| 207 | | PyBufferProcs as_buffer; |
| 208 | | PyObject *name, slots; |
| 209 | | } |
| 210 | | alias _heaptypeobject PyHeapTypeObject; |
| 211 | | |
| 212 | | void * PyMem_Malloc(size_t); |
| 213 | | void * PyMem_Realloc(void *, size_t); |
| 214 | | void PyMem_Free(void *); |
| 215 | | |
| 216 | | |
| 217 | | /////////////////////////////////////////////////////////////////////////////////////////////// |
| | 42 | /////////////////////////////////////////////////////////////////////////////// |
| | 43 | // Python-header-file: Include/Python.h: |
| | 44 | const int Py_single_input = 256; |
| | 45 | const int Py_file_input = 257; |
| | 46 | const int Py_eval_input = 258; |
| | 47 | |
| | 48 | // Python-header-file: Include/object.h: |
| | 49 | |
| | 50 | // XXX:Conditionalize in if running debug build of Python interpreter: |
| | 51 | /* |
| | 52 | version (Python_Debug_Build) { |
| | 53 | template _PyObject_HEAD_EXTRA() { |
| | 54 | PyObject *_ob_next; |
| | 55 | PyObject *_ob_prev; |
| | 56 | } |
| | 57 | } else { |
| | 58 | */ |
| | 59 | template _PyObject_HEAD_EXTRA() {} |
| | 60 | /*}*/ |
| | 61 | |
| | 62 | template PyObject_HEAD() { |
| | 63 | mixin _PyObject_HEAD_EXTRA; |
| | 64 | int ob_refcnt; |
| | 65 | PyTypeObject *ob_type; |
| | 66 | } |
| | 67 | |
| | 68 | struct PyObject { |
| | 69 | mixin PyObject_HEAD; |
| | 70 | } |
| | 71 | |
| | 72 | template PyObject_VAR_HEAD() { |
| | 73 | mixin PyObject_HEAD; |
| | 74 | int ob_size; /* Number of items in variable part */ |
| | 75 | } |
| | 76 | |
| | 77 | struct PyVarObject { |
| | 78 | mixin PyObject_VAR_HEAD; |
| | 79 | } |
| | 80 | |
| | 81 | alias PyObject * (*unaryfunc)(PyObject *); |
| | 82 | alias PyObject * (*binaryfunc)(PyObject *, PyObject *); |
| | 83 | alias PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *); |
| | 84 | alias int (*inquiry)(PyObject *); |
| | 85 | alias int (*coercion)(PyObject **, PyObject **); |
| | 86 | alias PyObject *(*intargfunc)(PyObject *, int); |
| | 87 | alias PyObject *(*intintargfunc)(PyObject *, int, int); |
| | 88 | alias int(*intobjargproc)(PyObject *, int, PyObject *); |
| | 89 | alias int(*intintobjargproc)(PyObject *, int, int, PyObject *); |
| | 90 | alias int(*objobjargproc)(PyObject *, PyObject *, PyObject *); |
| | 91 | alias int (*getreadbufferproc)(PyObject *, int, void **); |
| | 92 | alias int (*getwritebufferproc)(PyObject *, int, void **); |
| | 93 | alias int (*getsegcountproc)(PyObject *, int *); |
| | 94 | alias int (*getcharbufferproc)(PyObject *, int, char **); |
| | 95 | alias int (*objobjproc)(PyObject *, PyObject *); |
| | 96 | alias int (*visitproc)(PyObject *, void *); |
| | 97 | alias int (*traverseproc)(PyObject *, visitproc, void *); |
| | 98 | |
| | 99 | // Python-header-file: Include/object.h: |
| | 100 | struct PyNumberMethods { |
| | 101 | binaryfunc nb_add; |
| | 102 | binaryfunc nb_subtract; |
| | 103 | binaryfunc nb_multiply; |
| | 104 | binaryfunc nb_divide; |
| | 105 | binaryfunc nb_remainder; |
| | 106 | binaryfunc nb_divmod; |
| | 107 | ternaryfunc nb_power; |
| | 108 | unaryfunc nb_negative; |
| | 109 | unaryfunc nb_positive; |
| | 110 | unaryfunc nb_absolute; |
| | 111 | inquiry nb_nonzero; |
| | 112 | unaryfunc nb_invert; |
| | 113 | binaryfunc nb_lshift; |
| | 114 | binaryfunc nb_rshift; |
| | 115 | binaryfunc nb_and; |
| | 116 | binaryfunc nb_xor; |
| | 117 | binaryfunc nb_or; |
| | 118 | coercion nb_coerce; |
| | 119 | unaryfunc nb_int; |
| | 120 | unaryfunc nb_long; |
| | 121 | unaryfunc nb_float; |
| | 122 | unaryfunc nb_oct; |
| | 123 | unaryfunc nb_hex; |
| | 124 | |
| | 125 | binaryfunc nb_inplace_add; |
| | 126 | binaryfunc nb_inplace_subtract; |
| | 127 | binaryfunc nb_inplace_multiply; |
| | 128 | binaryfunc nb_inplace_divide; |
| | 129 | binaryfunc nb_inplace_remainder; |
| | 130 | ternaryfunc nb_inplace_power; |
| | 131 | binaryfunc nb_inplace_lshift; |
| | 132 | binaryfunc nb_inplace_rshift; |
| | 133 | binaryfunc nb_inplace_and; |
| | 134 | binaryfunc nb_inplace_xor; |
| | 135 | binaryfunc nb_inplace_or; |
| | 136 | |
| | 137 | |
| | 138 | binaryfunc nb_floor_divide; |
| | 139 | binaryfunc nb_true_divide; |
| | 140 | binaryfunc nb_inplace_floor_divide; |
| | 141 | binaryfunc nb_inplace_true_divide; |
| | 142 | } |
| | 143 | |
| | 144 | struct PySequenceMethods { |
| | 145 | inquiry sq_length; |
| | 146 | binaryfunc sq_concat; |
| | 147 | intargfunc sq_repeat; |
| | 148 | intargfunc sq_item; |
| | 149 | intintargfunc sq_slice; |
| | 150 | intobjargproc sq_ass_item; |
| | 151 | intintobjargproc sq_ass_slice; |
| | 152 | objobjproc sq_contains; |
| | 153 | binaryfunc sq_inplace_concat; |
| | 154 | intargfunc sq_inplace_repeat; |
| | 155 | } |
| | 156 | |
| | 157 | struct PyMappingMethods { |
| | 158 | inquiry mp_length; |
| | 159 | binaryfunc mp_subscript; |
| | 160 | objobjargproc mp_ass_subscript; |
| | 161 | } |
| | 162 | |
| | 163 | struct PyBufferProcs { |
| | 164 | getreadbufferproc bf_getreadbuffer; |
| | 165 | getwritebufferproc bf_getwritebuffer; |
| | 166 | getsegcountproc bf_getsegcount; |
| | 167 | getcharbufferproc bf_getcharbuffer; |
| | 168 | } |
| | 169 | |
| | 170 | |
| | 171 | alias void (*freefunc)(void *); |
| | 172 | alias void (*destructor)(PyObject *); |
| | 173 | alias int (*printfunc)(PyObject *, FILE *, int); |
| | 174 | alias PyObject *(*getattrfunc)(PyObject *, char *); |
| | 175 | alias PyObject *(*getattrofunc)(PyObject *, PyObject *); |
| | 176 | alias int (*setattrfunc)(PyObject *, char *, PyObject *); |
| | 177 | alias int (*setattrofunc)(PyObject *, PyObject *, PyObject *); |
| | 178 | alias int (*cmpfunc)(PyObject *, PyObject *); |
| | 179 | alias PyObject *(*reprfunc)(PyObject *); |
| | 180 | alias C_long (*hashfunc)(PyObject *); |
| | 181 | alias PyObject *(*richcmpfunc) (PyObject *, PyObject *, int); |
| | 182 | alias PyObject *(*getiterfunc) (PyObject *); |
| | 183 | alias PyObject *(*iternextfunc) (PyObject *); |
| | 184 | alias PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *); |
| | 185 | alias int (*descrsetfunc) (PyObject *, |