lloda pushed a commit to branch wip-vector-cleanup in repository guile. commit 7f8612493db799a6261cd6fd37024ea95e566456 Author: Daniel Llorens <ll...@sarc.name> AuthorDate: Wed Feb 5 15:00:25 2020 +0100
Add lenp parameter back to scm_vector_(writable_)elements Also fix uses. --- NEWS-wip-vector-cleanup.txt | 5 ++--- doc/ref/api-data.texi | 12 ++++++------ libguile/sort.c | 2 +- libguile/vectors.c | 8 ++++++-- libguile/vectors.h | 4 ++-- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/NEWS-wip-vector-cleanup.txt b/NEWS-wip-vector-cleanup.txt index 58e13ec..8edd5bb 100644 --- a/NEWS-wip-vector-cleanup.txt +++ b/NEWS-wip-vector-cleanup.txt @@ -32,12 +32,11 @@ calls. Use SCM_VECTOR_REF, SCM_VECTOR_SET and SCM_VECTOR_LENGTH instead. -** scm_vector_elements / scm_vector_writable_elements take a single argument that must be a vector. +** The vector argument to scm_vector_elements / scm_vector_writable_elements must be a true vector. Handle/inc arguments have been removed. Use scm_array_get_handle and scm_array_handle_elements / scm_array_handle_writable_elements on general arrays. -Use scm_c_vector_length to get the length of a vector. -** scm_bitvector_elements / scm_bitvector_writable_elements take a single argument that must be a bitvector +** The vector argument to scm_bitvector_elements / scm_bitvector_writable_elements must be a true bitvector. Handle/inc arguments have been removed. Use scm_array_get_handle and scm_array_handle_bit_elements / scm_array_handle_bit_writable_elements on bit arrays. Use scm_array1_bit_elements (NEW) / scm_array1_bit_writable_elements (NEW) on rank-1 bit arrays. diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi index 148900d..a764188 100644 --- a/doc/ref/api-data.texi +++ b/doc/ref/api-data.texi @@ -6441,7 +6441,7 @@ Sets the element at position @var{idx} in the vector @var{vec} to @var{val}. No type or range checking is done. @end deftypefn -@deftypefn {C Function} {const SCM *} scm_vector_elements (SCM vec) +@deftypefn {C Function} {const SCM *} scm_vector_elements (SCM vec, size_t *lenp) Return a pointer to the elements of @var{vec}. This pointer can only be used to read the elements of @var{vec}. When @var{vec} is not a vector, an error is signaled. @@ -6452,8 +6452,8 @@ The following example shows the typical way to use this function. It creates a list of all elements of @var{vec} (in reverse order). @example -size_t len = scm_c_vector_length (vec); -const SCM *elt = scm_vector_elements (vec); +size_t len; +const SCM *elt = scm_vector_elements (vec, &len); SCM list = SCM_EOL; for (size_t i = 0; i < len; ++i) @@ -6462,7 +6462,7 @@ for (size_t i = 0; i < len; ++i) @end deftypefn -@deftypefn {C Function} {SCM *} scm_vector_writable_elements (SCM vec, scm_t_array_handle *handle, size_t *lenp, ssize_t *incp) +@deftypefn {C Function} {SCM *} scm_vector_writable_elements (SCM vec, size_t *lenp) Like @code{scm_vector_elements} but the pointer can be used to modify the vector. @@ -6472,8 +6472,8 @@ The following example shows the typical way to use this function. It fills a vector with @code{#t} (but see @code{vector-fill!}). @example -size_t len = scm_c_vector_length (vec); -SCM *elt = scm_vector_writable_elements (vec); +size_t len; +SCM *elt = scm_vector_writable_elements (vec, &len); for (size_t i = 0; i < len; ++i) elt[i] = SCM_BOOL_T; diff --git a/libguile/sort.c b/libguile/sort.c index 977a0b6..090a621 100644 --- a/libguile/sort.c +++ b/libguile/sort.c @@ -577,7 +577,7 @@ SCM_DEFINE (scm_stable_sort_x, "stable-sort!", 2, 0, 0, } SCM temp = scm_c_make_vector (len, SCM_UNDEFINED); - SCM *temp_elts = scm_vector_writable_elements (temp); + SCM *temp_elts = scm_vector_writable_elements (temp, 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 d481b14..0f74af2 100644 --- a/libguile/vectors.c +++ b/libguile/vectors.c @@ -56,19 +56,23 @@ scm_is_vector (SCM obj) } const SCM * -scm_vector_elements (SCM vec) +scm_vector_elements (SCM vec, size_t *lenp) #define FUNC_NAME "scm_vector_elements" { SCM_VALIDATE_VECTOR (1, vec); + if (lenp) + *lenp = SCM_I_VECTOR_LENGTH (vec); return SCM_I_VECTOR_ELTS (vec); } #undef FUNC_NAME SCM * -scm_vector_writable_elements (SCM vec) +scm_vector_writable_elements (SCM vec, size_t *lenp) #define FUNC_NAME "scm_vector_writable_elements" { SCM_VALIDATE_MUTABLE_VECTOR (1, vec); + if (lenp) + *lenp = SCM_I_VECTOR_LENGTH (vec); return SCM_I_VECTOR_WELTS (vec); } #undef FUNC_NAME diff --git a/libguile/vectors.h b/libguile/vectors.h index 0fa320b..455e394 100644 --- a/libguile/vectors.h +++ b/libguile/vectors.h @@ -47,8 +47,8 @@ SCM_API SCM scm_c_make_vector (size_t len, SCM fill); SCM_API size_t scm_c_vector_length (SCM vec); SCM_API SCM scm_c_vector_ref (SCM vec, size_t k); SCM_API void scm_c_vector_set_x (SCM vec, size_t k, SCM obj); -SCM_API const SCM *scm_vector_elements (SCM vec); -SCM_API SCM *scm_vector_writable_elements (SCM vec); +SCM_API const SCM *scm_vector_elements (SCM vec, size_t *lenp); +SCM_API SCM *scm_vector_writable_elements (SCM vec, size_t *lenp); #define SCM_VALIDATE_VECTOR(pos, v) \ do { \