mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-17 01:00:20 +02:00
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.
This commit is contained in:
parent
1008ea3154
commit
4212f29655
4 changed files with 30 additions and 12 deletions
|
@ -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;
|
||||
|
|
|
@ -263,7 +263,7 @@ racp (SCM src, SCM dst)
|
|||
{
|
||||
SCM const * el_s = h_s.elements;
|
||||
SCM * el_d = h_d.writable_elements;
|
||||
if (!el_d)
|
||||
if (!el_d && n>0)
|
||||
scm_wrong_type_arg_msg ("array-copy!", SCM_ARG2, dst, "mutable array");
|
||||
for (; n-- > 0; i_s += inc_s, i_d += inc_d)
|
||||
el_d[i_d] = el_s[i_s];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue