[pypy-commit] pypy cpyext-leakchecking: Add more information when the leakfinder finds an error
rlamy
pypy.commits at gmail.com
Mon Jul 31 09:46:22 EDT 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: cpyext-leakchecking
Changeset: r91999:e4f438ccf573
Date: 2017-07-31 14:19 +0100
http://bitbucket.org/pypy/pypy/changeset/e4f438ccf573/
Log: Add more information when the leakfinder finds an error
diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -7,6 +7,8 @@
from pypy.interpreter.error import OperationError
from rpython.rtyper.lltypesystem import lltype
from pypy.module.cpyext import api
+from pypy.module.cpyext.api import cts
+from pypy.module.cpyext.pyobject import from_ref
from pypy.module.cpyext.state import State
from rpython.tool import leakfinder
from rpython.rlib import rawrefcount
@@ -82,8 +84,6 @@
return space.is_interned_str(s)
def is_allowed_to_leak(space, obj):
- from pypy.module.cpyext.pyobject import from_ref
- from pypy.module.cpyext.api import cts
from pypy.module.cpyext.methodobject import W_PyCFunctionObject
try:
w_obj = from_ref(space, cts.cast('PyObject*', obj._as_ptr()))
@@ -95,6 +95,21 @@
# the test, but the w_obj is referred to from elsewhere.
return is_interned_string(space, w_obj)
+def _get_w_obj(space, c_obj):
+ return from_ref(space, cts.cast('PyObject*', c_obj._as_ptr()))
+
+class CpyextLeak(leakfinder.MallocMismatch):
+ def __str__(self):
+ lines = [leakfinder.MallocMismatch.__str__(self), '']
+ lines.append(
+ "These objects are attached to the following W_Root objects:")
+ for c_obj in self.args[0]:
+ try:
+ lines.append(" %s" % (_get_w_obj(self.args[1], c_obj),))
+ except:
+ pass
+ return '\n'.join(lines)
+
class LeakCheckingTest(object):
"""Base class for all cpyext tests."""
@@ -116,7 +131,7 @@
if not is_allowed_to_leak(self.space, obj):
filtered_result[obj] = value
if filtered_result:
- raise leakfinder.MallocMismatch(filtered_result)
+ raise CpyextLeak(filtered_result, self.space)
assert not self.space.finalizer_queue.next_dead()
More information about the pypy-commit
mailing list