diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-05-19 22:11:50 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-05-19 22:11:50 -0700 |
commit | 12d65cff8c48ac1f86b056f542296adbc1fd3651 (patch) | |
tree | 5f983a6dfd2af6f483aacb5cb516a018a986f133 | |
parent | f4c156db5e4505fc1a18ae7d4a6597b656a20aa2 (diff) | |
download | txr-12d65cff8c48ac1f86b056f542296adbc1fd3651.tar.gz txr-12d65cff8c48ac1f86b056f542296adbc1fd3651.tar.bz2 txr-12d65cff8c48ac1f86b056f542296adbc1fd3651.zip |
ffi: new function, carray-cptr.
* ffi.c (carray_cptr): New function.
(ffi_init): Registered intrinsic.
* ffi.h (carray_cptr): Declared.
* txr.1: Documented.
-rw-r--r-- | ffi.c | 9 | ||||
-rw-r--r-- | ffi.h | 1 | ||||
-rw-r--r-- | txr.1 | 41 |
3 files changed, 51 insertions, 0 deletions
@@ -2615,6 +2615,14 @@ val carray_buf(val buf, val type) return make_carray(type, data, nelem, buf); } +val carray_cptr(val cptr, val type, val len) +{ + mem_t *data = cptr_get(cptr); + cnum nelem = c_num(default_arg(len, negone)); + (void) ffi_type_struct(type); + return make_carray(type, data, nelem, 0); +} + val vec_carray(val carray, val null_term_p) { val nt_p = default_null_arg(null_term_p); @@ -2744,6 +2752,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-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)); reg_fun(intern(lit("carray-ref"), user_package), func_n2(carray_ref)); @@ -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_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); @@ -54968,6 +54968,47 @@ 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-cptr +.synb +.mets (carray-cptr < cptr < type <> [ length ]) +.syne +.desc +The +.code carray-cptr +function creates a +.code carray +object based on a pointer derived from a +.code cptr +object. + +The +.meta cptr +argument must be of type +.codn cptr . +The object's +.code cptr +type tag is ignored. + +The +.meta type +argument must specify a compiled FFI type, which will become +the element type of the returned +.codn carray . + +If +.meta length +is specified as +.codn nil , +or not specified, +then the returned +.code carray +object will be of unknown length. Otherwise, +.meta length +must be a non-negative integer which will be taken as the +length of the array. + +Note: this conversion is inherently unsafe. + .coNP Function @ length-carray .synb .mets (length-carray << carray ) |