Debian Codegraph @

Modules/_testlimitedcapi/abstract.c

raw
1 #include "parts.h"
2 #include "util.h"
3
4
5 static PyObject *
6 object_repr(PyObject *self, PyObject *arg)
7 {
8 NULLABLE(arg);
9 return PyObject_Repr(arg);
10 }
11
12 static PyObject *
13 object_ascii(PyObject *self, PyObject *arg)
14 {
15 NULLABLE(arg);
16 return PyObject_ASCII(arg);
17 }
18
19 static PyObject *
20 object_str(PyObject *self, PyObject *arg)
21 {
22 NULLABLE(arg);
23 return PyObject_Str(arg);
24 }
25
26 static PyObject *
27 object_bytes(PyObject *self, PyObject *arg)
28 {
29 NULLABLE(arg);
30 return PyObject_Bytes(arg);
31 }
32
33 static PyObject *
34 object_getattr(PyObject *self, PyObject *args)
35 {
36 PyObject *obj, *attr_name;
37 if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
38 return NULL;
39 }
40 NULLABLE(obj);
41 NULLABLE(attr_name);
42 return PyObject_GetAttr(obj, attr_name);
43 }
44
45 static PyObject *
46 object_getattrstring(PyObject *self, PyObject *args)
47 {
48 PyObject *obj;
49 const char *attr_name;
50 Py_ssize_t size;
51 if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
52 return NULL;
53 }
54 NULLABLE(obj);
55 return PyObject_GetAttrString(obj, attr_name);
56 }
57
58 static PyObject *
59 object_hasattr(PyObject *self, PyObject *args)
60 {
61 PyObject *obj, *attr_name;
62 if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
63 return NULL;
64 }
65 NULLABLE(obj);
66 NULLABLE(attr_name);
67 return PyLong_FromLong(PyObject_HasAttr(obj, attr_name));
68 }
69
70 static PyObject *
71 object_hasattrstring(PyObject *self, PyObject *args)
72 {
73 PyObject *obj;
74 const char *attr_name;
75 Py_ssize_t size;
76 if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
77 return NULL;
78 }
79 NULLABLE(obj);
80 return PyLong_FromLong(PyObject_HasAttrString(obj, attr_name));
81 }
82
83 static PyObject *
84 object_setattr(PyObject *self, PyObject *args)
85 {
86 PyObject *obj, *attr_name, *value;
87 if (!PyArg_ParseTuple(args, "OOO", &obj, &attr_name, &value)) {
88 return NULL;
89 }
90 NULLABLE(obj);
91 NULLABLE(attr_name);
92 NULLABLE(value);
93 RETURN_INT(PyObject_SetAttr(obj, attr_name, value));
94 }
95
96 static PyObject *
97 object_setattrstring(PyObject *self, PyObject *args)
98 {
99 PyObject *obj, *value;
100 const char *attr_name;
101 Py_ssize_t size;
102 if (!PyArg_ParseTuple(args, "Oz#O", &obj, &attr_name, &size, &value)) {
103 return NULL;
104 }
105 NULLABLE(obj);
106 NULLABLE(value);
107 RETURN_INT(PyObject_SetAttrString(obj, attr_name, value));
108 }
109
110 static PyObject *
111 object_delattr(PyObject *self, PyObject *args)
112 {
113 PyObject *obj, *attr_name;
114 if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
115 return NULL;
116 }
117 NULLABLE(obj);
118 NULLABLE(attr_name);
119 RETURN_INT(PyObject_DelAttr(obj, attr_name));
120 }
121
122 static PyObject *
123 object_delattrstring(PyObject *self, PyObject *args)
124 {
125 PyObject *obj;
126 const char *attr_name;
127 Py_ssize_t size;
128 if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
129 return NULL;
130 }
131 NULLABLE(obj);
132 RETURN_INT(PyObject_DelAttrString(obj, attr_name));
133 }
134
135 static PyObject *
136 number_check(PyObject *self, PyObject *obj)
137 {
138 NULLABLE(obj);
139 return PyBool_FromLong(PyNumber_Check(obj));
140 }
141
142 static PyObject *
143 mapping_check(PyObject *self, PyObject *obj)
144 {
145 NULLABLE(obj);
146 return PyLong_FromLong(PyMapping_Check(obj));
147 }
148
149 static PyObject *
150 mapping_size(PyObject *self, PyObject *obj)
151 {
152 NULLABLE(obj);
153 RETURN_SIZE(PyMapping_Size(obj));
154 }
155
156 static PyObject *
157 mapping_length(PyObject *self, PyObject *obj)
158 {
159 NULLABLE(obj);
160 RETURN_SIZE(PyMapping_Length(obj));
161 }
162
163 static PyObject *
164 object_getitem(PyObject *self, PyObject *args)
165 {
166 PyObject *mapping, *key;
167 if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
168 return NULL;
169 }
170 NULLABLE(mapping);
171 NULLABLE(key);
172 return PyObject_GetItem(mapping, key);
173 }
174
175 static PyObject *
176 mapping_getitemstring(PyObject *self, PyObject *args)
177 {
178 PyObject *mapping;
179 const char *key;
180 Py_ssize_t size;
181 if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
182 return NULL;
183 }
184 NULLABLE(mapping);
185 return PyMapping_GetItemString(mapping, key);
186 }
187
188 static PyObject *
189 mapping_haskey(PyObject *self, PyObject *args)
190 {
191 PyObject *mapping, *key;
192 if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
193 return NULL;
194 }
195 NULLABLE(mapping);
196 NULLABLE(key);
197 return PyLong_FromLong(PyMapping_HasKey(mapping, key));
198 }
199
200 static PyObject *
201 mapping_haskeystring(PyObject *self, PyObject *args)
202 {
203 PyObject *mapping;
204 const char *key;
205 Py_ssize_t size;
206 if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
207 return NULL;
208 }
209 NULLABLE(mapping);
210 return PyLong_FromLong(PyMapping_HasKeyString(mapping, key));
211 }
212
213 static PyObject *
214 mapping_haskeywitherror(PyObject *self, PyObject *args)
215 {
216 PyObject *mapping, *key;
217 if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
218 return NULL;
219 }
220 NULLABLE(mapping);
221 NULLABLE(key);
222 RETURN_INT(PyMapping_HasKeyWithError(mapping, key));
223 }
224
225 static PyObject *
226 mapping_haskeystringwitherror(PyObject *self, PyObject *args)
227 {
228 PyObject *mapping;
229 const char *key;
230 Py_ssize_t size;
231 if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
232 return NULL;
233 }
234 NULLABLE(mapping);
235 RETURN_INT(PyMapping_HasKeyStringWithError(mapping, key));
236 }
237
238 static PyObject *
239 object_setitem(PyObject *self, PyObject *args)
240 {
241 PyObject *mapping, *key, *value;
242 if (!PyArg_ParseTuple(args, "OOO", &mapping, &key, &value)) {
243 return NULL;
244 }
245 NULLABLE(mapping);
246 NULLABLE(key);
247 NULLABLE(value);
248 RETURN_INT(PyObject_SetItem(mapping, key, value));
249 }
250
251 static PyObject *
252 mapping_setitemstring(PyObject *self, PyObject *args)
253 {
254 PyObject *mapping, *value;
255 const char *key;
256 Py_ssize_t size;
257 if (!PyArg_ParseTuple(args, "Oz#O", &mapping, &key, &size, &value)) {
258 return NULL;
259 }
260 NULLABLE(mapping);
261 NULLABLE(value);
262 RETURN_INT(PyMapping_SetItemString(mapping, key, value));
263 }
264
265 static PyObject *
266 object_delitem(PyObject *self, PyObject *args)
267 {
268 PyObject *mapping, *key;
269 if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
270 return NULL;
271 }
272 NULLABLE(mapping);
273 NULLABLE(key);
274 RETURN_INT(PyObject_DelItem(mapping, key));
275 }
276
277 static PyObject *
278 mapping_delitem(PyObject *self, PyObject *args)
279 {
280 PyObject *mapping, *key;
281 if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
282 return NULL;
283 }
284 NULLABLE(mapping);
285 NULLABLE(key);
286 RETURN_INT(PyMapping_DelItem(mapping, key));
287 }
288
289 static PyObject *
290 mapping_delitemstring(PyObject *self, PyObject *args)
291 {
292 PyObject *mapping;
293 const char *key;
294 Py_ssize_t size;
295 if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
296 return NULL;
297 }
298 NULLABLE(mapping);
299 RETURN_INT(PyMapping_DelItemString(mapping, key));
300 }
301
302 static PyObject *
303 mapping_keys(PyObject *self, PyObject *obj)
304 {
305 NULLABLE(obj);
306 return PyMapping_Keys(obj);
307 }
308
309 static PyObject *
310 mapping_values(PyObject *self, PyObject *obj)
311 {
312 NULLABLE(obj);
313 return PyMapping_Values(obj);
314 }
315
316 static PyObject *
317 mapping_items(PyObject *self, PyObject *obj)
318 {
319 NULLABLE(obj);
320 return PyMapping_Items(obj);
321 }
322
323
324 static PyObject *
325 sequence_check(PyObject* self, PyObject *obj)
326 {
327 NULLABLE(obj);
328 return PyLong_FromLong(PySequence_Check(obj));
329 }
330
331 static PyObject *
332 sequence_size(PyObject* self, PyObject *obj)
333 {
334 NULLABLE(obj);
335 RETURN_SIZE(PySequence_Size(obj));
336 }
337
338 static PyObject *
339 sequence_length(PyObject* self, PyObject *obj)
340 {
341 NULLABLE(obj);
342 RETURN_SIZE(PySequence_Length(obj));
343 }
344
345 static PyObject *
346 sequence_concat(PyObject *self, PyObject *args)
347 {
348 PyObject *seq1, *seq2;
349 if (!PyArg_ParseTuple(args, "OO", &seq1, &seq2)) {
350 return NULL;
351 }
352 NULLABLE(seq1);
353 NULLABLE(seq2);
354
355 return PySequence_Concat(seq1, seq2);
356 }
357
358 static PyObject *
359 sequence_repeat(PyObject *self, PyObject *args)
360 {
361 PyObject *seq;
362 Py_ssize_t count;
363 if (!PyArg_ParseTuple(args, "On", &seq, &count)) {
364 return NULL;
365 }
366 NULLABLE(seq);
367
368 return PySequence_Repeat(seq, count);
369 }
370
371 static PyObject *
372 sequence_inplaceconcat(PyObject *self, PyObject *args)
373 {
374 PyObject *seq1, *seq2;
375 if (!PyArg_ParseTuple(args, "OO", &seq1, &seq2)) {
376 return NULL;
377 }
378 NULLABLE(seq1);
379 NULLABLE(seq2);
380
381 return PySequence_InPlaceConcat(seq1, seq2);
382 }
383
384 static PyObject *
385 sequence_inplacerepeat(PyObject *self, PyObject *args)
386 {
387 PyObject *seq;
388 Py_ssize_t count;
389 if (!PyArg_ParseTuple(args, "On", &seq, &count)) {
390 return NULL;
391 }
392 NULLABLE(seq);
393
394 return PySequence_InPlaceRepeat(seq, count);
395 }
396
397 static PyObject *
398 sequence_getitem(PyObject *self, PyObject *args)
399 {
400 PyObject *seq;
401 Py_ssize_t i;
402 if (!PyArg_ParseTuple(args, "On", &seq, &i)) {
403 return NULL;
404 }
405 NULLABLE(seq);
406
407 return PySequence_GetItem(seq, i);
408 }
409
410 static PyObject *
411 sequence_setitem(PyObject *self, PyObject *args)
412 {
413 Py_ssize_t i;
414 PyObject *seq, *val;
415 if (!PyArg_ParseTuple(args, "OnO", &seq, &i, &val)) {
416 return NULL;
417 }
418 NULLABLE(seq);
419 NULLABLE(val);
420
421 RETURN_INT(PySequence_SetItem(seq, i, val));
422 }
423
424
425 static PyObject *
426 sequence_delitem(PyObject *self, PyObject *args)
427 {
428 Py_ssize_t i;
429 PyObject *seq;
430 if (!PyArg_ParseTuple(args, "On", &seq, &i)) {
431 return NULL;
432 }
433 NULLABLE(seq);
434
435 RETURN_INT(PySequence_DelItem(seq, i));
436 }
437
438 static PyObject *
439 sequence_setslice(PyObject* self, PyObject *args)
440 {
441 PyObject *sequence, *obj;
442 Py_ssize_t i1, i2;
443 if (!PyArg_ParseTuple(args, "OnnO", &sequence, &i1, &i2, &obj)) {
444 return NULL;
445 }
446 NULLABLE(sequence);
447 NULLABLE(obj);
448
449 RETURN_INT(PySequence_SetSlice(sequence, i1, i2, obj));
450 }
451
452 static PyObject *
453 sequence_delslice(PyObject *self, PyObject *args)
454 {
455 PyObject *sequence;
456 Py_ssize_t i1, i2;
457 if (!PyArg_ParseTuple(args, "Onn", &sequence, &i1, &i2)) {
458 return NULL;
459 }
460 NULLABLE(sequence);
461
462 RETURN_INT(PySequence_DelSlice(sequence, i1, i2));
463 }
464
465 static PyObject *
466 sequence_count(PyObject *self, PyObject *args)
467 {
468 PyObject *seq, *value;
469 if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
470 return NULL;
471 }
472 NULLABLE(seq);
473 NULLABLE(value);
474
475 RETURN_SIZE(PySequence_Count(seq, value));
476 }
477
478 static PyObject *
479 sequence_contains(PyObject *self, PyObject *args)
480 {
481 PyObject *seq, *value;
482 if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
483 return NULL;
484 }
485 NULLABLE(seq);
486 NULLABLE(value);
487
488 RETURN_INT(PySequence_Contains(seq, value));
489 }
490
491 static PyObject *
492 sequence_index(PyObject *self, PyObject *args)
493 {
494 PyObject *seq, *value;
495 if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
496 return NULL;
497 }
498 NULLABLE(seq);
499 NULLABLE(value);
500
501 RETURN_SIZE(PySequence_Index(seq, value));
502 }
503
504 static PyObject *
505 sequence_list(PyObject *self, PyObject *obj)
506 {
507 NULLABLE(obj);
508 return PySequence_List(obj);
509 }
510
511 static PyObject *
512 sequence_tuple(PyObject *self, PyObject *obj)
513 {
514 NULLABLE(obj);
515 return PySequence_Tuple(obj);
516 }
517
518
519 static PyObject *
520 sequence_fast(PyObject *self, PyObject *args)
521 {
522 PyObject *obj;
523 const char *err_msg;
524 if (!PyArg_ParseTuple(args, "Os", &obj, &err_msg)) {
525 return NULL;
526 }
527 NULLABLE(obj);
528 return PySequence_Fast(obj, err_msg);
529 }
530
531
532 static PyMethodDef test_methods[] = {
533 {"object_repr", object_repr, METH_O},
534 {"object_ascii", object_ascii, METH_O},
535 {"object_str", object_str, METH_O},
536 {"object_bytes", object_bytes, METH_O},
537
538 {"object_getattr", object_getattr, METH_VARARGS},
539 {"object_getattrstring", object_getattrstring, METH_VARARGS},
540 {"object_hasattr", object_hasattr, METH_VARARGS},
541 {"object_hasattrstring", object_hasattrstring, METH_VARARGS},
542 {"object_setattr", object_setattr, METH_VARARGS},
543 {"object_setattrstring", object_setattrstring, METH_VARARGS},
544 {"object_delattr", object_delattr, METH_VARARGS},
545 {"object_delattrstring", object_delattrstring, METH_VARARGS},
546
547 {"number_check", number_check, METH_O},
548 {"mapping_check", mapping_check, METH_O},
549 {"mapping_size", mapping_size, METH_O},
550 {"mapping_length", mapping_length, METH_O},
551 {"object_getitem", object_getitem, METH_VARARGS},
552 {"mapping_getitemstring", mapping_getitemstring, METH_VARARGS},
553 {"mapping_haskey", mapping_haskey, METH_VARARGS},
554 {"mapping_haskeystring", mapping_haskeystring, METH_VARARGS},
555 {"mapping_haskeywitherror", mapping_haskeywitherror, METH_VARARGS},
556 {"mapping_haskeystringwitherror", mapping_haskeystringwitherror, METH_VARARGS},
557 {"object_setitem", object_setitem, METH_VARARGS},
558 {"mapping_setitemstring", mapping_setitemstring, METH_VARARGS},
559 {"object_delitem", object_delitem, METH_VARARGS},
560 {"mapping_delitem", mapping_delitem, METH_VARARGS},
561 {"mapping_delitemstring", mapping_delitemstring, METH_VARARGS},
562 {"mapping_keys", mapping_keys, METH_O},
563 {"mapping_values", mapping_values, METH_O},
564 {"mapping_items", mapping_items, METH_O},
565
566 {"sequence_check", sequence_check, METH_O},
567 {"sequence_size", sequence_size, METH_O},
568 {"sequence_length", sequence_length, METH_O},
569 {"sequence_concat", sequence_concat, METH_VARARGS},
570 {"sequence_repeat", sequence_repeat, METH_VARARGS},
571 {"sequence_inplaceconcat", sequence_inplaceconcat, METH_VARARGS},
572 {"sequence_inplacerepeat", sequence_inplacerepeat, METH_VARARGS},
573 {"sequence_getitem", sequence_getitem, METH_VARARGS},
574 {"sequence_setitem", sequence_setitem, METH_VARARGS},
575 {"sequence_delitem", sequence_delitem, METH_VARARGS},
576 {"sequence_setslice", sequence_setslice, METH_VARARGS},
577 {"sequence_delslice", sequence_delslice, METH_VARARGS},
578 {"sequence_count", sequence_count, METH_VARARGS},
579 {"sequence_contains", sequence_contains, METH_VARARGS},
580 {"sequence_index", sequence_index, METH_VARARGS},
581 {"sequence_list", sequence_list, METH_O},
582 {"sequence_tuple", sequence_tuple, METH_O},
583 {"sequence_fast", sequence_fast, METH_VARARGS},
584
585 {NULL},
586 };
587
588 int
589 _PyTestLimitedCAPI_Init_Abstract(PyObject *m)
590 {
591 if (PyModule_AddFunctions(m, test_methods) < 0) {
592 return -1;
593 }
594
595 return 0;
596 }