[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

struct tail array, compare and segv

From: Kevin Ryde
Subject: struct tail array, compare and segv
Date: Tue, 13 Feb 2007 07:31:50 +1100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

Brought across from bug-guile ...

address@hidden (Ludovic Courtès) writes:
> Actually, `scm_i_struct_equalp ()' should also compare the "tail
> elements" (when there are tail elements),

Is it as easy as using getting the size (of each) from
"scm_struct_i_n_words", instead of just using the layout?  I see
scm_struct_ref uses that for its range check.

> but their semantics are a
> little fuzzy to me.  In particular, I don't understand why the size of
> the tail array can be specified in both `make-vtable-vtable' and
> `make-struct': What does that mean?

Nosing around the code, I think make-vtable-vtable adds space to the
vtable (or rather vtable-vtable) struct like "class data".  Then
make-struct adds space to a struct created from it like "instance

> Which one should really be taken into account?

Both :-).  But since both are structs I think both birds can be killed
with the one stone.

> It seems that the code is a bit unclear on this too:
>   guile> (define v (make-vtable-vtable "pr" 0))
>   guile> (define s (make-struct v 123))
>   guile> (struct-ref s 10)
>   Segmentation fault

Digging around I think that to have a tail array you're meant to say
"pR" or "pW" or whatever at the end of the layout.  Without R, W or O
then it looks like the internal func scm_struct_init doesn't
initialize the tail array contents, so then scm_struct_ref reads out
garbage as an SCM, and that can cause a segv if you attempt to print

Should make-struct throw an error, or should it initialize?  I guess
initializing is the smallest change, but it looks like struct-set!
refuses to work in the tail part without "W" at the end, so maybe
R,W,O is how it's meant to be.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]