guile-user
[Top][All Lists]
Advanced

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

smob mark functions in 2.0


From: Andy Wingo
Subject: smob mark functions in 2.0
Date: Wed, 23 Nov 2011 22:20:45 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Hello all,

I don't know how you feel, but for me the BDW garbage collector used in
Guile 2.0 has made my life much easier than it was.  You typically don't
have to write SMOB marking functions any more.

However, I just fixed a bug in g-wrap that was a bit surprising to me.
If you do implement a SMOB marking function, and you touch Scheme
objects in that marking function, you need to be very careful.

Specifically, there is a warning in gc/gc_mark.h:

    /* WARNING: Such a mark procedure may be invoked on an unused object    */
    /* residing on a free list.  Such objects are cleared, except for a     */
    /* free list link field in the first word.  Thus mark procedures may    */
    /* not count on the presence of a type descriptor, and must handle this */
    /* case correctly somehow.                                              */

So, your mark function might see freed objects.  This is terrible, but
it is the way that it is.  The key is that, if you touch a Scheme object
in your mark function, to first do a check on that object, to see that
it is valid.  You can check the TC bits of the first word, or otherwise
check that other words are non-NULL.

Caveat mercator!

Andy
-- 
http://wingolog.org/



reply via email to

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