On 25 Jul 2000, Mikael Djurfeldt wrote:
> Dirk Herrmann <[EMAIL PROTECTED]> writes:
>
> > In scm_make_struct, there is the following initialization sequence:
> >
> > SCM_SET_CELL_WORD_1 (handle, data);
> > SCM_SET_CELL_WORD_0 (handle, (scm_bits_t) SCM_STRUCT_DATA (vtable) +
>scm_tc3_cons_gloc);
> > scm_struct_init (handle, tail_elts, init);
> >
> > I. e. the cell type (word 0) is set before the object is initialized. The
> > initialization is enclosed within SCM_DEFER/ALLOW_INTS, but as I
> > understand it these are basically no-ops now. Is this a bug and should it
> > be fixed?
>
> It is a bug and should be fixed.
Well, then, below is a fix. It works by calling scm_struct_init _before_
setting the cell type. However, since up to now scm_struct_init extracted
most of its data from the partially initialized cell, scm_struct_init had
to be changed. I checked with guile and goops and realized that the
function is only used within struct.c in guile. Thus, in my patch below
I suggest to make the modified scm_struct_init a static function and just
remove it from struct.h. Since I don't know if the removal of
scm_struct_init from struct.h is considered an API change, I will wait for
approval before applying that patch.
Best regards
Dirk
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/struct.c,v
retrieving revision 1.53
diff -u -r1.53 struct.c
--- struct.c 2000/05/18 08:47:52 1.53
+++ struct.c 2000/07/25 07:01:06
@@ -148,14 +148,12 @@
-void
-scm_struct_init (SCM handle, int tail_elts, SCM inits)
+static void
+scm_struct_init (SCM handle, SCM layout, scm_bits_t * mem, int tail_elts, SCM inits)
{
- SCM layout = SCM_STRUCT_LAYOUT (handle);
unsigned char * fields_desc = (unsigned char *) SCM_CHARS (layout) - 2;
unsigned char prot = 0;
int n_fields = SCM_LENGTH (layout) / 2;
- scm_bits_t * mem = SCM_STRUCT_DATA (handle);
int tailp = 0;
while (n_fields)
@@ -399,8 +397,8 @@
scm_struct_n_extra_words,
"make-struct");
SCM_SET_CELL_WORD_1 (handle, data);
+ scm_struct_init (handle, layout, data, tail_elts, init);
SCM_SET_CELL_WORD_0 (handle, (scm_bits_t) SCM_STRUCT_DATA (vtable) +
scm_tc3_cons_gloc);
- scm_struct_init (handle, tail_elts, init);
SCM_ALLOW_INTS;
return handle;
}
@@ -489,9 +487,9 @@
scm_struct_n_extra_words,
"make-vtable-vtable");
SCM_SET_CELL_WORD_1 (handle, data);
+ data [scm_vtable_index_layout] = SCM_UNPACK (layout);
+ scm_struct_init (handle, layout, data, tail_elts, scm_cons (layout, init));
SCM_SET_CELL_WORD_0 (handle, (scm_bits_t) data + scm_tc3_cons_gloc);
- SCM_SET_STRUCT_LAYOUT (handle, layout);
- scm_struct_init (handle, tail_elts, scm_cons (layout, init));
SCM_ALLOW_INTS;
return handle;
}
Index: libguile/struct.h
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/struct.h,v
retrieving revision 1.31
diff -u -r1.31 struct.h
--- struct.h 2000/04/18 14:12:07 1.31
+++ struct.h 2000/07/25 07:01:06
@@ -104,7 +104,6 @@
extern scm_sizet scm_struct_free_light (scm_bits_t * vtable, scm_bits_t * data);
extern scm_sizet scm_struct_free_standard (scm_bits_t * vtable, scm_bits_t * data);
extern scm_sizet scm_struct_free_entity (scm_bits_t * vtable, scm_bits_t * data);
-extern void scm_struct_init (SCM handle, int tail_elts, SCM inits);
extern SCM scm_make_struct_layout (SCM fields);
extern SCM scm_struct_p (SCM x);
extern SCM scm_struct_vtable_p (SCM x);
Index: libguile/vectors.c
===================================================================