No need for carry to be type twodigits in _PyLong_AsByteArray; digit is large enough.
[python.git] / Doc / includes / shoddy.c
blob07a41775484cc9265a8df416d92815b3873a1aa2
1 #include <Python.h>
3 typedef struct {
4 PyListObject list;
5 int state;
6 } Shoddy;
9 static PyObject *
10 Shoddy_increment(Shoddy *self, PyObject *unused)
12 self->state++;
13 return PyInt_FromLong(self->state);
17 static PyMethodDef Shoddy_methods[] = {
18 {"increment", (PyCFunction)Shoddy_increment, METH_NOARGS,
19 PyDoc_STR("increment state counter")},
20 {NULL, NULL},
23 static int
24 Shoddy_init(Shoddy *self, PyObject *args, PyObject *kwds)
26 if (PyList_Type.tp_init((PyObject *)self, args, kwds) < 0)
27 return -1;
28 self->state = 0;
29 return 0;
33 static PyTypeObject ShoddyType = {
34 PyObject_HEAD_INIT(NULL)
35 0, /* ob_size */
36 "shoddy.Shoddy", /* tp_name */
37 sizeof(Shoddy), /* tp_basicsize */
38 0, /* tp_itemsize */
39 0, /* tp_dealloc */
40 0, /* tp_print */
41 0, /* tp_getattr */
42 0, /* tp_setattr */
43 0, /* tp_compare */
44 0, /* tp_repr */
45 0, /* tp_as_number */
46 0, /* tp_as_sequence */
47 0, /* tp_as_mapping */
48 0, /* tp_hash */
49 0, /* tp_call */
50 0, /* tp_str */
51 0, /* tp_getattro */
52 0, /* tp_setattro */
53 0, /* tp_as_buffer */
54 Py_TPFLAGS_DEFAULT |
55 Py_TPFLAGS_BASETYPE, /* tp_flags */
56 0, /* tp_doc */
57 0, /* tp_traverse */
58 0, /* tp_clear */
59 0, /* tp_richcompare */
60 0, /* tp_weaklistoffset */
61 0, /* tp_iter */
62 0, /* tp_iternext */
63 Shoddy_methods, /* tp_methods */
64 0, /* tp_members */
65 0, /* tp_getset */
66 0, /* tp_base */
67 0, /* tp_dict */
68 0, /* tp_descr_get */
69 0, /* tp_descr_set */
70 0, /* tp_dictoffset */
71 (initproc)Shoddy_init, /* tp_init */
72 0, /* tp_alloc */
73 0, /* tp_new */
76 PyMODINIT_FUNC
77 initshoddy(void)
79 PyObject *m;
81 ShoddyType.tp_base = &PyList_Type;
82 if (PyType_Ready(&ShoddyType) < 0)
83 return;
85 m = Py_InitModule3("shoddy", NULL, "Shoddy module");
86 if (m == NULL)
87 return;
89 Py_INCREF(&ShoddyType);
90 PyModule_AddObject(m, "Shoddy", (PyObject *) &ShoddyType);