[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 11/27: Add lenp parameter back to scm_bitvector_(writabl
From: |
Daniel Llorens |
Subject: |
[Guile-commits] 11/27: Add lenp parameter back to scm_bitvector_(writable_)elements |
Date: |
Wed, 8 Apr 2020 04:03:49 -0400 (EDT) |
lloda pushed a commit to branch wip-vector-cleanup
in repository guile.
commit cfddf5357f07fc92411e6dcfd0b673d41b6335f7
Author: Daniel Llorens <address@hidden>
AuthorDate: Wed Feb 5 15:55:19 2020 +0100
Add lenp parameter back to scm_bitvector_(writable_)elements
---
NEWS-wip-vector-cleanup.txt | 4 ++--
doc/ref/api-data.texi | 4 ++--
libguile/bitvectors.c | 22 ++++++++++++++--------
libguile/bitvectors.h | 4 ++--
4 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/NEWS-wip-vector-cleanup.txt b/NEWS-wip-vector-cleanup.txt
index 8edd5bb..1eb40ff 100644
--- a/NEWS-wip-vector-cleanup.txt
+++ b/NEWS-wip-vector-cleanup.txt
@@ -34,11 +34,11 @@ Use SCM_VECTOR_REF, SCM_VECTOR_SET and SCM_VECTOR_LENGTH
instead.
** 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_array_get_handle and scm_array_handle_elements /
scm_array_handle_writable_elements on general #t arrays.
** 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_array_get_handle and scm_array_handle_bit_elements /
scm_array_handle_bit_writable_elements on general 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 a764188..010d4c8 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -6663,13 +6663,13 @@ For example,
@end example
@end deffn
-@deftypefn {C Function} {const scm_t_uint32 *} scm_bitvector_elements (SCM vec)
+@deftypefn {C Function} {const scm_t_uint32 *} scm_bitvector_elements (SCM
vec, size_t *lenp)
Like @code{scm_vector_elements} (@pxref{Vector Accessing from C}), but
for bitvectors. See @code{scm_array_handle_bit_elements} for how to use the
returned
pointer.
@end deftypefn
-@deftypefn {C Function} {scm_t_uint32 *} scm_bitvector_writable_elements (SCM
vec)
+@deftypefn {C Function} {scm_t_uint32 *} scm_bitvector_writable_elements (SCM
vec, size_t *lenp)
Like @code{scm_bitvector_elements}, but the pointer is good for reading
and writing.
@end deftypefn
diff --git a/libguile/bitvectors.c b/libguile/bitvectors.c
index f3d4cf2..2b41f6d 100644
--- a/libguile/bitvectors.c
+++ b/libguile/bitvectors.c
@@ -218,16 +218,20 @@ scm_array_handle_bit_elements_offset (scm_t_array_handle
*h)
} while (0)
const uint32_t *
-scm_bitvector_elements (SCM vec)
+scm_bitvector_elements (SCM vec, size_t *lenp)
{
SCM_VALIDATE_BITVECTOR (1, vec);
+ if (lenp)
+ *lenp = BITVECTOR_LENGTH (vec);
return BITVECTOR_BITS (vec);
}
uint32_t *
-scm_bitvector_writable_elements (SCM vec)
+scm_bitvector_writable_elements (SCM vec, size_t *lenp)
{
SCM_VALIDATE_MUTABLE_BITVECTOR (1, vec);
+ if (lenp)
+ *lenp = BITVECTOR_LENGTH (vec);
return BITVECTOR_BITS (vec);
}
@@ -250,8 +254,9 @@ bitset_ (uint32_t *bits, size_t idx, bool b)
SCM
scm_c_bitvector_ref (SCM vec, size_t idx)
{
- const uint32_t *bits = scm_bitvector_elements (vec);
- if (idx >= BITVECTOR_LENGTH (vec))
+ size_t len;
+ const uint32_t *bits = scm_bitvector_elements (vec, &len);
+ if (idx >= len)
scm_out_of_range (NULL, scm_from_size_t (idx));
return scm_from_bool (bitref_(bits, idx));
}
@@ -269,8 +274,9 @@ SCM_DEFINE (scm_bitvector_ref, "bitvector-ref", 2, 0, 0,
void
scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val)
{
- uint32_t *bits = scm_bitvector_writable_elements (vec);
- if (idx >= BITVECTOR_LENGTH (vec))
+ size_t len;
+ uint32_t *bits = scm_bitvector_writable_elements (vec, &len);
+ if (idx >= len)
scm_out_of_range (NULL, scm_from_size_t (idx));
bitset_(bits, idx, scm_is_true (val));
@@ -335,7 +341,7 @@ SCM_DEFINE (scm_list_to_bitvector, "list->bitvector", 1, 0,
0,
size_t bit_len = scm_to_size_t (scm_length (list));
SCM vec = scm_c_make_bitvector (bit_len, SCM_UNDEFINED);
size_t word_len = (bit_len+31)/32;
- uint32_t *bits = scm_bitvector_writable_elements (vec);
+ uint32_t *bits = scm_bitvector_writable_elements (vec, NULL);
size_t i, j;
for (i = 0; i < word_len && scm_is_pair (list); i++, bit_len -= 32)
@@ -745,7 +751,7 @@ scm_istr2bve (SCM str)
const char *c_str;
uint32_t *data;
- data = scm_bitvector_writable_elements (vec);
+ data = scm_bitvector_writable_elements (vec, NULL);
c_str = scm_i_string_chars (str);
for (k = 0; k < (len + 31) / 32; k++)
diff --git a/libguile/bitvectors.h b/libguile/bitvectors.h
index 8263907..1c5b7df 100644
--- a/libguile/bitvectors.h
+++ b/libguile/bitvectors.h
@@ -57,8 +57,8 @@ SCM_API void scm_c_bitvector_set_x (SCM vec, size_t idx, SCM
val);
SCM_API const uint32_t *scm_array_handle_bit_elements (scm_t_array_handle *h);
SCM_API uint32_t *scm_array_handle_bit_writable_elements (scm_t_array_handle
*h);
SCM_API size_t scm_array_handle_bit_elements_offset (scm_t_array_handle *h);
-SCM_API const uint32_t *scm_bitvector_elements (SCM vec);
-SCM_API uint32_t *scm_bitvector_writable_elements (SCM vec);
+SCM_API const uint32_t *scm_bitvector_elements (SCM vec, size_t *lenp);
+SCM_API uint32_t *scm_bitvector_writable_elements (SCM vec, size_t *lenp);
SCM_INTERNAL uint32_t *scm_i_bitvector_bits (SCM vec);
SCM_INTERNAL int scm_i_is_mutable_bitvector (SCM vec);
- [Guile-commits] branch wip-vector-cleanup updated (98bf49d -> 6b85b0f), Daniel Llorens, 2020/04/08
- [Guile-commits] 02/27: Require vector as argument to vector->list, Daniel Llorens, 2020/04/08
- [Guile-commits] 01/27: Require vector as argument to vector-copy, Daniel Llorens, 2020/04/08
- [Guile-commits] 08/27: Fix doc for last bitvector patch, Daniel Llorens, 2020/04/08
- [Guile-commits] 03/27: Require vector argument to scm_vector_elements, scm_vector_writable_elements, Daniel Llorens, 2020/04/08
- [Guile-commits] 04/27: Remove the unused argument from scm_array_p, Daniel Llorens, 2020/04/08
- [Guile-commits] 06/27: Simplify interfaces to scm_vector_elements and scm_vector_writable_elements, Daniel Llorens, 2020/04/08
- [Guile-commits] 09/27: Simplify interfaces to scm_TYPEvector_(writable_)elements, Daniel Llorens, 2020/04/08
- [Guile-commits] 10/27: Add lenp parameter back to scm_vector_(writable_)elements, Daniel Llorens, 2020/04/08
- [Guile-commits] 11/27: Add lenp parameter back to scm_bitvector_(writable_)elements,
Daniel Llorens <=
- [Guile-commits] 07/27: Simplify interfaces to scm_bitvector_elements and scm_bitvector_writable_elements, Daniel Llorens, 2020/04/08
- [Guile-commits] 12/27: Remove generalized vector support for vector-move-right!, vector-move-left!, Daniel Llorens, 2020/04/08
- [Guile-commits] 13/27: Move bitvector functions using array_handle to libguile/array-handle.[ch], Daniel Llorens, 2020/04/08
- [Guile-commits] 15/27: Rewrite vector-copy! using memmove, Daniel Llorens, 2020/04/08
- [Guile-commits] 14/27: Golf in srfi-4.h, Daniel Llorens, 2020/04/08
- [Guile-commits] 16/27: Pull generalized-vectors from under bitvector/string/vector, Daniel Llorens, 2020/04/08
- [Guile-commits] 17/27: Pull generalized-vectors from under typed vectors, Daniel Llorens, 2020/04/08
- [Guile-commits] 20/27: Update branch news file, Daniel Llorens, 2020/04/08
- [Guile-commits] 19/27: Remove generalized-vectors.[hc], Daniel Llorens, 2020/04/08
- [Guile-commits] 25/27: Remove superfluous type check in bitvector->list, Daniel Llorens, 2020/04/08