diff options
-rw-r--r-- | ffi.c | 9 | ||||
-rw-r--r-- | ffi.h | 2 | ||||
-rw-r--r-- | txr.1 | 18 |
3 files changed, 29 insertions, 0 deletions
@@ -4838,6 +4838,14 @@ val carray_buf_sync(val carray) return buf; } +val buf_carray(val carray) +{ + struct carray *scry = carray_struct_checked(carray); + struct txr_ffi_type *etft = scry->eltft; + cnum bytes = scry->nelem * etft->size; + return make_duplicate_buf(num(bytes), scry->data); +} + val carray_cptr(val cptr, val type, val len) { mem_t *data = cptr_get(cptr); @@ -5580,6 +5588,7 @@ void ffi_init(void) reg_fun(intern(lit("carray-blank"), user_package), func_n2(carray_blank)); reg_fun(intern(lit("carray-buf"), user_package), func_n3o(carray_buf, 2)); reg_fun(intern(lit("carray-buf-sync"), user_package), func_n1(carray_buf_sync)); + reg_fun(intern(lit("buf-carray"), user_package), func_n1(buf_carray)); reg_fun(intern(lit("carray-cptr"), user_package), func_n3o(carray_cptr, 2)); reg_fun(intern(lit("vec-carray"), user_package), func_n2o(vec_carray, 1)); reg_fun(intern(lit("list-carray"), user_package), func_n2o(list_carray, 1)); @@ -105,11 +105,13 @@ val carray_list(val list, val type, val null_term_p); val carray_blank(val nelem, val type); val carray_buf(val buf, val type, val offs); val carray_buf_sync(val carray); +val buf_carray(val carray); val carray_cptr(val cptr, val type, val len); val vec_carray(val carray, val null_term_p); val list_carray(val carray, val null_term_p); val carray_ref(val carray, val idx); val carray_refset(val carray, val idx, val newval); +val buf_carray(val carray); val carray_sub(val carray, val from, val to); val carray_replace(val carray, val values, val from, val to); val carray_get(val carray); @@ -58598,6 +58598,24 @@ length of .meta carray are altered to reflect the current state of the buffer. +.coNP Function @ buf-carray +.synb +.mets (buf-carray << carray ) +.syne +.desc +The +.code buf-carray +function duplicates the underlying storage of +.meta carray +and returns that storage represented as an object of +.code buf +type. + +The storage size is calculated by multiplying the +.code carray +object's element size by the number of elements. +Only that extent of the storage is duplicated. + .coNP Function @ carray-cptr .synb .mets (carray-cptr < cptr < type <> [ length ]) |