pycore_tuple.h 2.1 KB

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