You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.8 KiB

36 years ago
36 years ago
36 years ago
36 years ago
Merged revisions 53875-53911 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line Add more details when releasing interned strings ........ r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line Whitespace only changes ........ r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines Fix crash in exec when unicode filename can't be decoded. I can't think of an easy way to test this behavior. It only occurs when the file system default encoding and the interpreter default encoding are different, such that you can open the file but not decode its name. ........ r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines Put declarations before code. ........ r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines - SF patch #1657613: add documentation for the Element interface - clean up bogus use of the {datadescni} environment everywhere ........ r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines Variation of patch # 1624059 to speed up checking if an object is a subclass of some of the common builtin types. Use a bit in tp_flags for each common builtin type. Check the bit to determine if any instance is a subclass of these common types. The check avoids a function call and O(n) search of the base classes. The check is done in the various Py*_Check macros rather than calling PyType_IsSubtype(). All the bits are set in tp_flags when the type is declared in the Objects/*object.c files because PyType_Ready() is not called for all the types. Should PyType_Ready() be called for all types? If so and the change is made, the changes to the Objects/*object.c files can be reverted (remove setting the tp_flags). Objects/typeobject.c would also have to be modified to add conditions for Py*_CheckExact() in addition to each the PyType_IsSubtype check. ........
19 years ago
36 years ago
  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. #ifndef Py_LIMITED_API
  18. typedef struct {
  19. PyObject_VAR_HEAD
  20. /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
  21. PyObject **ob_item;
  22. /* ob_item contains space for 'allocated' elements. The number
  23. * currently in use is ob_size.
  24. * Invariants:
  25. * 0 <= ob_size <= allocated
  26. * len(list) == ob_size
  27. * ob_item == NULL implies ob_size == allocated == 0
  28. * list.sort() temporarily sets allocated to -1 to detect mutations.
  29. *
  30. * Items must normally not be NULL, except during construction when
  31. * the list is not yet visible outside the function that builds it.
  32. */
  33. Py_ssize_t allocated;
  34. } PyListObject;
  35. #endif
  36. PyAPI_DATA(PyTypeObject) PyList_Type;
  37. PyAPI_DATA(PyTypeObject) PyListIter_Type;
  38. PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
  39. PyAPI_DATA(PyTypeObject) PySortWrapper_Type;
  40. #define PyList_Check(op) \
  41. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
  42. #define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type)
  43. PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
  44. PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
  45. PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);
  46. PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);
  47. PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *);
  48. PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *);
  49. PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
  50. PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
  51. PyAPI_FUNC(int) PyList_Sort(PyObject *);
  52. PyAPI_FUNC(int) PyList_Reverse(PyObject *);
  53. PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
  54. #ifndef Py_LIMITED_API
  55. PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
  56. PyAPI_FUNC(int) PyList_ClearFreeList(void);
  57. PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
  58. #endif
  59. /* Macro, trading safety for speed */
  60. #ifndef Py_LIMITED_API
  61. #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
  62. #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
  63. #define PyList_GET_SIZE(op) Py_SIZE(op)
  64. #endif
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif /* !Py_LISTOBJECT_H */