[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 02/05: Deprecate useless C bitvector interface
From: |
Andy Wingo |
Subject: |
[Guile-commits] 02/05: Deprecate useless C bitvector interface |
Date: |
Wed, 29 Apr 2020 05:14:40 -0400 (EDT) |
wingo pushed a commit to branch master
in repository guile.
commit b517a91ba4aaccf920a81eb8bf71ca090a9b457c
Author: Andy Wingo <address@hidden>
AuthorDate: Tue Apr 21 22:35:00 2020 +0200
Deprecate useless C bitvector interface
C should use scm_c_bitvector_length, not scm_bitvector_length.
* doc/ref/api-data.texi (Bit Vectors): Reorganize a bit to put typed C
interfaces in their own section.
* libguile/bitvectors.h:
* libguile/bitvectors.c (bitvector-length, bitvector-count): Make
SCM-flavored C interface private.
(scm_c_bitvector_count): New function.
* libguile/deprecated.c (scm_bitvector_length): Deprecate.
(scm_bit_count): Adapt to changes.
---
doc/ref/api-data.texi | 15 +++++----------
libguile/bitvectors.c | 28 ++++++++++++++++++----------
libguile/bitvectors.h | 3 +--
libguile/deprecated.c | 14 ++++++++++++--
libguile/deprecated.h | 1 +
5 files changed, 37 insertions(+), 24 deletions(-)
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index abd4556..11b547c 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -6564,15 +6564,9 @@ Create a new bitvector with the arguments as elements.
@end deffn
@deffn {Scheme Procedure} bitvector-length vec
-@deffnx {C Function} scm_bitvector_length (vec)
Return the length of the bitvector @var{vec}.
@end deffn
-@deftypefn {C Function} size_t scm_c_bitvector_length (SCM vec)
-Like @code{scm_bitvector_length}, but the length is returned as a
-@code{size_t}.
-@end deftypefn
-
@deffn {Scheme Procedure} bitvector-bit-set? vec idx
@deffnx {Scheme Procedure} bitvector-bit-clear? vec idx
Return @code{#t} if the bit at index @var{idx} of the bitvector
@@ -6623,7 +6617,6 @@ of the bitvector @var{vec}.
@end deffn
@deffn {Scheme Procedure} bitvector-count bitvector
-@deffnx {C Function} scm_bitvector_count (bitvector)
Return a count of how many entries in @var{bitvector} are set.
@example
@@ -6643,9 +6636,11 @@ For example,
@end example
@end deffn
-@deftypefn {C Function} size_t scm_c_bitvector_count_bits (SCM bitvector, SCM
bits)
-Same as @code{bitvector-count-bits}, but returning a @code{size_t} for
-C.
+@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
diff --git a/libguile/bitvectors.c b/libguile/bitvectors.c
index e8993b8..042e988 100644
--- a/libguile/bitvectors.c
+++ b/libguile/bitvectors.c
@@ -184,10 +184,10 @@ scm_c_bitvector_length (SCM vec)
return BITVECTOR_LENGTH (vec);
}
-SCM_DEFINE (scm_bitvector_length, "bitvector-length", 1, 0, 0,
- (SCM vec),
- "Return the length of the bitvector @var{vec}.")
-#define FUNC_NAME s_scm_bitvector_length
+SCM_DEFINE_STATIC (bitvector_length, "bitvector-length", 1, 0, 0,
+ (SCM vec),
+ "Return the length of the bitvector @var{vec}.")
+#define FUNC_NAME s_bitvector_length
{
return scm_from_size_t (scm_c_bitvector_length (vec));
}
@@ -490,17 +490,16 @@ count_ones (uint32_t x)
return (x+(x>>16)) & 0xff;
}
-SCM_DEFINE (scm_bitvector_count, "bitvector-count", 1, 0, 0,
- (SCM bitvector),
- "Return the number of set bits in @var{bitvector}.")
-#define FUNC_NAME s_scm_bitvector_count
+size_t
+scm_c_bitvector_count (SCM bitvector)
+#define FUNC_NAME "bitvector-count"
{
VALIDATE_BITVECTOR (1, bitvector);
size_t len = BITVECTOR_LENGTH (bitvector);
if (len == 0)
- return SCM_INUM0;
+ return 0;
const uint32_t *bits = BITVECTOR_BITS (bitvector);
size_t count = 0;
@@ -513,7 +512,16 @@ SCM_DEFINE (scm_bitvector_count, "bitvector-count", 1, 0,
0,
uint32_t last_mask = ((uint32_t)-1) >> (32*word_len - len);
count += count_ones (bits[i] & last_mask);
- return scm_from_size_t (count);
+ return count;
+}
+#undef FUNC_NAME
+
+SCM_DEFINE_STATIC (scm_bitvector_count, "bitvector-count", 1, 0, 0,
+ (SCM bitvector),
+ "Return the number of set bits in @var{bitvector}.")
+#define FUNC_NAME s_scm_bitvector_count
+{
+ return scm_from_size_t (scm_c_bitvector_count (bitvector));
}
#undef FUNC_NAME
diff --git a/libguile/bitvectors.h b/libguile/bitvectors.h
index a855e1f..b1231e2 100644
--- a/libguile/bitvectors.h
+++ b/libguile/bitvectors.h
@@ -35,11 +35,9 @@
SCM_API SCM scm_bitvector_p (SCM vec);
SCM_API SCM scm_bitvector (SCM bits);
SCM_API SCM scm_make_bitvector (SCM len, SCM fill);
-SCM_API SCM scm_bitvector_length (SCM vec);
SCM_API SCM scm_list_to_bitvector (SCM list);
SCM_API SCM scm_bitvector_to_list (SCM vec);
-SCM_API SCM scm_bitvector_count (SCM v);
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);
@@ -47,6 +45,7 @@ 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);
SCM_API size_t scm_c_bitvector_length (SCM vec);
+SCM_API size_t scm_c_bitvector_count (SCM v);
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);
diff --git a/libguile/deprecated.c b/libguile/deprecated.c
index 861ade5..1a480ec 100644
--- a/libguile/deprecated.c
+++ b/libguile/deprecated.c
@@ -89,6 +89,16 @@ scm_find_executable (const char *name)
SCM
+scm_bitvector_length (SCM vec)
+{
+ scm_c_issue_deprecation_warning
+ ("scm_bitvector_length is deprecated. Use scm_c_bitvector_length "
+ "instead.");
+
+ return scm_from_size_t (scm_c_bitvector_length (vec));
+}
+
+SCM
scm_c_bitvector_ref (SCM vec, size_t idx)
{
scm_c_issue_deprecation_warning
@@ -251,7 +261,7 @@ SCM_DEFINE (scm_bit_count, "bit-count", 2, 0, 0,
if (scm_is_bitvector (bitvector))
{
len = scm_to_size_t (scm_bitvector_length (bitvector));
- count = scm_to_size_t (scm_bitvector_count (bitvector));
+ count = scm_c_bitvector_count (bitvector);
}
else
{
@@ -309,7 +319,7 @@ SCM_DEFINE (scm_bit_count_star, "bit-count*", 3, 0, 0,
{
count = scm_c_bitvector_count_bits (v, kv);
if (count == 0)
- count = scm_to_size_t (scm_bitvector_count (kv)) - count;
+ count = scm_c_bitvector_count (kv) - count;
}
else
{
diff --git a/libguile/deprecated.h b/libguile/deprecated.h
index 6366e5e..a41199e 100644
--- a/libguile/deprecated.h
+++ b/libguile/deprecated.h
@@ -115,6 +115,7 @@ typedef struct scm_thread scm_i_thread SCM_DEPRECATED_TYPE;
SCM_DEPRECATED char* scm_find_executable (const char *name);
+SCM_DEPRECATED SCM scm_bitvector_length (SCM vec);
SCM_DEPRECATED SCM scm_c_bitvector_ref (SCM vec, size_t idx);
SCM_DEPRECATED SCM scm_bitvector_ref (SCM vec, SCM idx);
SCM_DEPRECATED void scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val);
- [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, 2020/04/29
- [Guile-commits] 02/05: Deprecate useless C bitvector interface,
Andy Wingo <=
- [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