[pypy-svn] r24660 - in pypy/dist/pypy/translator/c: . src test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Mar 21 00:58:13 CET 2006


Author: cfbolz
Date: Tue Mar 21 00:58:12 2006
New Revision: 24660

Modified:
   pypy/dist/pypy/translator/c/exceptiontransform.py
   pypy/dist/pypy/translator/c/src/exception.h
   pypy/dist/pypy/translator/c/test/test_exceptiontransform.py
Log:
the transformed graphs compile, but the functions segfault in strange ways :-(.
I have a feeling that there is a strange interaction with the conversion to
real CPython exceptions.


Modified: pypy/dist/pypy/translator/c/exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/c/exceptiontransform.py	(original)
+++ pypy/dist/pypy/translator/c/exceptiontransform.py	Tue Mar 21 00:58:12 2006
@@ -19,7 +19,7 @@
     if isinstance(T, lltype.Primitive):
         return Constant(PrimitiveErrorValue[T], T)
     elif isinstance(T, lltype.Ptr):
-        return Constant(None, T)
+        return Constant(lltype.nullptr(T.TO), T)
     assert 0, "not implemented yet"
 
 # dummy functions to make the resulting graphs runnable on the llinterpreter

Modified: pypy/dist/pypy/translator/c/src/exception.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/exception.h	(original)
+++ pypy/dist/pypy/translator/c/src/exception.h	Tue Mar 21 00:58:12 2006
@@ -33,6 +33,17 @@
 		rpython_exc_value = NULL;				\
 	} while (0)
 
+#define RPyFetchExceptionValue() rpython_exc_value
+
+#define RPyFetchExceptionType() rpython_exc_type
+
+#define RPyClearException() do {                                        \
+		rpython_exc_type = NULL;				\
+		rpython_exc_value = NULL;				\
+	} while (0)
+
+                
+
 #define RPyMatchException(etype)	RPYTHON_EXCEPTION_MATCH(rpython_exc_type,  \
 					(RPYTHON_EXCEPTION_VTABLE) etype)
 

Modified: pypy/dist/pypy/translator/c/test/test_exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_exceptiontransform.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_exceptiontransform.py	Tue Mar 21 00:58:12 2006
@@ -1,9 +1,10 @@
+import py
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.translator.simplify import join_blocks
-from pypy.translator.c import exceptiontransform
+from pypy.translator.c import exceptiontransform, genc, gc
 from pypy.objspace.flow.model import c_last_exception
 from pypy.rpython.test.test_llinterp import get_interpreter
-
+from pypy.translator.tool.cbuild import skip_missing_compiler
 from pypy import conftest
 
 def transform_func(fn, inputtypes):
@@ -30,6 +31,20 @@
         etrafo.transform_completely()
         _already_transformed[t] = True
     return interp.eval_graph(graph, values)
+
+def compile_func(fn, inputtypes):
+    t = TranslationContext()
+    t.buildannotator().build_types(fn, inputtypes)
+    t.buildrtyper().specialize()
+    etrafo = exceptiontransform.ExceptionTransformer(t)
+    etrafo.transform_completely()
+    builder = genc.CExtModuleBuilder(t, fn, gcpolicy=gc.RefcountingGcPolicy)
+    builder.generate_source()
+    skip_missing_compiler(builder.compile)
+    builder.import_module()
+    if conftest.option.view:
+        t.view()
+    return builder.get_entry_point()
  
 def test_simple():
     def one():
@@ -43,6 +58,8 @@
     assert len(list(g.iterblocks())) == 2 # graph does not change 
     result = interpret(foo, [])
     assert result == 1
+    f = compile_func(foo, [])
+#    assert f() == 1
     
 def test_passthrough():
     def one(x):
@@ -54,6 +71,8 @@
         one(1)
     t, g = transform_func(foo, [])
     assert len(list(g.iterblocks())) == 4
+    f = compile_func(foo, [])
+#    py.test.raises(ValueError, f)
 
 def test_catches():
     def one(x):
@@ -76,12 +95,19 @@
         return 4 + x
     t, g = transform_func(foo, [int])
     assert len(list(g.iterblocks())) == 9
+    f = compile_func(foo, [int])
     result = interpret(foo, [6])
     assert result == 2
+#    result = f(6)
+#    assert result == 2
     result = interpret(foo, [7])
     assert result == 4
+#    result = f(7)
+#    assert result == 4
     result = interpret(foo, [8])
     assert result == 2
+#    result = f(8)
+#    assert result == 2
 
 
 def test_raises():
@@ -90,5 +116,7 @@
             raise ValueError()
     t, g = transform_func(foo, [int])
     assert len(list(g.iterblocks())) == 4
-   
+    f = compile_func(foo, [int])
+#    f(0)
+#    py.test.raises(ValueError, f, 0)
 



More information about the Pypy-commit mailing list