PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/Include/listobject.h

https://bitbucket.org/mirror/python-py3k
C Header | 71 lines | 36 code | 10 blank | 25 comment | 1 complexity | a7d48dfe6209fa261893cdf8d61db239 MD5 | raw file
Possible License(s): 0BSD
  1. /* List object interface */
  2. /*
  3. Another generally useful object type is an list of object pointers.
  4. This is a mutable type: the list items can be changed, and items can be
  5. added or removed. Out-of-range indices or non-list objects are ignored.
  6. *** WARNING *** PyList_SetItem does not increment the new item's reference
  7. count, but does decrement the reference count of the item it replaces,
  8. if not nil. It does *decrement* the reference count if it is *not*
  9. inserted in the list. Similarly, PyList_GetItem does not increment the
  10. returned item's reference count.
  11. */
  12. #ifndef Py_LISTOBJECT_H
  13. #define Py_LISTOBJECT_H
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef struct {
  18. PyObject_VAR_HEAD
  19. /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
  20. PyObject **ob_item;
  21. /* ob_item contains space for 'allocated' elements. The number
  22. * currently in use is ob_size.
  23. * Invariants:
  24. * 0 <= ob_size <= allocated
  25. * len(list) == ob_size
  26. * ob_item == NULL implies ob_size == allocated == 0
  27. * list.sort() temporarily sets allocated to -1 to detect mutations.
  28. *
  29. * Items must normally not be NULL, except during construction when
  30. * the list is not yet visible outside the function that builds it.
  31. */
  32. Py_ssize_t allocated;
  33. } PyListObject;
  34. PyAPI_DATA(PyTypeObject) PyList_Type;
  35. PyAPI_DATA(PyTypeObject) PyListIter_Type;
  36. PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
  37. PyAPI_DATA(PyTypeObject) PySortWrapper_Type;
  38. #define PyList_Check(op) \
  39. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
  40. #define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type)
  41. PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
  42. PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
  43. PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);
  44. PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);
  45. PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *);
  46. PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *);
  47. PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
  48. PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
  49. PyAPI_FUNC(int) PyList_Sort(PyObject *);
  50. PyAPI_FUNC(int) PyList_Reverse(PyObject *);
  51. PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
  52. PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
  53. /* Macro, trading safety for speed */
  54. #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
  55. #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
  56. #define PyList_GET_SIZE(op) Py_SIZE(op)
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif /* !Py_LISTOBJECT_H */