1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Require vector as argument to vector->list

* libguile/vectors.c (vector->list): As stated. Simplify.
* test-suite/tests/vectors.test: Remove shared array test.
This commit is contained in:
Daniel Llorens 2020-02-03 11:42:01 +01:00
parent 21ede682af
commit fa19f702f6
2 changed files with 7 additions and 18 deletions

View file

@ -280,8 +280,8 @@ SCM_DEFINE (scm_vector_copy, "vector-copy", 1, 0, 0,
SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0, SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0,
(SCM v), (SCM vec),
"Return a newly allocated list composed of the elements of @var{v}.\n" "Return a newly allocated list composed of the elements of @var{vec}.\n"
"\n" "\n"
"@lisp\n" "@lisp\n"
"(vector->list '#(dah dah didah)) @result{} (dah dah didah)\n" "(vector->list '#(dah dah didah)) @result{} (dah dah didah)\n"
@ -289,19 +289,12 @@ SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0,
"@end lisp") "@end lisp")
#define FUNC_NAME s_scm_vector_to_list #define FUNC_NAME s_scm_vector_to_list
{ {
SCM_VALIDATE_VECTOR(1, vec);
SCM res = SCM_EOL; SCM res = SCM_EOL;
const SCM *data; ssize_t len = SCM_I_VECTOR_LENGTH (vec);
scm_t_array_handle handle; const SCM * data = SCM_I_VECTOR_ELTS (vec);
size_t i, count, len; for (ssize_t i = len-1; i >= 0; --i)
ssize_t inc;
data = scm_vector_elements (v, &handle, &len, &inc);
for (i = (len - 1) * inc, count = 0;
count < len;
i -= inc, count++)
res = scm_cons (data[i], res); res = scm_cons (data[i], res);
scm_array_handle_release (&handle);
return res; return res;
} }
#undef FUNC_NAME #undef FUNC_NAME

View file

@ -41,11 +41,7 @@
(pass-if "string-vector 2" (pass-if "string-vector 2"
(equal? '("abc\u0100" "def\u0101" "ghi\u0102") (equal? '("abc\u0100" "def\u0101" "ghi\u0102")
(vector->list #("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))))))
(with-test-prefix "make-vector" (with-test-prefix "make-vector"