1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-06 07:30:28 +02:00

Simplify interfaces to scm_TYPEvector_(writable_)elements

Nothing is lost in these since the functions already required true typed
vectors, the extra arguments didn't serve any purpose.

Changing my mind from (vec) to (vec, lenp), though. Will fix
vector/bitvector next.

* libguile/srfi-4.h: scm_TYPEvector_(writable_)elements take (vec, lenp).
* libguile/srfi-4.c: Fix implementation.
* libguile/bitvectors.c: Fix use.
* test-suite/standalone/test-srfi-4.c: Fix old test and write variant
  with full array handle interface.
* doc/ref/srfi-modules.texi: Fix doc for srfi-4
  scm_TYPEvector_(writable_)elements.
This commit is contained in:
Daniel Llorens 2020-02-05 14:40:19 +01:00
parent e3795a39fa
commit 04c80519bf
6 changed files with 106 additions and 162 deletions

View file

@ -134,28 +134,21 @@
scm_wrong_type_arg_msg (NULL, 0, h->array, "mutable " #tag "vector"); \
return (ctype *) scm_array_handle_##tag##_elements (h); \
} \
const ctype *scm_##tag##vector_elements (SCM uvec, \
scm_t_array_handle *h, \
size_t *lenp, ssize_t *incp) \
const ctype *scm_##tag##vector_elements (SCM uvec, size_t *lenp) \
{ \
size_t byte_width = width * sizeof (ctype); \
if (!scm_is_bytevector (uvec) \
|| (scm_c_bytevector_length (uvec) % byte_width)) \
scm_wrong_type_arg_msg (NULL, 0, uvec, #tag "vector"); \
scm_array_get_handle (uvec, h); \
if (lenp) \
*lenp = scm_c_bytevector_length (uvec) / byte_width; \
if (incp) \
*incp = 1; \
return ((const ctype *) h->elements); \
*lenp = SCM_BYTEVECTOR_LENGTH (uvec) / byte_width; \
return ((const ctype *) SCM_BYTEVECTOR_CONTENTS(uvec)); \
} \
ctype *scm_##tag##vector_writable_elements (SCM uvec, \
scm_t_array_handle *h, \
size_t *lenp, ssize_t *incp) \
ctype *scm_##tag##vector_writable_elements (SCM uvec, size_t *lenp) \
{ \
const ctype *ret = scm_##tag##vector_elements (uvec, h, lenp, incp);\
if (h->writable_elements != h->elements) \
scm_wrong_type_arg_msg (NULL, 0, h->array, "mutable " #tag "vector"); \
const ctype *ret = scm_##tag##vector_elements (uvec, lenp); \
if (!SCM_MUTABLE_BYTEVECTOR_P (uvec)) \
scm_wrong_type_arg_msg (NULL, 0, uvec, "mutable " #tag "vector"); \
return (ctype *) ret; \
}