[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to correctly define using scm_define ?
From: |
Marius Vollmer |
Subject: |
Re: how to correctly define using scm_define ? |
Date: |
Tue, 02 Nov 2004 17:18:39 +0100 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux) |
Tano Fotang <address@hidden> writes:
> So I decide to skip scm_define and just do:
>
> tt = proc;
This is the correct way. scm_define is for defining new global Scheme
variables. See
http://www-dt.e-technik.uni-dortmund.de/~mvo/guile.html/Accessing-Modules-from-C.html
> That appears okay until the following line is seen some minutes later:
>
> scm_apply_0(tt, args)
>
> then this error is displayed:
>
> wrong-type-arg: [apply] Wrong type argument in position 1: #<freed
> cell 0x406303b0; GC missed a reference>
>
> I'd be glad for any pointers on how to proceed.
You need to 'protect' the SCM value stored into a global C variable.
Otherwise, the garbage collector might not know that it is in use and
will free that SCM value. See
http://www-dt.e-technik.uni-dortmund.de/~mvo/guile.html/Garbage-Collection-Functions.html
and more generally
http://www-dt.e-technik.uni-dortmund.de/~mvo/guile.html/Garbage-Collection.html
The functions scm_gc_protect and scm_gc_unprotect are likely what you
want:
SCM tt;
void
set_tt (SCM proc)
{
scm_gc_unprotect (tt);
tt = proc;
scm_gc_protect (tt);
}
There is also scm_gc_register_root, but it is not documented yet...