2 /* Tuple object implementation */
6 /* Speed optimization to avoid frequent malloc/free of small tuples */
7 #ifndef PyTuple_MAXSAVESIZE
8 #define PyTuple_MAXSAVESIZE 20 /* Largest tuple to save on free list */
10 #ifndef PyTuple_MAXFREELIST
11 #define PyTuple_MAXFREELIST 2000 /* Maximum number of tuples of each size to save */
14 #if PyTuple_MAXSAVESIZE > 0
15 /* Entries 1 up to PyTuple_MAXSAVESIZE are free lists, entry 0 is the empty
16 tuple () of which at most one instance will be allocated.
18 static PyTupleObject
*free_list
[PyTuple_MAXSAVESIZE
];
19 static int numfree
[PyTuple_MAXSAVESIZE
];
22 int fast_tuple_allocs
;
23 int tuple_zero_allocs
;
27 PyTuple_New(register Py_ssize_t size
)
29 register PyTupleObject
*op
;
32 PyErr_BadInternalCall();
35 #if PyTuple_MAXSAVESIZE > 0
36 if (size
== 0 && free_list
[0]) {
42 return (PyObject
*) op
;
44 if (size
< PyTuple_MAXSAVESIZE
&& (op
= free_list
[size
]) != NULL
) {
45 free_list
[size
] = (PyTupleObject
*) op
->ob_item
[0];
50 /* Inline PyObject_InitVar */
53 Py_TYPE(op
) = &PyTuple_Type
;
55 _Py_NewReference((PyObject
*)op
);
60 Py_ssize_t nbytes
= size
* sizeof(PyObject
*);
61 /* Check for overflow */
62 if (nbytes
/ sizeof(PyObject
*) != (size_t)size
||
63 (nbytes
+= sizeof(PyTupleObject
) - sizeof(PyObject
*))
66 return PyErr_NoMemory();
68 op
= PyObject_GC_NewVar(PyTupleObject
, &PyTuple_Type
, size
);
72 for (i
=0; i
< size
; i
++)
73 op
->ob_item
[i
] = NULL
;
74 #if PyTuple_MAXSAVESIZE > 0
78 Py_INCREF(op
); /* extra INCREF so that this is never freed */
81 _PyObject_GC_TRACK(op
);
82 return (PyObject
*) op
;
86 PyTuple_Size(register PyObject
*op
)
88 if (!PyTuple_Check(op
)) {
89 PyErr_BadInternalCall();
97 PyTuple_GetItem(register PyObject
*op
, register Py_ssize_t i
)
99 if (!PyTuple_Check(op
)) {
100 PyErr_BadInternalCall();
103 if (i
< 0 || i
>= Py_SIZE(op
)) {
104 PyErr_SetString(PyExc_IndexError
, "tuple index out of range");
107 return ((PyTupleObject
*)op
) -> ob_item
[i
];
111 PyTuple_SetItem(register PyObject
*op
, register Py_ssize_t i
, PyObject
*newitem
)
113 register PyObject
*olditem
;
114 register PyObject
**p
;
115 if (!PyTuple_Check(op
) || op
->ob_refcnt
!= 1) {
117 PyErr_BadInternalCall();
120 if (i
< 0 || i
>= Py_SIZE(op
)) {
122 PyErr_SetString(PyExc_IndexError
,
123 "tuple assignment index out of range");
126 p
= ((PyTupleObject
*)op
) -> ob_item
+ i
;
134 PyTuple_Pack(Py_ssize_t n
, ...)
143 result
= PyTuple_New(n
);
146 items
= ((PyTupleObject
*)result
)->ob_item
;
147 for (i
= 0; i
< n
; i
++) {
148 o
= va_arg(vargs
, PyObject
*);
160 tupledealloc(register PyTupleObject
*op
)
162 register Py_ssize_t i
;
163 register Py_ssize_t len
= Py_SIZE(op
);
164 PyObject_GC_UnTrack(op
);
165 Py_TRASHCAN_SAFE_BEGIN(op
)
169 Py_XDECREF(op
->ob_item
[i
]);
170 #if PyTuple_MAXSAVESIZE > 0
171 if (len
< PyTuple_MAXSAVESIZE
&&
172 numfree
[len
] < PyTuple_MAXFREELIST
&&
173 Py_TYPE(op
) == &PyTuple_Type
)
175 op
->ob_item
[0] = (PyObject
*) free_list
[len
];
178 goto done
; /* return */
182 Py_TYPE(op
)->tp_free((PyObject
*)op
);
184 Py_TRASHCAN_SAFE_END(op
)
188 tupleprint(PyTupleObject
*op
, FILE *fp
, int flags
)
191 Py_BEGIN_ALLOW_THREADS
194 for (i
= 0; i
< Py_SIZE(op
); i
++) {
196 Py_BEGIN_ALLOW_THREADS
200 if (PyObject_Print(op
->ob_item
[i
], fp
, 0) != 0)
204 Py_BEGIN_ALLOW_THREADS
213 tuplerepr(PyTupleObject
*v
)
217 PyObject
*pieces
, *result
= NULL
;
221 return PyString_FromString("()");
223 /* While not mutable, it is still possible to end up with a cycle in a
224 tuple through an object that stores itself within a tuple (and thus
225 infinitely asks for the repr of itself). This should only be
226 possible within a type. */
227 i
= Py_ReprEnter((PyObject
*)v
);
229 return i
> 0 ? PyString_FromString("(...)") : NULL
;
232 pieces
= PyTuple_New(n
);
236 /* Do repr() on each element. */
237 for (i
= 0; i
< n
; ++i
) {
238 if (Py_EnterRecursiveCall(" while getting the repr of a tuple"))
240 s
= PyObject_Repr(v
->ob_item
[i
]);
241 Py_LeaveRecursiveCall();
244 PyTuple_SET_ITEM(pieces
, i
, s
);
247 /* Add "()" decorations to the first and last items. */
249 s
= PyString_FromString("(");
252 temp
= PyTuple_GET_ITEM(pieces
, 0);
253 PyString_ConcatAndDel(&s
, temp
);
254 PyTuple_SET_ITEM(pieces
, 0, s
);
258 s
= PyString_FromString(n
== 1 ? ",)" : ")");
261 temp
= PyTuple_GET_ITEM(pieces
, n
-1);
262 PyString_ConcatAndDel(&temp
, s
);
263 PyTuple_SET_ITEM(pieces
, n
-1, temp
);
267 /* Paste them all together with ", " between. */
268 s
= PyString_FromString(", ");
271 result
= _PyString_Join(s
, pieces
);
276 Py_ReprLeave((PyObject
*)v
);
280 /* The addend 82520, was selected from the range(0, 1000000) for
281 generating the greatest number of prime multipliers for tuples
284 1082527, 1165049, 1082531, 1165057, 1247581, 1330103, 1082533,
285 1330111, 1412633, 1165069, 1247599, 1495177, 1577699
289 tuplehash(PyTupleObject
*v
)
292 register Py_ssize_t len
= Py_SIZE(v
);
293 register PyObject
**p
;
294 long mult
= 1000003L;
298 y
= PyObject_Hash(*p
++);
302 /* the cast might truncate len; that doesn't change hash stability */
303 mult
+= (long)(82520L + len
+ len
);
312 tuplelength(PyTupleObject
*a
)
318 tuplecontains(PyTupleObject
*a
, PyObject
*el
)
323 for (i
= 0, cmp
= 0 ; cmp
== 0 && i
< Py_SIZE(a
); ++i
)
324 cmp
= PyObject_RichCompareBool(el
, PyTuple_GET_ITEM(a
, i
),
330 tupleitem(register PyTupleObject
*a
, register Py_ssize_t i
)
332 if (i
< 0 || i
>= Py_SIZE(a
)) {
333 PyErr_SetString(PyExc_IndexError
, "tuple index out of range");
336 Py_INCREF(a
->ob_item
[i
]);
337 return a
->ob_item
[i
];
341 tupleslice(register PyTupleObject
*a
, register Py_ssize_t ilow
,
342 register Py_ssize_t ihigh
)
344 register PyTupleObject
*np
;
345 PyObject
**src
, **dest
;
346 register Py_ssize_t i
;
350 if (ihigh
> Py_SIZE(a
))
354 if (ilow
== 0 && ihigh
== Py_SIZE(a
) && PyTuple_CheckExact(a
)) {
356 return (PyObject
*)a
;
359 np
= (PyTupleObject
*)PyTuple_New(len
);
362 src
= a
->ob_item
+ ilow
;
364 for (i
= 0; i
< len
; i
++) {
365 PyObject
*v
= src
[i
];
369 return (PyObject
*)np
;
373 PyTuple_GetSlice(PyObject
*op
, Py_ssize_t i
, Py_ssize_t j
)
375 if (op
== NULL
|| !PyTuple_Check(op
)) {
376 PyErr_BadInternalCall();
379 return tupleslice((PyTupleObject
*)op
, i
, j
);
383 tupleconcat(register PyTupleObject
*a
, register PyObject
*bb
)
385 register Py_ssize_t size
;
386 register Py_ssize_t i
;
387 PyObject
**src
, **dest
;
389 if (!PyTuple_Check(bb
)) {
390 PyErr_Format(PyExc_TypeError
,
391 "can only concatenate tuple (not \"%.200s\") to tuple",
392 Py_TYPE(bb
)->tp_name
);
395 #define b ((PyTupleObject *)bb)
396 size
= Py_SIZE(a
) + Py_SIZE(b
);
398 return PyErr_NoMemory();
399 np
= (PyTupleObject
*) PyTuple_New(size
);
405 for (i
= 0; i
< Py_SIZE(a
); i
++) {
406 PyObject
*v
= src
[i
];
411 dest
= np
->ob_item
+ Py_SIZE(a
);
412 for (i
= 0; i
< Py_SIZE(b
); i
++) {
413 PyObject
*v
= src
[i
];
417 return (PyObject
*)np
;
422 tuplerepeat(PyTupleObject
*a
, Py_ssize_t n
)
427 PyObject
**p
, **items
;
430 if (Py_SIZE(a
) == 0 || n
== 1) {
431 if (PyTuple_CheckExact(a
)) {
432 /* Since tuples are immutable, we can return a shared
435 return (PyObject
*)a
;
438 return PyTuple_New(0);
440 size
= Py_SIZE(a
) * n
;
441 if (size
/Py_SIZE(a
) != n
)
442 return PyErr_NoMemory();
443 np
= (PyTupleObject
*) PyTuple_New(size
);
448 for (i
= 0; i
< n
; i
++) {
449 for (j
= 0; j
< Py_SIZE(a
); j
++) {
455 return (PyObject
*) np
;
459 tupleindex(PyTupleObject
*self
, PyObject
*args
)
461 Py_ssize_t i
, start
=0, stop
=Py_SIZE(self
);
464 if (!PyArg_ParseTuple(args
, "O|O&O&:index", &v
,
465 _PyEval_SliceIndex
, &start
,
466 _PyEval_SliceIndex
, &stop
))
469 start
+= Py_SIZE(self
);
474 stop
+= Py_SIZE(self
);
478 for (i
= start
; i
< stop
&& i
< Py_SIZE(self
); i
++) {
479 int cmp
= PyObject_RichCompareBool(self
->ob_item
[i
], v
, Py_EQ
);
481 return PyInt_FromSsize_t(i
);
485 PyErr_SetString(PyExc_ValueError
, "tuple.index(x): x not in list");
490 tuplecount(PyTupleObject
*self
, PyObject
*v
)
492 Py_ssize_t count
= 0;
495 for (i
= 0; i
< Py_SIZE(self
); i
++) {
496 int cmp
= PyObject_RichCompareBool(self
->ob_item
[i
], v
, Py_EQ
);
502 return PyInt_FromSsize_t(count
);
506 tupletraverse(PyTupleObject
*o
, visitproc visit
, void *arg
)
510 for (i
= Py_SIZE(o
); --i
>= 0; )
511 Py_VISIT(o
->ob_item
[i
]);
516 tuplerichcompare(PyObject
*v
, PyObject
*w
, int op
)
518 PyTupleObject
*vt
, *wt
;
520 Py_ssize_t vlen
, wlen
;
522 if (!PyTuple_Check(v
) || !PyTuple_Check(w
)) {
523 Py_INCREF(Py_NotImplemented
);
524 return Py_NotImplemented
;
527 vt
= (PyTupleObject
*)v
;
528 wt
= (PyTupleObject
*)w
;
533 /* Note: the corresponding code for lists has an "early out" test
534 * here when op is EQ or NE and the lengths differ. That pays there,
535 * but Tim was unable to find any real code where EQ/NE tuple
536 * compares don't have the same length, so testing for it here would
537 * have cost without benefit.
540 /* Search for the first index where items are different.
541 * Note that because tuples are immutable, it's safe to reuse
542 * vlen and wlen across the comparison calls.
544 for (i
= 0; i
< vlen
&& i
< wlen
; i
++) {
545 int k
= PyObject_RichCompareBool(vt
->ob_item
[i
],
546 wt
->ob_item
[i
], Py_EQ
);
553 if (i
>= vlen
|| i
>= wlen
) {
554 /* No more items to compare -- compare sizes */
558 case Py_LT
: cmp
= vlen
< wlen
; break;
559 case Py_LE
: cmp
= vlen
<= wlen
; break;
560 case Py_EQ
: cmp
= vlen
== wlen
; break;
561 case Py_NE
: cmp
= vlen
!= wlen
; break;
562 case Py_GT
: cmp
= vlen
> wlen
; break;
563 case Py_GE
: cmp
= vlen
>= wlen
; break;
564 default: return NULL
; /* cannot happen */
574 /* We have an item that differs -- shortcuts for EQ/NE */
584 /* Compare the final item again using the proper operator */
585 return PyObject_RichCompare(vt
->ob_item
[i
], wt
->ob_item
[i
], op
);
589 tuple_subtype_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
);
592 tuple_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
594 PyObject
*arg
= NULL
;
595 static char *kwlist
[] = {"sequence", 0};
597 if (type
!= &PyTuple_Type
)
598 return tuple_subtype_new(type
, args
, kwds
);
599 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "|O:tuple", kwlist
, &arg
))
603 return PyTuple_New(0);
605 return PySequence_Tuple(arg
);
609 tuple_subtype_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
611 PyObject
*tmp
, *newobj
, *item
;
614 assert(PyType_IsSubtype(type
, &PyTuple_Type
));
615 tmp
= tuple_new(&PyTuple_Type
, args
, kwds
);
618 assert(PyTuple_Check(tmp
));
619 newobj
= type
->tp_alloc(type
, n
= PyTuple_GET_SIZE(tmp
));
622 for (i
= 0; i
< n
; i
++) {
623 item
= PyTuple_GET_ITEM(tmp
, i
);
625 PyTuple_SET_ITEM(newobj
, i
, item
);
631 PyDoc_STRVAR(tuple_doc
,
632 "tuple() -> an empty tuple\n"
633 "tuple(sequence) -> tuple initialized from sequence's items\n"
635 "If the argument is a tuple, the return value is the same object.");
637 static PySequenceMethods tuple_as_sequence
= {
638 (lenfunc
)tuplelength
, /* sq_length */
639 (binaryfunc
)tupleconcat
, /* sq_concat */
640 (ssizeargfunc
)tuplerepeat
, /* sq_repeat */
641 (ssizeargfunc
)tupleitem
, /* sq_item */
642 (ssizessizeargfunc
)tupleslice
, /* sq_slice */
644 0, /* sq_ass_slice */
645 (objobjproc
)tuplecontains
, /* sq_contains */
649 tuplesubscript(PyTupleObject
* self
, PyObject
* item
)
651 if (PyIndex_Check(item
)) {
652 Py_ssize_t i
= PyNumber_AsSsize_t(item
, PyExc_IndexError
);
653 if (i
== -1 && PyErr_Occurred())
656 i
+= PyTuple_GET_SIZE(self
);
657 return tupleitem(self
, i
);
659 else if (PySlice_Check(item
)) {
660 Py_ssize_t start
, stop
, step
, slicelength
, cur
, i
;
663 PyObject
**src
, **dest
;
665 if (PySlice_GetIndicesEx((PySliceObject
*)item
,
666 PyTuple_GET_SIZE(self
),
667 &start
, &stop
, &step
, &slicelength
) < 0) {
671 if (slicelength
<= 0) {
672 return PyTuple_New(0);
674 else if (start
== 0 && step
== 1 &&
675 slicelength
== PyTuple_GET_SIZE(self
) &&
676 PyTuple_CheckExact(self
)) {
678 return (PyObject
*)self
;
681 result
= PyTuple_New(slicelength
);
682 if (!result
) return NULL
;
685 dest
= ((PyTupleObject
*)result
)->ob_item
;
686 for (cur
= start
, i
= 0; i
< slicelength
;
697 PyErr_Format(PyExc_TypeError
,
698 "tuple indices must be integers, not %.200s",
699 Py_TYPE(item
)->tp_name
);
705 tuple_getnewargs(PyTupleObject
*v
)
707 return Py_BuildValue("(N)", tupleslice(v
, 0, Py_SIZE(v
)));
712 tuple_sizeof(PyTupleObject
*self
)
716 res
= PyTuple_Type
.tp_basicsize
+ Py_SIZE(self
) * sizeof(PyObject
*);
717 return PyInt_FromSsize_t(res
);
720 PyDoc_STRVAR(index_doc
,
721 "T.index(value, [start, [stop]]) -> integer -- return first index of value");
722 PyDoc_STRVAR(count_doc
,
723 "T.count(value) -> integer -- return number of occurrences of value");
724 PyDoc_STRVAR(sizeof_doc
,
725 "T.__sizeof__() -- size of T in memory, in bytes");
727 static PyMethodDef tuple_methods
[] = {
728 {"__getnewargs__", (PyCFunction
)tuple_getnewargs
, METH_NOARGS
},
729 {"__sizeof__", (PyCFunction
)tuple_sizeof
, METH_NOARGS
, sizeof_doc
},
730 {"index", (PyCFunction
)tupleindex
, METH_VARARGS
, index_doc
},
731 {"count", (PyCFunction
)tuplecount
, METH_O
, count_doc
},
732 {NULL
, NULL
} /* sentinel */
735 static PyMappingMethods tuple_as_mapping
= {
736 (lenfunc
)tuplelength
,
737 (binaryfunc
)tuplesubscript
,
741 static PyObject
*tuple_iter(PyObject
*seq
);
743 PyTypeObject PyTuple_Type
= {
744 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
746 sizeof(PyTupleObject
) - sizeof(PyObject
*),
748 (destructor
)tupledealloc
, /* tp_dealloc */
749 (printfunc
)tupleprint
, /* tp_print */
753 (reprfunc
)tuplerepr
, /* tp_repr */
754 0, /* tp_as_number */
755 &tuple_as_sequence
, /* tp_as_sequence */
756 &tuple_as_mapping
, /* tp_as_mapping */
757 (hashfunc
)tuplehash
, /* tp_hash */
760 PyObject_GenericGetAttr
, /* tp_getattro */
762 0, /* tp_as_buffer */
763 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
|
764 Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_TUPLE_SUBCLASS
, /* tp_flags */
765 tuple_doc
, /* tp_doc */
766 (traverseproc
)tupletraverse
, /* tp_traverse */
768 tuplerichcompare
, /* tp_richcompare */
769 0, /* tp_weaklistoffset */
770 tuple_iter
, /* tp_iter */
772 tuple_methods
, /* tp_methods */
777 0, /* tp_descr_get */
778 0, /* tp_descr_set */
779 0, /* tp_dictoffset */
782 tuple_new
, /* tp_new */
783 PyObject_GC_Del
, /* tp_free */
786 /* The following function breaks the notion that tuples are immutable:
787 it changes the size of a tuple. We get away with this only if there
788 is only one module referencing the object. You can also think of it
789 as creating a new tuple object and destroying the old one, only more
790 efficiently. In any case, don't use this if the tuple may already be
791 known to some other part of the code. */
794 _PyTuple_Resize(PyObject
**pv
, Py_ssize_t newsize
)
796 register PyTupleObject
*v
;
797 register PyTupleObject
*sv
;
801 v
= (PyTupleObject
*) *pv
;
802 if (v
== NULL
|| Py_TYPE(v
) != &PyTuple_Type
||
803 (Py_SIZE(v
) != 0 && Py_REFCNT(v
) != 1)) {
806 PyErr_BadInternalCall();
809 oldsize
= Py_SIZE(v
);
810 if (oldsize
== newsize
)
814 /* Empty tuples are often shared, so we should never
815 resize them in-place even if we do own the only
816 (current) reference */
818 *pv
= PyTuple_New(newsize
);
819 return *pv
== NULL
? -1 : 0;
822 /* XXX UNREF/NEWREF interface should be more symmetrical */
824 _PyObject_GC_UNTRACK(v
);
825 _Py_ForgetReference((PyObject
*) v
);
826 /* DECREF items deleted by shrinkage */
827 for (i
= newsize
; i
< oldsize
; i
++) {
828 Py_XDECREF(v
->ob_item
[i
]);
829 v
->ob_item
[i
] = NULL
;
831 sv
= PyObject_GC_Resize(PyTupleObject
, v
, newsize
);
837 _Py_NewReference((PyObject
*) sv
);
838 /* Zero out items added by growing */
839 if (newsize
> oldsize
)
840 memset(&sv
->ob_item
[oldsize
], 0,
841 sizeof(*sv
->ob_item
) * (newsize
- oldsize
));
842 *pv
= (PyObject
*) sv
;
843 _PyObject_GC_TRACK(sv
);
848 PyTuple_ClearFreeList(void)
850 int freelist_size
= 0;
851 #if PyTuple_MAXSAVESIZE > 0
853 for (i
= 1; i
< PyTuple_MAXSAVESIZE
; i
++) {
854 PyTupleObject
*p
, *q
;
856 freelist_size
+= numfree
[i
];
861 p
= (PyTupleObject
*)(p
->ob_item
[0]);
866 return freelist_size
;
872 #if PyTuple_MAXSAVESIZE > 0
873 /* empty tuples are used all over the place and applications may
874 * rely on the fact that an empty tuple is a singleton. */
875 Py_XDECREF(free_list
[0]);
878 (void)PyTuple_ClearFreeList();
882 /*********************** Tuple Iterator **************************/
887 PyTupleObject
*it_seq
; /* Set to NULL when iterator is exhausted */
891 tupleiter_dealloc(tupleiterobject
*it
)
893 _PyObject_GC_UNTRACK(it
);
894 Py_XDECREF(it
->it_seq
);
899 tupleiter_traverse(tupleiterobject
*it
, visitproc visit
, void *arg
)
901 Py_VISIT(it
->it_seq
);
906 tupleiter_next(tupleiterobject
*it
)
915 assert(PyTuple_Check(seq
));
917 if (it
->it_index
< PyTuple_GET_SIZE(seq
)) {
918 item
= PyTuple_GET_ITEM(seq
, it
->it_index
);
930 tupleiter_len(tupleiterobject
*it
)
934 len
= PyTuple_GET_SIZE(it
->it_seq
) - it
->it_index
;
935 return PyInt_FromSsize_t(len
);
938 PyDoc_STRVAR(length_hint_doc
, "Private method returning an estimate of len(list(it)).");
940 static PyMethodDef tupleiter_methods
[] = {
941 {"__length_hint__", (PyCFunction
)tupleiter_len
, METH_NOARGS
, length_hint_doc
},
942 {NULL
, NULL
} /* sentinel */
945 PyTypeObject PyTupleIter_Type
= {
946 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
947 "tupleiterator", /* tp_name */
948 sizeof(tupleiterobject
), /* tp_basicsize */
951 (destructor
)tupleiter_dealloc
, /* tp_dealloc */
957 0, /* tp_as_number */
958 0, /* tp_as_sequence */
959 0, /* tp_as_mapping */
963 PyObject_GenericGetAttr
, /* tp_getattro */
965 0, /* tp_as_buffer */
966 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
,/* tp_flags */
968 (traverseproc
)tupleiter_traverse
, /* tp_traverse */
970 0, /* tp_richcompare */
971 0, /* tp_weaklistoffset */
972 PyObject_SelfIter
, /* tp_iter */
973 (iternextfunc
)tupleiter_next
, /* tp_iternext */
974 tupleiter_methods
, /* tp_methods */
979 tuple_iter(PyObject
*seq
)
983 if (!PyTuple_Check(seq
)) {
984 PyErr_BadInternalCall();
987 it
= PyObject_GC_New(tupleiterobject
, &PyTupleIter_Type
);
992 it
->it_seq
= (PyTupleObject
*)seq
;
993 _PyObject_GC_TRACK(it
);
994 return (PyObject
*)it
;