Exemple #1
0
def make_buf(value):
    buf = memoryview(bytes(value))
    rv = ffi.new("RelayBuf *")
    rv.data = ffi.from_buffer(buf)
    rv.len = len(buf)
    attached_refs[rv] = buf
    return rv
Exemple #2
0
def _init_valid_platforms():
    global VALID_PLATFORMS

    size_out = ffi.new("uintptr_t *")
    strings = rustcall(lib.relay_valid_platforms, size_out)

    valid_platforms = []
    for i in range(int(size_out[0])):
        valid_platforms.append(decode_str(strings[i], free=True))

    VALID_PLATFORMS = frozenset(valid_platforms)
Exemple #3
0
def encode_str(s, mutable=False):
    """Encodes a RelayStr"""
    rv = ffi.new("RelayStr *")
    if isinstance(s, text_type):
        s = s.encode("utf-8")
    if mutable:
        s = bytearray(s)
    rv.data = ffi.from_buffer(s)
    rv.len = len(s)
    # we have to hold a weak reference here to ensure our string does not
    # get collected before the string is used.
    attached_refs[rv] = s
    return rv