annotate Modules/gcmodule.c @ 48416:fb02fedfe647

Merged revisions 64677 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64677 | brett.cannon | 2008-07-02 14:52:42 -0700 (Wed, 02 Jul 2008) | 2 lines Revert r64673 and instead just change the file encoding. ........
author Brett Cannon <bcannon@gmail.com>
date Wed, 02 Jul 2008 22:06:12 +0000
parents 94f64f11fdd0
children d040a3b63df4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1 /*
24072
86b3760d285d SF bug #574132: Major GC related performance regression
Tim Peters <tim.peters@gmail.com>
parents: 24036
diff changeset
2
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
3 Reference Cycle Garbage Collection
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
4 ==================================
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
5
15013
25bc16952a24 - update Neil's email address
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15012
diff changeset
6 Neil Schemenauer <nas@arctrix.com>
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
7
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
8 Based on a post on the python-dev list. Ideas from Guido van Rossum,
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
9 Eric Tiedemann, and various others.
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
10
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
11 http://www.arctrix.com/nas/python/gc/
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
12 http://www.python.org/pipermail/python-dev/2000-March/003869.html
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
13 http://www.python.org/pipermail/python-dev/2000-March/004010.html
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
14 http://www.python.org/pipermail/python-dev/2000-March/004022.html
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
15
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
16 For a highlevel view of the collection process, read the collect
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
17 function.
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
18
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
19 */
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
20
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
21 #include "Python.h"
45371
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
22 #include "frameobject.h" /* for PyFrame_ClearFreeList */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
23
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
24 /* Get an object's GC head */
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
25 #define AS_GC(o) ((PyGC_Head *)(o)-1)
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
26
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
27 /* Get the object given the GC head */
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
28 #define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1))
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
29
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
30 /*** Global GC state ***/
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
31
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
32 struct gc_generation {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
33 PyGC_Head head;
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
34 int threshold; /* collection threshold */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
35 int count; /* count of allocations or collections of younger
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
36 generations */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
37 };
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
38
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
39 #define NUM_GENERATIONS 3
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
40 #define GEN_HEAD(n) (&generations[n].head)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
41
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
42 /* linked lists of container objects */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
43 static struct gc_generation generations[NUM_GENERATIONS] = {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
44 /* PyGC_Head, threshold, count */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
45 {{{GEN_HEAD(0), GEN_HEAD(0), 0}}, 700, 0},
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
46 {{{GEN_HEAD(1), GEN_HEAD(1), 0}}, 10, 0},
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
47 {{{GEN_HEAD(2), GEN_HEAD(2), 0}}, 10, 0},
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
48 };
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
49
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
50 PyGC_Head *_PyGC_generation0 = GEN_HEAD(0);
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
51
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
52 static int enabled = 1; /* automatic collection enabled? */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
53
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
54 /* true if we are currently running the collector */
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
55 static int collecting = 0;
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
56
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
57 /* list of uncollectable objects */
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
58 static PyObject *garbage = NULL;
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
59
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
60 /* Python string to use if unhandled exception occurs */
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
61 static PyObject *gc_str = NULL;
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
62
28507
a0503bdb0c24 Fixed new seemingly random segfaults, by moving the initialization of
Tim Peters <tim.peters@gmail.com>
parents: 28504
diff changeset
63 /* Python string used to look for __del__ attribute. */
a0503bdb0c24 Fixed new seemingly random segfaults, by moving the initialization of
Tim Peters <tim.peters@gmail.com>
parents: 28504
diff changeset
64 static PyObject *delstr = NULL;
28504
cb5db5561cdc Fix Tim's boom example.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28498
diff changeset
65
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
66 /* set for debugging information */
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
67 #define DEBUG_STATS (1<<0) /* print collection statistics */
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
68 #define DEBUG_COLLECTABLE (1<<1) /* print collectable objects */
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
69 #define DEBUG_UNCOLLECTABLE (1<<2) /* print uncollectable objects */
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
70 #define DEBUG_SAVEALL (1<<5) /* save all garbage in gc.garbage */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
71 #define DEBUG_LEAK DEBUG_COLLECTABLE | \
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
72 DEBUG_UNCOLLECTABLE | \
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
73 DEBUG_SAVEALL
14330
6dee1985c681 refactor __del__ exception handler into PyErr_WriteUnraisable
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14294
diff changeset
74 static int debug;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
75 static PyObject *tmod = NULL;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
76
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
77 /*--------------------------------------------------------------------------
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
78 gc_refs values.
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
79
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
80 Between collections, every gc'ed object has one of two gc_refs values:
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
81
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
82 GC_UNTRACKED
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
83 The initial state; objects returned by PyObject_GC_Malloc are in this
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
84 state. The object doesn't live in any generation list, and its
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
85 tp_traverse slot must not be called.
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
86
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
87 GC_REACHABLE
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
88 The object lives in some generation list, and its tp_traverse is safe to
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
89 call. An object transitions to GC_REACHABLE when PyObject_GC_Track
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
90 is called.
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
91
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
92 During a collection, gc_refs can temporarily take on other states:
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
93
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
94 >= 0
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
95 At the start of a collection, update_refs() copies the true refcount
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
96 to gc_refs, for each object in the generation being collected.
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
97 subtract_refs() then adjusts gc_refs so that it equals the number of
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
98 times an object is referenced directly from outside the generation
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
99 being collected.
26138
4ab6b7c3f311 Fix typo.
Martin v. Löwis <martin@v.loewis.de>
parents: 24714
diff changeset
100 gc_refs remains >= 0 throughout these steps.
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
101
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
102 GC_TENTATIVELY_UNREACHABLE
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
103 move_unreachable() then moves objects not reachable (whether directly or
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
104 indirectly) from outside the generation into an "unreachable" set.
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
105 Objects that are found to be reachable have gc_refs set to GC_REACHABLE
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
106 again. Objects that are found to be unreachable have gc_refs set to
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
107 GC_TENTATIVELY_UNREACHABLE. It's "tentatively" because the pass doing
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
108 this can't be sure until it ends, and GC_TENTATIVELY_UNREACHABLE may
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
109 transition back to GC_REACHABLE.
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
110
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
111 Only objects with GC_TENTATIVELY_UNREACHABLE still set are candidates
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
112 for collection. If it's decided not to collect such an object (e.g.,
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
113 it has a __del__ method), its gc_refs is restored to GC_REACHABLE again.
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
114 ----------------------------------------------------------------------------
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
115 */
24077
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
116 #define GC_UNTRACKED _PyGC_REFS_UNTRACKED
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
117 #define GC_REACHABLE _PyGC_REFS_REACHABLE
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
118 #define GC_TENTATIVELY_UNREACHABLE _PyGC_REFS_TENTATIVELY_UNREACHABLE
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
119
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
120 #define IS_TRACKED(o) ((AS_GC(o))->gc.gc_refs != GC_UNTRACKED)
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
121 #define IS_REACHABLE(o) ((AS_GC(o))->gc.gc_refs == GC_REACHABLE)
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
122 #define IS_TENTATIVELY_UNREACHABLE(o) ( \
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
123 (AS_GC(o))->gc.gc_refs == GC_TENTATIVELY_UNREACHABLE)
23495
68e3f3dd4d48 Add IS_TRACKED and IS_MOVED macros. This makes the logic a little more clear.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23377
diff changeset
124
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
125 /*** list functions ***/
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
126
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
127 static void
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
128 gc_list_init(PyGC_Head *list)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
129 {
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
130 list->gc.gc_prev = list;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
131 list->gc.gc_next = list;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
132 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
133
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
134 static int
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
135 gc_list_is_empty(PyGC_Head *list)
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
136 {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
137 return (list->gc.gc_next == list);
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
138 }
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
139
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
140 #if 0
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
141 /* This became unused after gc_list_move() was introduced. */
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
142 /* Append `node` to `list`. */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
143 static void
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
144 gc_list_append(PyGC_Head *node, PyGC_Head *list)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
145 {
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
146 node->gc.gc_next = list;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
147 node->gc.gc_prev = list->gc.gc_prev;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
148 node->gc.gc_prev->gc.gc_next = node;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
149 list->gc.gc_prev = node;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
150 }
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
151 #endif
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
152
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
153 /* Remove `node` from the gc list it's currently in. */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
154 static void
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
155 gc_list_remove(PyGC_Head *node)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
156 {
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
157 node->gc.gc_prev->gc.gc_next = node->gc.gc_next;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
158 node->gc.gc_next->gc.gc_prev = node->gc.gc_prev;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
159 node->gc.gc_next = NULL; /* object is not currently tracked */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
160 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
161
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
162 /* Move `node` from the gc list it's currently in (which is not explicitly
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
163 * named here) to the end of `list`. This is semantically the same as
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
164 * gc_list_remove(node) followed by gc_list_append(node, list).
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
165 */
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
166 static void
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
167 gc_list_move(PyGC_Head *node, PyGC_Head *list)
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
168 {
33876
633cadebf68d gc_list_move(): Make this truly equivalent to remove+append. While
Tim Peters <tim.peters@gmail.com>
parents: 33869
diff changeset
169 PyGC_Head *new_prev;
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
170 PyGC_Head *current_prev = node->gc.gc_prev;
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
171 PyGC_Head *current_next = node->gc.gc_next;
33876
633cadebf68d gc_list_move(): Make this truly equivalent to remove+append. While
Tim Peters <tim.peters@gmail.com>
parents: 33869
diff changeset
172 /* Unlink from current list. */
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
173 current_prev->gc.gc_next = current_next;
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
174 current_next->gc.gc_prev = current_prev;
33876
633cadebf68d gc_list_move(): Make this truly equivalent to remove+append. While
Tim Peters <tim.peters@gmail.com>
parents: 33869
diff changeset
175 /* Relink at end of new list. */
633cadebf68d gc_list_move(): Make this truly equivalent to remove+append. While
Tim Peters <tim.peters@gmail.com>
parents: 33869
diff changeset
176 new_prev = node->gc.gc_prev = list->gc.gc_prev;
633cadebf68d gc_list_move(): Make this truly equivalent to remove+append. While
Tim Peters <tim.peters@gmail.com>
parents: 33869
diff changeset
177 new_prev->gc.gc_next = list->gc.gc_prev = node;
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
178 node->gc.gc_next = list;
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
179 }
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
180
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
181 /* append list `from` onto list `to`; `from` becomes an empty list */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
182 static void
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
183 gc_list_merge(PyGC_Head *from, PyGC_Head *to)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
184 {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
185 PyGC_Head *tail;
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
186 assert(from != to);
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
187 if (!gc_list_is_empty(from)) {
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
188 tail = to->gc.gc_prev;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
189 tail->gc.gc_next = from->gc.gc_next;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
190 tail->gc.gc_next->gc.gc_prev = tail;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
191 to->gc.gc_prev = from->gc.gc_prev;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
192 to->gc.gc_prev->gc.gc_next = to;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
193 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
194 gc_list_init(from);
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
195 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
196
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
197 static Py_ssize_t
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
198 gc_list_size(PyGC_Head *list)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
199 {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
200 PyGC_Head *gc;
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
201 Py_ssize_t n = 0;
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
202 for (gc = list->gc.gc_next; gc != list; gc = gc->gc.gc_next) {
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
203 n++;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
204 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
205 return n;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
206 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
207
28515
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
208 /* Append objects in a GC list to a Python list.
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
209 * Return 0 if all OK, < 0 if error (out of memory for list).
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
210 */
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
211 static int
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
212 append_objects(PyObject *py_list, PyGC_Head *gc_list)
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
213 {
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
214 PyGC_Head *gc;
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
215 for (gc = gc_list->gc.gc_next; gc != gc_list; gc = gc->gc.gc_next) {
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
216 PyObject *op = FROM_GC(gc);
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
217 if (op != py_list) {
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
218 if (PyList_Append(py_list, op)) {
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
219 return -1; /* exception */
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
220 }
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
221 }
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
222 }
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
223 return 0;
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
224 }
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
225
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
226 /*** end of list stuff ***/
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
227
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
228
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
229 /* Set all gc_refs = ob_refcnt. After this, gc_refs is > 0 for all objects
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
230 * in containers, and is GC_REACHABLE for all tracked gc objects not in
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
231 * containers.
24072
86b3760d285d SF bug #574132: Major GC related performance regression
Tim Peters <tim.peters@gmail.com>
parents: 24036
diff changeset
232 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
233 static void
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
234 update_refs(PyGC_Head *containers)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
235 {
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
236 PyGC_Head *gc = containers->gc.gc_next;
24077
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
237 for (; gc != containers; gc = gc->gc.gc_next) {
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
238 assert(gc->gc.gc_refs == GC_REACHABLE);
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: 44265
diff changeset
239 gc->gc.gc_refs = Py_REFCNT(FROM_GC(gc));
30918
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
240 /* Python's cyclic gc should never see an incoming refcount
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
241 * of 0: if something decref'ed to 0, it should have been
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
242 * deallocated immediately at that time.
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
243 * Possible cause (if the assert triggers): a tp_dealloc
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
244 * routine left a gc-aware object tracked during its teardown
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
245 * phase, and did something-- or allowed something to happen --
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
246 * that called back into Python. gc can trigger then, and may
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
247 * see the still-tracked dying object. Before this assert
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
248 * was added, such mistakes went on to allow gc to try to
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
249 * delete the object again. In a debug build, that caused
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
250 * a mysterious segfault, when _Py_ForgetReference tried
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
251 * to remove the object from the doubly-linked list of all
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
252 * objects a second time. In a release build, an actual
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
253 * double deallocation occurred, which leads to corruption
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
254 * of the allocator's internal bookkeeping pointers. That's
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
255 * so serious that maybe this should be a release-build
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
256 * check instead of an assert?
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
257 */
8aa9237f6dd6 update_refs(): assert that incoming refcounts aren't 0. The comment
Tim Peters <tim.peters@gmail.com>
parents: 30311
diff changeset
258 assert(gc->gc.gc_refs != 0);
24077
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
259 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
260 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
261
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
262 /* A traversal callback for subtract_refs. */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
263 static int
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
264 visit_decref(PyObject *op, void *data)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
265 {
24074
a1805a54666f visit_decref(): Two optimizations.
Tim Peters <tim.peters@gmail.com>
parents: 24072
diff changeset
266 assert(op != NULL);
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
267 if (PyObject_IS_GC(op)) {
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
268 PyGC_Head *gc = AS_GC(op);
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
269 /* We're only interested in gc_refs for objects in the
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
270 * generation being collected, which can be recognized
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
271 * because only they have positive gc_refs.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
272 */
24097
f7abbd15b4f4 visit_decref(): Added another assert.
Tim Peters <tim.peters@gmail.com>
parents: 24085
diff changeset
273 assert(gc->gc.gc_refs != 0); /* else refcount was too small */
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
274 if (gc->gc.gc_refs > 0)
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
275 gc->gc.gc_refs--;
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
276 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
277 return 0;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
278 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
279
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
280 /* Subtract internal references from gc_refs. After this, gc_refs is >= 0
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
281 * for all objects in containers, and is GC_REACHABLE for all tracked gc
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
282 * objects not in containers. The ones with gc_refs > 0 are directly
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
283 * reachable from outside containers, and so can't be collected.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
284 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
285 static void
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
286 subtract_refs(PyGC_Head *containers)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
287 {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
288 traverseproc traverse;
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
289 PyGC_Head *gc = containers->gc.gc_next;
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
290 for (; gc != containers; gc=gc->gc.gc_next) {
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: 44265
diff changeset
291 traverse = Py_TYPE(FROM_GC(gc))->tp_traverse;
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
292 (void) traverse(FROM_GC(gc),
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
293 (visitproc)visit_decref,
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
294 NULL);
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
295 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
296 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
297
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
298 /* A traversal callback for move_unreachable. */
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
299 static int
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
300 visit_reachable(PyObject *op, PyGC_Head *reachable)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
301 {
24077
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
302 if (PyObject_IS_GC(op)) {
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
303 PyGC_Head *gc = AS_GC(op);
36769
ab1b53d54901 Change GC refcount to Py_ssize_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 36524
diff changeset
304 const Py_ssize_t gc_refs = gc->gc.gc_refs;
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
305
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
306 if (gc_refs == 0) {
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
307 /* This is in move_unreachable's 'young' list, but
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
308 * the traversal hasn't yet gotten to it. All
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
309 * we need to do is tell move_unreachable that it's
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
310 * reachable.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
311 */
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
312 gc->gc.gc_refs = 1;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
313 }
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
314 else if (gc_refs == GC_TENTATIVELY_UNREACHABLE) {
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
315 /* This had gc_refs = 0 when move_unreachable got
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
316 * to it, but turns out it's reachable after all.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
317 * Move it back to move_unreachable's 'young' list,
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
318 * and move_unreachable will eventually get to it
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
319 * again.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
320 */
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
321 gc_list_move(gc, reachable);
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
322 gc->gc.gc_refs = 1;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
323 }
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
324 /* Else there's nothing to do.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
325 * If gc_refs > 0, it must be in move_unreachable's 'young'
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
326 * list, and move_unreachable will eventually get to it.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
327 * If gc_refs == GC_REACHABLE, it's either in some other
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
328 * generation so we don't care about it, or move_unreachable
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
329 * already dealt with it.
24077
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
330 * If gc_refs == GC_UNTRACKED, it must be ignored.
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
331 */
24077
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
332 else {
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
333 assert(gc_refs > 0
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
334 || gc_refs == GC_REACHABLE
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
335 || gc_refs == GC_UNTRACKED);
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
336 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
337 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
338 return 0;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
339 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
340
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
341 /* Move the unreachable objects from young to unreachable. After this,
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
342 * all objects in young have gc_refs = GC_REACHABLE, and all objects in
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
343 * unreachable have gc_refs = GC_TENTATIVELY_UNREACHABLE. All tracked
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
344 * gc objects not in young or unreachable still have gc_refs = GC_REACHABLE.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
345 * All objects in young after this are directly or indirectly reachable
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
346 * from outside the original young; and all objects in unreachable are
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
347 * not.
24072
86b3760d285d SF bug #574132: Major GC related performance regression
Tim Peters <tim.peters@gmail.com>
parents: 24036
diff changeset
348 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
349 static void
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
350 move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
351 {
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
352 PyGC_Head *gc = young->gc.gc_next;
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
353
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
354 /* Invariants: all objects "to the left" of us in young have gc_refs
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
355 * = GC_REACHABLE, and are indeed reachable (directly or indirectly)
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
356 * from outside the young list as it was at entry. All other objects
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
357 * from the original young "to the left" of us are in unreachable now,
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
358 * and have gc_refs = GC_TENTATIVELY_UNREACHABLE. All objects to the
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
359 * left of us in 'young' now have been scanned, and no objects here
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
360 * or to the right have been scanned yet.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
361 */
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
362
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
363 while (gc != young) {
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
364 PyGC_Head *next;
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
365
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
366 if (gc->gc.gc_refs) {
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
367 /* gc is definitely reachable from outside the
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
368 * original 'young'. Mark it as such, and traverse
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
369 * its pointers to find any other objects that may
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
370 * be directly reachable from it. Note that the
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
371 * call to tp_traverse may append objects to young,
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
372 * so we have to wait until it returns to determine
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
373 * the next object to visit.
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
374 */
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
375 PyObject *op = FROM_GC(gc);
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: 44265
diff changeset
376 traverseproc traverse = Py_TYPE(op)->tp_traverse;
24085
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
377 assert(gc->gc.gc_refs > 0);
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
378 gc->gc.gc_refs = GC_REACHABLE;
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
379 (void) traverse(op,
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
380 (visitproc)visit_reachable,
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
381 (void *)young);
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
382 next = gc->gc.gc_next;
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
383 }
22d2f037af9d Finished transitioning to using gc_refs to track gc objects' states.
Tim Peters <tim.peters@gmail.com>
parents: 24077
diff changeset
384 else {
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
385 /* This *may* be unreachable. To make progress,
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
386 * assume it is. gc isn't directly reachable from
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
387 * any object we've already traversed, but may be
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
388 * reachable from an object we haven't gotten to yet.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
389 * visit_reachable will eventually move gc back into
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
390 * young if that's so, and we'll see it again.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
391 */
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
392 next = gc->gc.gc_next;
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
393 gc_list_move(gc, unreachable);
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
394 gc->gc.gc_refs = GC_TENTATIVELY_UNREACHABLE;
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
395 }
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
396 gc = next;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
397 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
398 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
399
44265
2c6fe2dcc88e Minor cleanup in the gc module.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44099
diff changeset
400 /* Return true if object has a finalization method. */
20818
9aded6235d89 Add has_finalizer predictate function. Use it when deciding which
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20810
diff changeset
401 static int
9aded6235d89 Add has_finalizer predictate function. Use it when deciding which
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20810
diff changeset
402 has_finalizer(PyObject *op)
9aded6235d89 Add has_finalizer predictate function. Use it when deciding which
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20810
diff changeset
403 {
39536
8f5b9982beba Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents: 38453
diff changeset
404 if (PyGen_CheckExact(op))
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
405 return PyGen_NeedsFinalizing((PyGenObject *)op);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
406 else
39620
3982475c5144 Fix test_gc failure by fixing the bug test_gc found: __del__ methods were no
Thomas Wouters <thomas@python.org>
parents: 39536
diff changeset
407 return op->ob_type->tp_del != NULL;
20818
9aded6235d89 Add has_finalizer predictate function. Use it when deciding which
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20810
diff changeset
408 }
9aded6235d89 Add has_finalizer predictate function. Use it when deciding which
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20810
diff changeset
409
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
410 /* Move the objects in unreachable with __del__ methods into `finalizers`.
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
411 * Objects moved into `finalizers` have gc_refs set to GC_REACHABLE; the
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
412 * objects remaining in unreachable are left at GC_TENTATIVELY_UNREACHABLE.
28504
cb5db5561cdc Fix Tim's boom example.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28498
diff changeset
413 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
414 static void
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
415 move_finalizers(PyGC_Head *unreachable, PyGC_Head *finalizers)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
416 {
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
417 PyGC_Head *gc;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
418 PyGC_Head *next;
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
419
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
420 /* March over unreachable. Move objects with finalizers into
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
421 * `finalizers`.
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
422 */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
423 for (gc = unreachable->gc.gc_next; gc != unreachable; gc = next) {
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
424 PyObject *op = FROM_GC(gc);
28504
cb5db5561cdc Fix Tim's boom example.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28498
diff changeset
425
28510
0de0ded19968 move_finalizers(): Rewrote. It's not necessary for this routine
Tim Peters <tim.peters@gmail.com>
parents: 28508
diff changeset
426 assert(IS_TENTATIVELY_UNREACHABLE(op));
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
427 next = gc->gc.gc_next;
28510
0de0ded19968 move_finalizers(): Rewrote. It's not necessary for this routine
Tim Peters <tim.peters@gmail.com>
parents: 28508
diff changeset
428
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
429 if (has_finalizer(op)) {
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
430 gc_list_move(gc, finalizers);
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
431 gc->gc.gc_refs = GC_REACHABLE;
28504
cb5db5561cdc Fix Tim's boom example.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28498
diff changeset
432 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
433 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
434 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
435
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
436 /* A traversal callback for move_finalizer_reachable. */
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
437 static int
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
438 visit_move(PyObject *op, PyGC_Head *tolist)
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
439 {
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
440 if (PyObject_IS_GC(op)) {
24077
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
441 if (IS_TENTATIVELY_UNREACHABLE(op)) {
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
442 PyGC_Head *gc = AS_GC(op);
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
443 gc_list_move(gc, tolist);
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
444 gc->gc.gc_refs = GC_REACHABLE;
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
445 }
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
446 }
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
447 return 0;
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
448 }
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
449
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
450 /* Move objects that are reachable from finalizers, from the unreachable set
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
451 * into finalizers set.
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
452 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
453 static void
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
454 move_finalizer_reachable(PyGC_Head *finalizers)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
455 {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
456 traverseproc traverse;
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
457 PyGC_Head *gc = finalizers->gc.gc_next;
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
458 for (; gc != finalizers; gc = gc->gc.gc_next) {
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
459 /* Note that the finalizers list may grow during this. */
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: 44265
diff changeset
460 traverse = Py_TYPE(FROM_GC(gc))->tp_traverse;
24072
86b3760d285d SF bug #574132: Major GC related performance regression
Tim Peters <tim.peters@gmail.com>
parents: 24036
diff changeset
461 (void) traverse(FROM_GC(gc),
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
462 (visitproc)visit_move,
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
463 (void *)finalizers);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
464 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
465 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
466
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
467 /* Clear all weakrefs to unreachable objects, and if such a weakref has a
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
468 * callback, invoke it if necessary. Note that it's possible for such
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
469 * weakrefs to be outside the unreachable set -- indeed, those are precisely
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
470 * the weakrefs whose callbacks must be invoked. See gc_weakref.txt for
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
471 * overview & some details. Some weakrefs with callbacks may be reclaimed
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
472 * directly by this routine; the number reclaimed is the return value. Other
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
473 * weakrefs with callbacks may be moved into the `old` generation. Objects
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
474 * moved into `old` have gc_refs set to GC_REACHABLE; the objects remaining in
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
475 * unreachable are left at GC_TENTATIVELY_UNREACHABLE. When this returns,
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
476 * no object in `unreachable` is weakly referenced anymore.
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
477 */
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
478 static int
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
479 handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
480 {
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
481 PyGC_Head *gc;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
482 PyObject *op; /* generally FROM_GC(gc) */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
483 PyWeakReference *wr; /* generally a cast of op */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
484 PyGC_Head wrcb_to_call; /* weakrefs with callbacks to call */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
485 PyGC_Head *next;
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
486 int num_freed = 0;
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
487
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
488 gc_list_init(&wrcb_to_call);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
489
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
490 /* Clear all weakrefs to the objects in unreachable. If such a weakref
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
491 * also has a callback, move it into `wrcb_to_call` if the callback
33867
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
492 * needs to be invoked. Note that we cannot invoke any callbacks until
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
493 * all weakrefs to unreachable objects are cleared, lest the callback
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
494 * resurrect an unreachable object via a still-active weakref. We
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
495 * make another pass over wrcb_to_call, invoking callbacks, after this
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
496 * pass completes.
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
497 */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
498 for (gc = unreachable->gc.gc_next; gc != unreachable; gc = next) {
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
499 PyWeakReference **wrlist;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
500
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
501 op = FROM_GC(gc);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
502 assert(IS_TENTATIVELY_UNREACHABLE(op));
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
503 next = gc->gc.gc_next;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
504
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: 44265
diff changeset
505 if (! PyType_SUPPORTS_WEAKREFS(Py_TYPE(op)))
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
506 continue;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
507
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
508 /* It supports weakrefs. Does it have any? */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
509 wrlist = (PyWeakReference **)
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
510 PyObject_GET_WEAKREFS_LISTPTR(op);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
511
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
512 /* `op` may have some weakrefs. March over the list, clear
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
513 * all the weakrefs, and move the weakrefs with callbacks
33867
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
514 * that must be called into wrcb_to_call.
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
515 */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
516 for (wr = *wrlist; wr != NULL; wr = *wrlist) {
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
517 PyGC_Head *wrasgc; /* AS_GC(wr) */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
518
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
519 /* _PyWeakref_ClearRef clears the weakref but leaves
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
520 * the callback pointer intact. Obscure: it also
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
521 * changes *wrlist.
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
522 */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
523 assert(wr->wr_object == op);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
524 _PyWeakref_ClearRef(wr);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
525 assert(wr->wr_object == Py_None);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
526 if (wr->wr_callback == NULL)
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
527 continue; /* no callback */
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
528
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
529 /* Headache time. `op` is going away, and is weakly referenced by
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
530 * `wr`, which has a callback. Should the callback be invoked? If wr
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
531 * is also trash, no:
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
532 *
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
533 * 1. There's no need to call it. The object and the weakref are
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
534 * both going away, so it's legitimate to pretend the weakref is
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
535 * going away first. The user has to ensure a weakref outlives its
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
536 * referent if they want a guarantee that the wr callback will get
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
537 * invoked.
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
538 *
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
539 * 2. It may be catastrophic to call it. If the callback is also in
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
540 * cyclic trash (CT), then although the CT is unreachable from
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
541 * outside the current generation, CT may be reachable from the
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
542 * callback. Then the callback could resurrect insane objects.
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
543 *
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
544 * Since the callback is never needed and may be unsafe in this case,
33867
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
545 * wr is simply left in the unreachable set. Note that because we
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
546 * already called _PyWeakref_ClearRef(wr), its callback will never
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
547 * trigger.
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
548 *
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
549 * OTOH, if wr isn't part of CT, we should invoke the callback: the
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
550 * weakref outlived the trash. Note that since wr isn't CT in this
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
551 * case, its callback can't be CT either -- wr acted as an external
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
552 * root to this generation, and therefore its callback did too. So
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
553 * nothing in CT is reachable from the callback either, so it's hard
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
554 * to imagine how calling it later could create a problem for us. wr
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
555 * is moved to wrcb_to_call in this case.
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
556 */
33867
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
557 if (IS_TENTATIVELY_UNREACHABLE(wr))
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
558 continue;
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
559 assert(IS_REACHABLE(wr));
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
560
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
561 /* Create a new reference so that wr can't go away
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
562 * before we can process it again.
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
563 */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
564 Py_INCREF(wr);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
565
33867
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
566 /* Move wr to wrcb_to_call, for the next pass. */
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
567 wrasgc = AS_GC(wr);
33867
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
568 assert(wrasgc != next); /* wrasgc is reachable, but
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
569 next isn't, so they can't
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
570 be the same */
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
571 gc_list_move(wrasgc, &wrcb_to_call);
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
572 }
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
573 }
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
574
33867
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
575 /* Invoke the callbacks we decided to honor. It's safe to invoke them
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
576 * because they can't reference unreachable objects.
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
577 */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
578 while (! gc_list_is_empty(&wrcb_to_call)) {
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
579 PyObject *temp;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
580 PyObject *callback;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
581
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
582 gc = wrcb_to_call.gc.gc_next;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
583 op = FROM_GC(gc);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
584 assert(IS_REACHABLE(op));
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
585 assert(PyWeakref_Check(op));
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
586 wr = (PyWeakReference *)op;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
587 callback = wr->wr_callback;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
588 assert(callback != NULL);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
589
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
590 /* copy-paste of weakrefobject.c's handle_callback() */
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
591 temp = PyObject_CallFunctionObjArgs(callback, wr, NULL);
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
592 if (temp == NULL)
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
593 PyErr_WriteUnraisable(callback);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
594 else
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
595 Py_DECREF(temp);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
596
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
597 /* Give up the reference we created in the first pass. When
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
598 * op's refcount hits 0 (which it may or may not do right now),
33867
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
599 * op's tp_dealloc will decref op->wr_callback too. Note
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
600 * that the refcount probably will hit 0 now, and because this
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
601 * weakref was reachable to begin with, gc didn't already
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
602 * add it to its count of freed objects. Example: a reachable
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
603 * weak value dict maps some key to this reachable weakref.
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
604 * The callback removes this key->weakref mapping from the
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
605 * dict, leaving no other references to the weakref (excepting
07d94a162cf8 handle_weakrefs(): Simplification -- there's no need to make a second
Tim Peters <tim.peters@gmail.com>
parents: 33862
diff changeset
606 * ours).
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
607 */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
608 Py_DECREF(op);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
609 if (wrcb_to_call.gc.gc_next == gc) {
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
610 /* object is still alive -- move it */
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
611 gc_list_move(gc, old);
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
612 }
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
613 else
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
614 ++num_freed;
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
615 }
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
616
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
617 return num_freed;
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
618 }
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
619
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
620 static void
14294
053627e7ac14 apply patch #101362 by Vladimir Marangozov
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13878
diff changeset
621 debug_cycle(char *msg, PyObject *op)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
622 {
44265
2c6fe2dcc88e Minor cleanup in the gc module.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44099
diff changeset
623 PySys_WriteStderr("gc: %.100s <%.100s %p>\n",
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: 44265
diff changeset
624 msg, Py_TYPE(op)->tp_name, op);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
625 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
626
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
627 /* Handle uncollectable garbage (cycles with finalizers, and stuff reachable
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
628 * only from such cycles).
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
629 * If DEBUG_SAVEALL, all objects in finalizers are appended to the module
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
630 * garbage list (a Python list), else only the objects in finalizers with
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
631 * __del__ methods are appended to garbage. All objects in finalizers are
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
632 * merged into the old list regardless.
28515
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
633 * Returns 0 if all OK, <0 on error (out of memory to grow the garbage list).
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
634 * The finalizers list is made empty on a successful return.
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
635 */
28515
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
636 static int
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
637 handle_finalizers(PyGC_Head *finalizers, PyGC_Head *old)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
638 {
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
639 PyGC_Head *gc = finalizers->gc.gc_next;
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
640
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
641 if (garbage == NULL) {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
642 garbage = PyList_New(0);
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
643 if (garbage == NULL)
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
644 Py_FatalError("gc couldn't create gc.garbage list");
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
645 }
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
646 for (; gc != finalizers; gc = gc->gc.gc_next) {
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
647 PyObject *op = FROM_GC(gc);
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
648
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
649 if ((debug & DEBUG_SAVEALL) || has_finalizer(op)) {
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
650 if (PyList_Append(garbage, op) < 0)
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
651 return -1;
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
652 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
653 }
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
654
28515
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
655 gc_list_merge(finalizers, old);
4c596dd60c22 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
Tim Peters <tim.peters@gmail.com>
parents: 28512
diff changeset
656 return 0;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
657 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
658
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
659 /* Break reference cycles by clearing the containers involved. This is
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
660 * tricky business as the lists can be changing and we don't know which
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
661 * objects may be freed. It is possible I screwed something up here.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
662 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
663 static void
28504
cb5db5561cdc Fix Tim's boom example.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28498
diff changeset
664 delete_garbage(PyGC_Head *collectable, PyGC_Head *old)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
665 {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
666 inquiry clear;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
667
28504
cb5db5561cdc Fix Tim's boom example.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28498
diff changeset
668 while (!gc_list_is_empty(collectable)) {
cb5db5561cdc Fix Tim's boom example.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28498
diff changeset
669 PyGC_Head *gc = collectable->gc.gc_next;
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
670 PyObject *op = FROM_GC(gc);
24072
86b3760d285d SF bug #574132: Major GC related performance regression
Tim Peters <tim.peters@gmail.com>
parents: 24036
diff changeset
671
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
672 assert(IS_TENTATIVELY_UNREACHABLE(op));
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
673 if (debug & DEBUG_SAVEALL) {
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
674 PyList_Append(garbage, op);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
675 }
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
676 else {
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: 44265
diff changeset
677 if ((clear = Py_TYPE(op)->tp_clear) != NULL) {
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
678 Py_INCREF(op);
23721
48e937e1b3fe Remove casts to PyObject * when declaration is for PyObject *
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23495
diff changeset
679 clear(op);
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
680 Py_DECREF(op);
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
681 }
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
682 }
28504
cb5db5561cdc Fix Tim's boom example.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28498
diff changeset
683 if (collectable->gc.gc_next == gc) {
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
684 /* object is still alive, move it, it may die later */
33869
223d20afc8b5 gc list function cleanup.
Tim Peters <tim.peters@gmail.com>
parents: 33867
diff changeset
685 gc_list_move(gc, old);
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
686 gc->gc.gc_refs = GC_REACHABLE;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
687 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
688 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
689 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
690
45371
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
691 /* Clear all free lists
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
692 * All free lists are cleared during the collection of the highest generation.
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
693 * Allocated items in the free list may keep a pymalloc arena occupied.
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
694 * Clearing the free lists may give back memory to the OS earlier.
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
695 */
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
696 static void
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
697 clear_freelists(void)
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
698 {
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
699 (void)PyMethod_ClearFreeList();
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
700 (void)PyFrame_ClearFreeList();
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
701 (void)PyCFunction_ClearFreeList();
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
702 (void)PyTuple_ClearFreeList();
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
703 (void)PyUnicode_ClearFreeList();
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
704 }
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
705
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
706 /* This is the main function. Read this to understand how the
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
707 * collection process works. */
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
708 static Py_ssize_t
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
709 collect(int generation)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
710 {
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
711 int i;
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
712 Py_ssize_t m = 0; /* # objects collected */
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
713 Py_ssize_t n = 0; /* # unreachable objects that couldn't be collected */
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
714 PyGC_Head *young; /* the generation we are examining */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
715 PyGC_Head *old; /* next older generation */
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
716 PyGC_Head unreachable; /* non-problematic unreachable trash */
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
717 PyGC_Head finalizers; /* objects with, & reachable from, __del__ */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
718 PyGC_Head *gc;
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
719 double t1 = 0.0;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
720
28507
a0503bdb0c24 Fixed new seemingly random segfaults, by moving the initialization of
Tim Peters <tim.peters@gmail.com>
parents: 28504
diff changeset
721 if (delstr == NULL) {
42013
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 40450
diff changeset
722 delstr = PyUnicode_InternFromString("__del__");
28507
a0503bdb0c24 Fixed new seemingly random segfaults, by moving the initialization of
Tim Peters <tim.peters@gmail.com>
parents: 28504
diff changeset
723 if (delstr == NULL)
a0503bdb0c24 Fixed new seemingly random segfaults, by moving the initialization of
Tim Peters <tim.peters@gmail.com>
parents: 28504
diff changeset
724 Py_FatalError("gc couldn't allocate \"__del__\"");
a0503bdb0c24 Fixed new seemingly random segfaults, by moving the initialization of
Tim Peters <tim.peters@gmail.com>
parents: 28504
diff changeset
725 }
a0503bdb0c24 Fixed new seemingly random segfaults, by moving the initialization of
Tim Peters <tim.peters@gmail.com>
parents: 28504
diff changeset
726
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
727 if (debug & DEBUG_STATS) {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
728 if (tmod != NULL) {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
729 PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
730 if (f == NULL) {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
731 PyErr_Clear();
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
732 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
733 else {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
734 t1 = PyFloat_AsDouble(f);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
735 Py_DECREF(f);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
736 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
737 }
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
738 PySys_WriteStderr("gc: collecting generation %d...\n",
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
739 generation);
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
740 PySys_WriteStderr("gc: objects in each generation:");
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
741 for (i = 0; i < NUM_GENERATIONS; i++)
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
742 PySys_WriteStderr(" %" PY_FORMAT_SIZE_T "d",
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
743 gc_list_size(GEN_HEAD(i)));
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
744 PySys_WriteStderr("\n");
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
745 }
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
746
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
747 /* update collection and allocation counters */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
748 if (generation+1 < NUM_GENERATIONS)
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
749 generations[generation+1].count += 1;
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
750 for (i = 0; i <= generation; i++)
24036
eae496efa460 Fix small bug. The count of objects in all generations younger then the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23832
diff changeset
751 generations[i].count = 0;
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
752
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
753 /* merge younger generations with one we are currently collecting */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
754 for (i = 0; i < generation; i++) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
755 gc_list_merge(GEN_HEAD(i), GEN_HEAD(generation));
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
756 }
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
757
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
758 /* handy references */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
759 young = GEN_HEAD(generation);
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
760 if (generation < NUM_GENERATIONS-1)
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
761 old = GEN_HEAD(generation+1);
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
762 else
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
763 old = young;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
764
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
765 /* Using ob_refcnt and gc_refs, calculate which objects in the
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
766 * container set are reachable from outside the set (i.e., have a
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
767 * refcount greater than 0 when all the references within the
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
768 * set are taken into account).
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
769 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
770 update_refs(young);
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
771 subtract_refs(young);
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
772
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
773 /* Leave everything reachable from outside young in young, and move
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
774 * everything else (in young) to unreachable.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
775 * NOTE: This used to move the reachable objects into a reachable
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
776 * set instead. But most things usually turn out to be reachable,
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
777 * so it's more efficient to move the unreachable things.
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
778 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
779 gc_list_init(&unreachable);
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
780 move_unreachable(young, &unreachable);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
781
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
782 /* Move reachable objects to next generation. */
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
783 if (young != old)
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
784 gc_list_merge(young, old);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
785
24075
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
786 /* All objects in unreachable are trash, but objects reachable from
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
787 * finalizers can't safely be deleted. Python programmers should take
32db075def3f OK, I couldn't stand it <0.5 wink>: removed all uncertainty about what's
Tim Peters <tim.peters@gmail.com>
parents: 24074
diff changeset
788 * care not to create such things. For Python, finalizers means
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
789 * instance objects with __del__ methods. Weakrefs with callbacks
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
790 * can also call arbitrary Python code but they will be dealt with by
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
791 * handle_weakrefs().
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
792 */
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
793 gc_list_init(&finalizers);
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
794 move_finalizers(&unreachable, &finalizers);
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
795 /* finalizers contains the unreachable objects with a finalizer;
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
796 * unreachable objects reachable *from* those are also uncollectable,
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
797 * and we move those into the finalizers list too.
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
798 */
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
799 move_finalizer_reachable(&finalizers);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
800
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
801 /* Collect statistics on collectable objects found and print
30988
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
802 * debugging information.
caa1a48da4cc SF bug 839548: Bug in type's GC handling causes segfaults.
Tim Peters <tim.peters@gmail.com>
parents: 30918
diff changeset
803 */
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
804 for (gc = unreachable.gc.gc_next; gc != &unreachable;
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
805 gc = gc->gc.gc_next) {
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
806 m++;
14294
053627e7ac14 apply patch #101362 by Vladimir Marangozov
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13878
diff changeset
807 if (debug & DEBUG_COLLECTABLE) {
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
808 debug_cycle("collectable", FROM_GC(gc));
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
809 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
810 if (tmod != NULL && (debug & DEBUG_STATS)) {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
811 PyObject *f = PyObject_CallMethod(tmod, "time", NULL);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
812 if (f == NULL) {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
813 PyErr_Clear();
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
814 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
815 else {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
816 t1 = PyFloat_AsDouble(f)-t1;
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
817 Py_DECREF(f);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
818 PySys_WriteStderr("gc: %.4fs elapsed.\n", t1);
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
819 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
820 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
821 }
33862
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
822
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
823 /* Clear weakrefs and invoke callbacks as necessary. */
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
824 m += handle_weakrefs(&unreachable, old);
facb5a2f4b53 SF 1055820: weakref callback vs gc vs threads
Tim Peters <tim.peters@gmail.com>
parents: 31341
diff changeset
825
28521
964bd97ac1f5 Comment repair; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 28520
diff changeset
826 /* Call tp_clear on objects in the unreachable set. This will cause
964bd97ac1f5 Comment repair; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 28520
diff changeset
827 * the reference cycles to be broken. It may also cause some objects
964bd97ac1f5 Comment repair; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 28520
diff changeset
828 * in finalizers to be freed.
964bd97ac1f5 Comment repair; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 28520
diff changeset
829 */
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
830 delete_garbage(&unreachable, old);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
831
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
832 /* Collect statistics on uncollectable objects found and print
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
833 * debugging information. */
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
834 for (gc = finalizers.gc.gc_next;
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
835 gc != &finalizers;
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
836 gc = gc->gc.gc_next) {
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
837 n++;
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
838 if (debug & DEBUG_UNCOLLECTABLE)
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
839 debug_cycle("uncollectable", FROM_GC(gc));
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
840 }
14294
053627e7ac14 apply patch #101362 by Vladimir Marangozov
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13878
diff changeset
841 if (debug & DEBUG_STATS) {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
842 if (m == 0 && n == 0)
14294
053627e7ac14 apply patch #101362 by Vladimir Marangozov
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13878
diff changeset
843 PySys_WriteStderr("gc: done.\n");
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
844 else
36860
8ebf7997c6cd Fix warnings on x86 (32-bit) and support Win64.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36839
diff changeset
845 PySys_WriteStderr(
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
846 "gc: done, "
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
847 "%" PY_FORMAT_SIZE_T "d unreachable, "
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
848 "%" PY_FORMAT_SIZE_T "d uncollectable.\n",
36860
8ebf7997c6cd Fix warnings on x86 (32-bit) and support Win64.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36839
diff changeset
849 n+m, n);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
850 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
851
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
852 /* Append instances in the uncollectable set to a Python
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
853 * reachable list of garbage. The programmer has to deal with
28511
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
854 * this if they insist on creating this type of structure.
acf3596fcc28 Reworked move_finalizer_reachable() to create two distinct lists:
Tim Peters <tim.peters@gmail.com>
parents: 28510
diff changeset
855 */
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
856 (void)handle_finalizers(&finalizers, old);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
857
45371
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
858 /* Clear free list only during the collection of the higest
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
859 * generation */
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
860 if (generation == NUM_GENERATIONS-1) {
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
861 clear_freelists();
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
862 }
7c4c46342137 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
863
14330
6dee1985c681 refactor __del__ exception handler into PyErr_WriteUnraisable
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14294
diff changeset
864 if (PyErr_Occurred()) {
28520
6653a56002ef Reworked has_finalizer() to use the new _PyObject_Lookup() instead
Tim Peters <tim.peters@gmail.com>
parents: 28516
diff changeset
865 if (gc_str == NULL)
42750
ce52cd71a8d9 Convert a bunch of constant strings in C to unicode.
Neal Norwitz <nnorwitz@gmail.com>
parents: 42334
diff changeset
866 gc_str = PyUnicode_FromString("garbage collection");
14330
6dee1985c681 refactor __del__ exception handler into PyErr_WriteUnraisable
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14294
diff changeset
867 PyErr_WriteUnraisable(gc_str);
6dee1985c681 refactor __del__ exception handler into PyErr_WriteUnraisable
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14294
diff changeset
868 Py_FatalError("unexpected exception during garbage collection");
6dee1985c681 refactor __del__ exception handler into PyErr_WriteUnraisable
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14294
diff changeset
869 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
870 return n+m;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
871 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
872
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
873 static Py_ssize_t
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
874 collect_generations(void)
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
875 {
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
876 int i;
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
877 Py_ssize_t n = 0;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
878
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
879 /* Find the oldest generation (higest numbered) where the count
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
880 * exceeds the threshold. Objects in the that generation and
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
881 * generations younger than it will be collected. */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
882 for (i = NUM_GENERATIONS-1; i >= 0; i--) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
883 if (generations[i].count > generations[i].threshold) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
884 n = collect(i);
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
885 break;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
886 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
887 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
888 return n;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
889 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
890
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
891 PyDoc_STRVAR(gc_enable__doc__,
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
892 "enable() -> None\n"
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
893 "\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
894 "Enable automatic garbage collection.\n");
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
895
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
896 static PyObject *
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
897 gc_enable(PyObject *self, PyObject *noargs)
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
898 {
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
899 enabled = 1;
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
900 Py_INCREF(Py_None);
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
901 return Py_None;
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
902 }
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
903
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
904 PyDoc_STRVAR(gc_disable__doc__,
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
905 "disable() -> None\n"
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
906 "\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
907 "Disable automatic garbage collection.\n");
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
908
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
909 static PyObject *
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
910 gc_disable(PyObject *self, PyObject *noargs)
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
911 {
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
912 enabled = 0;
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
913 Py_INCREF(Py_None);
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
914 return Py_None;
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
915 }
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
916
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
917 PyDoc_STRVAR(gc_isenabled__doc__,
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
918 "isenabled() -> status\n"
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
919 "\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
920 "Returns true if automatic garbage collection is enabled.\n");
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
921
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
922 static PyObject *
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
923 gc_isenabled(PyObject *self, PyObject *noargs)
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
924 {
31341
4915fbec608f Convert return value to boolean.
Raymond Hettinger <python@rcn.com>
parents: 31010
diff changeset
925 return PyBool_FromLong((long)enabled);
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
926 }
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
927
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
928 PyDoc_STRVAR(gc_collect__doc__,
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
929 "collect([generation]) -> n\n"
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
930 "\n"
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
931 "With no arguments, run a full collection. The optional argument\n"
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
932 "may be an integer specifying which generation to collect. A ValueError\n"
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
933 "is raised if the generation number is invalid.\n\n"
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
934 "The number of unreachable objects is returned.\n");
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
935
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
936 static PyObject *
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
937 gc_collect(PyObject *self, PyObject *args, PyObject *kws)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
938 {
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
939 static char *keywords[] = {"generation", NULL};
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
940 int genarg = NUM_GENERATIONS - 1;
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
941 Py_ssize_t n;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
942
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
943 if (!PyArg_ParseTupleAndKeywords(args, kws, "|i", keywords, &genarg))
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
944 return NULL;
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
945
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
946 else if (genarg < 0 || genarg >= NUM_GENERATIONS) {
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
947 PyErr_SetString(PyExc_ValueError, "invalid generation");
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
948 return NULL;
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
949 }
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
950
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
951 if (collecting)
20796
9c23abab962d Make the gc.collect() function respect the collection lock. This fixes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20393
diff changeset
952 n = 0; /* already collecting, don't do anything */
9c23abab962d Make the gc.collect() function respect the collection lock. This fixes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20393
diff changeset
953 else {
9c23abab962d Make the gc.collect() function respect the collection lock. This fixes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20393
diff changeset
954 collecting = 1;
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
955 n = collect(genarg);
20796
9c23abab962d Make the gc.collect() function respect the collection lock. This fixes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20393
diff changeset
956 collecting = 0;
9c23abab962d Make the gc.collect() function respect the collection lock. This fixes
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 20393
diff changeset
957 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
958
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42750
diff changeset
959 return PyLong_FromSsize_t(n);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
960 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
961
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
962 PyDoc_STRVAR(gc_set_debug__doc__,
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
963 "set_debug(flags) -> None\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
964 "\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
965 "Set the garbage collection debugging flags. Debugging information is\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
966 "written to sys.stderr.\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
967 "\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
968 "flags is an integer and can have the following bits turned on:\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
969 "\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
970 " DEBUG_STATS - Print statistics during collection.\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
971 " DEBUG_COLLECTABLE - Print collectable objects found.\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
972 " DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects found.\n"
14756
6e9331e68a3b - Add DEBUG_SAVEALL option. When enabled all garbage objects found by the
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14424
diff changeset
973 " DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
974 " DEBUG_LEAK - Debug leaking programs (everything but STATS).\n");
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
975
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
976 static PyObject *
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
977 gc_set_debug(PyObject *self, PyObject *args)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
978 {
14774
52174b002f1f Fix some long/"l" int/"i" mismatches. Fixes bug #113779.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14756
diff changeset
979 if (!PyArg_ParseTuple(args, "i:set_debug", &debug))
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
980 return NULL;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
981
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
982 Py_INCREF(Py_None);
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
983 return Py_None;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
984 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
985
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
986 PyDoc_STRVAR(gc_get_debug__doc__,
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
987 "get_debug() -> flags\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
988 "\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
989 "Get the garbage collection debugging flags.\n");
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
990
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
991 static PyObject *
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
992 gc_get_debug(PyObject *self, PyObject *noargs)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
993 {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
994 return Py_BuildValue("i", debug);
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
995 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
996
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
997 PyDoc_STRVAR(gc_set_thresh__doc__,
21833
070d392042e3 Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21139
diff changeset
998 "set_threshold(threshold0, [threshold1, threshold2]) -> None\n"
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
999 "\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1000 "Sets the collection thresholds. Setting threshold0 to zero disables\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
1001 "collection.\n");
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1002
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1003 static PyObject *
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
1004 gc_set_thresh(PyObject *self, PyObject *args)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1005 {
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1006 int i;
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1007 if (!PyArg_ParseTuple(args, "i|ii:set_threshold",
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1008 &generations[0].threshold,
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1009 &generations[1].threshold,
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1010 &generations[2].threshold))
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1011 return NULL;
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1012 for (i = 2; i < NUM_GENERATIONS; i++) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1013 /* generations higher than 2 get the same threshold */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1014 generations[i].threshold = generations[2].threshold;
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1015 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1016
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1017 Py_INCREF(Py_None);
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1018 return Py_None;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1019 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1020
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
1021 PyDoc_STRVAR(gc_get_thresh__doc__,
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1022 "get_threshold() -> (threshold0, threshold1, threshold2)\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1023 "\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
1024 "Return the current collection thresholds\n");
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1025
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1026 static PyObject *
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1027 gc_get_thresh(PyObject *self, PyObject *noargs)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1028 {
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1029 return Py_BuildValue("(iii)",
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1030 generations[0].threshold,
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1031 generations[1].threshold,
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1032 generations[2].threshold);
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1033 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1034
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1035 PyDoc_STRVAR(gc_get_count__doc__,
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1036 "get_count() -> (count0, count1, count2)\n"
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1037 "\n"
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1038 "Return the current collection counts\n");
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1039
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1040 static PyObject *
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1041 gc_get_count(PyObject *self, PyObject *noargs)
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1042 {
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1043 return Py_BuildValue("(iii)",
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1044 generations[0].count,
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1045 generations[1].count,
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1046 generations[2].count);
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1047 }
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1048
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1049 static int
21038
afb789aada16 Rename get_referents to get_referrers. Fixes #483815.
Martin v. Löwis <martin@v.loewis.de>
parents: 20820
diff changeset
1050 referrersvisit(PyObject* obj, PyObject *objs)
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1051 {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
1052 Py_ssize_t i;
21105
d19513e2893c Use identity instead of equality when looking for referrers. Fixes #485781.
Martin v. Löwis <martin@v.loewis.de>
parents: 21038
diff changeset
1053 for (i = 0; i < PyTuple_GET_SIZE(objs); i++)
d19513e2893c Use identity instead of equality when looking for referrers. Fixes #485781.
Martin v. Löwis <martin@v.loewis.de>
parents: 21038
diff changeset
1054 if (PyTuple_GET_ITEM(objs, i) == obj)
d19513e2893c Use identity instead of equality when looking for referrers. Fixes #485781.
Martin v. Löwis <martin@v.loewis.de>
parents: 21038
diff changeset
1055 return 1;
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1056 return 0;
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1057 }
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1058
19128
4901a935490d Remove "referents" structure (it's not needed). Check return value
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19097
diff changeset
1059 static int
21038
afb789aada16 Rename get_referents to get_referrers. Fixes #483815.
Martin v. Löwis <martin@v.loewis.de>
parents: 20820
diff changeset
1060 gc_referrers_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist)
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1061 {
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1062 PyGC_Head *gc;
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1063 PyObject *obj;
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1064 traverseproc traverse;
20381
b4f829941f3d SF bug [#467145] Python 2.2a4 build problem on HPUX 11.0.
Tim Peters <tim.peters@gmail.com>
parents: 20296
diff changeset
1065 for (gc = list->gc.gc_next; gc != list; gc = gc->gc.gc_next) {
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1066 obj = FROM_GC(gc);
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: 44265
diff changeset
1067 traverse = Py_TYPE(obj)->tp_traverse;
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1068 if (obj == objs || obj == resultlist)
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1069 continue;
21038
afb789aada16 Rename get_referents to get_referrers. Fixes #483815.
Martin v. Löwis <martin@v.loewis.de>
parents: 20820
diff changeset
1070 if (traverse(obj, (visitproc)referrersvisit, objs)) {
19128
4901a935490d Remove "referents" structure (it's not needed). Check return value
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19097
diff changeset
1071 if (PyList_Append(resultlist, obj) < 0)
4901a935490d Remove "referents" structure (it's not needed). Check return value
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19097
diff changeset
1072 return 0; /* error */
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1073 }
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1074 }
19128
4901a935490d Remove "referents" structure (it's not needed). Check return value
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19097
diff changeset
1075 return 1; /* no error */
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1076 }
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1077
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
1078 PyDoc_STRVAR(gc_get_referrers__doc__,
21038
afb789aada16 Rename get_referents to get_referrers. Fixes #483815.
Martin v. Löwis <martin@v.loewis.de>
parents: 20820
diff changeset
1079 "get_referrers(*objs) -> list\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
1080 Return the list of objects that directly refer to any of objs.");
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1081
19128
4901a935490d Remove "referents" structure (it's not needed). Check return value
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19097
diff changeset
1082 static PyObject *
21038
afb789aada16 Rename get_referents to get_referrers. Fixes #483815.
Martin v. Löwis <martin@v.loewis.de>
parents: 20820
diff changeset
1083 gc_get_referrers(PyObject *self, PyObject *args)
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1084 {
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1085 int i;
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1086 PyObject *result = PyList_New(0);
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
1087 if (!result) return NULL;
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
1088
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1089 for (i = 0; i < NUM_GENERATIONS; i++) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1090 if (!(gc_referrers_for(args, GEN_HEAD(i), result))) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1091 Py_DECREF(result);
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1092 return NULL;
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1093 }
19128
4901a935490d Remove "referents" structure (it's not needed). Check return value
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19097
diff changeset
1094 }
19096
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1095 return result;
45ccf3b889b5 Add get_referents function. Closes SF patch #402925.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15013
diff changeset
1096 }
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1097
28522
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1098 /* Append obj to list; return true if error (out of memory), false if OK. */
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1099 static int
28523
c01fdc3a9180 s/referrents/referents/g. Gotta love that referrers remains rife with rs.
Tim Peters <tim.peters@gmail.com>
parents: 28522
diff changeset
1100 referentsvisit(PyObject *obj, PyObject *list)
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1101 {
28522
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1102 return PyList_Append(list, obj) < 0;
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1103 }
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1104
28523
c01fdc3a9180 s/referrents/referents/g. Gotta love that referrers remains rife with rs.
Tim Peters <tim.peters@gmail.com>
parents: 28522
diff changeset
1105 PyDoc_STRVAR(gc_get_referents__doc__,
c01fdc3a9180 s/referrents/referents/g. Gotta love that referrers remains rife with rs.
Tim Peters <tim.peters@gmail.com>
parents: 28522
diff changeset
1106 "get_referents(*objs) -> list\n\
28498
3e399a8618db Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28497
diff changeset
1107 Return the list of objects that are directly referred to by objs.");
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1108
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1109 static PyObject *
28523
c01fdc3a9180 s/referrents/referents/g. Gotta love that referrers remains rife with rs.
Tim Peters <tim.peters@gmail.com>
parents: 28522
diff changeset
1110 gc_get_referents(PyObject *self, PyObject *args)
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1111 {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
1112 Py_ssize_t i;
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1113 PyObject *result = PyList_New(0);
28522
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1114
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1115 if (result == NULL)
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1116 return NULL;
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1117
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1118 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
28522
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1119 traverseproc traverse;
28507
a0503bdb0c24 Fixed new seemingly random segfaults, by moving the initialization of
Tim Peters <tim.peters@gmail.com>
parents: 28504
diff changeset
1120 PyObject *obj = PyTuple_GET_ITEM(args, i);
28522
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1121
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1122 if (! PyObject_IS_GC(obj))
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1123 continue;
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: 44265
diff changeset
1124 traverse = Py_TYPE(obj)->tp_traverse;
28522
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1125 if (! traverse)
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1126 continue;
28523
c01fdc3a9180 s/referrents/referents/g. Gotta love that referrers remains rife with rs.
Tim Peters <tim.peters@gmail.com>
parents: 28522
diff changeset
1127 if (traverse(obj, (visitproc)referentsvisit, result)) {
28522
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1128 Py_DECREF(result);
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1129 return NULL;
28522
487df294d328 Finished implementing gc.get_referrents(): dealt with error and end
Tim Peters <tim.peters@gmail.com>
parents: 28521
diff changeset
1130 }
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1131 }
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1132 return result;
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1133 }
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1134
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
1135 PyDoc_STRVAR(gc_get_objects__doc__,
19097
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1136 "get_objects() -> [...]\n"
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1137 "\n"
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1138 "Return a list of objects tracked by the collector (excluding the list\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
1139 "returned).\n");
19097
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1140
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1141 static PyObject *
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1142 gc_get_objects(PyObject *self, PyObject *noargs)
19097
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1143 {
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1144 int i;
19097
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1145 PyObject* result;
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1146
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1147 result = PyList_New(0);
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1148 if (result == NULL)
19097
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1149 return NULL;
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1150 for (i = 0; i < NUM_GENERATIONS; i++) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1151 if (append_objects(result, GEN_HEAD(i))) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1152 Py_DECREF(result);
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1153 return NULL;
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1154 }
21130
6e34151aefe6 Patch #486743: remove bad INCREF, propagate exception in append_objects.
Martin v. Löwis <martin@v.loewis.de>
parents: 21105
diff changeset
1155 }
19097
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1156 return result;
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1157 }
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1158
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1159
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23721
diff changeset
1160 PyDoc_STRVAR(gc__doc__,
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1161 "This module provides access to the garbage collector for reference cycles.\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1162 "\n"
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
1163 "enable() -- Enable automatic garbage collection.\n"
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
1164 "disable() -- Disable automatic garbage collection.\n"
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
1165 "isenabled() -- Returns true if automatic collection is enabled.\n"
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1166 "collect() -- Do a full collection right now.\n"
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39620
diff changeset
1167 "get_count() -- Return the current collection counts.\n"
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1168 "set_debug() -- Set debugging flags.\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1169 "get_debug() -- Get debugging flags.\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1170 "set_threshold() -- Set the collection thresholds.\n"
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1171 "get_threshold() -- Return the current the collection thresholds.\n"
19097
9e6f7804ef14 Add get_objects function. This is a low level function (like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19096
diff changeset
1172 "get_objects() -- Return a list of all objects tracked by the collector.\n"
28497
40d9659b56c9 Add get_referrents() helper function.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 26138
diff changeset
1173 "get_referrers() -- Return the list of objects that refer to an object.\n"
28523
c01fdc3a9180 s/referrents/referents/g. Gotta love that referrers remains rife with rs.
Tim Peters <tim.peters@gmail.com>
parents: 28522
diff changeset
1174 "get_referents() -- Return the list of objects that an object refers to.\n");
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1175
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1176 static PyMethodDef GcMethods[] = {
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1177 {"enable", gc_enable, METH_NOARGS, gc_enable__doc__},
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1178 {"disable", gc_disable, METH_NOARGS, gc_disable__doc__},
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1179 {"isenabled", gc_isenabled, METH_NOARGS, gc_isenabled__doc__},
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
1180 {"set_debug", gc_set_debug, METH_VARARGS, gc_set_debug__doc__},
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1181 {"get_debug", gc_get_debug, METH_NOARGS, gc_get_debug__doc__},
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1182 {"get_count", gc_get_count, METH_NOARGS, gc_get_count__doc__},
13878
abfa4e4b2f3e Neil Schemenauer: GC enable(), disable(), isenabled() interface.
Vladimir Marangozov <vladimir.marangozov@t-online.de>
parents: 13570
diff changeset
1183 {"set_threshold", gc_set_thresh, METH_VARARGS, gc_set_thresh__doc__},
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1184 {"get_threshold", gc_get_thresh, METH_NOARGS, gc_get_thresh__doc__},
36863
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1185 {"collect", (PyCFunction)gc_collect,
2d24f3a37a1b SF patch #1443865; gc.get_count() added and optional argument 'generation'
Barry Warsaw <barry@python.org>
parents: 36860
diff changeset
1186 METH_VARARGS | METH_KEYWORDS, gc_collect__doc__},
28512
174ce4cdec47 Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
Tim Peters <tim.peters@gmail.com>
parents: 28511
diff changeset
1187 {"get_objects", gc_get_objects,METH_NOARGS, gc_get_objects__doc__},
21038
afb789aada16 Rename get_referents to get_referrers. Fixes #483815.
Martin v. Löwis <martin@v.loewis.de>
parents: 20820
diff changeset
1188 {"get_referrers", gc_get_referrers, METH_VARARGS,
afb789aada16 Rename get_referents to get_referrers. Fixes #483815.
Martin v. Löwis <martin@v.loewis.de>
parents: 20820
diff changeset
1189 gc_get_referrers__doc__},
28523
c01fdc3a9180 s/referrents/referents/g. Gotta love that referrers remains rife with rs.
Tim Peters <tim.peters@gmail.com>
parents: 28522
diff changeset
1190 {"get_referents", gc_get_referents, METH_VARARGS,
c01fdc3a9180 s/referrents/referents/g. Gotta love that referrers remains rife with rs.
Tim Peters <tim.peters@gmail.com>
parents: 28522
diff changeset
1191 gc_get_referents__doc__},
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1192 {NULL, NULL} /* Sentinel */
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1193 };
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1194
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1195 static struct PyModuleDef gcmodule = {
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1196 PyModuleDef_HEAD_INIT,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1197 "gc",
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1198 gc__doc__,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1199 -1,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1200 GcMethods,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1201 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1202 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1203 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1204 NULL
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1205 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1206
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1207
30311
f003e48f562d Bug #794140: cygwin builds do not embed
Jason Tishler <jason@tishler.net>
parents: 28651
diff changeset
1208 PyMODINIT_FUNC
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1209 PyInit_gc(void)
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1210 {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1211 PyObject *m;
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1212
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1213 m = PyModule_Create(&gcmodule);
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1214
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35298
diff changeset
1215 if (m == NULL)
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1216 return NULL;
28516
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1217
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1218 if (garbage == NULL) {
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1219 garbage = PyList_New(0);
28516
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1220 if (garbage == NULL)
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1221 return NULL;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1222 }
35103
234b22a2acf3 Add missing INCREF.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33876
diff changeset
1223 Py_INCREF(garbage);
28516
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1224 if (PyModule_AddObject(m, "garbage", garbage) < 0)
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1225 return NULL;
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1226
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1227 /* Importing can't be done in collect() because collect()
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1228 * can be called via PyGC_Collect() in Py_Finalize().
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1229 * This wouldn't be a problem, except that <initialized> is
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1230 * reset to 0 before calling collect which trips up
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1231 * the import and triggers an assertion.
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1232 */
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1233 if (tmod == NULL) {
44441
b91ca87e6f32 Merged revisions 59666-59679 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44351
diff changeset
1234 tmod = PyImport_ImportModuleNoBlock("time");
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1235 if (tmod == NULL)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1236 PyErr_Clear();
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1237 }
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
1238
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1239 #define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return NULL
28516
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1240 ADD_INT(DEBUG_STATS);
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1241 ADD_INT(DEBUG_COLLECTABLE);
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1242 ADD_INT(DEBUG_UNCOLLECTABLE);
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1243 ADD_INT(DEBUG_SAVEALL);
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1244 ADD_INT(DEBUG_LEAK);
78f846fb570a initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size.
Tim Peters <tim.peters@gmail.com>
parents: 28515
diff changeset
1245 #undef ADD_INT
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45371
diff changeset
1246 return m;
13183
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1247 }
54bffdddc0ef final patches from Neil Schemenauer for garbage collection
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1248
28651
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1249 /* API to invoke gc.collect() from C */
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
1250 Py_ssize_t
28651
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1251 PyGC_Collect(void)
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1252 {
36839
7c1aca8e3d7d Make PyGC_Collect() use Py_ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36769
diff changeset
1253 Py_ssize_t n;
28651
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1254
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1255 if (collecting)
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1256 n = 0; /* already collecting, don't do anything */
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1257 else {
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1258 collecting = 1;
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1259 n = collect(NUM_GENERATIONS - 1);
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1260 collecting = 0;
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1261 }
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1262
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1263 return n;
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1264 }
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1265
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1266 /* for debugging */
28651
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1267 void
7fda09f751ad - New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents: 28523
diff changeset
1268 _PyGC_Dump(PyGC_Head *g)
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1269 {
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1270 _PyObject_Dump(FROM_GC(g));
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1271 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1272
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1273 /* extension modules might be compiled with GC support so these
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1274 functions must always be available */
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1275
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1276 #undef PyObject_GC_Track
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1277 #undef PyObject_GC_UnTrack
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1278 #undef PyObject_GC_Del
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1279 #undef _PyObject_GC_Malloc
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1280
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1281 void
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1282 PyObject_GC_Track(void *op)
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1283 {
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1284 _PyObject_GC_TRACK(op);
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1285 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1286
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1287 /* for binary compatibility with 2.2 */
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1288 void
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1289 _PyObject_GC_Track(PyObject *op)
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1290 {
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1291 PyObject_GC_Track(op);
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1292 }
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1293
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1294 void
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1295 PyObject_GC_UnTrack(void *op)
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1296 {
24122
d332484e394a Trashcan cleanup: Now that cyclic gc is always there, the trashcan
Tim Peters <tim.peters@gmail.com>
parents: 24121
diff changeset
1297 /* Obscure: the Py_TRASHCAN mechanism requires that we be able to
d332484e394a Trashcan cleanup: Now that cyclic gc is always there, the trashcan
Tim Peters <tim.peters@gmail.com>
parents: 24121
diff changeset
1298 * call PyObject_GC_UnTrack twice on an object.
d332484e394a Trashcan cleanup: Now that cyclic gc is always there, the trashcan
Tim Peters <tim.peters@gmail.com>
parents: 24121
diff changeset
1299 */
23495
68e3f3dd4d48 Add IS_TRACKED and IS_MOVED macros. This makes the logic a little more clear.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23377
diff changeset
1300 if (IS_TRACKED(op))
22625
898c392477d9 This is Neil's fix for SF bug 535905 (Evil Trashcan and GC interaction).
Guido van Rossum <guido@python.org>
parents: 22449
diff changeset
1301 _PyObject_GC_UNTRACK(op);
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1302 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1303
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1304 /* for binary compatibility with 2.2 */
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1305 void
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1306 _PyObject_GC_UnTrack(PyObject *op)
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1307 {
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1308 PyObject_GC_UnTrack(op);
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1309 }
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1310
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1311 PyObject *
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1312 _PyObject_GC_Malloc(size_t basicsize)
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1313 {
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1314 PyObject *op;
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
1315 PyGC_Head *g = (PyGC_Head *)PyObject_MALLOC(
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
1316 sizeof(PyGC_Head) + basicsize);
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1317 if (g == NULL)
23721
48e937e1b3fe Remove casts to PyObject * when declaration is for PyObject *
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23495
diff changeset
1318 return PyErr_NoMemory();
24077
a5162fd65c3d Reserved another gc_refs value for untracked objects. Every live gc
Tim Peters <tim.peters@gmail.com>
parents: 24075
diff changeset
1319 g->gc.gc_refs = GC_UNTRACKED;
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1320 generations[0].count++; /* number of allocated GC objects */
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1321 if (generations[0].count > generations[0].threshold &&
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1322 enabled &&
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1323 generations[0].threshold &&
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1324 !collecting &&
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1325 !PyErr_Occurred()) {
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1326 collecting = 1;
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1327 collect_generations();
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1328 collecting = 0;
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1329 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1330 op = FROM_GC(g);
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1331 return op;
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1332 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1333
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1334 PyObject *
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1335 _PyObject_GC_New(PyTypeObject *tp)
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1336 {
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1337 PyObject *op = _PyObject_GC_Malloc(_PyObject_SIZE(tp));
23296
17cafe805f04 _PyObject_GC_New: Could call PyObject_INIT with a NULL 1st argument.
Tim Peters <tim.peters@gmail.com>
parents: 22972
diff changeset
1338 if (op != NULL)
17cafe805f04 _PyObject_GC_New: Could call PyObject_INIT with a NULL 1st argument.
Tim Peters <tim.peters@gmail.com>
parents: 22972
diff changeset
1339 op = PyObject_INIT(op, tp);
17cafe805f04 _PyObject_GC_New: Could call PyObject_INIT with a NULL 1st argument.
Tim Peters <tim.peters@gmail.com>
parents: 22972
diff changeset
1340 return op;
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1341 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1342
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1343 PyVarObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
1344 _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1345 {
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1346 const size_t size = _PyObject_VAR_SIZE(tp, nitems);
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1347 PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(size);
23296
17cafe805f04 _PyObject_GC_New: Could call PyObject_INIT with a NULL 1st argument.
Tim Peters <tim.peters@gmail.com>
parents: 22972
diff changeset
1348 if (op != NULL)
17cafe805f04 _PyObject_GC_New: Could call PyObject_INIT with a NULL 1st argument.
Tim Peters <tim.peters@gmail.com>
parents: 22972
diff changeset
1349 op = PyObject_INIT_VAR(op, tp, nitems);
17cafe805f04 _PyObject_GC_New: Could call PyObject_INIT with a NULL 1st argument.
Tim Peters <tim.peters@gmail.com>
parents: 22972
diff changeset
1350 return op;
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1351 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1352
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1353 PyVarObject *
36524
4c8606191c0c Change _PyObject_GC_Resize to expect Py_ssize_t.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
1354 _PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1355 {
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: 44265
diff changeset
1356 const size_t basicsize = _PyObject_VAR_SIZE(Py_TYPE(op), nitems);
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1357 PyGC_Head *g = AS_GC(op);
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 36863
diff changeset
1358 g = (PyGC_Head *)PyObject_REALLOC(g, sizeof(PyGC_Head) + basicsize);
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1359 if (g == NULL)
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1360 return (PyVarObject *)PyErr_NoMemory();
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1361 op = (PyVarObject *) FROM_GC(g);
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: 44265
diff changeset
1362 Py_SIZE(op) = nitems;
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1363 return op;
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1364 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1365
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1366 void
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1367 PyObject_GC_Del(void *op)
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1368 {
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1369 PyGC_Head *g = AS_GC(op);
23495
68e3f3dd4d48 Add IS_TRACKED and IS_MOVED macros. This makes the logic a little more clear.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23377
diff changeset
1370 if (IS_TRACKED(op))
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1371 gc_list_remove(g);
23377
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1372 if (generations[0].count > 0) {
2f7d869dad4d Move all data for a single generation into a structure. The set of
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 23296
diff changeset
1373 generations[0].count--;
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1374 }
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1375 PyObject_FREE(g);
19585
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1376 }
c43d7a8f00a4 Make more things internal to this file. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19128
diff changeset
1377
22972
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1378 /* for binary compatibility with 2.2 */
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1379 #undef _PyObject_GC_Del
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1380 void
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1381 _PyObject_GC_Del(PyObject *op)
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1382 {
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1383 PyObject_GC_Del(op);
95819f7f0bcd Allow PyObject_Del to be used as a function designator. Provide binary
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22648
diff changeset
1384 }