Esempio n. 1
0
def _reveal(space, ptr):
    addr = rffi.cast(llmemory.Address, ptr)
    gcref = rgc.reveal_gcref(addr)
    if not gcref:
        raise oefmt(space.w_RuntimeError,
                    "cannot use from_handle() on NULL pointer")
    cd = rgc.try_cast_gcref_to_instance(cdataobj.W_CDataHandle, gcref)
    if cd is None:
        raise oefmt(space.w_SystemError,
                    "ffi.from_handle(): dead or bogus object handle")
    return cd.w_keepalive
Esempio n. 2
0
def _reveal(space, ptr):
    addr = rffi.cast(llmemory.Address, ptr)
    gcref = rgc.reveal_gcref(addr)
    if not gcref:
        raise oefmt(space.w_RuntimeError,
                    "cannot use from_handle() on NULL pointer")
    cd = rgc.try_cast_gcref_to_instance(cdataobj.W_CDataHandle, gcref)
    if cd is None:
        raise oefmt(space.w_SystemError,
                    "ffi.from_handle(): dead or bogus object handle")
    return cd.w_keepalive
Esempio n. 3
0
def invoke_callback(ffi_cif, ll_res, ll_args, ll_userdata):
    """ Callback specification.
    ffi_cif - something ffi specific, don't care
    ll_args - rffi.VOIDPP - pointer to array of pointers to args
    ll_res - rffi.VOIDP - pointer to result
    ll_userdata - a special structure which holds necessary information
                  (what the real callback is for example), casted to VOIDP
    """
    # Reveal the callback.
    addr = rffi.cast(llmemory.Address, ll_userdata)
    gcref = rgc.reveal_gcref(addr)
    callback = rgc.try_cast_gcref_to_instance(Callback, gcref)
    if callback is None:
        try:
            os.write(STDERR,
                "Critical error: invoking a callback that was already freed\n")
        except:
            pass
        # We cannot do anything here.
    else:
        #must_leave = False
        try:
            # must_leave = space.threadlocals.try_enter_thread(space)
            # Should check for separate threads here and crash
            # if the callback comes from a thread that has no execution context.
            cfunc = callback.cfunc
            argv = []
            for i in range(0, len(cfunc.argtypes)):
                argv.append( cfunc.argtypes[i].load(ll_args[i], False) )
            value = callback.callback.call(argv)
            if isinstance(cfunc.restype, Type):
                cfunc.restype.store(None, ll_res, value)
        except Unwinder as unwinder:
            core.root_unwind(unwinder)
        except Exception as e:
            try:
                os.write(STDERR, "SystemError: callback raised ")
                os.write(STDERR, str(e))
                os.write(STDERR, "\n")
            except:
                pass
Esempio n. 4
0
def reveal_callback(raw_ptr):
    addr = rffi.cast(llmemory.Address, raw_ptr)
    gcref = rgc.reveal_gcref(addr)
    return rgc.try_cast_gcref_to_instance(W_ExternPython, gcref)
Esempio n. 5
0
def reveal_callback(raw_ptr):
    addr = rffi.cast(llmemory.Address, raw_ptr)
    gcref = rgc.reveal_gcref(addr)
    return rgc.try_cast_gcref_to_instance(W_ExternPython, gcref)
Esempio n. 6
0
 def reveal_object(Class, raw_ptr):
     addr = rffi.cast(llmemory.Address, raw_ptr)
     gcref = rgc.reveal_gcref(addr)
     return rgc.try_cast_gcref_to_instance(Class, gcref)