Coverage Report

Created: 2026-03-23 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/enumobject.c
Line
Count
Source
1
/* enumerate object */
2
3
#include "Python.h"
4
#include "pycore_call.h"          // _PyObject_CallNoArgs()
5
#include "pycore_long.h"          // _PyLong_GetOne()
6
#include "pycore_modsupport.h"    // _PyArg_NoKwnames()
7
#include "pycore_object.h"        // _PyObject_GC_TRACK()
8
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString
9
#include "pycore_tuple.h"         // _PyTuple_Recycle()
10
11
#include "clinic/enumobject.c.h"
12
13
/*[clinic input]
14
class enumerate "enumobject *" "&PyEnum_Type"
15
class reversed "reversedobject *" "&PyReversed_Type"
16
[clinic start generated code]*/
17
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d2dfdf1a88c88975]*/
18
19
typedef struct {
20
    PyObject_HEAD
21
    Py_ssize_t en_index;           /* current index of enumeration */
22
    PyObject* en_sit;              /* secondary iterator of enumeration */
23
    PyObject* en_result;           /* result tuple  */
24
    PyObject* en_longindex;        /* index for sequences >= PY_SSIZE_T_MAX */
25
    PyObject* one;                 /* borrowed reference */
26
} enumobject;
27
28
27.3M
#define _enumobject_CAST(op)    ((enumobject *)(op))
29
30
/*[clinic input]
31
@classmethod
32
enumerate.__new__ as enum_new
33
34
    iterable: object
35
        an object supporting iteration
36
    start: object = 0
37
38
Return an enumerate object.
39
40
The enumerate object yields pairs containing a count (from start, which
41
defaults to zero) and a value yielded by the iterable argument.
42
43
enumerate is useful for obtaining an indexed list:
44
    (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
45
[clinic start generated code]*/
46
47
static PyObject *
48
enum_new_impl(PyTypeObject *type, PyObject *iterable, PyObject *start)
49
/*[clinic end generated code: output=e95e6e439f812c10 input=782e4911efcb8acf]*/
50
7.42M
{
51
7.42M
    enumobject *en;
52
53
7.42M
    en = (enumobject *)type->tp_alloc(type, 0);
54
7.42M
    if (en == NULL)
55
0
        return NULL;
56
7.42M
    if (start != NULL) {
57
8.52k
        start = PyNumber_Index(start);
58
8.52k
        if (start == NULL) {
59
0
            Py_DECREF(en);
60
0
            return NULL;
61
0
        }
62
8.52k
        assert(PyLong_Check(start));
63
8.52k
        en->en_index = PyLong_AsSsize_t(start);
64
8.52k
        if (en->en_index == -1 && PyErr_Occurred()) {
65
0
            PyErr_Clear();
66
0
            en->en_index = PY_SSIZE_T_MAX;
67
0
            en->en_longindex = start;
68
8.52k
        } else {
69
8.52k
            en->en_longindex = NULL;
70
8.52k
            Py_DECREF(start);
71
8.52k
        }
72
7.41M
    } else {
73
7.41M
        en->en_index = 0;
74
7.41M
        en->en_longindex = NULL;
75
7.41M
    }
76
7.42M
    en->en_sit = PyObject_GetIter(iterable);
77
7.42M
    if (en->en_sit == NULL) {
78
0
        Py_DECREF(en);
79
0
        return NULL;
80
0
    }
81
7.42M
    en->en_result = PyTuple_Pack(2, Py_None, Py_None);
82
7.42M
    if (en->en_result == NULL) {
83
0
        Py_DECREF(en);
84
0
        return NULL;
85
0
    }
86
7.42M
    en->one = _PyLong_GetOne();    /* borrowed reference */
87
7.42M
    return (PyObject *)en;
88
7.42M
}
89
90
static int check_keyword(PyObject *kwnames, int index,
91
                         const char *name)
92
6.03k
{
93
6.03k
    PyObject *kw = PyTuple_GET_ITEM(kwnames, index);
94
6.03k
    if (!_PyUnicode_EqualToASCIIString(kw, name)) {
95
0
        PyErr_Format(PyExc_TypeError,
96
0
            "'%S' is an invalid keyword argument for enumerate()", kw);
97
0
        return 0;
98
0
    }
99
6.03k
    return 1;
100
6.03k
}
101
102
// TODO: Use AC when bpo-43447 is supported
103
static PyObject *
104
enumerate_vectorcall(PyObject *type, PyObject *const *args,
105
                     size_t nargsf, PyObject *kwnames)
