summaryrefslogtreecommitdiff
path: root/Lib/test/leakers
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-04-21 10:40:58 +0000
committerThomas Wouters <thomas@python.org>2006-04-21 10:40:58 +0000
commit49fd7fa4431da299196d74087df4a04f99f9c46f (patch)
tree35ace5fe78d3d52c7a9ab356ab9f6dbf8d4b71f4 /Lib/test/leakers
parent9ada3d6e29d5165dadacbe6be07bcd35cfbef59d (diff)
downloadcpython-git-49fd7fa4431da299196d74087df4a04f99f9c46f.tar.gz
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described here (it's not a Py3K issue, just something Py3K discovers): http://mail.python.org/pipermail/python-dev/2006-April/064051.html Hye-Shik Chang promised to look for a fix, so no need to fix it here. The tests that are expected to break are: test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp test_codecencodings_kr test_codecencodings_tw test_codecs test_multibytecodec This merge fixes an actual test failure (test_weakref) in this branch, though, so I believe merging is the right thing to do anyway.
Diffstat (limited to 'Lib/test/leakers')
-rw-r--r--Lib/test/leakers/README.txt13
-rw-r--r--Lib/test/leakers/test_ctypes.py16
-rw-r--r--Lib/test/leakers/test_selftype.py13
-rw-r--r--Lib/test/leakers/test_tee.py19
4 files changed, 42 insertions, 19 deletions
diff --git a/Lib/test/leakers/README.txt b/Lib/test/leakers/README.txt
index 69ee35a884..beeee0e7fa 100644
--- a/Lib/test/leakers/README.txt
+++ b/Lib/test/leakers/README.txt
@@ -5,6 +5,15 @@ the interpreter was built in debug mode. If the total ref count
doesn't increase, the bug has been fixed and the file should be removed
from the repository.
+Note: be careful to check for cyclic garbage. Sometimes it may be helpful
+to define the leak function like:
+
+def leak():
+ def inner_leak():
+ # this is the function that leaks, but also creates cycles
+ inner_leak()
+ gc.collect() ; gc.collect() ; gc.collect()
+
Here's an example interpreter session for test_gestalt which still leaks:
>>> from test.leakers.test_gestalt import leak
@@ -17,3 +26,7 @@ Here's an example interpreter session for test_gestalt which still leaks:
[28940 refs]
>>>
+Once the leak is fixed, the test case should be moved into an appropriate
+test (even if it was originally from the test suite). This ensures the
+regression doesn't happen again. And if it does, it should be easier
+to track down.
diff --git a/Lib/test/leakers/test_ctypes.py b/Lib/test/leakers/test_ctypes.py
new file mode 100644
index 0000000000..0f9a2cdc9a
--- /dev/null
+++ b/Lib/test/leakers/test_ctypes.py
@@ -0,0 +1,16 @@
+
+# Taken from Lib/ctypes/test/test_keeprefs.py, PointerToStructure.test().
+# When this leak is fixed, remember to remove from Misc/build.sh LEAKY_TESTS.
+
+from ctypes import Structure, c_int, POINTER
+import gc
+
+def leak_inner():
+ class POINT(Structure):
+ _fields_ = [("x", c_int)]
+ class RECT(Structure):
+ _fields_ = [("a", POINTER(POINT))]
+
+def leak():
+ leak_inner()
+ gc.collect()
diff --git a/Lib/test/leakers/test_selftype.py b/Lib/test/leakers/test_selftype.py
new file mode 100644
index 0000000000..4207c328ba
--- /dev/null
+++ b/Lib/test/leakers/test_selftype.py
@@ -0,0 +1,13 @@
+# Reference cycles involving only the ob_type field are rather uncommon
+# but possible. Inspired by SF bug 1469629.
+
+import gc
+
+def leak():
+ class T(type):
+ pass
+ class U(type):
+ __metaclass__ = T
+ U.__class__ = U
+ del U
+ gc.collect(); gc.collect(); gc.collect()
diff --git a/Lib/test/leakers/test_tee.py b/Lib/test/leakers/test_tee.py
deleted file mode 100644
index 4ce24cae30..0000000000
--- a/Lib/test/leakers/test_tee.py
+++ /dev/null
@@ -1,19 +0,0 @@
-
-# Test case taken from test_itertools
-# See http://mail.python.org/pipermail/python-dev/2005-November/058339.html
-
-from itertools import tee
-
-def leak():
- def fib():
- def yield_identity_forever(g):
- while 1:
- yield g
- def _fib():
- for i in yield_identity_forever(head):
- yield i
- head, tail, result = tee(_fib(), 3)
- return result
-
- x = fib()
- x.next()