ยปCore Development>Code coverage>Doc/includes/shoddy.c

Python code coverage for Doc/includes/shoddy.c

#countcontent
1n/a#include <Python.h>
2n/a
3n/atypedef struct {
4n/a PyListObject list;
5n/a int state;
6n/a} Shoddy;
7n/a
8n/a
9n/astatic PyObject *
10n/aShoddy_increment(Shoddy *self, PyObject *unused)
11n/a{
12n/a self->state++;
13n/a return PyLong_FromLong(self->state);
14n/a}
15n/a
16n/a
17n/astatic PyMethodDef Shoddy_methods[] = {
18n/a {"increment", (PyCFunction)Shoddy_increment, METH_NOARGS,
19n/a PyDoc_STR("increment state counter")},
20n/a {NULL, NULL},
21n/a};
22n/a
23n/astatic int
24n/aShoddy_init(Shoddy *self, PyObject *args, PyObject *kwds)
25n/a{
26n/a if (PyList_Type.tp_init((PyObject *)self, args, kwds) < 0)
27n/a return -1;
28n/a self->state = 0;
29n/a return 0;
30n/a}
31n/a
32n/a
33n/astatic PyTypeObject ShoddyType = {
34n/a PyObject_HEAD_INIT(NULL)
35n/a "shoddy.Shoddy", /* tp_name */
36n/a sizeof(Shoddy), /* tp_basicsize */
37n/a 0, /* tp_itemsize */
38n/a 0, /* tp_dealloc */
39n/a 0, /* tp_print */
40n/a 0, /* tp_getattr */
41n/a 0, /* tp_setattr */
42n/a 0, /* tp_reserved */
43n/a 0, /* tp_repr */
44n/a 0, /* tp_as_number */
45n/a 0, /* tp_as_sequence */
46n/a 0, /* tp_as_mapping */
47n/a 0, /* tp_hash */
48n/a 0, /* tp_call */
49n/a 0, /* tp_str */
50n/a 0, /* tp_getattro */
51n/a 0, /* tp_setattro */
52n/a 0, /* tp_as_buffer */
53n/a Py_TPFLAGS_DEFAULT |
54n/a Py_TPFLAGS_BASETYPE, /* tp_flags */
55n/a 0, /* tp_doc */
56n/a 0, /* tp_traverse */
57n/a 0, /* tp_clear */
58n/a 0, /* tp_richcompare */
59n/a 0, /* tp_weaklistoffset */
60n/a 0, /* tp_iter */
61n/a 0, /* tp_iternext */
62n/a Shoddy_methods, /* tp_methods */
63n/a 0, /* tp_members */
64n/a 0, /* tp_getset */
65n/a 0, /* tp_base */
66n/a 0, /* tp_dict */
67n/a 0, /* tp_descr_get */
68n/a 0, /* tp_descr_set */
69n/a 0, /* tp_dictoffset */
70n/a (initproc)Shoddy_init, /* tp_init */
71n/a 0, /* tp_alloc */
72n/a 0, /* tp_new */
73n/a};
74n/a
75n/astatic PyModuleDef shoddymodule = {
76n/a PyModuleDef_HEAD_INIT,
77n/a "shoddy",
78n/a "Shoddy module",
79n/a -1,
80n/a NULL, NULL, NULL, NULL, NULL
81n/a};
82n/a
83n/aPyMODINIT_FUNC
84n/aPyInit_shoddy(void)
85n/a{
86n/a PyObject *m;
87n/a
88n/a ShoddyType.tp_base = &PyList_Type;
89n/a if (PyType_Ready(&ShoddyType) < 0)
90n/a return NULL;
91n/a
92n/a m = PyModule_Create(&shoddymodule);
93n/a if (m == NULL)
94n/a return NULL;
95n/a
96n/a Py_INCREF(&ShoddyType);
97n/a PyModule_AddObject(m, "Shoddy", (PyObject *) &ShoddyType);
98n/a return m;
99n/a}