This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Smob documentation



Jost Boekemeier <jostobfe@calvados.zrz.TU-Berlin.DE> writes:
> could someone please add a section to data-rep.texi
> that describes how and why it is neccesary to inhibit
> garbage collection while creating a smob.  It took
> me one hour to find the following bug:

As I understand it, it's not required to disable GC, but should GC run
(triggered by an allocation you do, or by something happening in
another thread), depending on how you construct your object, it might
not recognize the object you're in the middle of creating as being of
the smob type in question.  So references in it to other objects may
not get marked, and if there aren't other references to those objects,
they get destroyed.

If you set all the SCM fields to SCM_BOOL_F or SCM_MAKINUM(42) or
something, set the smob object's type and pointer fields right away
(so the right mark function gets called), then allocate the other
objects you need to fill in the object's slots etc, that'll probably
do it.  Or, create the smob object later but keep the handles on other
created Scheme objects in automatic variables, where the conservative
GC can find them.

Yeah, they can be a pain in the backside to track down.

Ken

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]