[pypy-svn] r48995 - in pypy/dist/pypy/translator/llvm: . module test
rxe at codespeak.net
rxe at codespeak.net
Fri Nov 23 18:44:27 CET 2007
Author: rxe
Date: Fri Nov 23 18:44:26 2007
New Revision: 48995
Modified:
pypy/dist/pypy/translator/llvm/module/boehm.h
pypy/dist/pypy/translator/llvm/opwriter.py
pypy/dist/pypy/translator/llvm/test/test_genllvm.py
Log:
(fijal, rxe) make finalizer ha ha work on genllvm
Modified: pypy/dist/pypy/translator/llvm/module/boehm.h
==============================================================================
--- pypy/dist/pypy/translator/llvm/module/boehm.h (original)
+++ pypy/dist/pypy/translator/llvm/module/boehm.h Fri Nov 23 18:44:26 2007
@@ -31,6 +31,10 @@
GC_invoke_finalizers();
}
+void pypy_register_finalizer(void *whatever, void *proc) {
+ GC_REGISTER_FINALIZER(whatever, (GC_finalization_proc)proc, NULL, NULL, NULL);
+}
+
extern GC_all_interior_pointers;
// startup specific code for boehm
Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py (original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py Fri Nov 23 18:44:26 2007
@@ -306,8 +306,9 @@
self.db.gcpolicy._zeromalloc(self.codewriter, opr.retref, opr.argrefs[0], atomic=True)
def boehm_register_finalizer(self, opr):
- # ha, ha
- pass
+ tmpvar = self._tmp()
+ self.codewriter.cast(tmpvar, opr.argtypes[1], opr.argrefs[1], 'i8 *')
+ self.codewriter.call(None, 'void', '@pypy_register_finalizer', ['i8 *', 'i8 *'], [opr.argrefs[0], tmpvar])
def call_boehm_gc_alloc(self, opr):
word = self.db.get_machine_word()
Modified: pypy/dist/pypy/translator/llvm/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm/test/test_genllvm.py Fri Nov 23 18:44:26 2007
@@ -4,6 +4,7 @@
import py
from pypy.rlib.rarithmetic import r_uint
+from pypy.rpython.lltypesystem import lltype
from pypy.translator.llvm.test.runtest import *
@@ -471,3 +472,39 @@
f = compile_function(f, [int])
res = f(4)
assert res == 4*(4+2)
+
+def test__del__():
+ from pypy.rpython.lltypesystem.lloperation import llop
+ class State:
+ pass
+ s = State()
+ class A(object):
+ def __del__(self):
+ s.a_dels += 1
+ class B(A):
+ def __del__(self):
+ s.b_dels += 1
+ class C(A):
+ pass
+ def f():
+ s.a_dels = 0
+ s.b_dels = 0
+ A()
+ B()
+ C()
+ A()
+ B()
+ C()
+ llop.gc__collect(lltype.Void)
+ return s.a_dels * 10 + s.b_dels
+ fn = compile_function(f, [])
+ # we can't demand that boehm has collected all of the objects,
+ # even with the gc__collect call. calling the compiled
+ # function twice seems to help, though.
+ res = 0
+ res += fn()
+ res += fn()
+
+ # if res is still 0, then we haven't tested anything so fail.
+ assert 0 < res <= 84
+
More information about the Pypy-commit
mailing list