106
7.42M
{
107
7.42M
    PyTypeObject *tp = _PyType_CAST(type);
108
7.42M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
109
7.42M
    Py_ssize_t nkwargs = 0;
110
7.42M
    if (kwnames != NULL) {
111
6.03k
        nkwargs = PyTuple_GET_SIZE(kwnames);
112
6.03k
    }
113
114
    // Manually implement enumerate(iterable, start=...)
115
7.42M
    if (nargs + nkwargs == 2) {
116
8.52k
        if (nkwargs == 1) {
117
6.03k
            if (!check_keyword(kwnames, 0, "start")) {
118
0
                return NULL;
119
0
            }
120
6.03k
        } else if (nkwargs == 2) {
121
0
            PyObject *kw0 = PyTuple_GET_ITEM(kwnames, 0);
122
0
            if (_PyUnicode_EqualToASCIIString(kw0, "start")) {
123
0
                if (!check_keyword(kwnames, 1, "iterable")) {
124
0
                    return NULL;
125
0
                }
126
0
                return enum_new_impl(tp, args[1], args[0]);
127
0
            }
128
0
            if (!check_keyword(kwnames, 0, "iterable") ||
129
0
                !check_keyword(kwnames, 1, "start")) {
130
0
                return NULL;
131
0
            }
132
133
0
        }
134
8.52k
        return enum_new_impl(tp, args[0], args[1]);
135
8.52k
    }
136
137
7.41M
    if (nargs + nkwargs == 1) {
138
7.41M
        if (nkwargs == 1 && !check_keyword(kwnames, 0, "iterable")) {
139
0
            return NULL;
140
0
        }
141
7.41M
        return enum_new_impl(tp, args[0], NULL);
142
7.41M
    }
143
144
0
    if (nargs == 0) {
145
0
        PyErr_SetString(PyExc_TypeError,
146
0
            "enumerate() missing required argument 'iterable'");
147
0
        return NULL;
148
0
    }
149
150
0
    PyErr_Format(PyExc_TypeError,
151
0
        "enumerate() takes at most 2 arguments (%d given)", nargs + nkwargs);
152
0
    return NULL;
153
0
}
154
155
static void
156
enum_dealloc(PyObject *op)
157
7.42M
{
158
7.42M
    enumobject *en = _enumobject_CAST(op);
159
7.42M
    PyObject_GC_UnTrack(en);
160
7.42M
    Py_XDECREF(en->en_sit);
161
7.42M
    Py_XDECREF(en->en_result);
162
7.42M
    Py_XDECREF(en->en_longindex);
163
7.42M
    Py_TYPE(en)->tp_free(en);
164
7.42M
}
165
166
static int
167
enum_traverse(PyObject *op, visitproc visit, void *arg)
168
1.65k
{
169
1.65k
    enumobject *en = _enumobject_CAST(op);
170
1.65k
    Py_VISIT(en->en_sit);
171
1.65k
    Py_VISIT(en->en_result);
172
1.65k
    Py_VISIT(en->en_longindex);
173
1.65k
    return 0;
174
1.65k
}
175
176
// increment en_longindex with lock held, return the next index to be used
177
// or NULL on error
178
static inline PyObject *
179
increment_longindex_lock_held(enumobject *en)
180
0
{
181
0
    if (en->en_longindex == NULL) {
182
0
        en->en_longindex = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
183
0
        if (en->en_longindex == NULL) {
184
0
            return NULL;
185
0
        }
186
0
    }
187
0
    assert(en->en_longindex != NULL);
188
    // We hold one reference to "next_index" (a.k.a. the old value of
189
    // en->en_longindex); we'll either return it or keep it in en->en_longindex
190
0
    PyObject *next_index = en->en_longindex;
191
0
    PyObject *stepped_up = PyNumber_Add(next_index, en->one);
192
0
    if (stepped_up == NULL) {
193
0
        return NULL;
194
0
    }
195
0
    en->en_longindex = stepped_up;
196
0
    return next_index;
197
0
}
198
199
static PyObject *
200
enum_next_long(enumobject *en, PyObject* next_item)
201
0
{
202
0
    PyObject *result = en->en_result;
203
0
    PyObject *next_index;
204
0
    PyObject *old_index;
205
0
    PyObject *old_item;
206
207
208
0
    Py_BEGIN_CRITICAL_SECTION(en);
209
0
    next_index = increment_longindex_lock_held(en);
210
0
    Py_END_CRITICAL_SECTION();
211
0
    if (next_index == NULL) {
212
0
        Py_DECREF(next_item);
213
0
        return NULL;
214
0
    }
215
216
0
    if (_PyObject_IsUniquelyReferenced(result)) {
217
0
        Py_INCREF(result);
218
0
        old_index = PyTuple_GET_ITEM(result, 0);
219
0
        old_item = PyTuple_GET_ITEM(result, 1);
220
0
        PyTuple_SET_ITEM(result, 0, next_index);
221
0
        PyTuple_SET_ITEM(result, 1, next_item);
222
0
        Py_DECREF(old_index);
223
0
        Py_DECREF(old_item);
224
        // bpo-42536: The GC may have untracked this result tuple. Since we're
225
        // recycling it, make sure it's tracked again:
226
0
        _PyTuple_Recycle(result);
227
0
        return result;
228
0
    }
229
0
    result = PyTuple_New(2);
230
0
    if (result == NULL) {
231
0
        Py_DECREF(next_index);
232
0
        Py_DECREF(next_item);
233
0
        return NULL;
234
0
    }
235
0
    PyTuple_SET_ITEM(result, 0, next_index);
236
0
    PyTuple_SET_ITEM(result, 1, next_item);
237
0
    return result;
238
0
}
239
240
static PyObject *
241
enum_next(PyObject *op)
242
19.9M
{
243
19.9M
    enumobject *en = _enumobject_CAST(op);
244
19.9M
    PyObject *next_index;
245
19.9M
    PyObject *next_item;
246
19.9M
    PyObject *result = en->en_result;
247
19.9M
    PyObject *it = en->en_sit;
248
19.9M
    PyObject *old_index;
249
19.9M
    PyObject *old_item;
250
251
19.9M
    next_item = (*Py_TYPE(it)->tp_iternext)(it);
252
19.9M
    if (next_item == NULL)
253
7.42M
        return NULL;
254
255
12.5M
    Py_ssize_t en_index = FT_ATOMIC_LOAD_SSIZE_RELAXED(en->en_index);
256
12.5M
    if (en_index == PY_SSIZE_T_MAX)
257
0
        return enum_next_long(en, next_item);
258
259
12.5M
    next_index = PyLong_FromSsize_t(en_index);
260
12.5M
    if (next_index == NULL) {
261
0
        Py_DECREF(next_item);
262
0
        return NULL;
263
0
    }
264
12.5M
    FT_ATOMIC_STORE_SSIZE_RELAXED(en->en_index, en_index + 1);
265
266
12.5M
    if (_PyObject_IsUniquelyReferenced(result)) {
267
12.5M
        Py_INCREF(result);
268
12.5M
        old_index = PyTuple_GET_ITEM(result, 0);
269
12.5M
        old_item = PyTuple_GET_ITEM(result, 1);
270
12.5M
        PyTuple_SET_ITEM(result, 0, next_index);
271
12.5M
        PyTuple_SET_ITEM(result, 1, next_item);
272
12.5M
        Py_DECREF(old_index);
273
12.5M
        Py_DECREF(old_item);
274
        // bpo-42536: The GC may have untracked this result tuple. Since we're
275
        // recycling it, make sure it's tracked again:
276
12.5M
        _PyTuple_Recycle(result);
277
12.5M
        return result;
278
12.5M
    }
279
0
    result = PyTuple_New(2);
280
0
    if (result == NULL) {
281
0
        Py_DECREF(next_index);
282
0
        Py_DECREF(next_item);
283
0
        return NULL;
284
0
    }
285
0
    PyTuple_SET_ITEM(result, 0, next_index);
286
0
    PyTuple_SET_ITEM(result, 1, next_item);
287
0
    return result;
288
0
}
289
290
static PyObject *
291
enum_reduce(PyObject *op, PyObject *Py_UNUSED(ignored))
292
0
{
293
0
    enumobject *en = _enumobject_CAST(op);
294
0
    PyObject *result;
295
0
    Py_BEGIN_CRITICAL_SECTION(en);
296
0
    if (en->en_longindex != NULL)
297
0
        result = Py_BuildValue("O(OO)", Py_TYPE(en), en->en_sit, en->en_longindex);
298
0
    else
299
0
        result = Py_BuildValue("O(On)", Py_TYPE(en), en->en_sit, en->en_index);
300
0
    Py_END_CRITICAL_SECTION();
301
0
    return result;
302
0
}
303
304
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
305
306
static PyMethodDef enum_methods[] = {
307
    {"__reduce__", enum_reduce, METH_NOARGS, reduce_doc},
308
    {"__class_getitem__",    Py_GenericAlias,
309
    METH_O|METH_CLASS,       PyDoc_STR("See PEP 585")},
310
    {NULL,              NULL}           /* sentinel */
311
};
312
313
PyTypeObject PyEnum_Type = {
314
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
315
    "enumerate",                    /* tp_name */
316
    sizeof(enumobject),             /* tp_basicsize */
317
    0,                              /* tp_itemsize */
318
    /* methods */
319
    enum_dealloc,                   /* tp_dealloc */
320
    0,                              /* tp_vectorcall_offset */
321
    0,                              /* tp_getattr */
322
    0,                              /* tp_setattr */
323
    0,                              /* tp_as_async */
324
    0,                              /* tp_repr */
325
    0,                              /* tp_as_number */
326
    0,                              /* tp_as_sequence */
327
    0,                              /* tp_as_mapping */
328
    0,                              /* tp_hash */
329
    0,                              /* tp_call */
330
    0,                              /* tp_str */
331
    PyObject_GenericGetAttr,        /* tp_getattro */
332
    0,                              /* tp_setattro */
333
    0,                              /* tp_as_buffer */
334
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
335
        Py_TPFLAGS_BASETYPE,        /* tp_flags */
336
    enum_new__doc__,                /* tp_doc */
337
    enum_traverse,                  /* tp_traverse */
338
    0,                              /* tp_clear */
339
    0,                              /* tp_richcompare */
340
    0,                              /* tp_weaklistoffset */
341
    PyObject_SelfIter,              /* tp_iter */
342
    enum_next,                      /* tp_iternext */
343
    enum_methods,                   /* tp_methods */
344
    0,                              /* tp_members */
345
    0,                              /* tp_getset */
346
    0,                              /* tp_base */
347
    0,                              /* tp_dict */
348
    0,                              /* tp_descr_get */
349
    0,                              /* tp_descr_set */
350
    0,                              /* tp_dictoffset */
351
    0,                              /* tp_init */
352
    PyType_GenericAlloc,            /* tp_alloc */
353
    enum_new,                       /* tp_new */
354
    PyObject_GC_Del,                /* tp_free */
355
    .tp_vectorcall = enumerate_vectorcall
356
};
357
358
/* Reversed Object ***************************************************************/
359
360
typedef struct {
361
    PyObject_HEAD
362
    Py_ssize_t      index;
363
    PyObject* seq;
364
} reversedobject;
365
366
816
#define _reversedobject_CAST(op)    ((reversedobject *)(op))
367
368
/*[clinic input]
369
@classmethod
370
reversed.__new__ as reversed_new
371
372
    object as seq: object
373
    /
374
375
Return a reverse iterator over the values of the given sequence.
376
[clinic start generated code]*/
377
378
static PyObject *
379
reversed_new_impl(PyTypeObject *type, PyObject *seq)
380
/*[clinic end generated code: output=f7854cc1df26f570 input=4781869729e3ba50]*/
381
39.2M
{
382
39.2M
    Py_ssize_t n;
383
39.2M
    PyObject *reversed_meth;
384
39.2M
    reversedobject *ro;
385
386
39.2M
    reversed_meth = _PyObject_LookupSpecial(seq, &_Py_ID(__reversed__));
387
39.2M
    if (reversed_meth == Py_None) {
388
0
        Py_DECREF(reversed_meth);
389
0
        PyErr_Format(PyExc_TypeError,
390
0
                     "'%.200s' object is not reversible",
391
0
                     Py_TYPE(seq)->tp_name);
392
0
        return NULL;
393
0
    }
394
39.2M
    if (reversed_meth != NULL) {
395
39.2M
        PyObject *res = _PyObject_CallNoArgs(reversed_meth);
396
39.2M
        Py_DECREF(reversed_meth);
397
39.2M
        return res;
398
39.2M
    }
399
144
    else if (PyErr_Occurred())
400
0
        return NULL;
401
402
144
    if (!PySequence_Check(seq)) {
403
0
        PyErr_Format(PyExc_TypeError,
404
0
                     "'%.200s' object is not reversible",
405
0
                     Py_TYPE(seq)->tp_name);
406
0
        return NULL;
407
0
    }
408
409
144
    n = PySequence_Size(seq);
410
144
    if (n == -1)
411
0
        return NULL;
412
413
144
    ro = (reversedobject *)type->tp_alloc(type, 0);
414
144
    if (ro == NULL)
415
0
        return NULL;
416
417
144
    ro->index = n-1;
418
144
    ro->seq = Py_NewRef(seq);
419
144
    return (PyObject *)ro;
420
144
}
421
422
static PyObject *
423
reversed_vectorcall(PyObject *type, PyObject * const*args,
424
                size_t nargsf, PyObject *kwnames)
