mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
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.
This commit is contained in:
parent
438974d08d
commit
cfb4702f58
3 changed files with 31 additions and 9 deletions
|
@ -26,6 +26,7 @@
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
|
|
||||||
#include "libguile/_scm.h"
|
#include "libguile/_scm.h"
|
||||||
|
#include "libguile/extensions.h"
|
||||||
#include "libguile/bytevectors.h"
|
#include "libguile/bytevectors.h"
|
||||||
#include "libguile/strings.h"
|
#include "libguile/strings.h"
|
||||||
#include "libguile/validate.h"
|
#include "libguile/validate.h"
|
||||||
|
@ -172,7 +173,7 @@
|
||||||
|
|
||||||
/* Bytevector type. */
|
/* Bytevector type. */
|
||||||
|
|
||||||
SCM_GLOBAL_SMOB (scm_tc16_bytevector, "r6rs-bytevector", 0);
|
scm_t_bits scm_tc16_bytevector;
|
||||||
|
|
||||||
#define SCM_BYTEVECTOR_SET_LENGTH(_bv, _len) \
|
#define SCM_BYTEVECTOR_SET_LENGTH(_bv, _len) \
|
||||||
SCM_SET_SMOB_DATA ((_bv), (scm_t_bits) (_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
|
#undef FUNC_NAME
|
||||||
|
|
||||||
SCM_SMOB_PRINT (scm_tc16_bytevector, print_bytevector,
|
static int
|
||||||
bv, port, pstate)
|
print_bytevector (SCM bv, SCM port, scm_print_state *pstate)
|
||||||
{
|
{
|
||||||
unsigned c_len, i;
|
unsigned c_len, i;
|
||||||
unsigned char *c_bv;
|
unsigned char *c_bv;
|
||||||
|
@ -363,12 +364,14 @@ SCM_SMOB_PRINT (scm_tc16_bytevector, print_bytevector,
|
||||||
return 1;
|
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);
|
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))
|
if (!SCM_BYTEVECTOR_INLINE_P (bv))
|
||||||
|
@ -2058,6 +2061,25 @@ SCM_DEFINE (scm_utf32_to_string, "utf32->string",
|
||||||
|
|
||||||
/* Initialization. */
|
/* 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
|
void
|
||||||
scm_init_bytevectors (void)
|
scm_init_bytevectors (void)
|
||||||
{
|
{
|
||||||
|
@ -2071,7 +2093,4 @@ scm_init_bytevectors (void)
|
||||||
|
|
||||||
scm_endianness_big = scm_sym_big;
|
scm_endianness_big = scm_sym_big;
|
||||||
scm_endianness_little = scm_sym_little;
|
scm_endianness_little = scm_sym_little;
|
||||||
|
|
||||||
scm_null_bytevector =
|
|
||||||
scm_gc_protect_object (make_bytevector_from_buffer (0, NULL));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,8 @@ SCM_API SCM scm_utf32_to_string (SCM, SCM);
|
||||||
/* Hint that is passed to `scm_gc_malloc ()' and friends. */
|
/* Hint that is passed to `scm_gc_malloc ()' and friends. */
|
||||||
#define SCM_GC_BYTEVECTOR "bytevector"
|
#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_t_bits scm_tc16_bytevector;
|
||||||
SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, size_t);
|
SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, size_t);
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "libguile/async.h"
|
#include "libguile/async.h"
|
||||||
#include "libguile/backtrace.h"
|
#include "libguile/backtrace.h"
|
||||||
#include "libguile/boolean.h"
|
#include "libguile/boolean.h"
|
||||||
|
#include "libguile/bytevectors.h"
|
||||||
#include "libguile/chars.h"
|
#include "libguile/chars.h"
|
||||||
#include "libguile/continuations.h"
|
#include "libguile/continuations.h"
|
||||||
#include "libguile/debug.h"
|
#include "libguile/debug.h"
|
||||||
|
@ -573,6 +574,7 @@ scm_i_init_guile (SCM_STACKITEM *base)
|
||||||
scm_init_rw ();
|
scm_init_rw ();
|
||||||
scm_init_extensions ();
|
scm_init_extensions ();
|
||||||
|
|
||||||
|
scm_bootstrap_bytevectors ();
|
||||||
scm_bootstrap_vm ();
|
scm_bootstrap_vm ();
|
||||||
|
|
||||||
atexit (cleanup_for_exit);
|
atexit (cleanup_for_exit);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue