summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-20 07:37:42 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-20 07:37:42 -0700
commit6d8f4f8f500c8e8d36ff66a1160788042e219b61 (patch)
tree27af96725c9b21049327f26042f3b1808f239032
parent92f85ff3b8a5ff6da61dd8ea2710e16a017fafbc (diff)
downloadtxr-6d8f4f8f500c8e8d36ff66a1160788042e219b61.tar.gz
txr-6d8f4f8f500c8e8d36ff66a1160788042e219b61.tar.bz2
txr-6d8f4f8f500c8e8d36ff66a1160788042e219b61.zip
ffi: new carray-buf-sync function.
* ffi.c (carray_buf_sync): New function. (ffi_init): carray-buf-sync intrinsic registered. * ffi.h (carray_buf_sync): Declared. * txr.1: Documented.
-rw-r--r--ffi.c14
-rw-r--r--ffi.h1
-rw-r--r--txr.127
3 files changed, 42 insertions, 0 deletions
diff --git a/ffi.c b/ffi.c
index 6dfd663c..5624b9dd 100644
--- a/ffi.c
+++ b/ffi.c
@@ -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));
diff --git a/ffi.h b/ffi.h
index 59a3ec30..5545126e 100644
--- a/ffi.h
+++ b/ffi.h
@@ -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);
diff --git a/txr.1 b/txr.1
index 4de55690..df361b52 100644
--- a/txr.1
+++ b/txr.1
@@ -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 ])