示例#1
0
 def _unwrap_object(self, space, w_obj):
     from pypy.module._cppyy.interp_cppyy import W_CPPInstance
     if isinstance(w_obj, W_CPPInstance):
         if capi.c_is_subtype(space, w_obj.cppclass, self.cppclass):
             rawobject = w_obj.get_rawobject()
             offset = capi.c_base_offset(space, w_obj.cppclass,
                                         self.cppclass, rawobject, 1)
             obj_address = capi.direct_ptradd(rawobject, offset)
             return rffi.cast(capi.C_OBJECT, obj_address)
     raise oefmt(space.w_TypeError, "cannot pass %T as %s", w_obj,
                 self.cppclass.name)
示例#2
0
文件: converter.py 项目: xen0n/pypy
    def _unwrap_object(self, space, w_obj):
        from pypy.module._cppyy.interp_cppyy import W_CPPInstance
        if isinstance(w_obj, W_CPPInstance):
            # w_obj could carry a 'hidden' smart ptr or be one, cover both cases
            have_match = False
            if w_obj.smartdecl and capi.c_is_subtype(space, w_obj.smartdecl, self.smartdecl):
                # hidden case, do not derefence when getting obj address
                have_match = True
                rawobject = w_obj._rawobject      # TODO: this direct access if fugly
                offset = capi.c_base_offset(space, w_obj.smartdecl, self.smartdecl, rawobject, 1)
            elif capi.c_is_subtype(space, w_obj.clsdecl, self.smartdecl):
                # exposed smart pointer
                have_match = True
                rawobject = w_obj.get_rawobject()
                offset = capi.c_base_offset(space, w_obj.clsdecl, self.smartdecl, rawobject, 1)
            if have_match:
                obj_address = capi.direct_ptradd(rawobject, offset)
                return rffi.cast(capi.C_OBJECT, obj_address)

        raise oefmt(space.w_TypeError,
                    "cannot pass %T instance as %s", w_obj, self.rawdecl.name)
示例#3
0
文件: converter.py 项目: xen0n/pypy
 def _unwrap_object(self, space, w_obj):
     from pypy.module._cppyy.interp_cppyy import W_CPPInstance
     if isinstance(w_obj, W_CPPInstance):
         from pypy.module._cppyy.interp_cppyy import INSTANCE_FLAGS_IS_RVALUE
         if w_obj.rt_flags & INSTANCE_FLAGS_IS_RVALUE:
             # reject moves as all are explicit
             raise ValueError("lvalue expected")
         if capi.c_is_subtype(space, w_obj.clsdecl, self.clsdecl):
             rawobject = w_obj.get_rawobject()
             offset = capi.c_base_offset(space, w_obj.clsdecl, self.clsdecl, rawobject, 1)
             obj_address = capi.direct_ptradd(rawobject, offset)
             return rffi.cast(capi.C_OBJECT, obj_address)
     raise oefmt(space.w_TypeError,
                 "cannot pass %T instance as %s", w_obj, self.clsdecl.name)
示例#4
0
文件: converter.py 项目: xen0n/pypy
 def to_memory(self, space, w_obj, w_value, offset):
     # the actual data member is of object* type, but we receive a pointer to that
     # data member in order to modify its value, so by convention, the internal type
     # used is object**
     address = rffi.cast(rffi.VOIDPP, self._get_raw_address(space, w_obj, offset))
     from pypy.module._cppyy.interp_cppyy import W_CPPInstance
     cppinstance = space.interp_w(W_CPPInstance, w_value, can_be_None=True)
     if cppinstance:
         rawobject = cppinstance.get_rawobject()
         offset = capi.c_base_offset(space, cppinstance.clsdecl, self.clsdecl, rawobject, 1)
         obj_address = capi.direct_ptradd(rawobject, offset)
         address[0] = rffi.cast(rffi.VOIDP, obj_address);
         # register the value for potential recycling
         from pypy.module._cppyy.interp_cppyy import memory_regulator
         memory_regulator.register(cppinstance)
     else:
         raise oefmt(space.w_TypeError,
             "cannot pass %T instance as %s", w_value, self.clsdecl.name)
示例#5
0
    def to_memory(self, space, w_obj, w_value, offset):
        from pypy.module._cppyy.interp_cppyy import W_CPPInstance
        cppinstance = space.interp_w(W_CPPInstance, w_value, can_be_None=True)
        if cppinstance:
            # get the object address from value, correct for hierarchy offset
            rawobject = cppinstance.get_rawobject()
            base_offset = capi.c_base_offset(space, cppinstance.clsdecl, self.clsdecl, rawobject, 1)
            rawptr = capi.direct_ptradd(rawobject, base_offset)

            # get the data member address and write the pointer in
            address = rffi.cast(rffi.VOIDPP, self._get_raw_address(space, w_obj, offset))
            address[0] = rffi.cast(rffi.VOIDP, rawptr)

            # register the value object for potential recycling
            from pypy.module._cppyy.interp_cppyy import memory_regulator
            memory_regulator.register(cppinstance)
        else:
            raise oefmt(space.w_TypeError,
                        "cannot pass %T instance as %s", w_value, self.clsdecl.name)