コード例 #1
0
ファイル: ccallback.py プロジェクト: sota/pypy-old
 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)
コード例 #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
 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
 def pypy_init_threads():
     if not space.config.objspace.usemodules.thread:
         return
     os_thread.setup_threads(space)
     before = rffi.aroundstate.before
     if before:
         before()
コード例 #5
0
ファイル: ccallback.py プロジェクト: mozillazg/pypy
 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)
コード例 #6
0
 def pypy_thread_attach():
     if not space.config.objspace.usemodules.thread:
         return
     os_thread.setup_threads(space)
     os_thread.bootstrapper.acquire(space, None, None)
     rthread.gc_thread_start()
     os_thread.bootstrapper.nbthreads += 1
     os_thread.bootstrapper.release()
     before = rffi.aroundstate.before
     if before: before()
コード例 #7
0
 def pypy_thread_attach():
     if not space.config.objspace.usemodules.thread:
         return
     os_thread.setup_threads(space)
     os_thread.bootstrapper.acquire(space, None, None)
     rthread.gc_thread_start()
     os_thread.bootstrapper.nbthreads += 1
     os_thread.bootstrapper.release()
     before = rffi.aroundstate.before
     if before: before()
コード例 #8
0
 def pypy_thread_attach():
     if not space.config.objspace.usemodules.thread:
         return
     os_thread.setup_threads(space)
     os_thread.bootstrapper.acquire(space, None, None)
     # XXX this doesn't really work.  Don't use os.fork(), and
     # if your embedder program uses fork(), don't use any PyPy
     # code in the fork
     rthread.gc_thread_start()
     os_thread.bootstrapper.nbthreads += 1
     os_thread.bootstrapper.release()
コード例 #9
0
 def pypy_thread_attach():
     if not space.config.objspace.usemodules.thread:
         return
     os_thread.setup_threads(space)
     os_thread.bootstrapper.acquire(space, None, None)
     # XXX this doesn't really work.  Don't use os.fork(), and
     # if your embedder program uses fork(), don't use any PyPy
     # code in the fork
     rthread.gc_thread_start()
     os_thread.bootstrapper.nbthreads += 1
     os_thread.bootstrapper.release()
コード例 #10
0
ファイル: ccallback.py プロジェクト: Qointum/pypy
 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)
コード例 #11
0
ファイル: ccallback.py プロジェクト: Qointum/pypy
 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)
コード例 #12
0
def load_embedded_cffi_module(space, version, init_struct):
    from pypy.module._cffi_backend.cffi1_module import load_cffi1_module
    declare_c_function()  # translation-time hint only:
    # declare _cffi_carefully_make_gil()
    #
    version = rffi.cast(lltype.Signed, version)
    if not (EMBED_VERSION_MIN <= version <= EMBED_VERSION_MAX):
        raise oefmt(space.w_ImportError,
                    "cffi embedded module has got unknown version tag %s",
                    hex(version))
    #
    if space.config.objspace.usemodules.thread:
        from pypy.module.thread import os_thread
        os_thread.setup_threads(space)
    #
    name = rffi.charp2str(init_struct.name)
    load_cffi1_module(space, name, None, init_struct.func)
    code = rffi.charp2str(init_struct.code)
    compiler = space.createcompiler()
    pycode = compiler.compile(code, "<init code for '%s'>" % name, 'exec', 0)
    w_globals = space.newdict(module=True)
    space.setitem_str(w_globals, "__builtins__", space.builtin)
    pycode.exec_code(space, w_globals, w_globals)
コード例 #13
0
ファイル: embedding.py プロジェクト: mozillazg/pypy
def load_embedded_cffi_module(space, version, init_struct):
    from pypy.module._cffi_backend.cffi1_module import load_cffi1_module
    declare_c_function()     # translation-time hint only:
                             # declare _cffi_carefully_make_gil()
    #
    version = rffi.cast(lltype.Signed, version)
    if not (EMBED_VERSION_MIN <= version <= EMBED_VERSION_MAX):
        raise oefmt(space.w_ImportError,
            "cffi embedded module has got unknown version tag %s",
            hex(version))
    #
    if space.config.objspace.usemodules.thread:
        from pypy.module.thread import os_thread
        os_thread.setup_threads(space)
    #
    name = rffi.charp2str(init_struct.name)
    load_cffi1_module(space, name, None, init_struct.func)
    code = rffi.charp2str(init_struct.code)
    compiler = space.createcompiler()
    pycode = compiler.compile(code, "<init code for '%s'>" % name, 'exec', 0)
    w_globals = space.newdict(module=True)
    space.setitem_str(w_globals, "__builtins__", space.wrap(space.builtin))
    pycode.exec_code(space, w_globals, w_globals)
コード例 #14
0
def PyEval_InitThreads(space):
    if not space.config.translation.thread:
        raise NoThreads
    from pypy.module.thread import os_thread
    os_thread.setup_threads(space)
コード例 #15
0
ファイル: pystate.py プロジェクト: Qointum/pypy
def PyEval_InitThreads(space):
    if not space.config.translation.thread:
        raise NoThreads
    from pypy.module.thread import os_thread
    os_thread.setup_threads(space)
コード例 #16
0
 def pypy_init_threads():
     if not space.config.objspace.usemodules.thread:
         return
     os_thread.setup_threads(space)
コード例 #17
0
ファイル: pystate.py プロジェクト: charred/pypy
def PyEval_InitThreads(space):
    os_thread.setup_threads(space)
コード例 #18
0
 def pypy_init_threads():
     if not space.config.objspace.usemodules.thread:
         return
     os_thread.setup_threads(space)
コード例 #19
0
 def pypy_init_threads():
     if not space.config.objspace.usemodules.thread:
         return
     os_thread.setup_threads(space)
     before = rffi.aroundstate.before
     if before: before()