guile-devel
[Top][All Lists]
Advanced

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

Re: Goops & Valgrind


From: Andy Wingo
Subject: Re: Goops & Valgrind
Date: Mon, 18 Aug 2008 11:58:27 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Hi Han-Wen,

On Fri 15 Aug 2008 22:15, Han-Wen Nienhuys <address@hidden> writes:

> Running the test suite through valgrind, I get some fishy errors.
>
> Can someone shed a light on this?  The culprit seems to be 
>
> #define SCM_NUMBER_OF_SLOTS(x) \
>  ((SCM_STRUCT_DATA (x)[scm_struct_i_n_words]) - scm_struct_n_extra_words)
>
> where scm_struct_i_n_words is -2

Classes that are not metaclasses allocate their instances using "light
structs". So the object layout goes like this:

                     the vtable word               the data word
                +-------------------------------+---------------------+
SCM of object = |SCM of class | scm_tc3_struct  | SCM* array of slots |
                +-------------------------------|---------------------+

For classes, the SCM* points to the middle of a SCM array, which has
some number of words before 0; 4 words normally, or 6 if the object is
an "entity", like a generic function. But for objects there are no words
before 0, hence the valid valgrind error.

  i = scm_to_unsigned_integer (index, 0, SCM_NUMBER_OF_SLOTS(obj)-1);

There could be two fixes. One would be to assume that the Scheme code
that calls %fast-slot-ref et al is well-formed, and thus we need no
bounds checking. It's all in goops.scm, so this would be a decent
assumption. The other would be to use a different definition of
SCM_NUMBER_OF SLOTS, which would probably have a different purpose:

#define SCM_NUMBER_OF_FIELDS(x) (SCM_STRUCT_VTABLE (x)[scm_si_nfields])

Cheers,

Andy
-- 
http://wingolog.org/




reply via email to

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