This is the mail archive of the
guile@sources.redhat.com
mailing list for the Guile project.
Re: Again: Guile + Boehm's gc
Hi,
>> It's MUCH more transparent then current guile's GC. It's MUCH
>> safer: with GUILE's GC you can screw system quite badly when
>> you'll forget about scm_protect/unprotect thing.
Jost> Hmm, when and how do you use scm_protect and scm_unprotect?
The general rule is anytime you stick an SCM value someplace that is
not on the stack (ie a local variable, or parameter), protect it. I
can only think of a couple situations where it's needed.
If you stick an SCM into a global:
SCM aGlobal=SCM_UNDEFINED;
SCM SetGlobal(SCM save) {
/* If aGlobal is holding an SCM value, then unprotect it */
if (aGlobal!=SCM_UNDEFINED) scm_unprotect(aGlobal);
aGlobal = save;
/* Protect the new SCM in aGlobal */
scm_protect(aGlobal);
return SCM_UNSPECIFIED;
}
Or if you stick an SCM into a malloced structure:
struct myStruct {
SCM val;
}
struct myStruct *MakeStruct(SCM save) {
struct myStruct *this;
this = (struct myStruct *) malloc(sizeof(struct myStruct));
this->val = save;
scm_protect(this->val);
return this;
}
void FreeStruct(struct myStruct *this) {
scm_unprotect(this->val);
free(this);
}
Cheers,
Clark