diff options
author | Daniel Llorens <daniel.llorens@bluewin.ch> | 2017-09-15 12:36:57 +0200 |
---|---|---|
committer | Daniel Llorens <daniel.llorens@bluewin.ch> | 2017-10-31 13:23:17 +0100 |
commit | 4212f29655db2e9ddca19ebd590bca5521c1b97b (patch) | |
tree | 962aafd11f614e068cdae1da2c54f8fb626e82b4 /libguile/array-handle.c | |
parent | 1008ea315483d1fb41b2a8c10680e511238836d0 (diff) | |
download | guile-4212f29655db2e9ddca19ebd590bca5521c1b97b.tar.gz |
Allow scm_XXX_writable_elements on empty vectors, even if immutable
* libguile/array-handle.c (initialize_vector_handle): Set both element
pointers to NULL if the vector is empty.
* libguile/array-map.c (racp): Ignore immutability if destination is
empty.
* test-suite/tests/sort.test: Check empty/mutable/immutable vectors with
sort!.
* test-suite/tests/array-map.test: Check array-copy! with
empty/immutable destination.
Diffstat (limited to 'libguile/array-handle.c')
-rw-r--r-- | libguile/array-handle.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libguile/array-handle.c b/libguile/array-handle.c index 3d81efc04..947462a59 100644 --- a/libguile/array-handle.c +++ b/libguile/array-handle.c @@ -149,8 +149,10 @@ initialize_vector_handle (scm_t_array_handle *h, size_t len, h->dim0.ubnd = (ssize_t) (len - 1U); h->dim0.inc = 1; h->element_type = element_type; - h->elements = elements; - h->writable_elements = mutable_p ? ((void *) elements) : NULL; + /* elements != writable_elements is used to check mutability later on. + Ignore it if the array is empty. */ + h->elements = len==0 ? NULL : elements; + h->writable_elements = mutable_p ? ((void *) h->elements) : NULL; h->vector = h->array; h->vref = vref; h->vset = vset; |