[pypy-commit] pypy reflex-support: rtyper fixes and initial attempt at class type data members

wlav noreply at buildbot.pypy.org
Fri Jul 1 01:15:56 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r45202:af95ab4c411e
Date: 2011-06-30 15:40 -0700
http://bitbucket.org/pypy/pypy/changeset/af95ab4c411e/

Log:	rtyper fixes and initial attempt at class type data members

diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -1,4 +1,5 @@
 import sys
+
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.buffer import Buffer
 from pypy.rpython.lltypesystem import rffi, lltype
@@ -359,7 +360,7 @@
             if capi.c_is_subtype(obj.cppclass.handle, self.cpptype.handle):
                 offset = capi.c_base_offset(obj.cppclass.handle, self.cpptype.handle)
                 obj_address = lltype.direct_ptradd(obj.rawobject, offset)
-                objptr = rffi.cast(rffi.CCHARP, obj_address)
+                objptr = rffi.cast(rffi.VOIDP, obj_address)
                 return objptr
         raise OperationError(space.w_TypeError,
                              space.wrap("cannot pass %s as %s" % (
@@ -368,7 +369,19 @@
 
     def free_argument(self, arg):
         pass
-        
+
+class InstanceConverter(InstancePtrConverter):
+    _immutable_ = True
+
+    def from_memory(self, space, w_obj, offset):
+        address = self._get_raw_address(space, w_obj, offset)
+        obj_address = rffi.cast(rffi.VOIDP, address)
+        from pypy.module.cppyy import interp_cppyy
+        return interp_cppyy.W_CPPInstance(space, self.cpptype, obj_address)
+
+    def free_argument(self, arg):
+        pass
+
 
 def get_converter(space, name):
     from pypy.module.cppyy import interp_cppyy
@@ -380,6 +393,8 @@
     #   5) generalized cases (covers basically all user classes)
     #   6) void converter, which fails on use
 
+    from pypy.module.cppyy import interp_cppyy
+
     #   1) full, exact match
     try:
         return _converters[name](space, -1)
@@ -405,12 +420,14 @@
 
     #   5) generalized cases (covers basically all user classes)
     cpptype = interp_cppyy.type_byname(space, clean_name)
-
-    if cpptype and (compound == "*" or compound == "&"):
+    if cpptype:
         # type check for the benefit of the annotator
         from pypy.module.cppyy.interp_cppyy import W_CPPType
         cpptype = space.interp_w(W_CPPType, cpptype, can_be_None=False)
-        return InstancePtrConverter(space, cpptype)
+        if compound == "*" or compound == "&":
+            return InstancePtrConverter(space, cpptype)
+        elif compound == "":
+            return InstanceConverter(space, cpptype)
     
     #   6) void converter, which fails on use
     #
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -1,7 +1,6 @@
 import sys
 
 from pypy.interpreter.error import OperationError
-
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.rlib import libffi
 
@@ -203,7 +202,7 @@
         # type check for the benefit of the annotator
         from pypy.module.cppyy.interp_cppyy import W_CPPType
         cpptype = space.interp_w(W_CPPType, cpptype, can_be_None=False)
-        if (compound == "*" or compound == "&"):
+        if compound == "*" or compound == "&":
             return InstancePtrExecutor(space, clean_name, cpptype)
         elif compound == "":
             return InstanceExecutor(space, clean_name, cpptype)
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -147,6 +147,7 @@
         assert gbl.T1(int)   is gbl.T1('int')
         assert gbl.T2('T1<int>')     is gbl.T2('T1<int>')
         assert gbl.T2(gbl.T1('int')) is gbl.T2('T1<int>')
+        assert gbl.T2(gbl.T1(int)) is gbl.T2('T1<int>')
         assert gbl.T3('int,double')    is gbl.T3('int,double')
         assert gbl.T3('int', 'double') is gbl.T3('int,double')
         assert gbl.T3(int, 'double')   is gbl.T3('int,double')
@@ -157,18 +158,28 @@
         assert gbl.a_ns.T4('a_ns::T4<T3<int,double> >')\
                is gbl.a_ns.T4(gbl.a_ns.T4(gbl.T3(int, 'double')))
 
+        #-----
         t1 = gbl.T1(int)()
         assert t1.m_t1    == 1
         assert t1.value() == 1
         t1.destruct()
 
+        #-----
         t1 = gbl.T1(int)(11)
         assert t1.m_t1    == 11
         assert t1.value() == 11
         t1.m_t1 = 111
         assert t1.value() == 111
+        assert t1.m_t1    == 111
         t1.destruct()
 
+        #-----
+        t2 = gbl.T2(gbl.T1(int))(gbl.T1(int)(32))
+#        t2.m_t2.m_t1 = 32
+#        assert t2.m_t2.value() == 32
+#        assert t2.m_t2.m_t1    == 32
+        t2.destruct()
+
     def test05_abstract_classes(self):
         """Test non-instatiatability of abstract classes"""
 


More information about the pypy-commit mailing list