Esempio n. 1
0
def new_xptr_p(x):
    h = ffi.new_handle(x)
    hp = ffi.cast("void*", h)
    _global_set[hp] = h
    s = lib.R_MakeExternalPtr(hp, lib.R_NilValue, lib.R_NilValue)
    lib.R_RegisterCFinalizerEx(s, finalizer, 1)
    return s
Esempio n. 2
0
def new_xptr_p(x):
    h = ffi.new_handle(x)
    hp = ffi.cast("void*", h)
    _global_set[hp] = h
    s = lib.R_MakeExternalPtr(hp, lib.R_NilValue, lib.R_NilValue)
    lib.Rf_protect(s)
    lib.R_RegisterCFinalizerEx(s, ffi.addressof(lib, "xptr_finalizer"), 1)
    lib.Rf_unprotect(1)
    return s
Esempio n. 3
0
def cb_read_console(p, buf, buflen, add_history):
    # cache the code as buflen is limited to 4096
    if _code[0]:
        code = _code[0]
    else:
        text = callback.read_console(rconsole2str(ffi.string(p)), add_history)
        if text is None:
            return 0
        code = utf8tosystem(text)
        _code[0] = code

    buf = ffi.cast("char*", buf)
    nb = min(len(code), buflen - 2)
    buf[0:nb] = code[0:nb]
    if nb < buflen - 2:
        buf[nb] = b'\n'
        buf[nb + 1] = b'\x00'

    _code[0] = _code[0][nb:]
    return 1
Esempio n. 4
0
def rcopy(_, s):  # noqa
    x = rcall(("base", "get"), "pyobj", s)
    p = ffi.cast("uintptr_t", lib.R_ExternalPtrAddr(unbox(x)))
    d = long(p)
    obj = ctypes.cast(d, ctypes.py_object)
    return obj.value