Ejemplo n.º 1
0
 def execute(self, space, cppmethod, cppthis, num_args, args):
     from pypy.module.cppyy import interp_cppyy
     voidp_result = capi.c_call_r(cppmethod, cppthis, num_args, args)
     ref_address = rffi.cast(rffi.VOIDPP, voidp_result)
     ptr_result = rffi.cast(capi.C_OBJECT, ref_address[0])
     return interp_cppyy.wrap_cppobject(
         space, space.w_None, self.cppclass, ptr_result, isref=False, python_owns=False)
Ejemplo n.º 2
0
 def execute_libffi(self, space, cif_descr, funcaddr, buffer):
     jit_libffi.jit_ffi_call(cif_descr, funcaddr, buffer)
     result = rffi.ptradd(buffer, cif_descr.exchange_result)
     from pypy.module.cppyy import interp_cppyy
     ptr_result = rffi.cast(capi.C_OBJECT,
                            rffi.cast(rffi.VOIDPP, result)[0])
     return interp_cppyy.wrap_cppobject(space, ptr_result, self.cppclass)
Ejemplo n.º 3
0
 def from_memory(self, space, w_obj, w_pycppclass, offset):
     address = rffi.cast(capi.C_OBJECT,
                         self._get_raw_address(space, w_obj, offset))
     from pypy.module.cppyy import interp_cppyy
     return interp_cppyy.wrap_cppobject(space,
                                        address,
                                        self.cppclass,
                                        do_cast=False)
Ejemplo n.º 4
0
def ttree_Branch(space, w_self, args_w):
    """Pythonized version of TTree::Branch(): takes proxy objects and by-passes
    the CINT-manual layer."""

    from pypy.module.cppyy import interp_cppyy
    tree_class = interp_cppyy.scope_byname(space, "TTree")

    # sigs to modify (and by-pass CINT):
    #  1. (const char*, const char*, T**,               Int_t=32000, Int_t=99)
    #  2. (const char*, T**,                            Int_t=32000, Int_t=99)
    argc = len(args_w)

    # basic error handling of wrong arguments is best left to the original call,
    # so that error messages etc. remain consistent in appearance: the following
    # block may raise TypeError or IndexError to break out anytime

    try:
        if argc < 2 or 5 < argc:
            raise TypeError("wrong number of arguments")

        tree = space.interp_w(interp_cppyy.W_CPPInstance, w_self, can_be_None=True)
        if (tree is None) or (tree.cppclass != tree_class):
            raise TypeError("not a TTree")

        # first argument must always always be cont char*
        branchname = space.str_w(args_w[0])

        # if args_w[1] is a classname, then case 1, else case 2
        try:
            classname = space.str_w(args_w[1])
            addr_idx  = 2
            w_address = args_w[addr_idx]
        except (OperationError, TypeError):
            addr_idx  = 1
            w_address = args_w[addr_idx]

        bufsize, splitlevel = 32000, 99
        if addr_idx+1 < argc: bufsize = space.c_int_w(args_w[addr_idx+1])
        if addr_idx+2 < argc: splitlevel = space.c_int_w(args_w[addr_idx+2])

        # now retrieve the W_CPPInstance and build other stub arguments
        space = tree.space    # holds the class cache in State
        cppinstance = space.interp_w(interp_cppyy.W_CPPInstance, w_address)
        address = rffi.cast(rffi.VOIDP, cppinstance.get_rawobject())
        klassname = cppinstance.cppclass.full_name()
        vtree = rffi.cast(rffi.VOIDP, tree.get_rawobject())

        # call the helper stub to by-pass CINT
        vbranch = _ttree_Branch(vtree, branchname, klassname, address, bufsize, splitlevel)
        branch_class = interp_cppyy.scope_byname(space, "TBranch")
        w_branch = interp_cppyy.wrap_cppobject(space, vbranch, branch_class)
        return w_branch
    except (OperationError, TypeError, IndexError):
        pass

    # return control back to the original, unpythonized overload
    ol = tree_class.get_overload("Branch")
    return ol.call(w_self, args_w)
