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: Is it OK to pass an SCM through (void *)?



rlb@cs.utexas.edu writes:
> 
> In gnucash, I need to attach some SCM values (Guile level function
> pointers) as the data to GTK callback functions.  So is it OK to do
> this:
> 
>     SCM setter_func;
>     ...
>     gtk_signal_connect (GTK_OBJECT (option_toggle), 
>                         "toggled",
>                         (GtkSignalFunc) call_boolean_setter,
>                         (gpointer) setter_func);
> 
> or do I need to do something safer like this:
> 
>     SCM setter_func;
>     SCM *setter_func_ptr = malloc(sizeof(SCM));
>     *setter_func_ptr = setter_func;
>     ...
>     gtk_signal_connect (GTK_OBJECT (option_toggle), 
>                         "toggled",
>                         (GtkSignalFunc) call_boolean_setter,
>                         (gpointer) setter_func_ptr);
> 

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.

 - Maciej Stachowiak