Heya, On Sat 06 Jun 2009 16:31, l...@gnu.org (Ludovic Courtès) writes:
> Hello, > > "Andy Wingo" <wi...@pobox.com> writes: > >> +SCM_DEFINE (scm_uniform_array_to_bytevector, "uniform-array->bytevector", >> + 1, 0, 0, (SCM array), >> + "Return a newly allocated bytevector whose contents\n" >> + "will be copied from the uniform array @var{array}.") >> +#define FUNC_NAME s_scm_uniform_array_to_bytevector >> +{ >> + SCM contents, ret; >> + size_t len; >> + scm_t_array_handle h; >> + const void *base; >> + size_t sz; >> + >> + contents = scm_array_contents (array, SCM_BOOL_T); >> + if (scm_is_false (contents)) >> + scm_wrong_type_arg_msg (FUNC_NAME, 0, array, "uniform contiguous >> array"); >> + >> + scm_array_get_handle (contents, &h); >> + >> + base = scm_array_handle_uniform_elements (&h); >> + len = h.dims->inc * (h.dims->ubnd - h.dims->lbnd + 1); >> + sz = scm_array_handle_uniform_element_size (&h); >> + >> + ret = make_bytevector (len * sz); >> + memcpy (SCM_BYTEVECTOR_CONTENTS (ret), base, len * sz); > > Is this memcpy valid in the case of shared arrays? Looks like we end up > copying more elements than needed, but maybe it's better this way. I'm not entirely sure. I thought that scm_array_contents will give me a contiguous array, though trolling around in srfi-4.[ch] and unif.[ch] makes me grumpy ;) >> + uniform-array->bytevector > > I would not export it from `(rnrs bytevector)' given that it has nothing > to do with RnRS. No, but it does have to with bytevectors... Where would you put it? > Also, I would make the new C functions private, given that they are not > intended for general use AIUI. Dunno. I could imagine calling both of them from C. Would there be a problem with leaving them to be public? Cheers, Andy -- http://wingolog.org/