[pypy-svn] r79219 - pypy/branch/reflex-support/pypy/module/cppyy

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Nov 17 19:24:24 CET 2010


Author: cfbolz
Date: Wed Nov 17 19:24:23 2010
New Revision: 79219

Modified:
   pypy/branch/reflex-support/pypy/module/cppyy/converter.py
Log:
 - factor some common code out into a helper function
 - also use space.interp_w to make sure that the objects in question are really
   W_CPPInstances. This should help translation.


Modified: pypy/branch/reflex-support/pypy/module/cppyy/converter.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/converter.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/converter.py	Wed Nov 17 19:24:23 2010
@@ -9,13 +9,20 @@
 
 _converters = {}
 
+def get_rawobject(space, w_obj):
+    from pypy.module.cppyy.interp_cppyy import W_CPPInstance
+    w_obj = space.findattr(w_obj, space.wrap("_cppinstance"))
+    obj = space.interp_w(W_CPPInstance, w_obj, can_be_None=True)
+    return obj.rawobject
+
+
 class TypeConverter(object):
     def __init__(self, space, extra=-1):
         pass
 
     def _get_fieldptr(self, space, w_obj, offset):
-        obj = space.interpclass_w(space.findattr(w_obj, space.wrap("_cppinstance")))
-        return lltype.direct_ptradd(obj.rawobject, offset)
+        rawobject = get_rawobject(space, w_obj)
+        return lltype.direct_ptradd(rawobject, offset)
 
     def _is_abstract(self):
         raise NotImplementedError(
@@ -188,8 +195,8 @@
 
     def to_memory(self, space, w_obj, w_value, offset):
         # copy only the pointer value
-        obj = space.interpclass_w(space.findattr(w_obj, space.wrap("_cppinstance")))
-        byteptr = rffi.cast(rffi.LONGP, obj.rawobject[offset])
+        rawobject = get_rawobject(space, w_obj)
+        byteptr = rffi.cast(rffi.LONGP, rawobject[offset])
         # TODO: now what ... ?? AFAICS, w_value is a pure python list, not an array?
 #        byteptr[0] = space.unwrap(space.id(w_value.getslotvalue(2)))
 
@@ -218,8 +225,8 @@
 
     def to_memory(self, space, w_obj, w_value, offset):
         # copy only the pointer value
-        obj = space.interpclass_w(space.findattr(w_obj, space.wrap("_cppinstance")))
-        byteptr = rffi.cast(rffi.LONGP, obj.rawobject[offset])
+        rawobject = get_rawobject(space, w_obj)
+        byteptr = rffi.cast(rffi.LONGP, rawobject[offset])
         # TODO: now what ... ?? AFAICS, w_value is a pure python list, not an array?
 #        byteptr[0] = space.unwrap(space.id(w_value.getslotvalue(2)))
 



More information about the Pypy-commit mailing list