Author: Antonio Cuni <anto.c...@gmail.com> Branch: gc-hooks Changeset: r94196:91b33ec9b345 Date: 2018-03-31 12:06 +0200 http://bitbucket.org/pypy/pypy/changeset/91b33ec9b345/
Log: enable/disable the low-level hook according to the value of w_on_gc_minor 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 @@ -9,6 +9,9 @@ self.space = space self.hooks = space.fromcache(AppLevelHooks) + def is_gc_minor_enabled(self): + return self.hooks.gc_minor_enabled + def on_gc_minor(self, total_memory_used, pinned_objects): action = self.hooks.gc_minor action.total_memory_used = total_memory_used @@ -30,10 +33,11 @@ def __init__(self, space): self.space = space + self.gc_minor_enabled = False self.gc_minor = GcMinorHookAction(space) def set_hooks(self, space, w_on_gc_minor): - # XXX: check for None and enable/disable accordingly + self.gc_minor_enabled = not space.is_none(w_on_gc_minor) self.gc_minor.w_callable = 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 @@ -24,3 +24,10 @@ (10, 20), (30, 40), ] + # + gc.set_hooks(on_gc_minor=None) + self.fire_gc_minor(50, 60) # won't fire because the hooks is disabled + assert lst == [ + (10, 20), + (30, 40), + ] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit