[pypy-commit] pypy gc-hooks: pass a 'stats' object to the hook instead of passing all the values individually
antocuni
pypy.commits at gmail.com
Sat Mar 31 09:42:09 EDT 2018
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: gc-hooks
Changeset: r94200:ce5745894545
Date: 2018-03-31 15:35 +0200
http://bitbucket.org/pypy/pypy/changeset/ce5745894545/
Log: pass a 'stats' object to the hook instead of passing all the values
individually
diff --git a/pypy/module/gc/hook.py b/pypy/module/gc/hook.py
--- a/pypy/module/gc/hook.py
+++ b/pypy/module/gc/hook.py
@@ -1,6 +1,7 @@
from rpython.memory.gc.hook import GcHooks
-from pypy.interpreter.baseobjspace import ObjSpace
from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.typedef import TypeDef, interp_attrproperty
from pypy.interpreter.executioncontext import AsyncAction
class LowLevelGcHooks(GcHooks):
@@ -47,11 +48,24 @@
pinned_objects = 0
def perform(self, ec, frame):
- self.space.call_function(self.w_callable,
- self.space.newint(self.total_memory_used),
- self.space.newint(self.pinned_objects))
+ w_stats = W_GcMinorStats(self.total_memory_used, self.pinned_objects)
+ self.space.call_function(self.w_callable, w_stats)
+class W_GcMinorStats(W_Root):
+
+ def __init__(self, total_memory_used, pinned_objects):
+ self.total_memory_used = total_memory_used
+ self.pinned_objects = pinned_objects
+
+
+W_GcMinorStats.typedef = TypeDef(
+ "GcMinorStats",
+ total_memory_used = interp_attrproperty("total_memory_used",
+ cls=W_GcMinorStats, wrapfn="newint"),
+ pinned_objects = interp_attrproperty("pinned_objects",
+ cls=W_GcMinorStats, wrapfn="newint"),
+ )
def set_hooks(space, w_on_gc_minor):
diff --git a/pypy/module/gc/test/test_hook.py b/pypy/module/gc/test/test_hook.py
--- a/pypy/module/gc/test/test_hook.py
+++ b/pypy/module/gc/test/test_hook.py
@@ -1,3 +1,4 @@
+from rpython.rlib.rarithmetic import r_uint
from pypy.module.gc.hook import gchooks
from pypy.interpreter.baseobjspace import ObjSpace
from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -7,7 +8,7 @@
def setup_class(cls):
space = cls.space
- @unwrap_spec(ObjSpace, int, int)
+ @unwrap_spec(ObjSpace, r_uint, int)
def fire_gc_minor(space, total_memory_used, pinned_objects):
gchooks.fire_gc_minor(total_memory_used, pinned_objects)
cls.w_fire_gc_minor = space.wrap(interp2app(fire_gc_minor))
@@ -15,8 +16,8 @@
def test_on_gc_minor(self):
import gc
lst = []
- def on_gc_minor(total_memory_used, pinned_objects):
- lst.append((total_memory_used, pinned_objects))
+ def on_gc_minor(stats):
+ lst.append((stats.total_memory_used, stats.pinned_objects))
gc.set_hooks(on_gc_minor=on_gc_minor)
self.fire_gc_minor(10, 20)
self.fire_gc_minor(30, 40)
More information about the pypy-commit
mailing list