guile-commits
[Top][All Lists]
Advanced

[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);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]