[pypy-commit] pypy sepcomp2: Make better use of controller: no need to access the class

amauryfa noreply at buildbot.pypy.org
Wed Feb 22 21:19:39 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: sepcomp2
Changeset: r52771:d772c8bbd652
Date: 2012-02-22 21:17 +0100
http://bitbucket.org/pypy/pypy/changeset/d772c8bbd652/

Log:	Make better use of controller: no need to access the class through
	the 'Module', the one accessible through RPython already redirects
	annotations.

diff --git a/pypy/translator/c/exportinfo.py b/pypy/translator/c/exportinfo.py
--- a/pypy/translator/c/exportinfo.py
+++ b/pypy/translator/c/exportinfo.py
@@ -80,7 +80,7 @@
         self.classrepr = rtyper.getrepr(model.SomeInstance(classdef)
                                         ).lowleveltype
         
-    def make_repr(self, module):
+    def make_controller(self, module):
         """Returns the class repr, but also installs a Controller that
         will intercept all operations on the class."""
         STRUCTPTR = self.classrepr
@@ -94,10 +94,10 @@
                 return constructor(*args)
 
         class Entry(ControllerEntry):
-            _about_ = STRUCTPTR
+            _about_ = self.cls
             _controller_ = ClassController
 
-        return STRUCTPTR
+        return self.cls
 
 
 class ModuleExportInfo:
@@ -205,7 +205,7 @@
             func = make_llexternal_function(import_name, funcptr, import_eci)
             setattr(mod, funcname, func)
         for clsname, class_info in self.classes.items():
-            structptr = class_info.make_repr(mod)
+            structptr = class_info.make_controller(mod)
             setattr(mod, clsname, structptr)
             
         return mod
diff --git a/pypy/translator/c/test/test_export.py b/pypy/translator/c/test/test_export.py
--- a/pypy/translator/c/test/test_export.py
+++ b/pypy/translator/c/test/test_export.py
@@ -85,13 +85,12 @@
         @export(Struct, Struct, int)
         def f(s, t, v):
             return s.x + t.x + v
-        firstmodule = self.compile_module("first", f=f, S=Struct)
+        firstmodule = self.compile_module("first", f=f, Struct=Struct)
         
-        S = firstmodule.S
         @export()
         def g():
-            s = S(3.0)
-            t = S(5.5)
+            s = Struct(3.0)
+            t = firstmodule.Struct(5.5)
             return firstmodule.f(s, t, 7)
         secondmodule = self.compile_module("second", g=g)
         assert secondmodule.g() == 70.3


More information about the pypy-commit mailing list