diff options
-rw-r--r-- | ffi.c | 9 | ||||
-rw-r--r-- | ffi.h | 1 | ||||
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | txr.1 | 25 |
4 files changed, 37 insertions, 0 deletions
@@ -4407,6 +4407,14 @@ val length_carray(val carray) return if3(scry->nelem < 0, nil, num(scry->nelem)); } +val copy_carray(val carray) +{ + struct carray *scry = carray_struct_checked(carray); + val copy = make_carray(scry->eltype, scry->data, scry->nelem, nil); + carray_dup(copy); + return copy; +} + mem_t *carray_ptr(val carray, val type, val self) { struct carray *scry = carray_struct_checked(carray); @@ -5014,6 +5022,7 @@ void ffi_init(void) reg_fun(intern(lit("carray-free"), user_package), func_n1(carray_free)); reg_fun(intern(lit("carray-type"), user_package), func_n1(carray_type)); reg_fun(intern(lit("length-carray"), user_package), func_n1(length_carray)); + reg_fun(intern(lit("copy-carray"), user_package), func_n1(copy_carray)); reg_fun(intern(lit("carray-vec"), user_package), func_n3o(carray_vec, 2)); reg_fun(intern(lit("carray-list"), user_package), func_n3o(carray_list, 2)); reg_fun(intern(lit("carray-blank"), user_package), func_n2(carray_blank)); @@ -94,6 +94,7 @@ val carray_own(val carray); val carray_free(val carray); val carray_type(val carray); val length_carray(val carray); +val copy_carray(val carray); mem_t *carray_ptr(val carray, val type, val self); val carray_vec(val vec, val type, val null_term_p); val carray_list(val list, val type, val null_term_p); @@ -9131,6 +9131,8 @@ val copy(val seq) return copy_hash(seq); if (seq->co.cls == random_state_s) return make_random_state(seq, nil); + if (seq->co.cls == carray_s) + return copy_carray(seq); if (structp(seq)) return copy_struct(seq); /* fallthrough */ @@ -24908,6 +24908,14 @@ is a structure, it returns .cblk .meti (copy-struct << object ). .cble +If +.meta object +is a +.codn carray , +it returns +.cblk +.meti (copy-carray << object ). +.cble Lastly, if .meta object is a random state, it returns @@ -56540,6 +56548,23 @@ has an unknown length, then .code nil is returned. +.coNP Function @ copy-carray +.synb +.mets (copy-carray << carray ) +.syne +.desc +The +.code copy-carray +function returns a duplicate of +.metn carray . + +The duplicate has the same element type and length, but has its own +copy of the underlying storage. This is true whether or not +.meta carray +owns its storage or not. In either case, the duplicate owns +.I its +copy of the storage. + .coNP Function @ carray-set-length .synb .mets (carray-set-length < carray << length ) |