annotate Include/listobject.h @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 26384b8180c7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* List object interface */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 Another generally useful object type is an list of object pointers.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 This is a mutable type: the list items can be changed, and items can be
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 added or removed. Out-of-range indices or non-list objects are ignored.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
9 *** WARNING *** PyList_SetItem does not increment the new item's reference
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 count, but does decrement the reference count of the item it replaces,
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 if not nil. It does *decrement* the reference count if it is *not*
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
12 inserted in the list. Similarly, PyList_GetItem does not increment the
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 returned item's reference count.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
16 #ifndef Py_LISTOBJECT_H
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
17 #define Py_LISTOBJECT_H
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
18 #ifdef __cplusplus
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
19 extern "C" {
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
20 #endif
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
21
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 48
diff changeset
22 typedef struct {
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
23 PyObject_VAR_HEAD
32876
018c43045b53 Fix typo in comment
Neal Norwitz <nnorwitz@gmail.com>
parents: 32858
diff changeset
24 /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
25 PyObject **ob_item;
32851
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
26
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
27 /* ob_item contains space for 'allocated' elements. The number
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
28 * currently in use is ob_size.
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
29 * Invariants:
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
30 * 0 <= ob_size <= allocated
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
31 * len(list) == ob_size
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
32 * ob_item == NULL implies ob_size == allocated == 0
32858
fa0526c30da8 * drop the unreasonable list invariant that ob_item should never come back
Armin Rigo <arigo@tunes.org>
parents: 32854
diff changeset
33 * list.sort() temporarily sets allocated to -1 to detect mutations.
33856
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 32876
diff changeset
34 *
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 32876
diff changeset
35 * Items must normally not be NULL, except during construction when
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 32876
diff changeset
36 * the list is not yet visible outside the function that builds it.
32851
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
37 */
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
38 Py_ssize_t allocated;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
39 } PyListObject;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 48
diff changeset
40
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 20275
diff changeset
41 PyAPI_DATA(PyTypeObject) PyList_Type;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
40908
d01bd37bf5ce Variation of patch # 1624059 to speed up checking if an object is a subclass
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
43 #define PyList_Check(op) \
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
44 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
45 #define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
47 PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
48 PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
49 PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
50 PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
51 PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 20275
diff changeset
52 PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
53 PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
54 PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 20275
diff changeset
55 PyAPI_FUNC(int) PyList_Sort(PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 20275
diff changeset
56 PyAPI_FUNC(int) PyList_Reverse(PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 20275
diff changeset
57 PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
31642
30e305bfdddb Eliminate a big block of duplicate code in PySequence_List() by
Raymond Hettinger <python@rcn.com>
parents: 31519
diff changeset
58 PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 48
diff changeset
59
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 48
diff changeset
60 /* Macro, trading safety for speed */
4896
50abb0850740 added PyList_GET_SIZE macro
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
61 #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
8138
9d0310143600 Fred's right -- we need PyList_SET_ITEM().
Guido van Rossum <guido@python.org>
parents: 4896
diff changeset
62 #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
63 #define PyList_GET_SIZE(op) Py_SIZE(op)
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
64
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
65 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
66 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
67 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
68 #endif /* !Py_LISTOBJECT_H */