diff options
-rw-r--r-- | ffi.c | 9 | ||||
-rw-r--r-- | ffi.h | 1 | ||||
-rw-r--r-- | stdlib/doc-syms.tl | 1 | ||||
-rw-r--r-- | txr.1 | 36 |
4 files changed, 47 insertions, 0 deletions
@@ -5549,6 +5549,14 @@ val carray_cptr(val cptr, val type, val len) return make_carray(type, data, nelem, nil, 0); } +val cptr_carray(val carray, val type_sym_in) +{ + val self = lit("cptr-carray"); + struct carray *scry = carray_struct_checked(self, carray); + val type_sym = default_null_arg(type_sym_in); + return cptr_typed(scry->data, type_sym, 0); +} + val vec_carray(val carray, val null_term_p) { val self = lit("vec-carray"); @@ -6779,6 +6787,7 @@ void ffi_init(void) 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("cptr-carray"), user_package), func_n2o(cptr_carray, 1)); 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)); @@ -111,6 +111,7 @@ 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 cptr_carray(val carray, val type_sym_in); 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); diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl index b51932ba..d88c3b0b 100644 --- a/stdlib/doc-syms.tl +++ b/stdlib/doc-syms.tl @@ -419,6 +419,7 @@ ("countqual" "N-01DF131F") ("cptr" "D-0013") ("cptr-buf" "N-037139E3") + ("cptr-carray" "N-02257F04") ("cptr-cast" "N-01A212ED") ("cptr-free" "N-02B1FBEF") ("cptr-get" "N-00513A70") @@ -80880,6 +80880,42 @@ length of the array. Note: this conversion is inherently unsafe. +.coNP Function @ cptr-carray +.synb +.mets (cptr-carray < carray <> [ type-symbol ]) +.syne +.desc +The +.code cptr-carray +function returns a +.code cptr +object which holds a pointer to a +.code carray +object's storage area. The +.meta carray +argument must be of type +.codn carray . + +The +.meta type-symbol +argument should be a symbol. If omitted, it defaults to +.codn nil . +This symbol becomes the +.code cptr +object's type tag. + +The lifetime of the returned +.code cptr +object is independent from that of +.metn carray . +If the lifetime of +.meta carray +reaches its end before that of the +.codn cptr , +the pointer stored inside the +.code cptr +becomes invalid. + .coNP Function @ length-carray .synb .mets (length-carray << carray ) |