guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 09/27: Simplify interfaces to scm_TYPEvector_(writable_)


From: Daniel Llorens
Subject: [Guile-commits] 09/27: Simplify interfaces to scm_TYPEvector_(writable_)elements
Date: Wed, 8 Apr 2020 04:03:48 -0400 (EDT)

lloda pushed a commit to branch wip-vector-cleanup
in repository guile.

commit 3e735bfb6143f538473577064890fa1376843042
Author: Daniel Llorens <address@hidden>
AuthorDate: Wed Feb 5 14:40:19 2020 +0100

    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.
---
 NEWS-wip-vector-cleanup.txt         |   1 -
 doc/ref/srfi-modules.texi           |  48 ++++++++--------
 libguile/bitvectors.c               |  29 +++-------
 libguile/srfi-4.c                   |  21 +++----
 libguile/srfi-4.h                   | 111 ++++++++----------------------------
 test-suite/standalone/test-srfi-4.c |  58 ++++++++++++++-----
 6 files changed, 106 insertions(+), 162 deletions(-)

diff --git a/NEWS-wip-vector-cleanup.txt b/NEWS-wip-vector-cleanup.txt
index d7915bb..58e13ec 100644
--- a/NEWS-wip-vector-cleanup.txt
+++ b/NEWS-wip-vector-cleanup.txt
@@ -35,7 +35,6 @@ Use SCM_VECTOR_REF, SCM_VECTOR_SET and SCM_VECTOR_LENGTH 
instead.
 ** scm_vector_elements / scm_vector_writable_elements take a single argument 
that must be a vector.
 
 Use scm_array_get_handle and scm_array_handle_elements / 
scm_array_handle_writable_elements on general arrays.
-
 Use scm_c_vector_length to get the length of a vector.
 
 ** scm_bitvector_elements / scm_bitvector_writable_elements take a single 
argument that must be a bitvector
diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index fd19079..0f8ad39 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -1705,35 +1705,35 @@ are at even indices in that array, the corresponding 
imaginary parts are
 at the following odd index.
 @end deftypefn
 
-@deftypefn {C Function} {const scm_t_uint8 *} scm_u8vector_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const scm_t_int8 *} scm_s8vector_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const scm_t_uint16 *} scm_u16vector_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const scm_t_int16 *} scm_s16vector_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const scm_t_uint32 *} scm_u32vector_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const scm_t_int32 *} scm_s32vector_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const scm_t_uint64 *} scm_u64vector_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const scm_t_int64 *} scm_s64vector_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const float *} scm_f32vector_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const double *} scm_f64vector_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const float *} scm_c32vector_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {const double *} scm_c64vector_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
+@deftypefn {C Function} {const scm_t_uint8 *} scm_u8vector_elements (SCM vec, 
size_t *lenp)
+@deftypefnx {C Function} {const scm_t_int8 *} scm_s8vector_elements (SCM vec, 
size_t *lenp)
+@deftypefnx {C Function} {const scm_t_uint16 *} scm_u16vector_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {const scm_t_int16 *} scm_s16vector_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {const scm_t_uint32 *} scm_u32vector_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {const scm_t_int32 *} scm_s32vector_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {const scm_t_uint64 *} scm_u64vector_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {const scm_t_int64 *} scm_s64vector_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {const float *} scm_f32vector_elements (SCM vec, 
size_t *lenp)
+@deftypefnx {C Function} {const double *} scm_f64vector_elements (SCM vec, 
size_t *lenp)
+@deftypefnx {C Function} {const float *} scm_c32vector_elements (SCM vec, 
size_t *lenp)
+@deftypefnx {C Function} {const double *} scm_c64vector_elements (SCM vec, 
size_t *lenp)
 Like @code{scm_vector_elements} (@pxref{Vector Accessing from C}), but
 returns a pointer to the elements of a uniform numeric vector of the
 indicated kind.
 @end deftypefn
 
