Debian Codegraph @

Modules/_testcapi/list.c

raw
1 #include "parts.h"
2 #include "util.h"
3
4
5 static PyObject *
6 list_get_size(PyObject *Py_UNUSED(module), PyObject *obj)
7 {
8 NULLABLE(obj);
9 RETURN_SIZE(PyList_GET_SIZE(obj));
10 }
11
12
13 static PyObject *
14 list_get_item(PyObject *Py_UNUSED(module), PyObject *args)
15 {
16 PyObject *obj;
17 Py_ssize_t i;
18 if (!PyArg_ParseTuple(args, "On", &obj, &i)) {
19 return NULL;
20 }
21 NULLABLE(obj);
22 return Py_XNewRef(PyList_GET_ITEM(obj, i));
23 }
24
25
26 static PyObject *
27 list_set_item(PyObject *Py_UNUSED(module), PyObject *args)
28 {
29 PyObject *obj, *value;
30 Py_ssize_t i;
31 if (!PyArg_ParseTuple(args, "OnO", &obj, &i, &value)) {
32 return NULL;
33 }
34 NULLABLE(obj);
35 NULLABLE(value);
36 PyList_SET_ITEM(obj, i, Py_XNewRef(value));
37 Py_RETURN_NONE;
38
39 }
40
41
42 static PyObject *
43 list_clear(PyObject* Py_UNUSED(module), PyObject *obj)
44 {
45 NULLABLE(obj);
46 RETURN_INT(PyList_Clear(obj));
47 }
48
49
50 static PyObject *
51 list_extend(PyObject* Py_UNUSED(module), PyObject *args)
52 {
53 PyObject *obj, *arg;
54 if (!PyArg_ParseTuple(args, "OO", &obj, &arg)) {
55 return NULL;
56 }
57 NULLABLE(obj);
58 NULLABLE(arg);
59 RETURN_INT(PyList_Extend(obj, arg));
60 }
61
62
63 static PyMethodDef test_methods[] = {
64 {"list_get_size", list_get_size, METH_O},
65 {"list_get_item", list_get_item, METH_VARARGS},
66 {"list_set_item", list_set_item, METH_VARARGS},
67 {"list_clear", list_clear, METH_O},
68 {"list_extend", list_extend, METH_VARARGS},
69
70 {NULL},
71 };
72
73 int
74 _PyTestCapi_Init_List(PyObject *m)
75 {
76 if (PyModule_AddFunctions(m, test_methods) < 0) {
77 return -1;
78 }
79
80 return 0;
81 }