示例#1
0
    def _getfunc(space, CDLL, w_name, w_argtypes, w_restype, variadic_args=0):
        argtypes_w, argtypes, w_restype, restype = unpack_argtypes(
            space, w_argtypes, w_restype)
        if (space.isinstance_w(w_name, space.w_bytes) or
                space.isinstance_w(w_name, space.w_unicode)):
            name = space.text_w(w_name)
            try:
                func = CDLL.cdll.getpointer(name, argtypes, restype,
                                            flags=CDLL.flags, variadic_args=variadic_args)
            except KeyError:
                raise oefmt(space.w_AttributeError,
                            "No symbol %s found in library %s",
                            name, CDLL.name)
            except LibFFIError:
                raise got_libffi_error(space)

            return W_FuncPtr(func, argtypes_w, w_restype)
        elif space.isinstance_w(w_name, space.w_int):
            ordinal = space.int_w(w_name)
            try:
                func = CDLL.cdll.getpointer_by_ordinal(
                    ordinal, argtypes, restype,
                    flags=CDLL.flags, variadic_args=variadic_args)
            except KeyError:
                raise oefmt(space.w_AttributeError,
                            "No ordinal %d found in library %s",
                            ordinal, CDLL.name)
            except LibFFIError:
                raise got_libffi_error(space)

            return W_FuncPtr(func, argtypes_w, w_restype)
        else:
            raise oefmt(space.w_TypeError,
                        "function name must be a string or integer")
示例#2
0
    def _getfunc(space, CDLL, w_name, w_argtypes, w_restype):
        argtypes_w, argtypes, w_restype, restype = unpack_argtypes(
            space, w_argtypes, w_restype)
        if space.isinstance_w(w_name, space.w_str):
            name = space.str_w(w_name)
            try:
                func = CDLL.cdll.getpointer(name, argtypes, restype,
                                            flags = CDLL.flags)
            except KeyError:
                raise oefmt(space.w_AttributeError,
                            "No symbol %s found in library %s",
                            name, CDLL.name)
            except LibFFIError:
                raise got_libffi_error(space)

            return W_FuncPtr(func, argtypes_w, w_restype)
        elif space.isinstance_w(w_name, space.w_int):
            ordinal = space.int_w(w_name)
            try:
                func = CDLL.cdll.getpointer_by_ordinal(
                    ordinal, argtypes, restype,
                    flags = CDLL.flags)
            except KeyError:
                raise oefmt(space.w_AttributeError,
                            "No ordinal %d found in library %s",
                            ordinal, CDLL.name)
            except LibFFIError:
                raise got_libffi_error(space)

            return W_FuncPtr(func, argtypes_w, w_restype)
        else:
            raise OperationError(space.w_TypeError, space.wrap(
                    'function name must be a string or integer'))
示例#3
0
 def __init__(self, space, w_callable, w_args, w_result,
              flags=FUNCFLAG_CDECL):
     self.space = space
     self.w_callable = w_callable
     self.argtypes = unpack_argshapes(space, w_args)
     ffiargs = [tp.get_basic_ffi_type() for tp in self.argtypes]
     if not space.is_w(w_result, space.w_None):
         self.result = space.text_w(w_result)
         ffiresult = letter2tp(space, self.result).get_basic_ffi_type()
     else:
         self.result = None
         ffiresult = ffi_type_void
     self.number = global_counter.add(self)
     try:
         self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
                                            callback, self.number, flags)
     except LibFFIError:
         raise got_libffi_error(space)
     self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.get_closure())
     if tracker.DO_TRACING:
         addr = rffi.cast(lltype.Signed, self.ll_callback.get_closure())
         tracker.trace_allocation(addr, self)
     #
     # We must setup the GIL here, in case the callback is invoked in
     # some other non-Pythonic thread.  This is the same as ctypes on
     # CPython (but only when creating a callback; on CPython it occurs
     # as soon as we import _ctypes)
     if space.config.translation.thread:
         from pypy.module.thread.os_thread import setup_threads
         setup_threads(space)
示例#4
0
文件: callback.py 项目: Qointum/pypy
 def __init__(self, space, w_callable, w_args, w_result,
              flags=FUNCFLAG_CDECL):
     self.space = space
     self.w_callable = w_callable
     self.argtypes = unpack_argshapes(space, w_args)
     ffiargs = [tp.get_basic_ffi_type() for tp in self.argtypes]
     if not space.is_w(w_result, space.w_None):
         self.result = space.str_w(w_result)
         ffiresult = letter2tp(space, self.result).get_basic_ffi_type()
     else:
         self.result = None
         ffiresult = ffi_type_void
     self.number = global_counter.add(self)
     try:
         self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
                                            callback, self.number, flags)
     except LibFFIError:
         raise got_libffi_error(space)
     self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.ll_closure)
     if tracker.DO_TRACING:
         addr = rffi.cast(lltype.Signed, self.ll_callback.ll_closure)
         tracker.trace_allocation(addr, self)
     #
     # We must setup the GIL here, in case the callback is invoked in
     # some other non-Pythonic thread.  This is the same as ctypes on
     # CPython (but only when creating a callback; on CPython it occurs
     # as soon as we import _ctypes)
     if space.config.translation.thread:
         from pypy.module.thread.os_thread import setup_threads
         setup_threads(space)
