/home/mdboom/Work/builds/cpython/Include/internal/pycore_tuple.h
Line | Count | Source |
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 PyStatus _PyTuple_InitTypes(PyInterpreterState *); |
18 | extern void _PyTuple_Fini(PyInterpreterState *); |
19 | |
20 | |
21 | /* other API */ |
22 | |
23 | // PyTuple_MAXSAVESIZE - largest tuple to save on free list |
24 | // PyTuple_MAXFREELIST - maximum number of tuples of each size to save |
25 | |
26 | #if defined(PyTuple_MAXSAVESIZE) && PyTuple_MAXSAVESIZE <= 0 |
27 | // A build indicated that tuple freelists should not be used. |
28 | # define PyTuple_NFREELISTS 0 |
29 | # undef PyTuple_MAXSAVESIZE |
30 | # undef PyTuple_MAXFREELIST |
31 | |
32 | #elif !defined(WITH_FREELISTS) |
33 | # define PyTuple_NFREELISTS 0 |
34 | # undef PyTuple_MAXSAVESIZE |
35 | # undef PyTuple_MAXFREELIST |
36 | |
37 | #else |
38 | // We are using a freelist for tuples. |
39 | # ifndef PyTuple_MAXSAVESIZE |
40 | # define PyTuple_MAXSAVESIZE 20 |
41 | # endif |
42 | # define PyTuple_NFREELISTS PyTuple_MAXSAVESIZE |
43 | # ifndef PyTuple_MAXFREELIST |
44 | # define PyTuple_MAXFREELIST 2000 |
45 | # endif |
46 | #endif |
47 | |
48 | struct _Py_tuple_state { |
49 | #if PyTuple_NFREELISTS > 0 |
50 | /* There is one freelist for each size from 1 to PyTuple_MAXSAVESIZE. |
51 | The empty tuple is handled separately. |
52 | |
53 | Each tuple stored in the array is the head of the linked list |
54 | (and the next available tuple) for that size. The actual tuple |
55 | object is used as the linked list node, with its first item |
56 | (ob_item[0]) pointing to the next node (i.e. the previous head). |
57 | Each linked list is initially NULL. */ |
58 | PyTupleObject *free_list[PyTuple_NFREELISTS]; |
59 | int numfree[PyTuple_NFREELISTS]; |
60 | #else |
61 | char _unused; // Empty structs are not allowed. |
62 | #endif |
63 | }; |
64 | |
65 | #define _PyTuple_ITEMS(op) (_PyTuple_CAST(op)->ob_item) |
66 | |
67 | extern PyObject *_PyTuple_FromArray(PyObject *const *, Py_ssize_t); |
68 | extern PyObject *_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t); |
69 | |
70 | #ifdef __cplusplus |
71 | } |
72 | #endif |
73 | #endif /* !Py_INTERNAL_TUPLE_H */ |