Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: kill-someobject
Changeset: r57862:1dd0eec7c927
Date: 2012-10-07 20:58 +0200
http://bitbucket.org/pypy/pypy/changeset/1dd0eec7c927/

Log:    (arigo, fijal, alex) kill more stuff, start passing C tests

diff --git a/pypy/translator/c/extfunc.py b/pypy/translator/c/extfunc.py
--- a/pypy/translator/c/extfunc.py
+++ b/pypy/translator/c/extfunc.py
@@ -112,13 +112,14 @@
     yield ('RPyClearException',        exctransformer.rpyexc_clear_ptr.value)
     yield ('RPyRaiseException',        exctransformer.rpyexc_raise_ptr.value)
 
-    for pyexccls in exceptiondata.standardexceptions:
-        exc_llvalue = exceptiondata
+    for exccls in exceptiondata.standardexceptions:
+        exc_llvalue = exceptiondata.get_standard_ll_exc_instance_by_class(
+            exccls)
         # strange naming here because the macro name must be
         # a substring of PyExc_%s
-        name = pyexccls.__name__
-        if pyexccls.__module__ != 'exceptions':
-            name = '%s_%s' % (pyexccls.__module__.replace('.', '__'), name)
+        name = exccls.__name__
+        if exccls.__module__ != 'exceptions':
+            name = '%s_%s' % (exccls.__module__.replace('.', '__'), name)
         yield ('RPyExc_%s' % name, exc_llvalue)
 
 
diff --git a/pypy/translator/c/src/exception.h 
b/pypy/translator/c/src/exception.h
--- a/pypy/translator/c/src/exception.h
+++ b/pypy/translator/c/src/exception.h
@@ -2,6 +2,8 @@
 /************************************************************/
  /***  C header subsection: exceptions                     ***/
 
+#ifdef HAVE_RTYPER // shrug, hopefully dies with PYPY_NOT_MAIN_FILE
+
 /* just a renaming, unless DO_LOG_EXC is set */
 #define RPyExceptionOccurred RPyExceptionOccurred1
 #define RPY_DEBUG_RETURN()   /* nothing */
@@ -64,3 +66,5 @@
        RPyRaiseException(RPYTHON_TYPE_OF_EXC_INST(rexc), rexc);
 }
 #endif /* PYPY_NOT_MAIN_FILE */
+
+#endif
diff --git a/pypy/translator/c/src/support.h b/pypy/translator/c/src/support.h
--- a/pypy/translator/c/src/support.h
+++ b/pypy/translator/c/src/support.h
@@ -91,5 +91,3 @@
 #  define RPyNLenItem(array, index)          ((array)->items[index])
 #  define RPyBareItem(array, index)          ((array)[index])
 #endif
-
-#endif /* PYPY_NOT_MAIN_FILE */
diff --git a/pypy/translator/c/test/test_genc.py 
b/pypy/translator/c/test/test_genc.py
--- a/pypy/translator/c/test/test_genc.py
+++ b/pypy/translator/c/test/test_genc.py
@@ -1,6 +1,7 @@
 import sys
 
 import py
+import ctypes
 
 from pypy.rpython.lltypesystem.lltype import *
 from pypy.annotation import model as annmodel
@@ -10,7 +11,6 @@
 from pypy.rlib.entrypoint import entrypoint
 from pypy.tool.nullpath import NullPyPathLocal
 
-
 def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
             annotatorpolicy=None):
     t = Translation(fn, argtypes, gc=gcpolicy, backend="c",
@@ -20,26 +20,20 @@
     t.annotate()
     # XXX fish
     t.driver.config.translation.countmallocs = True
-    compiled_fn = t.compile_c()
+    so_name = t.compile_c()
     try:
         if py.test.config.option.view:
             t.view()
     except AttributeError:
         pass
-    malloc_counters = t.driver.cbuilder.get_malloc_counters()
-    def checking_fn(*args, **kwds):
-        if 'expected_extra_mallocs' in kwds:
-            expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
-        else:
-            expected_extra_mallocs = 0
-        res = compiled_fn(*args, **kwds)
-        mallocs, frees = malloc_counters()
-        if isinstance(expected_extra_mallocs, int):
-            assert mallocs - frees == expected_extra_mallocs
-        else:
-            assert mallocs - frees in expected_extra_mallocs
-        return res
-    return checking_fn
+    def f(*args):
+        assert len(args) == len(argtypes)
+        for arg, argtype in zip(args, argtypes):
+            assert isinstance(arg, argtype)
+        dll = ctypes.CDLL(str(so_name))
+        return getattr(dll, 'pypy_g_' + fn.__name__)(*args)
+    f.__name__ = fn.__name__
+    return f
 
 def test_simple():
     def f(x):
@@ -62,46 +56,13 @@
 
     t.config.translation.countmallocs = True
     t.config.translation.dont_write_c_files = True
-    builder = genc.CExtModuleBuilder(t, f, config=t.config)
+    builder = genc.CStandaloneBuilder(t, f, config=t.config)
     builder.generate_source()
     assert isinstance(builder.targetdir, NullPyPathLocal)
-    assert builder.targetdir.listdir() == []
+    for f in builder.targetdir.listdir():
+        assert not str(f).endswith('.c')
 
 
-def test_simple_lambda():
-    f = lambda x: x*2
-    t = TranslationContext()
-    t.buildannotator().build_types(f, [int])
-    t.buildrtyper().specialize()
-
-    t.config.translation.countmallocs = True
-    builder = genc.CExtModuleBuilder(t, f, config=t.config)
-    builder.generate_source()
-    builder.compile()
-    f1 = builder.get_entry_point()
-
-    assert f1(5) == 10
-
-def test_py_capi_exc():
-    def f(x):
-        if x:
-            l = None
-        else:
-            l = [2]
-        x = x*2
-        return l[0]
-    t = TranslationContext()
-    t.buildannotator().build_types(f, [int])
-    t.buildrtyper().specialize()
-
-    builder = genc.CExtModuleBuilder(t, f, config=t.config)
-    builder.generate_source()
-    builder.compile()
-    f1 = builder.get_entry_point(isolated=True)
-
-    x = py.test.raises(Exception, f1, "world")
-    assert not isinstance(x.value, EOFError) # EOFError === segfault
-
 def test_rlist():
     def f(x):
         l = [x]
diff --git a/pypy/translator/driver.py b/pypy/translator/driver.py
--- a/pypy/translator/driver.py
+++ b/pypy/translator/driver.py
@@ -563,8 +563,7 @@
             self.c_entryp = cbuilder.executable_name
             self.create_exe()
         else:
-            isolated = self._backend_extra_options.get('c_isolated', False)
-            self.c_entryp = cbuilder.get_entry_point(isolated=isolated)
+            self.c_entryp = cbuilder.get_entry_point()
     #
     task_compile_c = taskdef(task_compile_c, ['source_c'], "Compiling c 
source")
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to