示例#5
0
 def __init__(self,
              space,
              w_callable,
              w_args,
              w_result,
              flags=FUNCFLAG_CDECL):
     self.space = space
     self.w_callable = w_callable
     self.argtypes = unpack_argshapes(space, w_args)
     ffiargs = [tp.get_basic_ffi_type() for tp in self.argtypes]
     if not space.is_w(w_result, space.w_None):
         self.result = space.str_w(w_result)
         ffiresult = letter2tp(space, self.result).get_basic_ffi_type()
     else:
         self.result = None
         ffiresult = ffi_type_void
     self.number = global_counter.add(self)
     try:
         self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult, callback,
                                            self.number, flags)
     except LibFFIError:
         raise got_libffi_error(space)
     self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.ll_closure)
     if tracker.DO_TRACING:
         addr = rffi.cast(lltype.Signed, self.ll_callback.ll_closure)
         tracker.trace_allocation(addr, self)
示例#6
0
def descr_fromaddr(space, w_cls, addr, name, w_argtypes, w_restype, flags=libffi.FUNCFLAG_CDECL):
    argtypes_w, argtypes, w_restype, restype = unpack_argtypes(space, w_argtypes, w_restype)
    addr = rffi.cast(rffi.VOIDP, addr)
    try:
        func = libffi.Func(name, argtypes, restype, addr, flags)
        return W_FuncPtr(func, argtypes_w, w_restype)
    except LibFFIError:
        raise got_libffi_error(space)
示例#7
0
    def _getfunc(space, CDLL, w_name, w_argtypes, w_restype):
        name = space.str_w(w_name)
        argtypes_w, argtypes, w_restype, restype = unpack_argtypes(space, w_argtypes, w_restype)
        try:
            func = CDLL.cdll.getpointer(name, argtypes, restype, flags=CDLL.flags)
        except KeyError:
            raise oefmt(space.w_AttributeError, "No symbol %s found in library %s", name, CDLL.name)
        except LibFFIError:
            raise got_libffi_error(space)

        return W_FuncPtr(func, argtypes_w, w_restype)
示例#8
0
def descr_fromaddr(space, w_cls, addr, name, w_argtypes,
                    w_restype, flags=libffi.FUNCFLAG_CDECL):
    argtypes_w, argtypes, w_restype, restype = unpack_argtypes(space,
                                                               w_argtypes,
                                                               w_restype)
    addr = rffi.cast(rffi.VOIDP, addr)
    try:
        func = libffi.Func(name, argtypes, restype, addr, flags)
        return W_FuncPtr(func, argtypes_w, w_restype)
    except LibFFIError:
        raise got_libffi_error(space)
示例#9
0
    def _getfunc(space, CDLL, w_name, w_argtypes, w_restype):
        argtypes_w, argtypes, w_restype, restype = unpack_argtypes(
            space, w_argtypes, w_restype)
        if space.isinstance_w(w_name, space.w_unicode):
            # XXX: support LoadLibraryW
            name = space.str_w(w_name)
            try:
                func = CDLL.cdll.getpointer(name,
                                            argtypes,
                                            restype,
                                            flags=CDLL.flags)
            except KeyError:
                raise oefmt(space.w_AttributeError,
                            "No symbol %s found in library %s", name,
                            CDLL.name)
            except LibFFIError:
                raise got_libffi_error(space)

            return W_FuncPtr(func, argtypes_w, w_restype)
        elif space.isinstance_w(w_name, space.w_int):
            ordinal = space.int_w(w_name)
            try:
                func = CDLL.cdll.getpointer_by_ordinal(ordinal,
                                                       argtypes,
                                                       restype,
                                                       flags=CDLL.flags)
            except KeyError:
                raise oefmt(space.w_AttributeError,
                            "No ordinal %d found in library %s", ordinal,
                            CDLL.name)
            except LibFFIError:
                raise got_libffi_error(space)

            return W_FuncPtr(func, argtypes_w, w_restype)
        else:
            raise OperationError(
                space.w_TypeError,
                space.wrap('function name must be a string or integer'))
示例#10
0
    def _getfunc(space, CDLL, w_name, w_argtypes, w_restype, variadic_args=0):
        name = space.text_w(w_name)
        argtypes_w, argtypes, w_restype, restype = unpack_argtypes(
            space, w_argtypes, w_restype)
        try:
            func = CDLL.cdll.getpointer(name, argtypes, restype,
                                        flags=CDLL.flags, variadic_args=variadic_args)
        except KeyError:
            raise oefmt(space.w_AttributeError,
                        "No symbol %s found in library %s", name, CDLL.name)
        except LibFFIError:
            raise got_libffi_error(space)

        return W_FuncPtr(func, argtypes_w, w_restype)
示例#11
0
文件: callback.py 项目: Darriall/pypy
 def __init__(self, space, w_callable, w_args, w_result,
              flags=FUNCFLAG_CDECL):
     self.space = space
     self.w_callable = w_callable
     self.argtypes = unpack_argshapes(space, w_args)
     ffiargs = [tp.get_basic_ffi_type() for tp in self.argtypes]
     if not space.is_w(w_result, space.w_None):
         self.result = space.str_w(w_result)
         ffiresult = letter2tp(space, self.result).get_basic_ffi_type()
     else:
         self.result = None
         ffiresult = ffi_type_void
     self.number = global_counter.add(self)
     try:
         self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
                                            callback, self.number, flags)
     except LibFFIError:
         raise got_libffi_error(space)
     self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.ll_closure)
     if tracker.DO_TRACING:
         addr = rffi.cast(lltype.Signed, self.ll_callback.ll_closure)
         tracker.trace_allocation(addr, self)