Commits

Amaury Forgeot d'Arc  committed 065aa9d

Add a test, which works.
Next: directly call the constructor

  • Participants
  • Parent commits adb2019
  • Branches separate-compilation

Comments (0)

Files changed (1)

File pypy/translator/c/test/test_separate.py

         assert fn() == 73.5
         c_fn = self.compile_function(fn, [])
         assert c_fn() == 73.5
+
+    def test_create_structure(self):
+        class S:
+            @export(float)
+            def __init__(self, x):
+                self.x = x
+
+        # functions exported from the 'first' module
+        @export(float)
+        def newS(x):
+            return S(x)
+
+        @export(S)
+        def f(s):
+            return s.x + 1.5
+        firstmodule = self.compile_separated("first", newS=newS, f=f)
+
+        # call them from a function compiled in another module
+        @export()
+        def g():
+            s = firstmodule.newS(41.0)
+            return firstmodule.f(s)
+        secondmodule = self.compile_separated("second", g=g)
+
+        def fn():
+            return secondmodule.g()
+
+        if sys.platform == 'win32':
+            filepath = os.path.dirname(firstmodule.__file__)
+            os.environ['PATH'] = "%s;%s" % (filepath, os.environ['PATH'])
+
+        assert fn() == 42.5
+        c_fn = self.compile_function(fn, [])
+        assert c_fn() == 42.5
+