* libguile/srfi-4.c (free_user_data): New function.
* libguile/srfi-4.i.c (scm_take_TAGvector): Register `free_user_data ()'
as a finalizer for DATA.
* libguile/objcodes.c (scm_objcode_to_bytecode): Allocate with
`scm_malloc ()' since the memory taken by `scm_take_u8vector ()' will
eventually be free(3)d.
* libguile/vm.c (really_make_boot_program): Likewise.
SCM_VALIDATE_OBJCODE (1, objcode);
len = sizeof(struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode);
- /* FIXME: Is `gc_malloc' ok here? */
- u8vector = scm_gc_malloc (len, "objcode-u8vector");
+
+ u8vector = scm_malloc (len);
memcpy (u8vector, SCM_OBJCODE_DATA (objcode), len);
return scm_take_u8vector (u8vector, len);
#include "libguile/_scm.h"
#include "libguile/__scm.h"
+#include "libguile/boehm-gc.h"
#include "libguile/srfi-4.h"
#include "libguile/bitvectors.h"
#include "libguile/bytevectors.h"
scm_wrong_type_arg_msg (NULL, 0, obj, uvec_names[type]);
}
+/* Invoke free(3) on DATA, a user-provided buffer passed to one of the
+ `scm_take_' functions. */
+static void
+free_user_data (GC_PTR data, GC_PTR unused)
+{
+ free (data);
+}
+
static SCM
take_uvec (int type, void *base, size_t len)
{
SCM
F(scm_take_,TAG,vector) (CTYPE *data, size_t n)
{
- scm_gc_register_collectable_memory ((void *)data, n*uvec_sizes[TYPE],
- uvec_names[TYPE]);
+ /* The manual says "Return a new uniform numeric vector [...] that uses the
+ memory pointed to by DATA". We *have* to use DATA as the underlying
+ storage; thus we must register a finalizer to eventually free(3) it. */
+ GC_finalization_proc prev_finalizer;
+ GC_PTR prev_finalization_data;
+
+ GC_REGISTER_FINALIZER_NO_ORDER (data, free_user_data, 0,
+ &prev_finalizer,
+ &prev_finalization_data);
+
return take_uvec (TYPE, data, n);
}
abort ();
text[1] = (scm_t_uint8)nargs;
- bp = scm_gc_malloc (sizeof (struct scm_objcode) + sizeof (text),
- "make-u8vector");
+ bp = scm_malloc (sizeof (struct scm_objcode) + sizeof (text));
memcpy (bp->base, text, sizeof (text));
bp->nargs = 0;
bp->nrest = 0;