Guile Mailing List Archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[LONG] Re: Calling Scheme from C and Garbage Collection



On Mon, Nov 30, 1998, Greg Harvey wrote:
> > Is this error really related to garbage collection, and what is then the
> > means to protect my newly created object ?
> 
> Looks like it could be. What happens sometimes is that the compiler is
> optimizing away the SCM value, so that the gc can miss it. What you
> can do is scm_remember(&r), or, if the function returns something,
> call return scm_return_first(something, r) (these are both defined in
> gc.c; they don't do anything, but the presence of r later on means
> that the compiler can't optimize it away).

Well, I have tried, and it doesn't solve my problem. I think I'll have to
be more precise :-)

I'm using guile to add "hooks" to an IRC bot. Hooks will only be called if
the string matches a regexp (like /on with ircII and bitchx, if you know
these programs.)

I define a function, bot-addhook, which take a hook type argument,
a string, which is the regexp (I want to compile the regexp myself), and a
Scheme function to be called. For example :

(define (test from to message) (bot-say to "Testing... 1, 2, 3"))
(bot-addhook hooks/public ".*test.*" test)

Then, the next call to scm_regexp_exec with the compiled regexp I stored
in my program gives a fatal error :

ERROR: In procedure regexp-exec:
ERROR: Wrong type argument in position 1: #<rgx 4024a498>

If I do not use scm_gc_mark(), I do not have the error immediately, but if
I redefine the "test" function 3 times:

This will call the "test" function when somebody says "test" on the
channel.

I think I have to scm_gc_mark() the regexp I compiled myself so that it
can not be garbage collected, right ? (this is what I've deduced from the
little documentation I have, and code I can read :-)

If I redefine the "test" function 3 times (why 3 ?) :

(define (test from to message) (bot-say to "Testing... 1, 2, 3"))
(define (test from to message) (bot-say to "Testing... 1, 2, 3"))
(define (test from to message) (bot-say to "Testing... 1, 2, 3"))

the next call to scm_regexp_exec will be fatal:

ERROR: In procedure regexp-exec:
ERROR: Wrong type argument in position 1: #<unknown-type (0x7f .
0x4024a490) @ 0x4024a498>

What could be important, that I didn't mention before, is that this is a
C++ program.

Do you know what I can modify to make my program work ?
If you need my source code, I can send it to you upon request.
-- 
Etienne BERNARD   ISIA, Mines de Paris / Ecole Centrale Paris, France.
E-Mail : eb@via.ecp.fr    WWW : http://www.via.ecp.fr/~eb/    IRC : eb

Guile Home | Main Index | Thread Index