[pypy-svn] r65615 - in pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm: . test

arigo at codespeak.net arigo at codespeak.net
Sat Jun 6 15:34:36 CEST 2009


Author: arigo
Date: Sat Jun  6 15:34:33 2009
New Revision: 65615

Added:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_1st.py
      - copied unchanged from r65614, pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_runner.py
Removed:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_runner.py
Modified:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/llvm_rffi.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_llvm_rffi.py
Log:
Rename test_runner to test_1st.
Move the teardown logic in llvm_rffi and call it from test_llvm_rffi too.


Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/llvm_rffi.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/llvm_rffi.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/llvm_rffi.py	Sat Jun  6 15:34:33 2009
@@ -41,6 +41,19 @@
     libraries    = ['pypy_cache_llvm'],
 )
 
+_teardown = None
+
+def set_teardown_function(fn):
+    global _teardown
+    _teardown = fn
+
+def teardown_now():
+    global _teardown
+    fn = _teardown
+    _teardown = None
+    if fn is not None:
+        fn()
+
 # ____________________________________________________________
 
 Debug = True

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/runner.py	Sat Jun  6 15:34:33 2009
@@ -26,7 +26,7 @@
 
     def setup_once(self):
         if not we_are_translated():
-            teardown_now()
+            llvm_rffi.teardown_now()
         llvm_rffi.LLVM_SetFlags()
         self.module = llvm_rffi.LLVMModuleCreateWithName("pypyjit")
         if sys.maxint == 2147483647:
@@ -45,7 +45,7 @@
         #
         self.ee = llvm_rffi.LLVM_EE_Create(self.module)
         if not we_are_translated():
-            set_teardown_function(self._teardown)
+            llvm_rffi.set_teardown_function(self._teardown)
 
     def _teardown(self):
         llvm_rffi.LLVMDisposeExecutionEngine(self.ee)
@@ -312,16 +312,3 @@
         if hasattr(LLVMJITCompiler, methname):
             all_operations[_value] = methname
 all_operations = unrolling_iterable(all_operations.items())
-
-_teardown = None
-
-def set_teardown_function(fn):
-    global _teardown
-    _teardown = fn
-
-def teardown_now():
-    global _teardown
-    fn = _teardown
-    _teardown = None
-    if fn is not None:
-        fn()

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_llvm_rffi.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_llvm_rffi.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/llvm/test/test_llvm_rffi.py	Sat Jun  6 15:34:33 2009
@@ -54,6 +54,7 @@
 
 
 def test_from_llvm_py_example_2():
+    teardown_now()
     d = test_from_llvm_py_example_1()
     my_module = d['my_module']
     ty_int = d['ty_int']
@@ -80,26 +81,24 @@
         lltype.free(error_out, flavor='raw')
         lltype.free(ee_out, flavor='raw')
 
-    try:
-        # The arguments needs to be passed as "GenericValue" objects.
-        args = lltype.malloc(rffi.CArray(LLVMGenericValueRef), 2, flavor='raw')
-        args[0] = LLVMCreateGenericValueOfInt(ty_int, 100, True)
-        args[1] = LLVMCreateGenericValueOfInt(ty_int, 42, True)
-
-        # Now let's compile and run!
-        retval = LLVMRunFunction(ee, f_sum, 2, args)
-        LLVMDisposeGenericValue(args[1])
-        LLVMDisposeGenericValue(args[0])
-        lltype.free(args, flavor='raw')
-
-        # The return value is also GenericValue. Let's check it.
-        ulonglong = LLVMGenericValueToInt(retval, True)
-        LLVMDisposeGenericValue(retval)
-        res = rffi.cast(lltype.Signed, ulonglong)
-        assert res == 142
+    set_teardown_function(lambda: LLVMDisposeExecutionEngine(ee))
 
-    finally:
-        LLVMDisposeExecutionEngine(ee)
+    # The arguments needs to be passed as "GenericValue" objects.
+    args = lltype.malloc(rffi.CArray(LLVMGenericValueRef), 2, flavor='raw')
+    args[0] = LLVMCreateGenericValueOfInt(ty_int, 100, True)
+    args[1] = LLVMCreateGenericValueOfInt(ty_int, 42, True)
+
+    # Now let's compile and run!
+    retval = LLVMRunFunction(ee, f_sum, 2, args)
+    LLVMDisposeGenericValue(args[1])
+    LLVMDisposeGenericValue(args[0])
+    lltype.free(args, flavor='raw')
+
+    # The return value is also GenericValue. Let's check it.
+    ulonglong = LLVMGenericValueToInt(retval, True)
+    LLVMDisposeGenericValue(retval)
+    res = rffi.cast(lltype.Signed, ulonglong)
+    assert res == 142
 
 
 def test_from_llvm_py_example_3():



More information about the Pypy-commit mailing list