Guile Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is it OK to pass an SCM through (void *)?
> Maciej Stachowiak <mstachow@MIT.EDU> writes:
> > The former is sufficient. You also need to make sure that setter_func
> > is protected against garbage-collection, of couse, since Gtk will keep
> > it hanging around.
> How do I protect it against garbage collection? Or more importantly,
> how do I know when I need to protect something against garbage
> collection? Is there a good overview of this somewhere I can read?
> I've always been a little fuzzy on the C level GC interaction issues.
The simple rule is, if it's on the stack (local variable or function
parameter), it doesn't need protection, if it's on the heap (global
variable or malloced memory) it does. If you're passing it to
gtk_signal_connect nothing guarantees it will stay on the stack.
One problem here is that the object will stay protected even if you
disconnect that signal handler, or even destroy the widget it is
associated with, unless you do some extra tracking so you can
unprotect it. This will result in memory leaks.
I noticed that you were trying to provide some interfaces for the user
to connect Scheme code to GUI elements. Why don't you just use
guile-gtk for this purpose, since it deals with all the GC issues? I
think it should be safe to embed it in gtk-based C apps with no extra
worries (someone correct me if I'm wrong).
Guile Home |
Main Index |