summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2009-06-22 00:56:00 +0200
committerLudovic Courtès <ludo@gnu.org>2009-06-22 01:11:10 +0200
commitcfb4702f5886f2df197521cc47b6ca86547b165e (patch)
tree1b5d551ff85b62be4c22a3b034bbb90a01a9ae28
parent438974d08dcb96a01fe62ea9b0446b8420e703c4 (diff)
downloadguile-cfb4702f5886f2df197521cc47b6ca86547b165e.tar.gz
Always create the bytevector SMOB type.
* libguile/bytevectors.c (scm_tc16_bytevector, print_bytevector, bytevector_equal_p, free_bytevector): Don't use the snarfing macros. (scm_bootstrap_bytevectors): New. (scm_init_bytevectors): No longer initialize SCM_NULL_BYTEVECTOR, which is done by `scm_bootstrap_bytevectors ()'. * libguile/bytevectors.h (scm_bootstrap_bytevectors): New declaration. (scm_init_bytevectors): Made internal. This can be done because we explicitly register it with `scm_c_register_extension ()' in `scm_bootstrap_bytevectors ()'. * libguile/init.c (scm_i_init_guile): Call `scm_bootstrap_bytevectors ()'. This is so that expressions like "(generalized-vector-length #vu8())" work even when `(rnrs bytevector)' hasn't been loaded.
-rw-r--r--libguile/bytevectors.c35
-rw-r--r--libguile/bytevectors.h3
-rw-r--r--libguile/init.c2
3 files changed, 31 insertions, 9 deletions
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index 2060192c6..fd9043ad1 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -26,6 +26,7 @@
#include <gmp.h>
#include "libguile/_scm.h"
+#include "libguile/extensions.h"
#include "libguile/bytevectors.h"
#include "libguile/strings.h"
#include "libguile/validate.h"
@@ -172,7 +173,7 @@
/* Bytevector type. */
-SCM_GLOBAL_SMOB (scm_tc16_bytevector, "r6rs-bytevector", 0);
+scm_t_bits scm_tc16_bytevector;
#define SCM_BYTEVECTOR_SET_LENGTH(_bv, _len) \
SCM_SET_SMOB_DATA ((_bv), (scm_t_bits) (_len))
@@ -337,8 +338,8 @@ scm_i_bytevector_generalized_set_x (SCM bv, size_t index, SCM value)
}
#undef FUNC_NAME
-SCM_SMOB_PRINT (scm_tc16_bytevector, print_bytevector,
- bv, port, pstate)
+static int
+print_bytevector (SCM bv, SCM port, scm_print_state *pstate)
{
unsigned c_len, i;
unsigned char *c_bv;
@@ -363,12 +364,14 @@ SCM_SMOB_PRINT (scm_tc16_bytevector, print_bytevector,
return 1;
}
-SCM_SMOB_EQUALP (scm_tc16_bytevector, bytevector_equal_p, bv1, bv2)
+static SCM
+bytevector_equal_p (SCM bv1, SCM bv2)
{
return scm_bytevector_eq_p (bv1, bv2);
}
-SCM_SMOB_FREE (scm_tc16_bytevector, free_bytevector, bv)
+static size_t
+free_bytevector (SCM bv)
{
if (!SCM_BYTEVECTOR_INLINE_P (bv))
@@ -2059,6 +2062,25 @@ SCM_DEFINE (scm_utf32_to_string, "utf32->string",
/* Initialization. */
void
+scm_bootstrap_bytevectors (void)
+{
+ /* The SMOB type must be instantiated here because the
+ generalized-vector API may want to access bytevectors even though
+ `(rnrs bytevector)' hasn't been loaded. */
+ scm_tc16_bytevector = scm_make_smob_type ("bytevector", 0);
+ scm_set_smob_free (scm_tc16_bytevector, free_bytevector);
+ scm_set_smob_print (scm_tc16_bytevector, print_bytevector);
+ scm_set_smob_equalp (scm_tc16_bytevector, bytevector_equal_p);
+
+ scm_null_bytevector =
+ scm_gc_protect_object (make_bytevector_from_buffer (0, NULL));
+
+ scm_c_register_extension ("libguile", "scm_init_bytevectors",
+ (scm_t_extension_init_func) scm_init_bytevectors,
+ NULL);
+}
+
+void
scm_init_bytevectors (void)
{
#include "libguile/bytevectors.x"
@@ -2071,7 +2093,4 @@ scm_init_bytevectors (void)
scm_endianness_big = scm_sym_big;
scm_endianness_little = scm_sym_little;
-
- scm_null_bytevector =
- scm_gc_protect_object (make_bytevector_from_buffer (0, NULL));
}
diff --git a/libguile/bytevectors.h b/libguile/bytevectors.h
index ccab27522..903ce7ae3 100644
--- a/libguile/bytevectors.h
+++ b/libguile/bytevectors.h
@@ -125,7 +125,8 @@ SCM_API SCM scm_utf32_to_string (SCM, SCM);
/* Hint that is passed to `scm_gc_malloc ()' and friends. */
#define SCM_GC_BYTEVECTOR "bytevector"
-SCM_API void scm_init_bytevectors (void);
+SCM_INTERNAL void scm_bootstrap_bytevectors (void);
+SCM_INTERNAL void scm_init_bytevectors (void);
SCM_INTERNAL scm_t_bits scm_tc16_bytevector;
SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, size_t);
diff --git a/libguile/init.c b/libguile/init.c
index 2b500ac3a..5ece01fb0 100644
--- a/libguile/init.c
+++ b/libguile/init.c
@@ -38,6 +38,7 @@
#include "libguile/async.h"
#include "libguile/backtrace.h"
#include "libguile/boolean.h"
+#include "libguile/bytevectors.h"
#include "libguile/chars.h"
#include "libguile/continuations.h"
#include "libguile/debug.h"
@@ -573,6 +574,7 @@ scm_i_init_guile (SCM_STACKITEM *base)
scm_init_rw ();
scm_init_extensions ();
+ scm_bootstrap_bytevectors ();
scm_bootstrap_vm ();
atexit (cleanup_for_exit);