425
39.2M
{
426
39.2M
    if (!_PyArg_NoKwnames("reversed", kwnames)) {
427
0
        return NULL;
428
0
    }
429
430
39.2M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
431
39.2M
    if (!_PyArg_CheckPositional("reversed", nargs, 1, 1)) {
432
0
        return NULL;
433
0
    }
434
435
39.2M
    return reversed_new_impl(_PyType_CAST(type), args[0]);
436
39.2M
}
437
438
static void
439
reversed_dealloc(PyObject *op)
440
144
{
441
144
    reversedobject *ro = _reversedobject_CAST(op);
442
144
    PyObject_GC_UnTrack(ro);
443
144
    Py_XDECREF(ro->seq);
444
144
    Py_TYPE(ro)->tp_free(ro);
445
144
}
446
447
static int
448
reversed_traverse(PyObject *op, visitproc visit, void *arg)
449
0
{
450
0
    reversedobject *ro = _reversedobject_CAST(op);
451
0
    Py_VISIT(ro->seq);
452
0
    return 0;
453
0
}
454
455
static PyObject *
456
reversed_next(PyObject *op)
457
672
{
458
672
    reversedobject *ro = _reversedobject_CAST(op);
459
672
    PyObject *item;
460
672
    Py_ssize_t index = FT_ATOMIC_LOAD_SSIZE_RELAXED(ro->index);
461
462
672
    if (index >= 0) {
463
558
        item = PySequence_GetItem(ro->seq, index);
464
558
        if (item != NULL) {
465
558
            FT_ATOMIC_STORE_SSIZE_RELAXED(ro->index, index - 1);
466
558
            return item;
467
558
        }
468
0
        if (PyErr_ExceptionMatches(PyExc_IndexError) ||
469
0
            PyErr_ExceptionMatches(PyExc_StopIteration))
470
0
            PyErr_Clear();
471
0
    }
472
114
    FT_ATOMIC_STORE_SSIZE_RELAXED(ro->index, -1);
473
114
#ifndef Py_GIL_DISABLED
474
114
    Py_CLEAR(ro->seq);
475
114
#endif
476
114
    return NULL;
477
672
}
478
479
static PyObject *
480
reversed_len(PyObject *op, PyObject *Py_UNUSED(ignored))
481
0
{
482
0
    reversedobject *ro = _reversedobject_CAST(op);
483
0
    Py_ssize_t position, seqsize;
484
0
    Py_ssize_t index = FT_ATOMIC_LOAD_SSIZE_RELAXED(ro->index);
485
486
0
    if (index == -1)
487
0
        return PyLong_FromLong(0);
488
0
    assert(ro->seq != NULL);
489
0
    seqsize = PySequence_Size(ro->seq);
490
0
    if (seqsize == -1)
491
0
        return NULL;
492
0
    position = index + 1;
493
0
    return PyLong_FromSsize_t((seqsize < position)  ?  0  :  position);
494
0
}
495
496
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
497
498
static PyObject *
499
reversed_reduce(PyObject *op, PyObject *Py_UNUSED(ignored))
500
0
{
501
0
    reversedobject *ro = _reversedobject_CAST(op);
502
0
    Py_ssize_t index = FT_ATOMIC_LOAD_SSIZE_RELAXED(ro->index);
503
0
    if (index != -1) {
504
0
        return Py_BuildValue("O(O)n", Py_TYPE(ro), ro->seq, ro->index);
505
0
    }
506
0
    else {
507
0
        return Py_BuildValue("O(())", Py_TYPE(ro));
508
0
    }
509
0
}
510
511
static PyObject *
512
reversed_setstate(PyObject *op, PyObject *state)
513
0
{
514
0
    reversedobject *ro = _reversedobject_CAST(op);
515
0
    Py_ssize_t index = PyLong_AsSsize_t(state);
516
0
    if (index == -1 && PyErr_Occurred())
517
0
        return NULL;
518
0
    Py_ssize_t ro_index = FT_ATOMIC_LOAD_SSIZE_RELAXED(ro->index);
519
    // if the iterator is exhausted we do not set the state
520
    // this is for backwards compatibility reasons. in practice this situation
521
    // will not occur, see gh-120971
522
0
    if (ro_index != -1) {
523
0
        Py_ssize_t n = PySequence_Size(ro->seq);
524
0
        if (n < 0)
525
0
            return NULL;
526
0
        if (index < -1)
527
0
            index = -1;
528
0
        else if (index > n-1)
529
0
            index = n-1;
530
0
        FT_ATOMIC_STORE_SSIZE_RELAXED(ro->index, index);
531
0
    }
532
0
    Py_RETURN_NONE;
533
0
}
534
535
PyDoc_STRVAR(setstate_doc, "Set state information for unpickling.");
536
537
static PyMethodDef reversediter_methods[] = {
538
    {"__length_hint__", reversed_len, METH_NOARGS, length_hint_doc},
539
    {"__reduce__", reversed_reduce, METH_NOARGS, reduce_doc},
540
    {"__setstate__", reversed_setstate, METH_O, setstate_doc},
541
    {NULL,              NULL}           /* sentinel */
542
};
543
544
PyTypeObject PyReversed_Type = {
545
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
546
    "reversed",                     /* tp_name */
547
    sizeof(reversedobject),         /* tp_basicsize */
548
    0,                              /* tp_itemsize */
549
    /* methods */
550
    reversed_dealloc,               /* tp_dealloc */
551
    0,                              /* tp_vectorcall_offset */
552
    0,                              /* tp_getattr */
553
    0,                              /* tp_setattr */
554
    0,                              /* tp_as_async */
555
    0,                              /* tp_repr */
556
    0,                              /* tp_as_number */
557
    0,                              /* tp_as_sequence */
558
    0,                              /* tp_as_mapping */
559
    0,                              /* tp_hash */
560
    0,                              /* tp_call */
561
    0,                              /* tp_str */
562
    PyObject_GenericGetAttr,        /* tp_getattro */
563
    0,                              /* tp_setattro */
564
    0,                              /* tp_as_buffer */
565
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
566
        Py_TPFLAGS_BASETYPE,        /* tp_flags */
567
    reversed_new__doc__,            /* tp_doc */
568
    reversed_traverse,              /* tp_traverse */
569
    0,                              /* tp_clear */
570
    0,                              /* tp_richcompare */
571
    0,                              /* tp_weaklistoffset */
572
    PyObject_SelfIter,              /* tp_iter */
573
    reversed_next,                  /* tp_iternext */
574
    reversediter_methods,           /* tp_methods */
575
    0,                              /* tp_members */
576
    0,                              /* tp_getset */
577
    0,                              /* tp_base */
578
    0,                              /* tp_dict */
579
    0,                              /* tp_descr_get */
580
    0,                              /* tp_descr_set */
581
    0,                              /* tp_dictoffset */
582
    0,                              /* tp_init */
583
    PyType_GenericAlloc,            /* tp_alloc */
584
    reversed_new,                   /* tp_new */
585
    PyObject_GC_Del,                /* tp_free */
586
    .tp_vectorcall = reversed_vectorcall,
587
};