def str_from_buffer(raw_buf, gc_buf, allocated_size, needed_size): """ Converts from a pair returned by alloc_buffer to a high-level string. The returned string will be truncated to needed_size. """ assert allocated_size >= needed_size if gc_buf and (allocated_size == needed_size): return hlstrtype(gc_buf) new_buf = lltype.malloc(STRTYPE, needed_size) if gc_buf: copy_string_contents(gc_buf, new_buf, 0, 0, needed_size) else: copy_raw_to_string(raw_buf, new_buf, 0, needed_size) return hlstrtype(new_buf)
def str_from_buffer(raw_buf, gc_buf, case_num, allocated_size, needed_size): """ Converts from a pair returned by alloc_buffer to a high-level string. The returned string will be truncated to needed_size. """ assert allocated_size >= needed_size if allocated_size != needed_size: from rpython.rtyper.lltypesystem.lloperation import llop if llop.shrink_array(lltype.Bool, gc_buf, needed_size): pass # now 'gc_buf' is smaller else: gc_buf = mallocfn(needed_size) case_num = 2 if case_num == 2: copy_raw_to_string(raw_buf, gc_buf, 0, needed_size) return hlstrtype(gc_buf)
def str_from_buffer(raw_buf, gc_buf, case_num, allocated_size, needed_size): """ Converts from a pair returned by alloc_buffer to a high-level string. The returned string will be truncated to needed_size. """ assert allocated_size >= needed_size if allocated_size != needed_size: from rpython.rtyper.lltypesystem.lloperation import llop if llop.shrink_array(lltype.Bool, gc_buf, needed_size): pass # now 'gc_buf' is smaller else: gc_buf = mallocfn(needed_size) case_num = 2 if case_num == 2: copy_raw_to_string(raw_buf, gc_buf, 0, needed_size) return hlstrtype(gc_buf)
def charpsize2str(cp, size): ll_str = mallocfn(size) copy_raw_to_string(cp, ll_str, 0, size) result = hlstrtype(ll_str) assert result is not None return result
def charpsize2str(cp, size): ll_str = mallocfn(size) copy_raw_to_string(cp, ll_str, 0, size) result = hlstrtype(ll_str) assert result is not None return result