tupleobject.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef Py_CPYTHON_TUPLEOBJECT_H
  2. # error "this header file must not be included directly"
  3. #endif
  4. typedef struct {
  5. PyObject_VAR_HEAD
  6. /* ob_item contains space for 'ob_size' elements.
  7. Items must normally not be NULL, except during construction when
  8. the tuple is not yet visible outside the function that builds it. */
  9. PyObject *ob_item[1];
  10. } PyTupleObject;
  11. PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t);
  12. PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
  13. /* Cast argument to PyTupleObject* type. */
  14. #define _PyTuple_CAST(op) \
  15. (assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
  16. // Macros and static inline functions, trading safety for speed
  17. static inline Py_ssize_t PyTuple_GET_SIZE(PyObject *op) {
  18. PyTupleObject *tuple = _PyTuple_CAST(op);
  19. return Py_SIZE(tuple);
  20. }
  21. #define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
  22. #define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
  23. /* Function *only* to be used to fill in brand new tuples */
  24. static inline void
  25. PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
  26. PyTupleObject *tuple = _PyTuple_CAST(op);
  27. tuple->ob_item[index] = value;
  28. }
  29. #define PyTuple_SET_ITEM(op, index, value) \
  30. PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
  31. PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);