-@deftypefn {C Function} {scm_t_uint8 *} scm_u8vector_writable_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {scm_t_int8 *} scm_s8vector_writable_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {scm_t_uint16 *} scm_u16vector_writable_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {scm_t_int16 *} scm_s16vector_writable_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {scm_t_uint32 *} scm_u32vector_writable_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {scm_t_int32 *} scm_s32vector_writable_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {scm_t_uint64 *} scm_u64vector_writable_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {scm_t_int64 *} scm_s64vector_writable_elements (SCM 
vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {float *} scm_f32vector_writable_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {double *} scm_f64vector_writable_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {float *} scm_c32vector_writable_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
-@deftypefnx {C Function} {double *} scm_c64vector_writable_elements (SCM vec, 
scm_t_array_handle *handle, size_t *lenp, ssize_t *incp)
+@deftypefn {C Function} {scm_t_uint8 *} scm_u8vector_writable_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {scm_t_int8 *} scm_s8vector_writable_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {scm_t_uint16 *} scm_u16vector_writable_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {scm_t_int16 *} scm_s16vector_writable_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {scm_t_uint32 *} scm_u32vector_writable_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {scm_t_int32 *} scm_s32vector_writable_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {scm_t_uint64 *} scm_u64vector_writable_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {scm_t_int64 *} scm_s64vector_writable_elements (SCM 
vec, size_t *lenp)
+@deftypefnx {C Function} {float *} scm_f32vector_writable_elements (SCM vec, 
size_t *lenp)
+@deftypefnx {C Function} {double *} scm_f64vector_writable_elements (SCM vec, 
size_t *lenp)
+@deftypefnx {C Function} {float *} scm_c32vector_writable_elements (SCM vec, 
size_t *lenp)
+@deftypefnx {C Function} {double *} scm_c64vector_writable_elements (SCM vec, 
size_t *lenp)
 Like @code{scm_vector_writable_elements} (@pxref{Vector Accessing from
 C}), but returns a pointer to the elements of a uniform numeric vector
 of the indicated kind.
diff --git a/libguile/bitvectors.c b/libguile/bitvectors.c
index 137262a..f3d4cf2 100644
--- a/libguile/bitvectors.c
+++ b/libguile/bitvectors.c
@@ -607,19 +607,12 @@ SCM_DEFINE (scm_bit_set_star_x, "bit-set*!", 3, 0, 0,
               bitset_ (v_bits, v_off+i*v_inc, bit);
        }
     }
-  /* FIXME This requires a true u32vector so handle, inc, etc. are superfluous 
*/
   else if (scm_is_true (scm_u32vector_p (kv)))
     {
-      scm_t_array_handle kv_handle;
-      size_t i, kv_len;
-      ssize_t kv_inc;
-      const uint32_t *kv_elts;
-
-      kv_elts = scm_u32vector_elements (kv, &kv_handle, &kv_len, &kv_inc);
-      for (i = 0; i < kv_len; i++, kv_elts += kv_inc)
-        bitset_ (v_bits, v_off+(*kv_elts)*v_inc, bit);
-
-      scm_array_handle_release (&kv_handle);
+      size_t kv_len;
+      const uint32_t *kv_elts  = scm_u32vector_elements (kv, &kv_len);
+      for (size_t i = 0; i < kv_len; i++)
+        bitset_ (v_bits, v_off+(kv_elts[i])*v_inc, bit);
     }
   else 
     scm_wrong_type_arg_msg (NULL, 0, kv, "bitvector or u32vector");
@@ -693,20 +686,14 @@ SCM_DEFINE (scm_bit_count_star, "bit-count*", 3, 0, 0,
   /* FIXME This requires a true u32vector so handle, inc, etc. are superfluous 
*/
   else if (scm_is_true (scm_u32vector_p (kv)))
     {
-      scm_t_array_handle kv_handle;
-      size_t i, kv_len;
-      ssize_t kv_inc;
-      const uint32_t *kv_elts;
-
-      kv_elts = scm_u32vector_elements (kv, &kv_handle, &kv_len, &kv_inc);
-      for (i = 0; i < kv_len; i++, kv_elts += kv_inc)
+      size_t kv_len;
+      const uint32_t *kv_elts = scm_u32vector_elements (kv, &kv_len);
+      for (size_t i = 0; i < kv_len; i++)
        {
-          bool elt = bitref_ (v_bits, v_off+(*kv_elts)*v_inc);
+          bool elt = bitref_ (v_bits, v_off+(kv_elts[i])*v_inc);
          if ((bit && elt) || (!bit && !elt))
            count++;
        }
-
-      scm_array_handle_release (&kv_handle);
     }
   else 
     scm_wrong_type_arg_msg (NULL, 0, kv, "bitvector or u32vector");
diff --git a/libguile/srfi-4.c b/libguile/srfi-4.c
index cb9de9d..912feeb 100644
--- a/libguile/srfi-4.c
+++ b/libguile/srfi-4.c
@@ -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;                                               \
   }
 
