diff --git a/libguile/struct.c b/libguile/struct.c index 000626fa3..288ad84c7 100644 --- a/libguile/struct.c +++ b/libguile/struct.c @@ -339,7 +339,11 @@ scm_i_alloc_struct (scm_t_bits vtable_bits, int n_words) { SCM ret; - ret = scm_words (vtable_bits | scm_tc3_struct, n_words + 1); + struct scm_struct *s = + scm_allocate_tagged (SCM_I_CURRENT_THREAD, + sizeof (*s) + n_words * sizeof (SCM)); + s->tagged_vtable = vtable_bits | scm_tc3_struct; + ret = scm_from_struct (s); /* vtable_bits can be 0 when making a vtable vtable */ if (vtable_bits && SCM_VTABLE_INSTANCE_FINALIZER (SCM_PACK (vtable_bits))) @@ -444,24 +448,24 @@ SCM_DEFINE (scm_make_struct_simple, "make-struct/simple", 1, 0, 1, "use @code{make-struct/no-tail}.") #define FUNC_NAME s_scm_make_struct_simple { - long i, n_init; - SCM ret; - SCM_VALIDATE_VTABLE (1, vtable); - n_init = scm_ilength (init); + long n_init = scm_ilength (init); if (n_init != SCM_VTABLE_SIZE (vtable)) SCM_MISC_ERROR ("Wrong number of initializers.", SCM_EOL); - ret = scm_words (SCM_UNPACK (vtable) | scm_tc3_struct, n_init + 1); + struct scm_struct *s = + scm_allocate_tagged (SCM_I_CURRENT_THREAD, + sizeof (*s) + n_init * sizeof (SCM)); + s->tagged_vtable = SCM_UNPACK (vtable) | scm_tc3_struct; - for (i = 0; i < n_init; i++, init = scm_cdr (init)) + for (long i = 0; i < n_init; i++, init = scm_cdr (init)) { SCM_ASSERT (!SCM_VTABLE_FIELD_IS_UNBOXED (vtable, i), vtable, 1, FUNC_NAME); - SCM_STRUCT_SLOT_SET (ret, i, scm_car (init)); + scm_i_struct_set_scm (s, i, scm_car (init)); } - return ret; + return scm_from_struct (s); } #undef FUNC_NAME