From 51785a23a88aae3585d40b44f0c706502ccdf8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Wed, 29 Nov 2006 09:25:32 +0000 Subject: [PATCH] Changes from arch/CVS synchronization --- libguile/ChangeLog | 2 +- libguile/vectors.c | 12 ++++++------ test-suite/ChangeLog | 2 +- test-suite/tests/vectors.test | 12 ++++++++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 0e5986066..ef88b2d17 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,4 +1,4 @@ -2006-11-29 Ludovic Courtès +2006-11-29 Ludovic Courtès * libguile/vectors.c (scm_vector_to_list): Fixed list construction: elements were not copied when INC is zero (see diff --git a/libguile/vectors.c b/libguile/vectors.c index 7a6fdfd92..fef48cc3e 100644 --- a/libguile/vectors.c +++ b/libguile/vectors.c @@ -392,15 +392,15 @@ SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0, SCM res = SCM_EOL; const SCM *data; scm_t_array_handle handle; - size_t i, len; + size_t i, count, len; ssize_t inc; data = scm_vector_elements (v, &handle, &len, &inc); - for (i = len*inc; i > 0;) - { - i -= inc; - res = scm_cons (data[i], res); - } + for (i = (len - 1) * inc, count = 0; + count < len; + i -= inc, count++) + res = scm_cons (data[i], res); + scm_array_handle_release (&handle); return res; } diff --git a/test-suite/ChangeLog b/test-suite/ChangeLog index b179bf353..117273be1 100644 --- a/test-suite/ChangeLog +++ b/test-suite/ChangeLog @@ -1,4 +1,4 @@ -2006-11-29 Ludovic Courtès +2006-11-29 Ludovic Courtès * test-suite/tests/vectors.test: Use `define-module'. (vector->list): New test prefix. "Shared array" test contributed diff --git a/test-suite/tests/vectors.test b/test-suite/tests/vectors.test index 1fb16bcb0..738a0828a 100644 --- a/test-suite/tests/vectors.test +++ b/test-suite/tests/vectors.test @@ -17,6 +17,8 @@ ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;;;; Boston, MA 02110-1301 USA +(define-module (test-suite vectors) + :use-module (test-suite lib)) ;; FIXME: As soon as guile supports immutable vectors, this has to be ;; replaced with the appropriate error type and message. @@ -29,3 +31,13 @@ (expect-fail-exception "vector constant" exception:immutable-vector (vector-set! '#(1 2 3) 0 4))) + +(with-test-prefix "vector->list" + + (pass-if "simple vector" + (equal? '(1 2 3) (vector->list #(1 2 3)))) + + (pass-if "shared array" + (let ((b (make-shared-array #(1) (lambda (x) '(0)) 2))) + (equal? b (list->vector (vector->list b)))))) +