[pypy-commit] pypy default: Move these three functions at interp-level: potential threading issues

arigo noreply at buildbot.pypy.org
Mon Jan 23 15:28:35 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r51685:c32fbc60b64c
Date: 2012-01-23 15:28 +0100
http://bitbucket.org/pypy/pypy/changeset/c32fbc60b64c/

Log:	Move these three functions at interp-level: potential threading
	issues if they are written at app-level.

diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -445,6 +445,7 @@
         AsyncAction.__init__(self, space)
         self.dying_objects = []
         self.finalizers_lock_count = 0
+        self.enabled_at_app_level = True
 
     def register_callback(self, w_obj, callback, descrname):
         self.dying_objects.append((w_obj, callback, descrname))
diff --git a/pypy/module/gc/__init__.py b/pypy/module/gc/__init__.py
--- a/pypy/module/gc/__init__.py
+++ b/pypy/module/gc/__init__.py
@@ -1,18 +1,18 @@
 from pypy.interpreter.mixedmodule import MixedModule
     
 class Module(MixedModule):
-    appleveldefs = {
-        'enable': 'app_gc.enable',
-        'disable': 'app_gc.disable',
-        'isenabled': 'app_gc.isenabled',
-    }
     interpleveldefs = {
         'collect': 'interp_gc.collect',
+        'enable': 'interp_gc.enable',
+        'disable': 'interp_gc.disable',
+        'isenabled': 'interp_gc.isenabled',
         'enable_finalizers': 'interp_gc.enable_finalizers',
         'disable_finalizers': 'interp_gc.disable_finalizers',
         'garbage' : 'space.newlist([])',
         #'dump_heap_stats': 'interp_gc.dump_heap_stats',
     }
+    appleveldefs = {
+    }
 
     def __init__(self, space, w_name):
         if (not space.config.translating or
diff --git a/pypy/module/gc/app_gc.py b/pypy/module/gc/app_gc.py
deleted file mode 100644
--- a/pypy/module/gc/app_gc.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# NOT_RPYTHON
-
-enabled = True
-
-def isenabled():
-    global enabled
-    return enabled
-
-def enable():
-    global enabled
-    import gc
-    if not enabled:
-        gc.enable_finalizers()
-        enabled = True
-
-def disable():
-    global enabled
-    import gc
-    if enabled:
-        gc.disable_finalizers()
-        enabled = False
diff --git a/pypy/module/gc/interp_gc.py b/pypy/module/gc/interp_gc.py
--- a/pypy/module/gc/interp_gc.py
+++ b/pypy/module/gc/interp_gc.py
@@ -17,6 +17,26 @@
     rgc.collect()
     return space.wrap(0)
 
+def enable(space):
+    """Non-recursive version.  Enable finalizers now.
+    If they were already enabled, no-op.
+    If they were disabled even several times, enable them anyway.
+    """
+    if not space.user_del_action.enabled_at_app_level:
+        space.user_del_action.enabled_at_app_level = True
+        enable_finalizers(space)
+
+def disable(space):
+    """Non-recursive version.  Disable finalizers now.  Several calls
+    to this function are ignored.
+    """
+    if space.user_del_action.enabled_at_app_level:
+        space.user_del_action.enabled_at_app_level = False
+        disable_finalizers(space)
+
+def isenabled(space):
+    return space.newbool(space.user_del_action.enabled_at_app_level)
+
 def enable_finalizers(space):
     if space.user_del_action.finalizers_lock_count == 0:
         raise OperationError(space.w_ValueError,


More information about the pypy-commit mailing list