diff --git a/libguile/srfi-4.h b/libguile/srfi-4.h
index 3f279e6..bbbff2b 100644
--- a/libguile/srfi-4.h
+++ b/libguile/srfi-4.h
@@ -42,13 +42,8 @@ SCM_API SCM scm_list_to_u8vector (SCM l);
 SCM_API SCM scm_any_to_u8vector (SCM obj);
 SCM_API const uint8_t *scm_array_handle_u8_elements (scm_t_array_handle *h);
 SCM_API uint8_t *scm_array_handle_u8_writable_elements (scm_t_array_handle *h);
-SCM_API const uint8_t *scm_u8vector_elements (SCM uvec, 
-                                                 scm_t_array_handle *h,
-                                                 size_t *lenp, ssize_t *incp);
-SCM_API uint8_t *scm_u8vector_writable_elements (SCM uvec, 
-                                                    scm_t_array_handle *h,
-                                                    size_t *lenp,
-                                                    ssize_t *incp);
+SCM_API const uint8_t *scm_u8vector_elements (SCM uvec, size_t *lenp);
+SCM_API uint8_t *scm_u8vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_s8vector_p (SCM obj);
 SCM_API SCM scm_make_s8vector (SCM n, SCM fill);
@@ -62,13 +57,8 @@ SCM_API SCM scm_list_to_s8vector (SCM l);
 SCM_API SCM scm_any_to_s8vector (SCM obj);
 SCM_API const int8_t *scm_array_handle_s8_elements (scm_t_array_handle *h);
 SCM_API int8_t *scm_array_handle_s8_writable_elements (scm_t_array_handle *h);
-SCM_API const int8_t *scm_s8vector_elements (SCM uvec, 
-                                                scm_t_array_handle *h,
-                                                size_t *lenp, ssize_t *incp);
-SCM_API int8_t *scm_s8vector_writable_elements (SCM uvec, 
-                                                   scm_t_array_handle *h,
-                                                   size_t *lenp,
-                                                   ssize_t *incp);
+SCM_API const int8_t *scm_s8vector_elements (SCM uvec, size_t *lenp);
+SCM_API int8_t *scm_s8vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_u16vector_p (SCM obj);
 SCM_API SCM scm_make_u16vector (SCM n, SCM fill);
@@ -82,14 +72,8 @@ SCM_API SCM scm_list_to_u16vector (SCM l);
 SCM_API SCM scm_any_to_u16vector (SCM obj);
 SCM_API const uint16_t *scm_array_handle_u16_elements (scm_t_array_handle *h);
 SCM_API uint16_t *scm_array_handle_u16_writable_elements (scm_t_array_handle 
*h);
-SCM_API const uint16_t *scm_u16vector_elements (SCM uvec, 
-                                                   scm_t_array_handle *h,
-                                                   size_t *lenp,
-                                                   ssize_t *incp);
-SCM_API uint16_t *scm_u16vector_writable_elements (SCM uvec, 
-                                                      scm_t_array_handle *h,
-                                                      size_t *lenp,
-                                                      ssize_t *incp);
+SCM_API const uint16_t *scm_u16vector_elements (SCM uvec, size_t *lenp);
+SCM_API uint16_t *scm_u16vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_s16vector_p (SCM obj);
 SCM_API SCM scm_make_s16vector (SCM n, SCM fill);
