diff options
-rw-r--r-- | ffi.c | 26 | ||||
-rw-r--r-- | ffi.h | 2 | ||||
-rw-r--r-- | txr.1 | 39 |
3 files changed, 67 insertions, 0 deletions
@@ -4899,6 +4899,30 @@ val num_carray(val carray) return sign_extend(normalize(ubn), unum(bits)); } +val put_carray(val carray, val offs, val stream) +{ + struct carray *scry = carray_struct_checked(carray); + struct txr_ffi_type *etft = scry->eltft; + ucnum size = (ucnum) etft->size * (ucnum) scry->nelem; + val buf = make_borrowed_buf(unum(size), scry->data); + val pos = default_arg(offs, zero); + val ret = put_buf(buf, pos, stream); + gc_hint(carray); + return ret; +} + +val fill_carray(val carray, val offs, val stream) +{ + struct carray *scry = carray_struct_checked(carray); + struct txr_ffi_type *etft = scry->eltft; + ucnum size = (ucnum) etft->size * (ucnum) scry->nelem; + val buf = make_borrowed_buf(unum(size), scry->data); + val pos = default_arg(offs, zero); + val ret = fill_buf(buf, pos, stream); + gc_hint(carray); + return ret; +} + void ffi_init(void) { prot1(&ffi_typedef_hash); @@ -5011,6 +5035,8 @@ void ffi_init(void) reg_fun(intern(lit("carray-num"), user_package), func_n2o(carray_num, 1)); reg_fun(intern(lit("unum-carray"), user_package), func_n1(unum_carray)); reg_fun(intern(lit("num-carray"), user_package), func_n1(num_carray)); + reg_fun(intern(lit("put-carray"), user_package), func_n3o(put_carray, 1)); + reg_fun(intern(lit("fill-carray"), user_package), func_n3o(fill_carray, 1)); ffi_typedef_hash = make_hash(nil, nil, nil); ffi_init_types(); ffi_init_extra_types(); @@ -116,4 +116,6 @@ val carray_unum(val num, val type); val carray_num(val num, val type); val unum_carray(val carray); val num_carray(val carray); +val put_carray(val carray, val offs, val stream); +val fill_carray(val carray, val offs, val stream); void ffi_init(void); @@ -57175,6 +57175,45 @@ of the bytes are .codn #xFF , the value -1 is returned. +.coNP Functions @ fill-carray and @ put-carray +.synb +.mets (fill-array < carray >> [ pos <> [ stream ]]) +.mets (put-array < carray >> [ pos <> [ stream ]]) +.syne +.desc +The +.code fill-array +and +.code put-array +functions perform stream output using the +.code carray +object as a buffer. + +The semantics of these functions is as follows. +A temporary buffer is created which aliases the storage of +.meta carray +and this buffer is used as an argument in an invocation of, respectively, +the buffer I/O function +.meta fill-buf +or +.metn put-buf . + +The value returned by buffer I/O function is returned. + +The +.meta pos +and +.meta stream +arguments are defaulted exactly in the same manner as by +.code fill-buf +and +.codn put-buf , +and have the same meaning. In particular, +.meta pos +indicates a byte offset into the +.meta carray +object's storage, not an array index. + .SH* INTERACTIVE LISTENER .SS* Overview |