diff options
-rw-r--r-- | ffi.c | 14 | ||||
-rw-r--r-- | ffi.h | 1 | ||||
-rw-r--r-- | txr.1 | 27 |
3 files changed, 42 insertions, 0 deletions
@@ -2619,6 +2619,19 @@ val carray_buf(val buf, val type) return make_carray(type, data, nelem, buf); } +val carray_buf_sync(val carray) +{ + val self = lit("carray-buf-sync"); + struct carray *scry = carray_struct_checked(carray); + val buf = scry->ref; + mem_t *data = buf_get(buf, self); + cnum blen = c_num(length_buf(buf)); + struct txr_ffi_type *tft = ffi_type_struct(scry->eltype); + scry->nelem = blen / tft->size; + scry->data = data; + return buf; +} + val carray_cptr(val cptr, val type, val len) { mem_t *data = cptr_get(cptr); @@ -2756,6 +2769,7 @@ void ffi_init(void) reg_fun(intern(lit("carray-vec"), user_package), func_n3o(carray_vec, 2)); reg_fun(intern(lit("carray-blank"), user_package), func_n2(carray_blank)); reg_fun(intern(lit("carray-buf"), user_package), func_n2(carray_buf)); + reg_fun(intern(lit("carray-buf-sync"), user_package), func_n1(carray_buf_sync)); 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)); @@ -74,6 +74,7 @@ mem_t *carray_get(val carray, val type, val self); val carray_vec(val vec, val type, val null_term_p); val carray_blank(val nelem, val type); val carray_buf(val buf, val type); +val carray_buf_sync(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); @@ -54968,6 +54968,33 @@ type, the calculated number of elements is rounded down. The trailing portion of the buffer corresponding to the division remainder, being insufficient to constitute a whole array element, is excluded from the array view. +.coNP Function @ carray-buf-sync +.synb +.mets (carray-buf-sync << carray ) +.syne +.desc +The +.code carray-buf-sync +function requires +.meta carray +to be a +.code carray +object which refers to a +.code buf +object for its storage. Such objects are created by the function +.codn carray-buf . + +The +.code carray-buf-sync +function retrieves and returns the buffer object associated with +.meta carray +and at the same time also updates the internal properties of +.meta carray +using the current information: the pointer to the data, and the +length of +.meta carray +are altered to reflect the current state of the buffer. + .coNP Function @ carray-cptr .synb .mets (carray-cptr < cptr < type <> [ length ]) |