Author: Armin Rigo <ar...@tunes.org>
Branch: stmgc-c7
Changeset: r73999:abb8d87229ef
Date: 2014-10-17 16:46 +0200
http://bitbucket.org/pypy/pypy/changeset/abb8d87229ef/

Log:    Add a light finalizer test (not passing yet)

diff --git a/rpython/translator/backendopt/finalizer.py 
b/rpython/translator/backendopt/finalizer.py
--- a/rpython/translator/backendopt/finalizer.py
+++ b/rpython/translator/backendopt/finalizer.py
@@ -18,7 +18,7 @@
     """
     ok_operations = ['ptr_nonzero', 'ptr_eq', 'ptr_ne', 'free', 'same_as',
                      'direct_ptradd', 'force_cast', 'track_alloc_stop',
-                     'raw_free']
+                     'raw_free', 'debug_print']
 
     def analyze_light_finalizer(self, graph):
         result = self.analyze_direct_call(graph)
diff --git a/rpython/translator/stm/test/test_ztranslated.py 
b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -523,11 +523,29 @@
             X()
 
         def main(argv):
+            x1 = X()
             g()
             rgc.collect()
             print 'destructors called:', g_counter.num
+            objectmodel.keepalive_until_here(x1)
             return 0
 
         t, cbuilder = self.compile(main)
         data = cbuilder.cmdexec('')
         assert 'destructors called: 1\n' in data
+
+    def test_light_finalizer(self):
+        class X:
+            @rgc.must_be_light_finalizer
+            def __del__(self):
+                debug_print("<del>")
+        def g():
+            X()
+        def main(argv):
+            g()
+            rgc.collect(0)
+            return 0
+
+        t, cbuilder = self.compile(main)
+        data, err = cbuilder.cmdexec('', err=True)
+        assert '<del>' in err
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to