@@ -103,13 +87,8 @@ SCM_API SCM scm_list_to_s16vector (SCM l);
 SCM_API SCM scm_any_to_s16vector (SCM obj);
 SCM_API const int16_t *scm_array_handle_s16_elements (scm_t_array_handle *h);
 SCM_API int16_t *scm_array_handle_s16_writable_elements (scm_t_array_handle 
*h);
-SCM_API const int16_t *scm_s16vector_elements (SCM uvec, 
-                                                  scm_t_array_handle *h,
-                                                  size_t *lenp, ssize_t *incp);
-SCM_API int16_t *scm_s16vector_writable_elements (SCM uvec, 
-                                                     scm_t_array_handle *h,
-                                                     size_t *lenp,
-                                                     ssize_t *incp);
+SCM_API const int16_t *scm_s16vector_elements (SCM uvec, size_t *lenp);
+SCM_API int16_t *scm_s16vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_u32vector_p (SCM obj);
 SCM_API SCM scm_make_u32vector (SCM n, SCM fill);
@@ -123,14 +102,8 @@ SCM_API SCM scm_list_to_u32vector (SCM l);
 SCM_API SCM scm_any_to_u32vector (SCM obj);
 SCM_API const uint32_t *scm_array_handle_u32_elements (scm_t_array_handle *h);
 SCM_API uint32_t *scm_array_handle_u32_writable_elements (scm_t_array_handle 
*h);
-SCM_API const uint32_t *scm_u32vector_elements (SCM uvec, 
-                                                   scm_t_array_handle *h,
-                                                   size_t *lenp,
-                                                   ssize_t *incp);
-SCM_API uint32_t *scm_u32vector_writable_elements (SCM uvec, 
-                                                      scm_t_array_handle *h,
-                                                      size_t *lenp,
-                                                      ssize_t *incp);
+SCM_API const uint32_t *scm_u32vector_elements (SCM uvec, size_t *lenp);
+SCM_API uint32_t *scm_u32vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_s32vector_p (SCM obj);
 SCM_API SCM scm_make_s32vector (SCM n, SCM fill);
@@ -144,13 +117,8 @@ SCM_API SCM scm_list_to_s32vector (SCM l);
 SCM_API SCM scm_any_to_s32vector (SCM obj);
 SCM_API const int32_t *scm_array_handle_s32_elements (scm_t_array_handle *h);
 SCM_API int32_t *scm_array_handle_s32_writable_elements (scm_t_array_handle 
*h);
-SCM_API const int32_t *scm_s32vector_elements (SCM uvec, 
-                                                  scm_t_array_handle *h,
-                                                  size_t *lenp, ssize_t *incp);
-SCM_API int32_t *scm_s32vector_writable_elements (SCM uvec, 
-                                                     scm_t_array_handle *h,
-                                                     size_t *lenp,
-                                                     ssize_t *incp);
+SCM_API const int32_t *scm_s32vector_elements (SCM uvec, size_t *lenp);
+SCM_API int32_t *scm_s32vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_u64vector_p (SCM obj);
 SCM_API SCM scm_make_u64vector (SCM n, SCM fill);
@@ -165,14 +133,8 @@ SCM_API SCM scm_any_to_u64vector (SCM obj);
 SCM_API SCM scm_take_u64vector (uint64_t *data, size_t n);
 SCM_API const uint64_t *scm_array_handle_u64_elements (scm_t_array_handle *h);
 SCM_API uint64_t *scm_array_handle_u64_writable_elements (scm_t_array_handle 
*h);
-SCM_API const uint64_t *scm_u64vector_elements (SCM uvec, 
-                                                   scm_t_array_handle *h,
-                                                   size_t *lenp,
-                                                   ssize_t *incp);
-SCM_API uint64_t *scm_u64vector_writable_elements (SCM uvec, 
-                                                      scm_t_array_handle *h,
-                                                      size_t *lenp,
-                                                      ssize_t *incp);
+SCM_API const uint64_t *scm_u64vector_elements (SCM uvec, size_t *lenp);
+SCM_API uint64_t *scm_u64vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_s64vector_p (SCM obj);
 SCM_API SCM scm_make_s64vector (SCM n, SCM fill);
