def __init__(self, space, cdata, ctype, w_callable, w_error, w_onerror): W_CData.__init__(self, space, cdata, ctype) # if not space.is_true(space.callable(w_callable)): raise oefmt(space.w_TypeError, "expected a callable object, not %T", w_callable) self.w_callable = w_callable if not space.is_none(w_onerror): if not space.is_true(space.callable(w_onerror)): raise oefmt(space.w_TypeError, "expected a callable object for 'onerror', not %T", w_onerror) self.w_onerror = w_onerror # fresult = self.getfunctype().ctitem size = fresult.size if size < 0: size = 0 elif fresult.is_primitive_integer and size < SIZE_OF_FFI_ARG: size = SIZE_OF_FFI_ARG with lltype.scoped_alloc(rffi.CCHARP.TO, size, zero=True) as ll_error: if not space.is_none(w_error): convert_from_object_fficallback(fresult, ll_error, w_error, self.decode_args_from_libffi) self.error_string = rffi.charpsize2str(ll_error, size) # # We must setup the GIL here, in case the callback is invoked in # some other non-Pythonic thread. This is the same as cffi on # CPython, or ctypes. if space.config.translation.thread: from pypy.module.thread.os_thread import setup_threads setup_threads(space)
def __init__(self, space, cdata, ctype, w_callable, w_error, w_onerror): W_CData.__init__(self, space, cdata, ctype) # if not space.is_true(space.callable(w_callable)): raise oefmt(space.w_TypeError, "expected a callable object, not %T", w_callable) self.w_callable = w_callable if not space.is_none(w_onerror): if not space.is_true(space.callable(w_onerror)): raise oefmt(space.w_TypeError, "expected a callable object for 'onerror', not %T", w_onerror) self.w_onerror = w_onerror # fresult = self.getfunctype().ctitem size = fresult.size if size < 0: size = 0 elif fresult.is_primitive_integer and size < SIZE_OF_FFI_ARG: size = SIZE_OF_FFI_ARG with lltype.scoped_alloc(rffi.CCHARP.TO, size, zero=True) as ll_error: if not space.is_none(w_error): convert_from_object_fficallback(fresult, ll_error, w_error, self.decode_args_from_libffi) self.error_string = rffi.charpsize2str(ll_error, size) # # We must setup the GIL here, in case the callback is invoked in # some other non-Pythonic thread. This is the same as cffi on # CPython, or ctypes. if space.config.translation.thread: from pypy.module.thread.os_thread import setup_threads setup_threads(space)
def __init__(self, space, ctype, w_callable, w_error): raw_closure = rffi.cast(rffi.CCHARP, clibffi.closureHeap.alloc()) W_CData.__init__(self, space, raw_closure, ctype) # if not space.is_true(space.callable(w_callable)): raise operationerrfmt(space.w_TypeError, "expected a callable object, not %T", w_callable) self.w_callable = w_callable # fresult = self.getfunctype().ctitem size = fresult.size if size > 0: if fresult.is_primitive_integer and size < SIZE_OF_FFI_ARG: size = SIZE_OF_FFI_ARG self.ll_error = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw', zero=True) if not space.is_none(w_error): convert_from_object_fficallback(fresult, self.ll_error, w_error) # self.unique_id = compute_unique_id(self) global_callback_mapping.set(self.unique_id, self) # cif_descr = self.getfunctype().cif_descr if not cif_descr: raise OperationError(space.w_NotImplementedError, space.wrap("callbacks with '...'")) res = clibffi.c_ffi_prep_closure(self.get_closure(), cif_descr.cif, invoke_callback, rffi.cast(rffi.VOIDP, self.unique_id)) if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK: raise OperationError(space.w_SystemError, space.wrap("libffi failed to build this callback"))
def __init__(self, space, ctype, w_callable, w_error, w_onerror): raw_closure = rffi.cast(rffi.CCHARP, clibffi.closureHeap.alloc()) W_CData.__init__(self, space, raw_closure, ctype) # if not space.is_true(space.callable(w_callable)): raise oefmt(space.w_TypeError, "expected a callable object, not %T", w_callable) self.w_callable = w_callable if not space.is_none(w_onerror): if not space.is_true(space.callable(w_onerror)): raise oefmt( space.w_TypeError, "expected a callable object for 'onerror', not %T", w_onerror) self.w_onerror = w_onerror # fresult = self.getfunctype().ctitem size = fresult.size if size > 0: if fresult.is_primitive_integer and size < SIZE_OF_FFI_ARG: size = SIZE_OF_FFI_ARG self.ll_error = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw', zero=True) if not space.is_none(w_error): convert_from_object_fficallback(fresult, self.ll_error, w_error) # self.unique_id = compute_unique_id(self) global_callback_mapping.set(self.unique_id, self) # cif_descr = self.getfunctype().cif_descr if not cif_descr: raise oefmt( space.w_NotImplementedError, "%s: callback with unsupported argument or " "return type or with '...'", self.getfunctype().name) with self as ptr: closure_ptr = rffi.cast(clibffi.FFI_CLOSUREP, ptr) unique_id = rffi.cast(rffi.VOIDP, self.unique_id) res = clibffi.c_ffi_prep_closure(closure_ptr, cif_descr.cif, invoke_callback, unique_id) if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK: raise OperationError( space.w_SystemError, space.wrap("libffi failed to build this callback")) # # We must setup the GIL here, in case the callback is invoked in # some other non-Pythonic thread. This is the same as cffi on # CPython. if space.config.translation.thread: from pypy.module.thread.os_thread import setup_threads setup_threads(space)
def __init__(self, space, ctype, w_callable, w_error, w_onerror): raw_closure = rffi.cast(rffi.CCHARP, clibffi.closureHeap.alloc()) W_CData.__init__(self, space, raw_closure, ctype) # if not space.is_true(space.callable(w_callable)): raise oefmt(space.w_TypeError, "expected a callable object, not %T", w_callable) self.w_callable = w_callable if not space.is_none(w_onerror): if not space.is_true(space.callable(w_onerror)): raise oefmt(space.w_TypeError, "expected a callable object for 'onerror', not %T", w_onerror) self.w_onerror = w_onerror # fresult = self.getfunctype().ctitem size = fresult.size if size > 0: if fresult.is_primitive_integer and size < SIZE_OF_FFI_ARG: size = SIZE_OF_FFI_ARG self.ll_error = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw', zero=True) if not space.is_none(w_error): convert_from_object_fficallback(fresult, self.ll_error, w_error) # self.unique_id = compute_unique_id(self) global_callback_mapping.set(self.unique_id, self) # cif_descr = self.getfunctype().cif_descr if not cif_descr: raise oefmt(space.w_NotImplementedError, "%s: callback with unsupported argument or " "return type or with '...'", self.getfunctype().name) with self as ptr: closure_ptr = rffi.cast(clibffi.FFI_CLOSUREP, ptr) unique_id = rffi.cast(rffi.VOIDP, self.unique_id) res = clibffi.c_ffi_prep_closure(closure_ptr, cif_descr.cif, invoke_callback, unique_id) if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK: raise OperationError(space.w_SystemError, space.wrap("libffi failed to build this callback")) # # We must setup the GIL here, in case the callback is invoked in # some other non-Pythonic thread. This is the same as cffi on # CPython. if space.config.translation.thread: from pypy.module.thread.os_thread import setup_threads setup_threads(space)