1 #ifndef Py_INTERNAL_TUPLE_H
2 #define Py_INTERNAL_TUPLE_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 #ifndef Py_BUILD_CORE
8 # error "this header requires Py_BUILD_CORE define"
9 #endif
10
11 #include "tupleobject.h" /* _PyTuple_CAST() */
12
13
14 /* runtime lifecycle */
15
16 extern PyStatus _PyTuple_InitGlobalObjects(PyInterpreterState *);
17 extern void _PyTuple_Fini(PyInterpreterState *);
18
19
20 /* other API */
21
22 // PyTuple_MAXSAVESIZE - largest tuple to save on free list
23 // PyTuple_MAXFREELIST - maximum number of tuples of each size to save
24
25 #if defined(PyTuple_MAXSAVESIZE) && PyTuple_MAXSAVESIZE <= 0
26 // A build indicated that tuple freelists should not be used.
27 # define PyTuple_NFREELISTS 0
28 # undef PyTuple_MAXSAVESIZE
29 # undef PyTuple_MAXFREELIST
30
31 #elif !defined(WITH_FREELISTS)
32 # define PyTuple_NFREELISTS 0
33 # undef PyTuple_MAXSAVESIZE
34 # undef PyTuple_MAXFREELIST
35
36 #else
37 // We are using a freelist for tuples.
38 # ifndef PyTuple_MAXSAVESIZE
39 # define PyTuple_MAXSAVESIZE 20
40 # endif
41 # define PyTuple_NFREELISTS PyTuple_MAXSAVESIZE
42 # ifndef PyTuple_MAXFREELIST
43 # define PyTuple_MAXFREELIST 2000
44 # endif
45 #endif
46
47 struct _Py_tuple_state {
48 #if PyTuple_NFREELISTS > 0
49 /* There is one freelist for each size from 1 to PyTuple_MAXSAVESIZE.
50 The empty tuple is handled separately.
51
52 Each tuple stored in the array is the head of the linked list
53 (and the next available tuple) for that size. The actual tuple
54 object is used as the linked list node, with its first item
55 (ob_item[0]) pointing to the next node (i.e. the previous head).
56 Each linked list is initially NULL. */
57 PyTupleObject *free_list[PyTuple_NFREELISTS];
58 int numfree[PyTuple_NFREELISTS];
59 #else
60 char _unused; // Empty structs are not allowed.
61 #endif
62 };
63
64 #define _PyTuple_ITEMS(op) _Py_RVALUE(_PyTuple_CAST(op)->ob_item)
65
66 extern PyObject *_PyTuple_FromArray(PyObject *const *, Py_ssize_t);
67 extern PyObject *_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);
68
69
70 typedef struct {
71 PyObject_HEAD
72 Py_ssize_t it_index;
73 PyTupleObject *it_seq; /* Set to NULL when iterator is exhausted */
74 } _PyTupleIterObject;
75
76 #ifdef __cplusplus
77 }
78 #endif
79 #endif /* !Py_INTERNAL_TUPLE_H */