blob: 4a83bb45aa6678e2105593a3345779ac0e0b3b71 [file] [log] [blame]
Guido van Rossum7dab2422002-04-26 19:40:56 +00001/* enumerate object */
2
3#include "Python.h"
4
Serhiy Storchaka41baebd2017-01-19 18:48:17 +02005#include "clinic/enumobject.c.h"
6
7/*[clinic input]
8class enumerate "enumobject *" "&PyEnum_Type"
9class reversed "reversedobject *" "&PyReversed_Type"
10[clinic start generated code]*/
11/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d2dfdf1a88c88975]*/
12
Guido van Rossum7dab2422002-04-26 19:40:56 +000013typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000014 PyObject_HEAD
15 Py_ssize_t en_index; /* current index of enumeration */
16 PyObject* en_sit; /* secondary iterator of enumeration */
17 PyObject* en_result; /* result tuple */
18 PyObject* en_longindex; /* index for sequences >= PY_SSIZE_T_MAX */
Guido van Rossum7dab2422002-04-26 19:40:56 +000019} enumobject;
20
Serhiy Storchaka41baebd2017-01-19 18:48:17 +020021
22/*[clinic input]
23@classmethod
24enumerate.__new__ as enum_new
25
26 iterable: object
27 an object supporting iteration
28 start: object = 0
29
30Return an enumerate object.
31
32The enumerate object yields pairs containing a count (from start, which
33defaults to zero) and a value yielded by the iterable argument.
34
35enumerate is useful for obtaining an indexed list:
36 (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
37[clinic start generated code]*/
38
Guido van Rossum7dab2422002-04-26 19:40:56 +000039static PyObject *
Serhiy Storchaka41baebd2017-01-19 18:48:17 +020040enum_new_impl(PyTypeObject *type, PyObject *iterable, PyObject *start)
41/*[clinic end generated code: output=e95e6e439f812c10 input=782e4911efcb8acf]*/
Guido van Rossum7dab2422002-04-26 19:40:56 +000042{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000043 enumobject *en;
Guido van Rossum7dab2422002-04-26 19:40:56 +000044
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000045 en = (enumobject *)type->tp_alloc(type, 0);
46 if (en == NULL)
47 return NULL;
48 if (start != NULL) {
49 start = PyNumber_Index(start);
50 if (start == NULL) {
51 Py_DECREF(en);
52 return NULL;
53 }
54 assert(PyLong_Check(start));
55 en->en_index = PyLong_AsSsize_t(start);
56 if (en->en_index == -1 && PyErr_Occurred()) {
57 PyErr_Clear();
58 en->en_index = PY_SSIZE_T_MAX;
59 en->en_longindex = start;
60 } else {
61 en->en_longindex = NULL;
62 Py_DECREF(start);
63 }
64 } else {
65 en->en_index = 0;
66 en->en_longindex = NULL;
67 }
Serhiy Storchaka41baebd2017-01-19 18:48:17 +020068 en->en_sit = PyObject_GetIter(iterable);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000069 if (en->en_sit == NULL) {
70 Py_DECREF(en);
71 return NULL;
72 }
73 en->en_result = PyTuple_Pack(2, Py_None, Py_None);
74 if (en->en_result == NULL) {
75 Py_DECREF(en);
76 return NULL;
77 }
78 return (PyObject *)en;
Guido van Rossum7dab2422002-04-26 19:40:56 +000079}
80
81static void
82enum_dealloc(enumobject *en)
83{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000084 PyObject_GC_UnTrack(en);
85 Py_XDECREF(en->en_sit);
86 Py_XDECREF(en->en_result);
87 Py_XDECREF(en->en_longindex);
88 Py_TYPE(en)->tp_free(en);
Guido van Rossum7dab2422002-04-26 19:40:56 +000089}
90
91static int
92enum_traverse(enumobject *en, visitproc visit, void *arg)
93{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000094 Py_VISIT(en->en_sit);
95 Py_VISIT(en->en_result);
96 Py_VISIT(en->en_longindex);
97 return 0;
Guido van Rossum7dab2422002-04-26 19:40:56 +000098}
99
100static PyObject *
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000101enum_next_long(enumobject *en, PyObject* next_item)
102{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000103 PyObject *result = en->en_result;
104 PyObject *next_index;
105 PyObject *stepped_up;
Raymond Hettinger8110dbd2017-09-25 02:15:53 -0700106 PyObject *old_index;
107 PyObject *old_item;
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000108
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000109 if (en->en_longindex == NULL) {
110 en->en_longindex = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
Serhiy Storchaka0e950dd2017-09-26 08:14:58 +0300111 if (en->en_longindex == NULL) {
112 Py_DECREF(next_item);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000113 return NULL;
Serhiy Storchaka0e950dd2017-09-26 08:14:58 +0300114 }
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000115 }
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000116 next_index = en->en_longindex;
117 assert(next_index != NULL);
Serhiy Storchakaba85d692017-03-30 09:09:41 +0300118 stepped_up = PyNumber_Add(next_index, _PyLong_One);
Serhiy Storchaka0e950dd2017-09-26 08:14:58 +0300119 if (stepped_up == NULL) {
120 Py_DECREF(next_item);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000121 return NULL;
Serhiy Storchaka0e950dd2017-09-26 08:14:58 +0300122 }
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000123 en->en_longindex = stepped_up;
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000124
Victor Stinnera93c51e2020-02-07 00:38:59 +0100125 if (Py_REFCNT(result) == 1) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000126 Py_INCREF(result);
Raymond Hettinger8110dbd2017-09-25 02:15:53 -0700127 old_index = PyTuple_GET_ITEM(result, 0);
128 old_item = PyTuple_GET_ITEM(result, 1);
129 PyTuple_SET_ITEM(result, 0, next_index);
130 PyTuple_SET_ITEM(result, 1, next_item);
131 Py_DECREF(old_index);
132 Py_DECREF(old_item);
133 return result;
134 }
135 result = PyTuple_New(2);
136 if (result == NULL) {
137 Py_DECREF(next_index);
138 Py_DECREF(next_item);
139 return NULL;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000140 }
141 PyTuple_SET_ITEM(result, 0, next_index);
142 PyTuple_SET_ITEM(result, 1, next_item);
143 return result;
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000144}
145
146static PyObject *
Guido van Rossum7dab2422002-04-26 19:40:56 +0000147enum_next(enumobject *en)
148{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000149 PyObject *next_index;
150 PyObject *next_item;
151 PyObject *result = en->en_result;
152 PyObject *it = en->en_sit;
Raymond Hettinger8110dbd2017-09-25 02:15:53 -0700153 PyObject *old_index;
154 PyObject *old_item;
Guido van Rossum7dab2422002-04-26 19:40:56 +0000155
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000156 next_item = (*Py_TYPE(it)->tp_iternext)(it);
157 if (next_item == NULL)
158 return NULL;
Guido van Rossumca5ed5b2002-07-16 21:02:42 +0000159
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000160 if (en->en_index == PY_SSIZE_T_MAX)
161 return enum_next_long(en, next_item);
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000162
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000163 next_index = PyLong_FromSsize_t(en->en_index);
164 if (next_index == NULL) {
165 Py_DECREF(next_item);
166 return NULL;
167 }
168 en->en_index++;
Raymond Hettingere8b0f042003-05-28 14:05:34 +0000169
Victor Stinnera93c51e2020-02-07 00:38:59 +0100170 if (Py_REFCNT(result) == 1) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000171 Py_INCREF(result);
Raymond Hettinger8110dbd2017-09-25 02:15:53 -0700172 old_index = PyTuple_GET_ITEM(result, 0);
173 old_item = PyTuple_GET_ITEM(result, 1);
174 PyTuple_SET_ITEM(result, 0, next_index);
175 PyTuple_SET_ITEM(result, 1, next_item);
176 Py_DECREF(old_index);
177 Py_DECREF(old_item);
178 return result;
179 }
180 result = PyTuple_New(2);
181 if (result == NULL) {
182 Py_DECREF(next_index);
183 Py_DECREF(next_item);
184 return NULL;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000185 }
186 PyTuple_SET_ITEM(result, 0, next_index);
187 PyTuple_SET_ITEM(result, 1, next_item);
188 return result;
Guido van Rossum7dab2422002-04-26 19:40:56 +0000189}
190
Kristján Valur Jónsson31668b82012-04-03 10:49:41 +0000191static PyObject *
Siddhesh Poyarekar55edd0c2018-04-30 00:29:33 +0530192enum_reduce(enumobject *en, PyObject *Py_UNUSED(ignored))
Kristján Valur Jónsson31668b82012-04-03 10:49:41 +0000193{
194 if (en->en_longindex != NULL)
195 return Py_BuildValue("O(OO)", Py_TYPE(en), en->en_sit, en->en_longindex);
196 else
197 return Py_BuildValue("O(On)", Py_TYPE(en), en->en_sit, en->en_index);
198}
199
200PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
201
202static PyMethodDef enum_methods[] = {
203 {"__reduce__", (PyCFunction)enum_reduce, METH_NOARGS, reduce_doc},
Ethan Smith7c4185d2020-04-09 21:25:53 -0700204 {"__class_getitem__", (PyCFunction)Py_GenericAlias,
205 METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
Kristján Valur Jónsson31668b82012-04-03 10:49:41 +0000206 {NULL, NULL} /* sentinel */
207};
208
Guido van Rossum7dab2422002-04-26 19:40:56 +0000209PyTypeObject PyEnum_Type = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000210 PyVarObject_HEAD_INIT(&PyType_Type, 0)
211 "enumerate", /* tp_name */
212 sizeof(enumobject), /* tp_basicsize */
213 0, /* tp_itemsize */
214 /* methods */
215 (destructor)enum_dealloc, /* tp_dealloc */
Jeroen Demeyer530f5062019-05-31 04:13:39 +0200216 0, /* tp_vectorcall_offset */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000217 0, /* tp_getattr */
218 0, /* tp_setattr */
Jeroen Demeyer530f5062019-05-31 04:13:39 +0200219 0, /* tp_as_async */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000220 0, /* tp_repr */
221 0, /* tp_as_number */
222 0, /* tp_as_sequence */
223 0, /* tp_as_mapping */
224 0, /* tp_hash */
225 0, /* tp_call */
226 0, /* tp_str */
227 PyObject_GenericGetAttr, /* tp_getattro */
228 0, /* tp_setattro */
229 0, /* tp_as_buffer */
230 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200231 Py_TPFLAGS_BASETYPE, /* tp_flags */
232 enum_new__doc__, /* tp_doc */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000233 (traverseproc)enum_traverse, /* tp_traverse */
234 0, /* tp_clear */
235 0, /* tp_richcompare */
236 0, /* tp_weaklistoffset */
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200237 PyObject_SelfIter, /* tp_iter */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000238 (iternextfunc)enum_next, /* tp_iternext */
Kristján Valur Jónsson31668b82012-04-03 10:49:41 +0000239 enum_methods, /* tp_methods */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000240 0, /* tp_members */
241 0, /* tp_getset */
242 0, /* tp_base */
243 0, /* tp_dict */
244 0, /* tp_descr_get */
245 0, /* tp_descr_set */
246 0, /* tp_dictoffset */
247 0, /* tp_init */
248 PyType_GenericAlloc, /* tp_alloc */
249 enum_new, /* tp_new */
250 PyObject_GC_Del, /* tp_free */
Guido van Rossum7dab2422002-04-26 19:40:56 +0000251};
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000252
253/* Reversed Object ***************************************************************/
254
255typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000256 PyObject_HEAD
257 Py_ssize_t index;
258 PyObject* seq;
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000259} reversedobject;
260
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200261/*[clinic input]
262@classmethod
263reversed.__new__ as reversed_new
264
265 sequence as seq: object
266 /
267
268Return a reverse iterator over the values of the given sequence.
269[clinic start generated code]*/
270
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000271static PyObject *
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200272reversed_new_impl(PyTypeObject *type, PyObject *seq)
273/*[clinic end generated code: output=f7854cc1df26f570 input=aeb720361e5e3f1d]*/
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000274{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000275 Py_ssize_t n;
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200276 PyObject *reversed_meth;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000277 reversedobject *ro;
Benjamin Petersonce798522012-01-22 11:24:29 -0500278 _Py_IDENTIFIER(__reversed__);
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000279
Benjamin Petersonce798522012-01-22 11:24:29 -0500280 reversed_meth = _PyObject_LookupSpecial(seq, &PyId___reversed__);
Guido van Rossum97c1adf2016-08-18 09:22:23 -0700281 if (reversed_meth == Py_None) {
282 Py_DECREF(reversed_meth);
283 PyErr_Format(PyExc_TypeError,
284 "'%.200s' object is not reversible",
285 Py_TYPE(seq)->tp_name);
286 return NULL;
287 }
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000288 if (reversed_meth != NULL) {
Victor Stinnerf17c3de2016-12-06 18:46:19 +0100289 PyObject *res = _PyObject_CallNoArg(reversed_meth);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000290 Py_DECREF(reversed_meth);
291 return res;
292 }
293 else if (PyErr_Occurred())
294 return NULL;
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000295
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000296 if (!PySequence_Check(seq)) {
Guido van Rossum97c1adf2016-08-18 09:22:23 -0700297 PyErr_Format(PyExc_TypeError,
298 "'%.200s' object is not reversible",
299 Py_TYPE(seq)->tp_name);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000300 return NULL;
301 }
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000302
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000303 n = PySequence_Size(seq);
304 if (n == -1)
305 return NULL;
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000306
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000307 ro = (reversedobject *)type->tp_alloc(type, 0);
308 if (ro == NULL)
309 return NULL;
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000310
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000311 ro->index = n-1;
312 Py_INCREF(seq);
313 ro->seq = seq;
314 return (PyObject *)ro;
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000315}
316
317static void
318reversed_dealloc(reversedobject *ro)
319{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000320 PyObject_GC_UnTrack(ro);
321 Py_XDECREF(ro->seq);
322 Py_TYPE(ro)->tp_free(ro);
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000323}
324
325static int
326reversed_traverse(reversedobject *ro, visitproc visit, void *arg)
327{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000328 Py_VISIT(ro->seq);
329 return 0;
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000330}
331
332static PyObject *
333reversed_next(reversedobject *ro)
334{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000335 PyObject *item;
336 Py_ssize_t index = ro->index;
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000337
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000338 if (index >= 0) {
339 item = PySequence_GetItem(ro->seq, index);
340 if (item != NULL) {
341 ro->index--;
342 return item;
343 }
344 if (PyErr_ExceptionMatches(PyExc_IndexError) ||
345 PyErr_ExceptionMatches(PyExc_StopIteration))
346 PyErr_Clear();
347 }
348 ro->index = -1;
349 Py_CLEAR(ro->seq);
350 return NULL;
Raymond Hettinger029dba52004-02-10 09:33:39 +0000351}
352
Raymond Hettinger6b27cda2005-09-24 21:23:05 +0000353static PyObject *
Siddhesh Poyarekar55edd0c2018-04-30 00:29:33 +0530354reversed_len(reversedobject *ro, PyObject *Py_UNUSED(ignored))
Raymond Hettingeref9bf402004-03-10 10:10:42 +0000355{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000356 Py_ssize_t position, seqsize;
Raymond Hettinger7892b1c2004-04-12 18:10:01 +0000357
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000358 if (ro->seq == NULL)
359 return PyLong_FromLong(0);
360 seqsize = PySequence_Size(ro->seq);
361 if (seqsize == -1)
362 return NULL;
363 position = ro->index + 1;
364 return PyLong_FromSsize_t((seqsize < position) ? 0 : position);
Raymond Hettingeref9bf402004-03-10 10:10:42 +0000365}
366
Armin Rigof5b3e362006-02-11 21:32:43 +0000367PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
Raymond Hettinger6b27cda2005-09-24 21:23:05 +0000368
Kristján Valur Jónsson31668b82012-04-03 10:49:41 +0000369static PyObject *
Siddhesh Poyarekar55edd0c2018-04-30 00:29:33 +0530370reversed_reduce(reversedobject *ro, PyObject *Py_UNUSED(ignored))
Kristján Valur Jónsson31668b82012-04-03 10:49:41 +0000371{
372 if (ro->seq)
373 return Py_BuildValue("O(O)n", Py_TYPE(ro), ro->seq, ro->index);
374 else
375 return Py_BuildValue("O(())", Py_TYPE(ro));
376}
377
378static PyObject *
379reversed_setstate(reversedobject *ro, PyObject *state)
380{
381 Py_ssize_t index = PyLong_AsSsize_t(state);
382 if (index == -1 && PyErr_Occurred())
383 return NULL;
384 if (ro->seq != 0) {
385 Py_ssize_t n = PySequence_Size(ro->seq);
386 if (n < 0)
387 return NULL;
388 if (index < -1)
389 index = -1;
390 else if (index > n-1)
391 index = n-1;
392 ro->index = index;
393 }
394 Py_RETURN_NONE;
395}
396
397PyDoc_STRVAR(setstate_doc, "Set state information for unpickling.");
398
Raymond Hettinger6b27cda2005-09-24 21:23:05 +0000399static PyMethodDef reversediter_methods[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000400 {"__length_hint__", (PyCFunction)reversed_len, METH_NOARGS, length_hint_doc},
Kristján Valur Jónsson31668b82012-04-03 10:49:41 +0000401 {"__reduce__", (PyCFunction)reversed_reduce, METH_NOARGS, reduce_doc},
402 {"__setstate__", (PyCFunction)reversed_setstate, METH_O, setstate_doc},
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000403 {NULL, NULL} /* sentinel */
Raymond Hettinger06353f72004-02-08 10:49:42 +0000404};
405
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000406PyTypeObject PyReversed_Type = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000407 PyVarObject_HEAD_INIT(&PyType_Type, 0)
408 "reversed", /* tp_name */
409 sizeof(reversedobject), /* tp_basicsize */
410 0, /* tp_itemsize */
411 /* methods */
412 (destructor)reversed_dealloc, /* tp_dealloc */
Jeroen Demeyer530f5062019-05-31 04:13:39 +0200413 0, /* tp_vectorcall_offset */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000414 0, /* tp_getattr */
415 0, /* tp_setattr */
Jeroen Demeyer530f5062019-05-31 04:13:39 +0200416 0, /* tp_as_async */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000417 0, /* tp_repr */
418 0, /* tp_as_number */
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200419 0, /* tp_as_sequence */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000420 0, /* tp_as_mapping */
421 0, /* tp_hash */
422 0, /* tp_call */
423 0, /* tp_str */
424 PyObject_GenericGetAttr, /* tp_getattro */
425 0, /* tp_setattro */
426 0, /* tp_as_buffer */
427 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200428 Py_TPFLAGS_BASETYPE, /* tp_flags */
429 reversed_new__doc__, /* tp_doc */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000430 (traverseproc)reversed_traverse,/* tp_traverse */
431 0, /* tp_clear */
432 0, /* tp_richcompare */
433 0, /* tp_weaklistoffset */
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200434 PyObject_SelfIter, /* tp_iter */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000435 (iternextfunc)reversed_next, /* tp_iternext */
Serhiy Storchaka41baebd2017-01-19 18:48:17 +0200436 reversediter_methods, /* tp_methods */
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000437 0, /* tp_members */
438 0, /* tp_getset */
439 0, /* tp_base */
440 0, /* tp_dict */
441 0, /* tp_descr_get */
442 0, /* tp_descr_set */
443 0, /* tp_dictoffset */
444 0, /* tp_init */
445 PyType_GenericAlloc, /* tp_alloc */
446 reversed_new, /* tp_new */
447 PyObject_GC_Del, /* tp_free */
Raymond Hettinger85c20a42003-11-06 14:06:48 +0000448};