[pypy-svn] r49043 - in pypy/branch/remove-extcompiler-rctypes/pypy/translator/c: src test

pedronis at codespeak.net pedronis at codespeak.net
Sat Nov 24 17:42:00 CET 2007


Author: pedronis
Date: Sat Nov 24 17:41:59 2007
New Revision: 49043

Modified:
   pypy/branch/remove-extcompiler-rctypes/pypy/translator/c/src/exception.h
   pypy/branch/remove-extcompiler-rctypes/pypy/translator/c/test/test_genc.py
Log:
more fixes



Modified: pypy/branch/remove-extcompiler-rctypes/pypy/translator/c/src/exception.h
==============================================================================
--- pypy/branch/remove-extcompiler-rctypes/pypy/translator/c/src/exception.h	(original)
+++ pypy/branch/remove-extcompiler-rctypes/pypy/translator/c/src/exception.h	Sat Nov 24 17:41:59 2007
@@ -105,7 +105,7 @@
 		v = NULL;
 	}
 	else {
-		pycls = RPythonError;
+		pycls = PyExc_Exception; /* XXX RPythonError */
 		v = PyString_FromString(clsname);
 	}
 	Py_INCREF(pycls);

Modified: pypy/branch/remove-extcompiler-rctypes/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/branch/remove-extcompiler-rctypes/pypy/translator/c/test/test_genc.py	(original)
+++ pypy/branch/remove-extcompiler-rctypes/pypy/translator/c/test/test_genc.py	Sat Nov 24 17:41:59 2007
@@ -3,33 +3,18 @@
 from pypy.annotation import model as annmodel
 from pypy.translator.translator import TranslationContext
 from pypy.translator.c.database import LowLevelDatabase
+from pypy.translator.c import genc
 from pypy.translator.c.genc import gen_source
 from pypy.translator.c.gc import NoneGcPolicy
 from pypy.objspace.flow.model import Constant, Variable, SpaceOperation
 from pypy.objspace.flow.model import Block, Link, FunctionGraph
 from pypy.tool.udir import udir
 from pypy.translator.tool.cbuild import make_module_from_c
-from pypy.translator.tool.cbuild import enable_fast_compilation
 from pypy.translator.gensupp import uniquemodulename
 from pypy.translator.backendopt.all import backend_optimizations
 from pypy.translator.interactive import Translation
 from pypy import conftest
 
-# XXX this tries to make compiling faster for full-scale testing
-# XXX tcc leaves some errors undetected! Bad!
-#from pypy.translator.tool import cbuild
-#cbuild.enable_fast_compilation()
-
-def compile_db(db):
-    enable_fast_compilation()  # for testing
-    modulename = uniquemodulename('testing')
-    targetdir = udir.join(modulename).ensure(dir=1)
-    gen_source(db, modulename, str(targetdir), defines={'COUNT_OP_MALLOCS': 1})
-    m = make_module_from_c(targetdir.join(modulename+'.c'),
-                           include_dirs = [os.path.dirname(autopath.this_dir)],
-                           libraries = db.gcpolicy.gc_libraries())
-    return m
-
 def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
             annotatorpolicy=None):
     t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
@@ -57,29 +42,24 @@
         return res
     return checking_fn
 
-def test_func_as_pyobject():
-    py.test.skip("")
+def test_simple():
     def f(x):
         return x*2
     t = TranslationContext()
     t.buildannotator().build_types(f, [int])
     t.buildrtyper().specialize()
 
-    db = LowLevelDatabase(t)
-    entrypoint = db.get(pyobjectptr(f))
-    db.complete()
-    module = compile_db(db)
+    t.config.translation.countmallocs = True
+    builder = genc.CExtModuleBuilder(t, f, config=t.config)
+    builder.generate_source()
+    builder.compile()
+    f1 = builder.get_entry_point()
 
-    f1 = getattr(module, entrypoint)
     assert f1(5) == 10
-    assert f1(x=5) == 10
     assert f1(-123) == -246
-    assert module.malloc_counters() == (0, 0)
+    assert builder.get_malloc_counters()() == (0, 0)
+
     py.test.raises(Exception, f1, "world")  # check that it's really typed
-    py.test.raises(Exception, f1)
-    py.test.raises(Exception, f1, 2, 3)
-    py.test.raises(Exception, f1, 2, x=2)
-    #py.test.raises(Exception, f1, 2, y=2)   XXX missing a check at the moment
 
 
 def test_rlist():
@@ -125,7 +105,6 @@
 
 
 def test_runtime_type_info():
-    py.test.skip("")
     S = GcStruct('s', ('is_actually_s1', Bool))
     S1 = GcStruct('s1', ('sub', S))
     attachRuntimeTypeInfo(S)
@@ -143,7 +122,7 @@
         p1 = malloc(S1)
         p1.sub.is_actually_s1 = True
         # and no crash when p and p1 are decref'ed
-        return sys
+        return None
     t = TranslationContext()
     t.buildannotator().build_types(does_stuff, [])
     rtyper = t.buildrtyper()
@@ -152,15 +131,14 @@
     rtyper.specialize()
     #t.view()
 
-    db = LowLevelDatabase(t)
-    entrypoint = db.get(pyobjectptr(does_stuff))
-    db.complete()
-
-    module = compile_db(db)
-
-    f1 = getattr(module, entrypoint)
+    from pypy.translator.c import genc
+    t.config.translation.countmallocs = True
+    builder = genc.CExtModuleBuilder(t, does_stuff, config=t.config)
+    builder.generate_source()
+    builder.compile()
+    f1 = builder.get_entry_point()
     f1()
-    mallocs, frees = module.malloc_counters()
+    mallocs, frees = builder.get_malloc_counters()()
     assert mallocs == frees
 
 



More information about the Pypy-commit mailing list