Ejemplo n.º 5
0
 def to_memory(self, space, w_obj, w_value, offset):
     try:
         address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj, offset))
         assign = self.cppclass.get_overload("__assign__")
         from pypy.module.cppyy import interp_cppyy
         assign.call(
             interp_cppyy.wrap_cppobject(space, address, self.cppclass, do_cast=False), [w_value])
     except Exception:
         InstanceConverter.to_memory(self, space, w_obj, w_value, offset)
Ejemplo n.º 6
0
 def execute(self, space, cppmethod, cppthis, num_args, args):
     from pypy.module.cppyy import interp_cppyy
     long_result = capi.c_call_o(space, cppmethod, cppthis, num_args, args,
                                 self.cppclass)
     ptr_result = rffi.cast(capi.C_OBJECT, long_result)
     return interp_cppyy.wrap_cppobject(space,
                                        ptr_result,
                                        self.cppclass,
                                        do_cast=False,
                                        python_owns=True,
                                        fresh=True)
Ejemplo n.º 7
0
 def to_memory(self, space, w_obj, w_value, offset):
     try:
         address = rffi.cast(capi.C_OBJECT,
                             self._get_raw_address(space, w_obj, offset))
         assign = self.cppclass.get_overload("__assign__")
         from pypy.module.cppyy import interp_cppyy
         assign.call(
             interp_cppyy.wrap_cppobject(space,
                                         address,
                                         self.cppclass,
                                         do_cast=False), [w_value])
     except Exception:
         InstanceConverter.to_memory(self, space, w_obj, w_value, offset)
Ejemplo n.º 8
0
 def execute(self, space, cppmethod, cppthis, num_args, args):
     from pypy.module.cppyy import interp_cppyy
     long_result = capi.c_call_o(space, cppmethod, cppthis, num_args, args, self.cppclass)
     ptr_result = rffi.cast(capi.C_OBJECT, long_result)
     return interp_cppyy.wrap_cppobject(space, ptr_result, self.cppclass,
                                        do_cast=False, python_owns=True, fresh=True)
Ejemplo n.º 9
0
 def execute_libffi(self, space, cif_descr, funcaddr, buffer):
     jit_libffi.jit_ffi_call(cif_descr, funcaddr, buffer)
     result = rffi.ptradd(buffer, cif_descr.exchange_result)
     from pypy.module.cppyy import interp_cppyy
     ptr_result = rffi.cast(capi.C_OBJECT, rffi.cast(rffi.VOIDPP, result)[0])
     return interp_cppyy.wrap_cppobject(space, ptr_result, self.cppclass)
Ejemplo n.º 10
0
 def execute(self, space, cppmethod, cppthis, num_args, args):
     from pypy.module.cppyy import interp_cppyy
     long_result = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
     ptr_result = rffi.cast(capi.C_OBJECT, long_result)
     pyres = interp_cppyy.wrap_cppobject(space, ptr_result, self.cppclass)
     return pyres
Ejemplo n.º 11
0
 def from_memory(self, space, w_obj, w_pycppclass, offset):
     address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj, offset))
     from pypy.module.cppyy import interp_cppyy
     return interp_cppyy.wrap_cppobject(space, address, self.cppclass,
                                        do_cast=False, is_ref=True)
Ejemplo n.º 12
0
 def execute(self, space, cppmethod, cppthis, num_args, args):
     from pypy.module.cppyy import interp_cppyy
     voidp_result = capi.c_call_r(space, cppmethod, cppthis, num_args, args)
     ref_address = rffi.cast(rffi.VOIDPP, voidp_result)
     ptr_result = rffi.cast(capi.C_OBJECT, ref_address[0])
     return interp_cppyy.wrap_cppobject(space, ptr_result, self.cppclass)
