summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gc.py
Commit message (Collapse)AuthorAgeFilesLines
* SF 1055820: weakref callback vs gc vs threadsTim Peters2004-10-301-0/+199
| | | | | | | | In cyclic gc, clear weakrefs to unreachable objects before allowing any Python code (weakref callbacks or __del__ methods) to run. This is a critical bugfix, affecting all versions of Python since weakrefs were introduced. I'll backport to 2.3.
* New tests identical to boom and boom2, except using new-style classes.Tim Peters2003-04-081-0/+44
| | | | | | | These never failed in 2.3, and the tests confirm it. They still blow up in the 2.2 branch, despite that all the gc-vs-__del__ fixes from 2.3 have been backported (and this is expected -- 2.2 needs more work than 2.3 needed).
* s/referrents/referents/g. Gotta love that referrers remains rife with rs.Tim Peters2003-04-081-11/+11
|
* Finished implementing gc.get_referrents(): dealt with error and endTim Peters2003-04-081-1/+25
| | | | cases, wrote docs, added a test.
* Reworked has_finalizer() to use the new _PyObject_Lookup() insteadTim Peters2003-04-071-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of PyObject_HasAttr(); the former promises never to execute arbitrary Python code. Undid many of the changes recently made to worm around the worst consequences of that PyObject_HasAttr() could execute arbitrary Python code. Compatibility is hard to discuss, because the dangerous cases are so perverse, and much of this appears to rely on implementation accidents. To start with, using hasattr() to check for __del__ wasn't only dangerous, in some cases it was wrong: if an instance of an old- style class didn't have "__del__" in its instance dict or in any base class dict, but a getattr hook said __del__ existed, then hasattr() said "yes, this object has a __del__". But instance_dealloc() ignores the possibility of getattr hooks when looking for a __del__, so while object.__del__ succeeds, no __del__ method is called when the object is deleted. gc was therefore incorrect in believing that the object had a finalizer. The new method doesn't suffer that problem (like instance_dealloc(), _PyObject_Lookup() doesn't believe __del__ exists in that case), but does suffer a somewhat opposite-- and even more obscure --oddity: if an instance of an old-style class doesn't have "__del__" in its instance dict, and a base class does have "__del__" in its dict, and the first base class with a "__del__" associates it with a descriptor (an object with a __get__ method), *and* if that descriptor raises an exception when __get__ is called, then (a) the current method believes the instance does have a __del__, but (b) hasattr() does not believe the instance has a __del__. While these disagree, I believe the new method is "more correct": because the descriptor *will* be called when the object is destructed, it can execute arbitrary Python code at the time the object is destructed, and that's really what gc means by "has a finalizer": not specifically a __del__ method, but more generally the possibility of executing arbitrary Python code at object destruction time. Code in a descriptor's __get__() executed at destruction time can be just as problematic as code in a __del__() executed then. So I believe the new method is better on all counts. Bugfix candidate, but it's unclear to me how all this differs in the 2.2 branch (e.g., new-style and old-style classes already took different gc paths in 2.3 before this last round of patches, but don't in the 2.2 branch).
* Reworked move_finalizer_reachable() to create two distinct lists:Tim Peters2003-04-061-4/+32
| | | | | | | | | externally unreachable objects with finalizers, and externally unreachable objects without finalizers reachable from such objects. This allows us to call has_finalizer() at most once per object, and so limit the pain of nasty getattr hooks. This fixes the failing "boom 2" example Jeremy posted (a non-printing variant of which is now part of test_gc), via never triggering the nasty part of its __getattr__ method.
* test_boom: More comments. Also check that len(gc.garbage) doesn'tTim Peters2003-04-051-4/+9
| | | | | change (it would be another kind of bug if the trash cycle weren't reclaimed).
* Add Tim's gc boom test to the test suite.Jeremy Hylton2003-04-041-0/+19
|
* test_saveall(): Another small simplification; plus s/l/L/g.Tim Peters2002-08-111-10/+8
| | | | test_del(), test_del_newclass(): No need to use apply() in these.
* And one more simplification to test_saveall().Tim Peters2002-08-101-11/+10
|
* test_saveall(): Simplified a little, given that we only expect one itemTim Peters2002-08-101-6/+4
| | | | | in gc.garbage (so no need to loop looking for it -- it's there or it's not).
* If any trash happened to be sitting around waiting to get collected atTim Peters2002-08-101-1/+8
| | | | | the time it's called, test_saveall() made it look a leak, triggering bogus warnings from regrtest's -l (findleaks) mode.
* Test finalizers and GC from inside __del__ for new classes.Guido van Rossum2002-08-091-0/+41
|
* Get rid of relative imports in all unittests. Now anything thatBarry Warsaw2002-07-231-1/+1
| | | | | | | | | | | imports e.g. test_support must do so using an absolute package name such as "import test.test_support" or "from test import test_support". This also updates the README in Lib/test, and gets rid of the duplicate data dirctory in Lib/test/data (replaced by Lib/email/test/data). Now Tim and Jack can have at it. :)
* test_trashcan() and supporting class Ouch(): Jeremy noted that this testTim Peters2002-07-111-3/+9
| | | | | | | | | | | | | | takes much longer to run in the context of the test suite than when run in isolation. That's because it forces a large number of full collections, which take time proportional to the total number of gc'ed objects in the whole system. But since the dangerous implementation trickery that caused this test to fail in 2.0, 2.1 and 2.2 doesn't exist in 2.3 anymore (the trashcan mechanism stopped doing evil things when the possibility for compiling without cyclic gc was taken away), such an expensive test is no longer justified. This checkin leaves the test intact, but fiddles the constants to reduce the runtime by about a factor of 5.
* Whitespace nit.Guido van Rossum2002-06-131-1/+1
|
* Add a testcase to ensure that cycles going through the __class__ linkGuido van Rossum2002-06-121-0/+6
| | | | of a new-style instance are detected by the garbage collector.
* test_trashcan: reword obscure code.Tim Peters2002-03-281-1/+1
| | | | Bugfix candidate.
* New test_traschcan() test in test_gc, which reliably provokes segfaultsTim Peters2002-03-281-0/+29
| | | | | | under 2.0, 2.1 and 2.2. Bugfix candidate.
* Remove obsolete __static__/__dynamic__ distinction.Tim Peters2001-10-151-11/+3
|
* Enable GC for new-style instances. This touches lots of files, sinceGuido van Rossum2001-10-051-0/+19
| | | | | | | | | | | | | | | | | | | | | | many types were subclassable but had a xxx_dealloc function that called PyObject_DEL(self) directly instead of deferring to self->ob_type->tp_free(self). It is permissible to set tp_free in the type object directly to _PyObject_Del, for non-GC types, or to _PyObject_GC_Del, for GC types. Still, PyObject_DEL was a tad faster, so I'm fearing that our pystone rating is going down again. I'm not sure if doing something like void xxx_dealloc(PyObject *self) { if (PyXxxCheckExact(self)) PyObject_DEL(self); else self->ob_type->tp_free(self); } is any faster than always calling the else branch, so I haven't attempted that -- however those types whose own dealloc is fancier (int, float, unicode) do use this pattern.
* Add Garbage Collection support to new-style classes (not yet to theirGuido van Rossum2001-10-021-7/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | instances). Also added GC support to various auxiliary types: super, property, descriptors, wrappers, dictproxy. (Only type objects have a tp_clear field; the other types are.) One change was necessary to the GC infrastructure. We have statically allocated type objects that don't have a GC header (and can't easily be given one) and heap-allocated type objects that do have a GC header. Giving these different metatypes would be really ugly: I tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new invent a new name for the new metatype and make it a built-in, change affected tests... In short, a mess. So instead, we add a new type slot tp_is_gc, which is a simple Boolean function that determines whether a particular instance has GC headers or not. This slot is only relevant for types that have the (new) GC flag bit set. If the tp_is_gc slot is NULL (by far the most common case), all instances of the type are deemed to have GC headers. This slot is called by the PyObject_IS_GC() macro (which is only used twice, both times in gcmodule.c). I also changed the extern declarations for a bunch of GC-related functions (_PyObject_GC_Del etc.): these always exist but objimpl.h only declared them when WITH_CYCLE_GC was defined, but I needed to be able to reference them without #ifdefs. (When WITH_CYCLE_GC is not defined, they do the same as their non-GC counterparts anyway.)
* The error reporting here was a bit sparse. In verbose mode, the codeGuido van Rossum2001-10-021-30/+24
| | | | | | | | | | in run_test() referenced two non-existent variables, and in non-verbose mode, the tests didn't report the actual number, when it differed from the expected number. Fixed this. Also added an extra call to gc.collect() at the start of test_all(). This will be needed when I check in the changes to add GC to new-style classes.
* Test GC of frame objects.Neil Schemenauer2001-07-121-0/+11
|
* This patch removes all uses of "assert" in the regression test suiteMarc-André Lemburg2001-01-171-3/+3
| | | | | | | and replaces them with a new API verify(). As a result the regression suite will also perform its tests in optimization mode. Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
* Make reindent.py happy (convert everything to 4-space indents!).Fred Drake2000-10-231-5/+5
|
* - Add test for new SAVEALL debugging flagNeil Schemenauer2000-09-221-31/+92
| | | | | - Use exceptions rather than asserts for failing tests. - Reorganize tests and produce some output if verbose option is set.
* - add a new testNeil Schemenauer2000-09-151-0/+22
| | | | - document some of the tricky tests (hopefully correctly :)
* Neil Schemenauer: GC enable(), disable(), isenabled() interface.Vladimir Marangozov2000-08-061-0/+12
| | | | | | Small stylistic changes by VM: - is_enabled() -> isenabled() - static ... Py_<func> -> static ... gc_<func>
* remove all prints (since the prints where of memory locations)Jeremy Hylton2000-06-301-13/+0
|
* final patches from Neil Schemenauer for garbage collectionJeremy Hylton2000-06-301-0/+100