@@ -187,13 +149,8 @@ SCM_API SCM scm_any_to_s64vector (SCM obj);
 SCM_API SCM scm_take_s64vector (int64_t *data, size_t n);
 SCM_API const int64_t *scm_array_handle_s64_elements (scm_t_array_handle *h);
 SCM_API int64_t *scm_array_handle_s64_writable_elements (scm_t_array_handle 
*h);
-SCM_API const int64_t *scm_s64vector_elements (SCM uvec, 
-                                                  scm_t_array_handle *h,
-                                                  size_t *lenp, ssize_t *incp);
-SCM_API int64_t *scm_s64vector_writable_elements (SCM uvec, 
-                                                     scm_t_array_handle *h,
-                                                     size_t *lenp,
-                                                     ssize_t *incp);
+SCM_API const int64_t *scm_s64vector_elements (SCM uvec, size_t *lenp);
+SCM_API int64_t *scm_s64vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_f32vector_p (SCM obj);
 SCM_API SCM scm_make_f32vector (SCM n, SCM fill);
@@ -207,13 +164,8 @@ SCM_API SCM scm_list_to_f32vector (SCM l);
 SCM_API SCM scm_any_to_f32vector (SCM obj);
 SCM_API const float *scm_array_handle_f32_elements (scm_t_array_handle *h);
 SCM_API float *scm_array_handle_f32_writable_elements (scm_t_array_handle *h);
-SCM_API const float *scm_f32vector_elements (SCM uvec, 
-                                           scm_t_array_handle *h,
-                                           size_t *lenp, ssize_t *incp);
-SCM_API float *scm_f32vector_writable_elements (SCM uvec, 
-                                               scm_t_array_handle *h,
-                                               size_t *lenp,
-                                               ssize_t *incp);
+SCM_API const float *scm_f32vector_elements (SCM uvec, size_t *lenp);
+SCM_API float *scm_f32vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_f64vector_p (SCM obj);
 SCM_API SCM scm_make_f64vector (SCM n, SCM fill);
@@ -227,13 +179,8 @@ SCM_API SCM scm_list_to_f64vector (SCM l);
 SCM_API SCM scm_any_to_f64vector (SCM obj);
 SCM_API const double *scm_array_handle_f64_elements (scm_t_array_handle *h);
 SCM_API double *scm_array_handle_f64_writable_elements (scm_t_array_handle *h);
-SCM_API const double *scm_f64vector_elements (SCM uvec, 
-                                             scm_t_array_handle *h,
-                                             size_t *lenp, ssize_t *incp);
-SCM_API double *scm_f64vector_writable_elements (SCM uvec, 
-                                                scm_t_array_handle *h,
-                                                size_t *lenp,
-                                                ssize_t *incp);
+SCM_API const double *scm_f64vector_elements (SCM uvec, size_t *lenp);
+SCM_API double *scm_f64vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_c32vector_p (SCM obj);
 SCM_API SCM scm_make_c32vector (SCM n, SCM fill);
@@ -247,13 +194,8 @@ SCM_API SCM scm_list_to_c32vector (SCM l);
 SCM_API SCM scm_any_to_c32vector (SCM obj);
 SCM_API const float *scm_array_handle_c32_elements (scm_t_array_handle *h);
 SCM_API float *scm_array_handle_c32_writable_elements (scm_t_array_handle *h);
-SCM_API const float *scm_c32vector_elements (SCM uvec, 
-                                            scm_t_array_handle *h,
-                                            size_t *lenp, ssize_t *incp);
-SCM_API float *scm_c32vector_writable_elements (SCM uvec, 
-                                               scm_t_array_handle *h,
-                                               size_t *lenp,
-                                               ssize_t *incp);
+SCM_API const float *scm_c32vector_elements (SCM uvec, size_t *lenp);
+SCM_API float *scm_c32vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_API SCM scm_c64vector_p (SCM obj);
 SCM_API SCM scm_make_c64vector (SCM n, SCM fill);
@@ -267,13 +209,8 @@ SCM_API SCM scm_list_to_c64vector (SCM l);
 SCM_API SCM scm_any_to_c64vector (SCM obj);
 SCM_API const double *scm_array_handle_c64_elements (scm_t_array_handle *h);
 SCM_API double *scm_array_handle_c64_writable_elements (scm_t_array_handle *h);
