tupleobject.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Tuple object interface */
  2. #ifndef Py_TUPLEOBJECT_H
  3. #define Py_TUPLEOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /*
  8. Another generally useful object type is a tuple of object pointers.
  9. For Python, this is an immutable type. C code can change the tuple items
  10. (but not their number), and even use tuples are general-purpose arrays of
  11. object references, but in general only brand new tuples should be mutated,
  12. not ones that might already have been exposed to Python code.
  13. *** WARNING *** PyTuple_SetItem does not increment the new item's reference
  14. count, but does decrement the reference count of the item it replaces,
  15. if not nil. It does *decrement* the reference count if it is *not*
  16. inserted in the tuple. Similarly, PyTuple_GetItem does not increment the
  17. returned item's reference count.
  18. */
  19. typedef struct {
  20. PyObject_VAR_HEAD
  21. PyObject *ob_item[1];
  22. /* ob_item contains space for 'ob_size' elements.
  23. * Items must normally not be NULL, except during construction when
  24. * the tuple is not yet visible outside the function that builds it.
  25. */
  26. } PyTupleObject;
  27. PyAPI_DATA(PyTypeObject) PyTuple_Type;
  28. #define PyTuple_Check(op) \
  29. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
  30. #define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type)
  31. PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);
  32. PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);
  33. PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t);
  34. PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
  35. PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
  36. PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t);
  37. PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
  38. PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
  39. /* Macro, trading safety for speed */
  40. #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
  41. #define PyTuple_GET_SIZE(op) Py_SIZE(op)
  42. /* Macro, *only* to be used to fill in brand new tuples */
  43. #define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
  44. PyAPI_FUNC(int) PyTuple_ClearFreeList(void);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif /* !Py_TUPLEOBJECT_H */