annotate Include/listobject.h @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents d63a80abfbec
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
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
22 #ifndef Py_LIMITED_API
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 48
diff changeset
23 typedef struct {
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
24 PyObject_VAR_HEAD
32876
018c43045b53 Fix typo in comment
Neal Norwitz <nnorwitz@gmail.com>
parents: 32858
diff changeset
25 /* 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
26 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
27
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
28 /* 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
29 * 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
30 * Invariants:
052a43aa35ec Document what the members of PyListObject are used for, and the crucial
Tim Peters <tim.peters@gmail.com>
parents: 31642
diff changeset
31 * 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
32 * 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
33 * 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
34 * 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
35 *
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 32876
diff changeset
36 * 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
37 * 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
38 */
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
39 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
40 } PyListObject;
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
41 #endif
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 48
diff changeset
42
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 20275
diff changeset
43 PyAPI_DATA(PyTypeObject) PyList_Type;
44061
0cc552ab76bd Added all PyTypeObjects to the appropriate header files.
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
44 PyAPI_DATA(PyTypeObject) PyListIter_Type;
0cc552ab76bd Added all PyTypeObjects to the appropriate header files.
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
45 PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
0cc552ab76bd Added all PyTypeObjects to the appropriate header files.
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
46 PyAPI_DATA(PyTypeObject) PySortWrapper_Type;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
40909
f2f0b41f270d Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
48 #define PyList_Check(op) \
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44061
diff changeset
49 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44061
diff changeset
50 #define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 PyAPI_FUNC(int) PyList_Sort(PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 20275
diff changeset
61 PyAPI_FUNC(int) PyList_Reverse(PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 20275
diff changeset
62 PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
63 #ifndef Py_LIMITED_API
31642
30e305bfdddb Eliminate a big block of duplicate code in PySequence_List() by
Raymond Hettinger <python@rcn.com>
parents: 31519
diff changeset
64 PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
73551
910986542a75 Issue #13389: Full garbage collection passes now clear the freelists for
Antoine Pitrou <solipsis@pitrou.net>
parents: 66664
diff changeset
65
910986542a75 Issue #13389: Full garbage collection passes now clear the freelists for
Antoine Pitrou <solipsis@pitrou.net>
parents: 66664
diff changeset
66 PyAPI_FUNC(int) PyList_ClearFreeList(void);
77577
d63a80abfbec Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
David Malcolm <dmalcolm@redhat.com>
parents: 73551
diff changeset
67 PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
68 #endif
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 48
diff changeset
69
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 48
diff changeset
70 /* Macro, trading safety for speed */
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
71 #ifndef Py_LIMITED_API
4896
50abb0850740 added PyList_GET_SIZE macro
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
72 #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
73 #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44061
diff changeset
74 #define PyList_GET_SIZE(op) Py_SIZE(op)
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 44351
diff changeset
75 #endif
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
76
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
77 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
78 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
79 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1313
diff changeset
80 #endif /* !Py_LISTOBJECT_H */