[pypy-commit] pypy reflex-support: translation fixes (all rawobject now ccharp for benefit of direct_ptradd)

wlav noreply at buildbot.pypy.org
Wed Jul 13 19:36:58 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r45568:5ccedc547337
Date: 2011-07-13 10:36 -0700
http://bitbucket.org/pypy/pypy/changeset/5ccedc547337/

Log:	translation fixes (all rawobject now ccharp for benefit of
	direct_ptradd)

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
@@ -21,7 +21,7 @@
         cpp_instance = space.interp_w(W_CPPInstance, w_cpp_instance, can_be_None=True)
         if cpp_instance:
             return cpp_instance.rawobject
-    return lltype.nullptr(rffi.VOIDP.TO)
+    return lltype.nullptr(rffi.CCHARP.TO)
 
 
 class TypeConverter(object):
@@ -35,6 +35,7 @@
     def _get_raw_address(self, space, w_obj, offset):
         rawobject = get_rawobject(space, w_obj)
         if rawobject:
+            assert lltype.typeOf(rawobject) == rffi.CCHARP
             field_address = lltype.direct_ptradd(rawobject, offset)
             fieldptr = rffi.cast(rffi.CCHARP, field_address)
         else:
@@ -121,6 +122,7 @@
     def to_memory(self, space, w_obj, w_value, offset):
         # copy only the pointer value
         rawobject = get_rawobject(space, w_obj)
+        assert lltype.typeOf(rawobject) == rffi.CCHARP
         field_address = lltype.direct_ptradd(rawobject, offset)
         byteptr = rffi.cast(rffi.CCHARPP, field_address)
         buf = space.buffer_w(w_value)
@@ -488,6 +490,7 @@
         if isinstance(obj, W_CPPInstance):
             if capi.c_is_subtype(obj.cppclass.handle, self.cpptype.handle):
                 offset = capi.c_base_offset(obj.cppclass.handle, self.cpptype.handle)
+                assert lltype.typeOf(obj.rawobject) == rffi.CCHARP
                 obj_address = lltype.direct_ptradd(obj.rawobject, offset)
                 objptr = rffi.cast(rffi.VOIDP, obj_address)
                 return objptr
@@ -510,9 +513,8 @@
 
     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, False)
+        return interp_cppyy.W_CPPInstance(space, self.cpptype, address, False)
 
     def free_argument(self, arg):
         pass
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
@@ -242,7 +242,7 @@
     def execute(self, space, func, cppthis, num_args, args):
         from pypy.module.cppyy import interp_cppyy
         long_result = capi.c_call_l(func.cpptype.handle, func.method_index, cppthis, num_args, args)
-        ptr_result = rffi.cast(rffi.VOIDP, long_result)
+        ptr_result = rffi.cast(rffi.CCHARP, long_result)
         return interp_cppyy.W_CPPInstance(space, self.cpptype, ptr_result, False)
 
     def execute_libffi(self, space, libffifunc, argchain):
@@ -257,7 +257,7 @@
         from pypy.module.cppyy import interp_cppyy
         long_result = capi.c_call_o(
             func.cpptype.handle, func.method_index, cppthis, num_args, args, self.cpptype.handle)
-        ptr_result = rffi.cast(rffi.VOIDP, long_result)
+        ptr_result = rffi.cast(rffi.CCHARP, long_result)
         return interp_cppyy.W_CPPInstance(space, self.cpptype, ptr_result, True)
 
 
diff --git a/pypy/module/cppyy/interp_cppyy.py b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -15,7 +15,8 @@
 class FastCallNotPossible(Exception):
     pass
 
-NULL_VOIDP = lltype.nullptr(rffi.VOIDP.TO)
+NULL_CCHARP = lltype.nullptr(rffi.CCHARP.TO)
+NULL_VOIDP  = lltype.nullptr(rffi.VOIDP.TO)
 
 def load_lib(space, name):
     # TODO: allow open in RTLD_GLOBAL mode
@@ -126,7 +127,7 @@
         if self.arg_converters is None:
             self._build_converters()
         jit.promote(self)
-        funcptr = self.methgetter(cppthis)
+        funcptr = self.methgetter(rffi.cast(rffi.VOIDP, cppthis))
         libffi_func = self._get_libffi_func(funcptr)
         if not libffi_func:
             raise FastCallNotPossible
@@ -210,7 +211,7 @@
         assert not cppthis
         args = self.prepare_arguments(args_w)
         try:
-            return self.executor.execute(self.space, self, NULL_VOIDP,
+            return self.executor.execute(self.space, self, NULL_CCHARP,
                                          len(args_w), args)
         finally:
             self.free_arguments(args, len(args_w))
@@ -222,12 +223,13 @@
     def call(self, cppthis, args_w):
         assert not cppthis
         newthis = capi.c_allocate(self.cpptype.handle)
+        ccharp_this = rffi.cast(rffi.CCHARP, newthis)
         try:
-            CPPMethod.call(self, newthis, args_w)
+            CPPMethod.call(self, ccharp_this, args_w)
         except Exception, e:
             capi.c_deallocate(self.cpptype.handle, newthis)
             raise
-        return W_CPPInstance(self.space, self.cpptype, newthis, True)
+        return W_CPPInstance(self.space, self.cpptype, ccharp_this, True)
 
 
 class W_CPPOverload(Wrappable):
@@ -250,7 +252,7 @@
         if cppinstance:
             cppthis = cppinstance.rawobject
         else:
-            cppthis = NULL_VOIDP
+            cppthis = NULL_CCHARP
 
         space = self.space
         errmsg = 'None of the overloads matched:'
@@ -534,6 +536,7 @@
     def __init__(self, space, cppclass, rawobject, python_owns):
         self.space = space
         self.cppclass = cppclass
+        assert lltype.typeOf(rawobject) == rffi.CCHARP
         self.rawobject = rawobject
         self.python_owns = python_owns
 
@@ -548,7 +551,7 @@
     def destruct(self):
         if self.rawobject:
             capi.c_destruct(self.cppclass.handle, self.rawobject)
-            self.rawobject = NULL_VOIDP
+            self.rawobject = NULL_CCHARP
 
     def __del__(self):
         if self.python_owns:


More information about the pypy-commit mailing list