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: Calling Scheme from C and Garbage Collection



Yes, it does look as if your regexp object got freed.

Guile should automatically protect your regexp from collection if you
store it in a local variable.  Are you perhaps storing your pointer to
it in a global variable, or in a non-Guile object in the heap?

See doc/data-rep.texi for an explanation of the Guile garbage
collector.  If that doesn't make it clearer, please let me know;
that's one of its primary purposes.


> I'm using Guile from my C program, and I use scm_make_regexp to create a
> regexp SCM object:
> 
> SCM r = scm_make_regexp(regex,
>                         gh_list(gh_lookup("regexp/icase"),
>                                 SCM_UNDEFINED));
> 
> I get strange errors when I call scm_regexp_exec which makes me think that
> the regexp got garbage collected somewhere:
> 
> ERROR: In procedure regexp-exec:
> ERROR: Wrong type argument in position 1: #<unknown-type (0x7f . 
> 0x4024a480) @ 0x4024a488>
> 
> (first argument of scm_regexp_exec was r)
> 
> Is this error really related to garbage collection, and what is then the
> means to protect my newly created object ?
> 
> Where can I get more information on Guile 1.3 garbage collection ?