[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 03/05: Prefer C-like interfaces for scm_c_bitvector_{set
From: |
Andy Wingo |
Subject: |
[Guile-commits] 03/05: Prefer C-like interfaces for scm_c_bitvector_{set, clear}_bits_x |
Date: |
Wed, 29 Apr 2020 05:14:41 -0400 (EDT) |
wingo pushed a commit to branch master
in repository guile.
commit 8861af39aee869c8a64f598e135966925433173c
Author: Andy Wingo <address@hidden>
AuthorDate: Thu Apr 23 21:30:24 2020 +0200
Prefer C-like interfaces for scm_c_bitvector_{set,clear}_bits_x
* libguile/bitvectors.h:
* libguile/bitvectors.c (scm_c_bitvector_set_bits_x)
(scm_c_bitvector_clear_bits_x): Expose only C-like interfaces. No
need to have a SCM_UNDEFINED return.
* libguile/deprecated.c (scm_bit_set_star_x): Adapt.
* doc/ref/api-data.texi (Bit Vectors): Update.
---
doc/ref/api-data.texi | 46 ++++++++++++---------------------
libguile/bitvectors.c | 70 ++++++++++++++++++++++++++++++---------------------
libguile/bitvectors.h | 4 +--
libguile/deprecated.c | 11 +++++---
4 files changed, 68 insertions(+), 63 deletions(-)
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index 11b547c..d28909a 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -6543,10 +6543,6 @@ Return @code{#t} when @var{obj} is a bitvector, else
return @code{#f}.
@end deffn
-@deftypefn {C Function} int scm_is_bitvector (SCM obj)
-Return @code{1} when @var{obj} is a bitvector, else return @code{0}.
-@end deftypefn
-
@deffn {Scheme Procedure} make-bitvector len [fill]
@deffnx {C Function} scm_make_bitvector (len, fill)
Create a new bitvector of length @var{len} and
@@ -6574,12 +6570,6 @@ Return @code{#t} if the bit at index @var{idx} of the
bitvector
@code{bitvector-bit-clear?}).
@end deffn
-@deftypefn {C Function} int scm_bitvector_bit_is_set (SCM vec, size_t idx)
-@deftypefnx {C Function} int scm_bitvector_bit_is_clear (SCM vec, size_t idx)
-Return 1 if the bit at index @var{idx} of the bitvector @var{vec} is set
-or clear, respectively, or 0 otherwise.
-@end deftypefn
-
@deffn {Scheme Procedure} bitvector-set-bit! vec idx
@deffnx {Scheme Procedure} bitvector-clear-bit! vec idx
Set (for @code{bitvector-set-bit!}) or clear (for
@@ -6587,23 +6577,12 @@ Set (for @code{bitvector-set-bit!}) or clear (for
@var{vec}.
@end deffn
-@deftypefn {C Function} void scm_c_bitvector_set_bit_x (SCM vec, size_t idx)
-@deftypefnx {C Function} void scm_c_bitvector_clear_bit_x (SCM vec, size_t idx)
-Set or clear the bit at index @var{idx} of the bitvector @var{vec}.
-@end deftypefn
-
@deffn {Scheme Procedure} bitvector-set-all-bits! vec
@deffnx {Scheme Procedure} bitvector-clear-all-bits! vec
@deffnx {Scheme Procedure} bitvector-flip-all-bits! vec
Set, clear, or flip all bits of @var{vec}.
@end deffn
-@deftypefn {C Function} void scm_c_bitvector_set_all_bits_x (SCM vec)
-@deftypefnx {C Function} void scm_c_bitvector_clear_all_bits_x (SCM vec)
-@deftypefnx {C Function} void scm_c_bitvector_flip_all_bits_x (SCM vec)
-Set, clear, or flip all bits in the bitvector @var{vec}.
-@end deftypefn
-
@deffn {Scheme Procedure} list->bitvector list
@deffnx {C Function} scm_list_to_bitvector (list)
Return a new bitvector initialized with the elements
@@ -6636,13 +6615,6 @@ For example,
@end example
@end deffn
-@deftypefn {C Function} size_t scm_c_bitvector_length (SCM bitvector)
-@deftypefnx {C Function} size_t scm_c_bitvector_count (SCM bitvector)
-@deftypefnx {C Function} size_t scm_c_bitvector_count_bits (SCM bitvector, SCM
bits)
-Same as @code{bitvector-length}, @code{bitvector-count}, and
-@code{bitvector-count-bits}, but returning a @code{size_t} result.
-@end deftypefn
-
@deffn {Scheme Procedure} bitvector-position bitvector bool start
@deffnx {C Function} scm_bitvector_position (bitvector, bool, start)
Return the index of the first occurrence of @var{bool} in
@@ -6657,7 +6629,6 @@ entry between @var{start} and the end of @var{bitvector},
then return
@end deffn
@deffn {Scheme Procedure} bitvector-set-bits! bitvector bits
-@deffnx {C Function} scm_bit_set_star_x (bitvector, bits)
Set entries of @var{bitvector} to @code{#t}, with @var{bits} selecting
the bits to set. The return value is unspecified. @var{bitvector} must
be at least as long as @var{bits}.
@@ -6671,7 +6642,6 @@ bv
@end deffn
@deffn {Scheme Procedure} bitvector-clear-bits! bitvector bits
-@deffnx {C Function} scm_bitvector_clear_bits_x (bitvector, bits)
Set entries of @var{bitvector} to @code{#f}, with @var{bits} selecting
the bits to clear. The return value is unspecified. @var{bitvector}
must be at least as long as @var{bits}.
@@ -6684,6 +6654,22 @@ bv
@end example
@end deffn
+@deftypefn {C Function} int scm_is_bitvector (SCM obj)
+@deftypefnx {C Function} int scm_bitvector_bit_is_set (SCM vec, size_t idx)
+@deftypefnx {C Function} int scm_bitvector_bit_is_clear (SCM vec, size_t idx)
+@deftypefnx {C Function} void scm_c_bitvector_set_bit_x (SCM vec, size_t idx)
+@deftypefnx {C Function} void scm_c_bitvector_clear_bit_x (SCM vec, size_t idx)
+@deftypefnx {C Function} void scm_c_bitvector_set_bits_x (SCM vec, SCM bits)
+@deftypefnx {C Function} void scm_c_bitvector_clear_bits_x (SCM vec, SCM bits)
+@deftypefnx {C Function} void scm_c_bitvector_set_all_bits_x (SCM vec)
+@deftypefnx {C Function} void scm_c_bitvector_clear_all_bits_x (SCM vec)
+@deftypefnx {C Function} void scm_c_bitvector_flip_all_bits_x (SCM vec)
+@deftypefnx {C Function} size_t scm_c_bitvector_length (SCM bitvector)
+@deftypefnx {C Function} size_t scm_c_bitvector_count (SCM bitvector)
+@deftypefnx {C Function} size_t scm_c_bitvector_count_bits (SCM bitvector, SCM
bits)
+C API for the corresponding Scheme bitvector interfaces.
+@end deftypefn
+
@deftypefn {C Function} {const scm_t_uint32 *} scm_bitvector_elements (SCM
vec, scm_t_array_handle *handle, size_t *offp, size_t *lenp, ssize_t *incp)
Like @code{scm_vector_elements} (@pxref{Vector Accessing from C}), but
for bitvectors. The variable pointed to by @var{offp} is set to the
diff --git a/libguile/bitvectors.c b/libguile/bitvectors.c
index 042e988..9c7519b 100644
--- a/libguile/bitvectors.c
+++ b/libguile/bitvectors.c
@@ -590,19 +590,9 @@ SCM_DEFINE (scm_bitvector_position, "bitvector-position",
2, 1, 0,
}
#undef FUNC_NAME
-SCM_DEFINE (scm_bitvector_set_bits_x, "bitvector-set-bits!", 2, 0, 0,
- (SCM v, SCM bits),
- "Update the bitvector @var{v} in place by performing a logical\n"
- "OR of its bits with those of @var{bits}.\n"
- "For example:\n"
- "\n"
- "@example\n"
- "(define bv (bitvector-copy #*11000010))\n"
- "(bitvector-set-bits! bv #*10010001)\n"
- "bv\n"
- "@result{} #*11010011\n"
- "@end example")
-#define FUNC_NAME s_scm_bitvector_set_bits_x
+void
+scm_c_bitvector_set_bits_x (SCM v, SCM bits)
+#define FUNC_NAME "bitvector-set-bits!"
{
VALIDATE_MUTABLE_BITVECTOR (1, v);
VALIDATE_BITVECTOR (2, bits);
@@ -625,24 +615,12 @@ SCM_DEFINE (scm_bitvector_set_bits_x,
"bitvector-set-bits!", 2, 0, 0,
v_bits[i] |= kv_bits[i];
v_bits[i] |= kv_bits[i] & last_mask;
}
-
- return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
-SCM_DEFINE (scm_bitvector_clear_bits_x, "bitvector-clear-bits!", 2, 0, 0,
- (SCM v, SCM bits),
- "Update the bitvector @var{v} in place by performing a logical\n"
- "AND of its bits with the complement of those of @var{bits}.\n"
- "For example:\n"
- "\n"
- "@example\n"
- "(define bv (bitvector-copy #*11000010))\n"
- "(bitvector-clear-bits! bv #*10010001)\n"
- "bv\n"
- "@result{} #*01000010\n"
- "@end example")
-#define FUNC_NAME s_scm_bitvector_clear_bits_x
+void
+scm_c_bitvector_clear_bits_x (SCM v, SCM bits)
+#define FUNC_NAME "bitvector-clear-bits!"
{
VALIDATE_MUTABLE_BITVECTOR (1, v);
VALIDATE_BITVECTOR (2, bits);
@@ -666,7 +644,43 @@ SCM_DEFINE (scm_bitvector_clear_bits_x,
"bitvector-clear-bits!", 2, 0, 0,
v_bits[i] &= ~kv_bits[i];
v_bits[i] &= ~(kv_bits[i] & last_mask);
}
+}
+#undef FUNC_NAME
+SCM_DEFINE_STATIC (scm_bitvector_set_bits_x, "bitvector-set-bits!", 2, 0, 0,
+ (SCM v, SCM bits),
+ "Update the bitvector @var{v} in place by performing a\n"
+ "logical OR of its bits with those of @var{bits}.\n"
+ "For example:\n"
+ "\n"
+ "@example\n"
+ "(define bv (bitvector-copy #*11000010))\n"
+ "(bitvector-set-bits! bv #*10010001)\n"
+ "bv\n"
+ "@result{} #*11010011\n"
+ "@end example")
+#define FUNC_NAME s_scm_bitvector_set_bits_x
+{
+ scm_c_bitvector_set_bits_x (v, bits);
+ return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+SCM_DEFINE_STATIC (scm_bitvector_clear_bits_x, "bitvector-clear-bits!", 2, 0,
0,
+ (SCM v, SCM bits),
+ "Update the bitvector @var{v} in place by performing a\n"
+ "logical AND of its bits with the complement of those of\n"
+ "@var{bits}. For example:\n"
+ "\n"
+ "@example\n"
+ "(define bv (bitvector-copy #*11000010))\n"
+ "(bitvector-clear-bits! bv #*10010001)\n"
+ "bv\n"
+ "@result{} #*01000010\n"
+ "@end example")
+#define FUNC_NAME s_scm_bitvector_clear_bits_x
+{
+ scm_c_bitvector_clear_bits_x (v, bits);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
diff --git a/libguile/bitvectors.h b/libguile/bitvectors.h
index b1231e2..61751d1 100644
--- a/libguile/bitvectors.h
+++ b/libguile/bitvectors.h
@@ -39,8 +39,6 @@ SCM_API SCM scm_list_to_bitvector (SCM list);
SCM_API SCM scm_bitvector_to_list (SCM vec);
SCM_API SCM scm_bitvector_position (SCM v, SCM item, SCM start);
-SCM_API SCM scm_bitvector_set_bits_x (SCM v, SCM bits);
-SCM_API SCM scm_bitvector_clear_bits_x (SCM v, SCM bits);
SCM_API int scm_is_bitvector (SCM obj);
SCM_API SCM scm_c_make_bitvector (size_t len, SCM fill);
@@ -50,6 +48,8 @@ SCM_API int scm_c_bitvector_bit_is_set (SCM vec, size_t idx);
SCM_API int scm_c_bitvector_bit_is_clear (SCM vec, size_t idx);
SCM_API void scm_c_bitvector_set_bit_x (SCM vec, size_t idx);
SCM_API void scm_c_bitvector_clear_bit_x (SCM vec, size_t idx);
+SCM_API void scm_c_bitvector_set_bits_x (SCM v, SCM bits);
+SCM_API void scm_c_bitvector_clear_bits_x (SCM v, SCM bits);
SCM_API void scm_c_bitvector_set_all_bits_x (SCM vec);
SCM_API void scm_c_bitvector_clear_all_bits_x (SCM vec);
SCM_API void scm_c_bitvector_flip_all_bits_x (SCM vec);
diff --git a/libguile/deprecated.c b/libguile/deprecated.c
index 1a480ec..5173468 100644
--- a/libguile/deprecated.c
+++ b/libguile/deprecated.c
@@ -447,9 +447,14 @@ SCM_DEFINE (scm_bit_set_star_x, "bit-set*!", 3, 0, 0,
int bit = scm_to_bool (obj);
if (scm_is_bitvector (v) && scm_is_bitvector (kv))
- return bit
- ? scm_bitvector_set_bits_x (v, kv)
- : scm_bitvector_clear_bits_x (v, kv);
+ {
+ if (bit)
+ scm_c_bitvector_set_bits_x (v, kv);
+ else
+ scm_c_bitvector_clear_bits_x (v, kv);
+
+ return SCM_UNSPECIFIED;
+ }
scm_t_array_handle v_handle;
size_t v_off, v_len;
- [Guile-commits] branch master updated (1fbe89f -> 3d96c87), Andy Wingo, 2020/04/29
- [Guile-commits] 01/05: bitvector-count-bits replaces bit-count*, Andy Wingo, 2020/04/29
- [Guile-commits] 03/05: Prefer C-like interfaces for scm_c_bitvector_{set, clear}_bits_x,
Andy Wingo <=
- [Guile-commits] 02/05: Deprecate useless C bitvector interface, Andy Wingo, 2020/04/29
- [Guile-commits] 04/05: Deprecate scm_bitvector, scm_make_bitvector, scm_bitvector_p, Andy Wingo, 2020/04/29
- [Guile-commits] 05/05: Remove unused analyze-lexicals function, Andy Wingo, 2020/04/29