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)
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)