-SCM_API const double *scm_c64vector_elements (SCM uvec, 
-                                             scm_t_array_handle *h,
-                                             size_t *lenp, ssize_t *incp);
-SCM_API double *scm_c64vector_writable_elements (SCM uvec, 
-                                                scm_t_array_handle *h,
-                                                size_t *lenp,
-                                                ssize_t *incp);
+SCM_API const double *scm_c64vector_elements (SCM uvec, size_t *lenp);
+SCM_API double *scm_c64vector_writable_elements (SCM uvec, size_t *lenp);
 
 SCM_INTERNAL void scm_init_srfi_4 (void);
 
diff --git a/test-suite/standalone/test-srfi-4.c 
b/test-suite/standalone/test-srfi-4.c
index 82897df..2d43604 100644
--- a/test-suite/standalone/test-srfi-4.c
+++ b/test-suite/standalone/test-srfi-4.c
@@ -34,28 +34,56 @@ test_writable_elements ()
 {
   SCM elts = scm_list_4 (scm_from_int (1), scm_from_int (2),
                          scm_from_int (3), scm_from_int (4));
-
+  /* Requiring true type vectors */
   {
     SCM v = scm_u32vector (elts);
     size_t len;
-    ssize_t inc;
-    scm_t_array_handle h;
-    uint32_t *elts = scm_u32vector_writable_elements (v, &h, &len, &inc);
+    uint32_t *elts = scm_u32vector_writable_elements (v, &len);
     assert (len == 4);
-    assert (inc == 1);
     assert (elts[0] == 1);
     assert (elts[3] == 4);
-    scm_array_handle_release (&h);
   }
 
   {
     SCM v = scm_f32vector (elts);
     size_t len;
-    ssize_t inc;
-    scm_t_array_handle h;
-    float *elts = scm_f32vector_writable_elements (v, &h, &len, &inc);
+    float *elts = scm_f32vector_writable_elements (v, &len);
     assert (len == 4);
-    assert (inc == 1);
+    assert (elts[0] == 1.0);
+    assert (elts[3] == 4.0);
+  }
+  {
+    SCM v = scm_c32vector (elts);
+    size_t len;
+    float *elts = scm_c32vector_writable_elements (v, &len);
+    assert (len == 4);
+    assert (elts[0] == 1.0);
+    assert (elts[1] == 0.0);
+    assert (elts[6] == 4.0);
+    assert (elts[7] == 0.0);
+  }
+  /* Accepting any typed array */
+  {
+    SCM v = scm_u32vector (elts);
+    scm_t_array_handle h;
+    scm_array_get_handle(v, &h);
+    scm_t_array_dim *dim = scm_array_handle_dims (&h);
+    uint32_t *elts = scm_array_handle_u32_writable_elements (&h);
+    assert (dim->ubnd + 1 - dim->lbnd == 4);
+    assert (dim->inc == 1);
+    assert (elts[0] == 1);
+    assert (elts[3] == 4);
+    scm_array_handle_release (&h);
+  }
+
+  {
+    SCM v = scm_f32vector (elts);
+    scm_t_array_handle h;
+    scm_array_get_handle(v, &h);
+    scm_t_array_dim *dim = scm_array_handle_dims (&h);
+    float *elts = scm_array_handle_f32_writable_elements (&h);
+    assert (dim->ubnd + 1 - dim->lbnd == 4);
+    assert (dim->inc == 1);
     assert (elts[0] == 1.0);
     assert (elts[3] == 4.0);
     scm_array_handle_release (&h);
@@ -63,12 +91,12 @@ test_writable_elements ()
 
   {
     SCM v = scm_c32vector (elts);
-    size_t len;
-    ssize_t inc;
     scm_t_array_handle h;
-    float *elts = scm_c32vector_writable_elements (v, &h, &len, &inc);
-    assert (len == 4);
-    assert (inc == 1);
+    scm_array_get_handle(v, &h);
+    scm_t_array_dim *dim = scm_array_handle_dims (&h);
+    float *elts = scm_array_handle_c32_writable_elements (&h);
+    assert (dim->ubnd + 1 - dim->lbnd == 4);
+    assert (dim->inc == 1);
     assert (elts[0] == 1.0);
     assert (elts[1] == 0.0);
     assert (elts[6] == 4.0);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]