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

commit 4135c3c3b2ea7b256097ae46fdddcaa9cbc753e5
Author: Daniel Llorens <ll...@sarc.name>
AuthorDate: Mon Feb 3 11:42:01 2020 +0100

    Require vector as argument to vector->list
    
    * libguile/vectors.c (vector->list): As stated. Simplify.
    * test-suite/tests/vectors.test: Remove shared array test.
---
 libguile/vectors.c            | 19 ++++++-------------
 test-suite/tests/vectors.test |  6 +-----
 2 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/libguile/vectors.c b/libguile/vectors.c
index e88354b..62a6428 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -276,8 +276,8 @@ SCM_DEFINE (scm_vector_copy, "vector-copy", 1, 0, 0,
 
 
 SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0, 
-           (SCM v),
-           "Return a newly allocated list composed of the elements of 
@var{v}.\n"
+           (SCM vec),
+           "Return a newly allocated list composed of the elements of 
@var{vec}.\n"
            "\n"
            "@lisp\n"
            "(vector->list '#(dah dah didah)) @result{}  (dah dah didah)\n"
@@ -285,19 +285,12 @@ SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0,
            "@end lisp")
 #define FUNC_NAME s_scm_vector_to_list
 {
+  SCM_VALIDATE_VECTOR(1, vec);
   SCM res = SCM_EOL;
-  const SCM *data;
-  scm_t_array_handle handle;
-  size_t i, count, len;
-  ssize_t inc;
-
-  data = scm_vector_elements (v, &handle, &len, &inc);
-  for (i = (len - 1) * inc, count = 0;
-       count < len;
-       i -= inc, count++)
+  ssize_t len = SCM_I_VECTOR_LENGTH (vec);
+  const SCM * data = SCM_I_VECTOR_ELTS (vec);
+  for (ssize_t i = len-1; i >= 0; --i)
     res = scm_cons (data[i], res);
-
-  scm_array_handle_release (&handle);
   return res;
 }
 #undef FUNC_NAME
diff --git a/test-suite/tests/vectors.test b/test-suite/tests/vectors.test
index 97b3f18..6db608c 100644
--- a/test-suite/tests/vectors.test
+++ b/test-suite/tests/vectors.test
@@ -41,11 +41,7 @@
 
   (pass-if "string-vector 2"
     (equal? '("abc\u0100" "def\u0101" "ghi\u0102") 
-            (vector->list #("abc\u0100" "def\u0101" "ghi\u0102"))))
-
-  (pass-if "shared array"
-    (let ((b (make-shared-array #(1) (lambda (x) '(0)) 2)))
-      (equal? b (list->vector (vector->list b))))))
+            (vector->list #("abc\u0100" "def\u0101" "ghi\u0102")))))
 
 (with-test-prefix "make-vector"
 

Reply via email to