|
57 | 57 | int ci_init(PyObject* self, PyObject* args, PyObject* kwds);
|
58 | 58 |
|
59 | 59 | PyObject* ci_iter(PyObject* self) {
|
60 |
| - return ((NativeCustomIterableObject*)self)->it; |
| 60 | + PyObject* result = ((NativeCustomIterableObject*)self)->it; |
| 61 | + Py_INCREF(result); |
| 62 | + return result; |
61 | 63 | }
|
62 | 64 |
|
63 | 65 | PyObject* cit_iter(PyObject* self) {
|
| 66 | + Py_INCREF(self); |
64 | 67 | return self;
|
65 | 68 | }
|
66 | 69 |
|
67 | 70 | PyObject* cit_next(PyObject* self) {
|
68 | 71 | NativeCustomIteratorObject* s = (NativeCustomIteratorObject*)self;
|
69 |
| - return PyLong_FromLongLong(ci_item((PyObject*)(s->obj), (s->pos)++)); |
| 72 | + return ci_item((PyObject*)(s->obj), (s->pos)++); |
70 | 73 | }
|
71 | 74 |
|
72 | 75 | PyObject* ci_item(PyObject* self, Py_ssize_t i) {
|
73 |
| - return ((NativeCustomIterableObject*)self)->scale * i; |
| 76 | + PyObject* result = PyLong_FromSsize_t(((NativeCustomIterableObject*)self)->scale * i); |
| 77 | + Py_INCREF(result); |
| 78 | + return result; |
74 | 79 | }
|
75 | 80 |
|
76 | 81 |
|
|
177 | 182 | };
|
178 | 183 |
|
179 | 184 | int ci_init(PyObject* self, PyObject* args, PyObject* kwds) {
|
| 185 | + Py_XINCREF(args); |
| 186 | + Py_XINCREF(kwds); |
180 | 187 | static char *kwlist[] = {"scale", NULL};
|
181 | 188 | Py_ssize_t n = 0;
|
182 | 189 |
|
|
187 | 194 | tself->scale = n + 1;
|
188 | 195 |
|
189 | 196 | PyObject *argList = PyTuple_New(0);
|
| 197 | + Py_INCREF(argList); |
190 | 198 | PyObject *obj = PyObject_CallObject((PyObject *) &CustomIteratorType, argList);
|
| 199 | + Py_DECREF(argList); |
| 200 | + Py_INCREF(obj); |
| 201 | + Py_INCREF(tself); |
191 | 202 | ((NativeCustomIteratorObject*)obj)->obj = tself;
|
192 | 203 | tself->it = obj;
|
193 | 204 |
|
|
221 | 232 | Py_INCREF(&CustomIteratorType);
|
222 | 233 | PyModule_AddObject(m, "NativeCustomIterable", (PyObject *)&CustomIterableType);
|
223 | 234 | PyModule_AddObject(m, "NativeCustomIterator", (PyObject *)&CustomIteratorType);
|
| 235 | + Py_INCREF(m); |
224 | 236 | return m;
|
225 | 237 | }
|
226 | 238 |
|
|
0 commit comments