diff options
author | Daniel Llorens <lloda@sarc.name> | 2020-02-03 13:04:13 +0100 |
---|---|---|
committer | Daniel Llorens <lloda@sarc.name> | 2020-04-09 16:59:39 +0200 |
commit | 996bbb47f20d9459d259a9a1a4a820a0b2960ca8 (patch) | |
tree | 4f6c5f333e60c941d5b7a89a970a93e0976d3d82 | |
parent | fa19f702f6698b7b82325a03b1b03cbcd042aa2d (diff) | |
download | guile-996bbb47f20d9459d259a9a1a4a820a0b2960ca8.tar.gz |
Require vector argument to scm_vector_elements, scm_vector_writable_elements
* libguile/vectors.c (scm_vector_elements, scm_vector_writable_elements): As
stated.
* libguile/sort.c: Fix usage of scm_vector_elements on possibly non-vector
array.
* doc/ref/api-data.texi (scm_vector_elements): Remove mention of non-vector
arrays.
-rw-r--r-- | doc/ref/api-data.texi | 5 | ||||
-rw-r--r-- | libguile/sort.c | 21 | ||||
-rw-r--r-- | libguile/vectors.c | 32 |
3 files changed, 32 insertions, 26 deletions
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi index a6b09c478..750f71195 100644 --- a/doc/ref/api-data.texi +++ b/doc/ref/api-data.texi @@ -6463,10 +6463,7 @@ handle must eventually be released with The variables pointed to by @var{lenp} and @var{incp} are filled with the number of elements of the vector and the increment (number of -elements) between successive elements, respectively. Successive -elements of @var{vec} need not be contiguous in their underlying -``root vector'' returned here; hence the increment is not necessarily -equal to 1 and may well be negative too (@pxref{Shared Arrays}). +elements) between successive elements, respectively. The following example shows the typical way to use this function. It creates a list of all elements of @var{vec} (in reverse order). diff --git a/libguile/sort.c b/libguile/sort.c index 05ecee577..0827ebe26 100644 --- a/libguile/sort.c +++ b/libguile/sort.c @@ -562,22 +562,23 @@ SCM_DEFINE (scm_stable_sort_x, "stable-sort!", 2, 0, 0, } else if (scm_is_array (items) && 1 == scm_c_array_rank (items)) { - scm_t_array_handle temp_handle, vec_handle; - SCM temp, *temp_elts, *vec_elts; - size_t len; - ssize_t inc; - - vec_elts = scm_vector_writable_elements (items, &vec_handle, - &len, &inc); + scm_t_array_handle vec_handle; + scm_array_get_handle (items, &vec_handle); + + SCM *vec_elts = scm_array_handle_writable_elements (&vec_handle); + scm_t_array_dim *vec_dim = scm_array_handle_dims (&vec_handle); + size_t len = vec_dim->ubnd + 1 - vec_dim->lbnd; + ssize_t inc = vec_dim->inc; + if (len == 0) { scm_array_handle_release (&vec_handle); return items; } - temp = scm_c_make_vector (len, SCM_UNDEFINED); - temp_elts = scm_vector_writable_elements (temp, &temp_handle, - NULL, NULL); + SCM temp = scm_c_make_vector (len, SCM_UNDEFINED); + scm_t_array_handle temp_handle; + SCM *temp_elts = scm_vector_writable_elements (temp, &temp_handle, NULL, NULL); scm_merge_vector_step (vec_elts, temp_elts, less, 0, len-1, inc); diff --git a/libguile/vectors.c b/libguile/vectors.c index fe07c6bb0..fa28c61ca 100644 --- a/libguile/vectors.c +++ b/libguile/vectors.c @@ -64,34 +64,42 @@ scm_is_simple_vector (SCM obj) const SCM * scm_vector_elements (SCM vec, scm_t_array_handle *h, size_t *lenp, ssize_t *incp) +#define FUNC_NAME "scm_vector_elements" { + SCM_VALIDATE_VECTOR (1, vec); scm_array_get_handle (vec, h); - if (1 != scm_array_handle_rank (h)) - { - scm_array_handle_release (h); - scm_wrong_type_arg_msg (NULL, 0, vec, "rank 1 array of Scheme values"); - } if (lenp) { scm_t_array_dim *dim = scm_array_handle_dims (h); *lenp = dim->ubnd - dim->lbnd + 1; - *incp = dim->inc; } + if (incp) + *incp = 1; + return scm_array_handle_elements (h); } +#undef FUNC_NAME SCM * scm_vector_writable_elements (SCM vec, scm_t_array_handle *h, size_t *lenp, ssize_t *incp) +#define FUNC_NAME "scm_vector_writable_elements" { - const SCM *ret = scm_vector_elements (vec, h, lenp, incp); - - if (h->writable_elements != h->elements) - scm_wrong_type_arg_msg (NULL, 0, vec, "mutable vector"); - - return (SCM *) ret; + SCM_VALIDATE_MUTABLE_VECTOR (1, vec); + scm_array_get_handle (vec, h); + + if (lenp) + { + scm_t_array_dim *dim = scm_array_handle_dims (h); + *lenp = dim->ubnd - dim->lbnd + 1; + } + if (incp) + *incp = 1; + + return scm_array_handle_writable_elements (h); } +#undef FUNC_NAME SCM_DEFINE (scm_vector_p, "vector?", 1, 0, 0, (SCM obj), |