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: Guile-C interfacing and defating garbage collection


Richard Frith-Macdonald <richard@brainstorm.co.uk> wrote:
> ...
> 1. Guile passes a SCM representing a procedure to some C library code
> which stores it somewhere.
> 2. Control returns from the C code to Guile and other things happen.
> 3. From the C library, I want to call the Guile procedure whose SCM I
> recorded earlier.

> How can I be sure that the procedure has not been garbage collected
> between stage 1 and stage 2?

Any kind of Guile structure which is visible from the top level (except
weak vectors) will protect the procedure from being garbage collected.
This includes the C stack, which is probably where the object is stored
between 1 and 2 above. You may think, how can the C-stack be used like
that?, but that's a "trick" performed by the gc, which makes it
"conservative". When it's scanning the C-stack it have to guess
what things may be scheme objects. The principle is, better to mark
than not, which means that there is a possibility for garbage to be
retained, but not the opposite. 

	Best regards
	Roland Orre