Debian Codegraph @

pypy/module/cpyext/parse/cpyext_object.h

raw symbols SCIP
1 #pragma once
2
3 #define PyObject_HEAD PyObject ob_base;
4 #define PyObject_VAR_HEAD PyVarObject ob_base;
5
6 typedef struct _object {
7 Py_ssize_t ob_refcnt;
8 Py_ssize_t ob_pypy_link;
9 struct _typeobject *ob_type;
10 } PyObject;
11
12 typedef struct {
13 PyObject ob_base;
14 Py_ssize_t ob_size; /* Number of items in variable part */
15 } PyVarObject;
16
17 struct _typeobject;
18 typedef void (*freefunc)(void *);
19 typedef void (*destructor)(PyObject *);
20 typedef Py_ssize_t printfunc;
21 typedef PyObject *(*getattrfunc)(PyObject *, char *);
22 typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
23 typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
24 typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
25 typedef int (*cmpfunc)(PyObject *, PyObject *);
26 typedef PyObject *(*reprfunc)(PyObject *);
27 typedef Py_hash_t (*hashfunc)(PyObject *);
28 typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
29 typedef PyObject *(*getiterfunc) (PyObject *);
30 typedef PyObject *(*iternextfunc) (PyObject *);
31 typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
32 typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
33 typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
34 typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
35 typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
36
37 typedef PyObject * (*unaryfunc)(PyObject *);
38 typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
39 typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
40 typedef int (*inquiry)(PyObject *);
41 typedef Py_ssize_t (*lenfunc)(PyObject *);
42 typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
43 typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
44 typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
45 typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
46 typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
47
48
49 /* Py3k buffer interface, adapted for PyPy */
50 /* Changing this constant changes the ABI */
51 #define PyBUF_MAX_NDIM 64
52 typedef struct bufferinfo {
53 void *buf;
54 PyObject *obj; /* owned reference */
55 Py_ssize_t len;
56 Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
57 pointed to by strides in simple case.*/
58 int readonly;
59 int ndim;
60 char *format;
61 Py_ssize_t *shape;
62 Py_ssize_t *strides;
63 Py_ssize_t *suboffsets; /* alway NULL for app-level objects*/
64 void *internal; /* always NULL for app-level objects */
65 /* PyPy extensions */
66 int flags;
67 Py_ssize_t _strides[PyBUF_MAX_NDIM];
68 Py_ssize_t _shape[PyBUF_MAX_NDIM];
69 /* static store for shape and strides of
70 mono-dimensional buffers. */
71 /* Py_ssize_t smalltable[2]; */
72 } Py_buffer;
73
74 typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
75 typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
76 /* end Py3k buffer interface */
77 typedef PyObject *(*vectorcallfunc)(PyObject *callable, PyObject *const *args,
78 size_t nargsf, PyObject *kwnames);
79
80 typedef int (*objobjproc)(PyObject *, PyObject *);
81 typedef int (*visitproc)(PyObject *, void *);
82 typedef int (*traverseproc)(PyObject *, visitproc, void *);
83
84
85 typedef struct {
86 /* Number implementations must check *both*
87 arguments for proper type and implement the necessary conversions
88 in the slot functions themselves. */
89
90 binaryfunc nb_add;
91 binaryfunc nb_subtract;
92 binaryfunc nb_multiply;
93 binaryfunc nb_remainder;
94 binaryfunc nb_divmod;
95 ternaryfunc nb_power;
96 unaryfunc nb_negative;
97 unaryfunc nb_positive;
98 unaryfunc nb_absolute;
99 inquiry nb_bool;
100 unaryfunc nb_invert;
101 binaryfunc nb_lshift;
102 binaryfunc nb_rshift;
103 binaryfunc nb_and;
104 binaryfunc nb_xor;
105 binaryfunc nb_or;
106 unaryfunc nb_int;
107 void *nb_reserved; /* the slot formerly known as nb_long */
108 unaryfunc nb_float;
109
110 binaryfunc nb_inplace_add;
111 binaryfunc nb_inplace_subtract;
112 binaryfunc nb_inplace_multiply;
113 binaryfunc nb_inplace_remainder;
114 ternaryfunc nb_inplace_power;
115 binaryfunc nb_inplace_lshift;
116 binaryfunc nb_inplace_rshift;
117 binaryfunc nb_inplace_and;
118 binaryfunc nb_inplace_xor;
119 binaryfunc nb_inplace_or;
120
121 binaryfunc nb_floor_divide;
122 binaryfunc nb_true_divide;
123 binaryfunc nb_inplace_floor_divide;
124 binaryfunc nb_inplace_true_divide;
125
126 unaryfunc nb_index;
127
128 binaryfunc nb_matrix_multiply;
129 binaryfunc nb_inplace_matrix_multiply;
130 } PyNumberMethods;
131
132 typedef struct {
133 lenfunc sq_length;
134 binaryfunc sq_concat;
135 ssizeargfunc sq_repeat;
136 ssizeargfunc sq_item;
137 void *was_sq_slice;
138 ssizeobjargproc sq_ass_item;
139 void *was_sq_ass_slice;
140 objobjproc sq_contains;
141
142 binaryfunc sq_inplace_concat;
143 ssizeargfunc sq_inplace_repeat;
144 } PySequenceMethods;
145
146 typedef struct {
147 lenfunc mp_length;
148 binaryfunc mp_subscript;
149 objobjargproc mp_ass_subscript;
150 } PyMappingMethods;
151
152 /* Result of calling PyIter_Send
153
154 Note: small deviation from CPython definitions here:
155 PyPy wants to return an int from "sendfunc" because it knows sizeof(int)
156 and doesn't know sizeof(enum PySendResult).
157 Therefore introduce the symbols like PYGEN_RETURN into the global namespace
158 with an anoymous enum, but define PySendResult as int so that functions
159 that are defined as returning PySendResult will be compatible with the definition
160 of sendfunc (especially on C++).
161 The only thing this breaks is C++ code that writes PySendResult::PYGEN_RETURN.
162 */
163 enum {
164 PYGEN_RETURN = 0,
165 PYGEN_ERROR = -1,
166 PYGEN_NEXT = 1,
167 };
168
169 typedef int PySendResult;
170
171 typedef int (*sendfunc)(PyObject *iter, PyObject *value, PyObject **result);
172
173 typedef struct {
174 unaryfunc am_await;
175 unaryfunc am_aiter;
176 unaryfunc am_anext;
177 sendfunc am_send;
178 } PyAsyncMethods;
179
180 typedef struct {
181 getbufferproc bf_getbuffer;
182 releasebufferproc bf_releasebuffer;
183 } PyBufferProcs;
184
185 /* from methodobject.h (the `PyObject **` are `PyObject *const *` in CPython) */
186 typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
187 typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject **, Py_ssize_t);
188 typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
189 PyObject *);
190 typedef PyObject *(*_PyCFunctionFastWithKeywords) (PyObject *,
191 PyObject **, Py_ssize_t,
192 PyObject *);
193
194 typedef PyObject *(*PyNoArgsFunction)(PyObject *);
195
196 struct PyMethodDef {
197 const char *ml_name; /* The name of the built-in function/method */
198 PyCFunction ml_meth; /* The C function that implements it */
199 int ml_flags; /* Combination of METH_xxx flags, which mostly
200 describe the args expected by the C func */
201 const char *ml_doc; /* The __doc__ attribute, or NULL */
202 };
203 typedef struct PyMethodDef PyMethodDef;
204
205 typedef struct {
206 PyObject_HEAD
207 PyMethodDef *m_ml; /* Description of the C function to call */
208 PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
209 PyObject *m_module; /* The __module__ attribute, can be anything */
210 PyObject *m_weakreflist; /* List of weak references */
211 } PyCFunctionObject;
212
213 /* from structmember.h */
214 typedef struct PyMemberDef {
215 /* Current version, use this */
216 const char *name;
217 int type;
218 Py_ssize_t offset;
219 int flags;
220 const char *doc;
221 } PyMemberDef;
222
223
224 typedef struct _typeobject {
225 PyObject_VAR_HEAD
226 const char *tp_name; /* For printing, in format "<module>.<name>" */
227 Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
228
229 /* Methods to implement standard operations */
230
231 destructor tp_dealloc;
232 Py_ssize_t tp_vectorcall_offset;
233 getattrfunc tp_getattr;
234 setattrfunc tp_setattr;
235 PyAsyncMethods *tp_as_async; /* formerly known as tp_compare (Python 2)
236 or tp_reserved (Python 3) */
237 reprfunc tp_repr;
238
239 /* Method suites for standard classes */
240
241 PyNumberMethods *tp_as_number;
242 PySequenceMethods *tp_as_sequence;
243 PyMappingMethods *tp_as_mapping;
244
245 /* More standard operations (here for binary compatibility) */
246
247 hashfunc tp_hash;
248 ternaryfunc tp_call;
249 reprfunc tp_str;
250 getattrofunc tp_getattro;
251 setattrofunc tp_setattro;
252
253 /* Functions to access object as input/output buffer */
254 PyBufferProcs *tp_as_buffer;
255
256 /* Flags to define presence of optional/expanded features */
257 unsigned long tp_flags;
258
259 const char *tp_doc; /* Documentation string */
260
261 /* Assigned meaning in release 2.0 */
262 /* call function for all accessible objects */
263 traverseproc tp_traverse;
264
265 /* delete references to contained objects */
266 inquiry tp_clear;
267
268 /* Assigned meaning in release 2.1 */
269 /* rich comparisons */
270 richcmpfunc tp_richcompare;
271
272 /* weak reference enabler */
273 Py_ssize_t tp_weaklistoffset;
274
275 /* Iterators */
276 getiterfunc tp_iter;
277 iternextfunc tp_iternext;
278
279 /* Attribute descriptor and subclassing stuff */
280 struct PyMethodDef *tp_methods;
281 struct PyMemberDef *tp_members;
282 struct PyGetSetDef *tp_getset;
283 struct _typeobject *tp_base;
284 PyObject *tp_dict;
285 descrgetfunc tp_descr_get;
286 descrsetfunc tp_descr_set;
287 Py_ssize_t tp_dictoffset;
288 initproc tp_init;
289 allocfunc tp_alloc;
290 newfunc tp_new;
291 freefunc tp_free; /* Low-level free-memory routine */
292 inquiry tp_is_gc; /* For PyObject_IS_GC */
293 PyObject *tp_bases;
294 PyObject *tp_mro; /* method resolution order */
295 PyObject *tp_cache;
296 PyObject *tp_subclasses;
297 PyObject *tp_weaklist;
298 destructor tp_del;
299
300 /* Type attribute cache version tag. Added in version 2.6 */
301 unsigned int tp_version_tag;
302
303 destructor tp_finalize;
304 vectorcallfunc tp_vectorcall;
305 } PyTypeObject;
306
307 typedef struct{
308 int slot; /* slot id, see below */
309 void *pfunc; /* function pointer */
310 } PyType_Slot;
311
312 typedef struct{
313 const char* name;
314 int basicsize;
315 int itemsize;
316 unsigned int flags;
317 PyType_Slot *slots; /* terminated by slot==0. */
318 } PyType_Spec;
319
320 typedef struct _heaptypeobject {
321 PyTypeObject ht_type;
322 PyAsyncMethods as_async;
323 PyNumberMethods as_number;
324 PyMappingMethods as_mapping;
325 PySequenceMethods as_sequence;
326 PyBufferProcs as_buffer;
327 PyObject *ht_name, *ht_slots, *ht_qualname;
328 PyObject *ht_module;
329 } PyHeapTypeObject;
330
331 /* access macro to the members which are floating "behind" the object */
332 #define PyHeapType_GET_MEMBERS(etype) \
333 ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
334
335 typedef struct {
336 PyCFunctionObject func;
337 PyTypeObject *mm_class; /* Class that defines this method */
338 } PyCMethodObject;
339
340 /* CPython uses PyObject *const * for the third arg, but we drop the const */
341 typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject **,
342 size_t, PyObject *);
343