Ejemplo n.º 13
0
 def execute(self, space, cppmethod, cppthis, num_args, args):
     from pypy.module.cppyy import interp_cppyy
     long_result = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
     ptr_result = rffi.cast(capi.C_OBJECT, long_result)
     pyres = interp_cppyy.wrap_cppobject(space, ptr_result, self.cppclass)
     return pyres
Ejemplo n.º 14
0
def ttree_Branch(space, w_self, args_w):
    """Pythonized version of TTree::Branch(): takes proxy objects and by-passes
    the CINT-manual layer."""

    from pypy.module.cppyy import interp_cppyy
    tree_class = interp_cppyy.scope_byname(space, "TTree")

    # sigs to modify (and by-pass CINT):
    #  1. (const char*, const char*, T**,               Int_t=32000, Int_t=99)
    #  2. (const char*, T**,                            Int_t=32000, Int_t=99)
    argc = len(args_w)

    # basic error handling of wrong arguments is best left to the original call,
    # so that error messages etc. remain consistent in appearance: the following
    # block may raise TypeError or IndexError to break out anytime

    try:
        if argc < 2 or 5 < argc:
            raise TypeError("wrong number of arguments")

        tree = space.interp_w(interp_cppyy.W_CPPInstance,
                              w_self,
                              can_be_None=True)
        if (tree is None) or (tree.cppclass != tree_class):
            raise TypeError("not a TTree")

        # first argument must always always be cont char*
        branchname = space.str_w(args_w[0])

        # if args_w[1] is a classname, then case 1, else case 2
        try:
            classname = space.str_w(args_w[1])
            addr_idx = 2
            w_address = args_w[addr_idx]
        except (OperationError, TypeError):
            addr_idx = 1
            w_address = args_w[addr_idx]

        bufsize, splitlevel = 32000, 99
        if addr_idx + 1 < argc: bufsize = space.c_int_w(args_w[addr_idx + 1])
        if addr_idx + 2 < argc:
            splitlevel = space.c_int_w(args_w[addr_idx + 2])

        # now retrieve the W_CPPInstance and build other stub arguments
        space = tree.space  # holds the class cache in State
        cppinstance = space.interp_w(interp_cppyy.W_CPPInstance, w_address)
        address = rffi.cast(rffi.VOIDP, cppinstance.get_rawobject())
        klassname = cppinstance.cppclass.full_name()
        vtree = rffi.cast(rffi.VOIDP, tree.get_rawobject())

        # call the helper stub to by-pass CINT
        vbranch = _ttree_Branch(vtree, branchname, klassname, address, bufsize,
                                splitlevel)
        branch_class = interp_cppyy.scope_byname(space, "TBranch")
        w_branch = interp_cppyy.wrap_cppobject(space, vbranch, branch_class)
        return w_branch
    except (OperationError, TypeError, IndexError):
        pass

    # return control back to the original, unpythonized overload
    ol = tree_class.get_overload("Branch")
    return ol.call(w_self, args_w)
Ejemplo n.º 15
0
 def execute_libffi(self, space, libffifunc, argchain):
     from pypy.module.cppyy import interp_cppyy
     ptr_result = rffi.cast(capi.C_OBJECT, libffifunc.call(argchain, rffi.VOIDP))
     return interp_cppyy.wrap_cppobject(
         space, space.w_None, self.cppclass, ptr_result, isref=False, python_owns=False)
Ejemplo n.º 16
0
 def execute(self, space, cppmethod, cppthis, num_args, args):
     from pypy.module.cppyy import interp_cppyy
     long_result = capi.c_call_l(cppmethod, cppthis, num_args, args)
     ptr_result = rffi.cast(capi.C_OBJECT, long_result)
     return interp_cppyy.wrap_cppobject(
         space, space.w_None, self.cppclass, ptr_result, isref=False, python_owns=False)