예제 #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)