예제 #1
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)
예제 #2
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)
예제 #3
0
파일: callback.py 프로젝트: zielmicha/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)
예제 #4
0
 def __init__(self, space, size, address=r_uint(0)):
     if address:
         self.ll_buffer = rffi.cast(rffi.VOIDP, address)
     else:
         self.ll_buffer = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw',
                                        zero=True, add_memory_pressure=True)
         if tracker.DO_TRACING:
             ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
             tracker.trace_allocation(ll_buf, self)
예제 #5
0
 def __init__(self, space, size, address=r_uint(0)):
     if address:
         self.ll_buffer = rffi.cast(rffi.VOIDP, address)
     else:
         self.ll_buffer = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw',
                                        zero=True, add_memory_pressure=True)
         if tracker.DO_TRACING:
             ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
             tracker.trace_allocation(ll_buf, self)
예제 #6
0
 def __init__(self, space, w_callable, w_args, w_result):
     number = global_counter.CallbackPtr_id
     global_counter.CallbackPtr_id += 1
     global_counter.CallbackPtr_by_number[number] = self
     self.space = space
     self.w_callable = w_callable
     self.number = number
     self.args = [space.str_w(w_arg) for w_arg in space.unpackiterable(
         w_args)]
     self.result = space.str_w(w_result)
     ffiargs = [_get_type_(space, arg) for arg in self.args]
     ffiresult = _get_type_(space, self.result)
     # necessary to keep stuff alive
     self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
                                        callback, number)
     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)
예제 #7
0
 def __init__(self, space, w_callable, w_args, w_result):
     number = global_counter.CallbackPtr_id
     global_counter.CallbackPtr_id += 1
     global_counter.CallbackPtr_by_number[number] = self
     self.space = space
     self.w_callable = w_callable
     self.number = number
     self.args = [space.str_w(w_arg) for w_arg in space.unpackiterable(
         w_args)]
     self.result = space.str_w(w_result)
     ffiargs = [_get_type_(space, arg) for arg in self.args]
     ffiresult = _get_type_(space, self.result)
     # necessary to keep stuff alive
     self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
                                        callback, number)
     self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.ll_closure)
     if tracker.DO_TRACING:
         addr = rffi.cast(rffi.INT, self.ll_callback.ll_closure)
         tracker.trace_allocation(addr, self)
예제 #8
0
파일: callback.py 프로젝트: Debug-Orz/Sypy
 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)
     self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
                                        callback, self.number, flags)
     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)