chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Help with problem involving GC mixing C/Scheme


From: Alejandro Forero Cuervo
Subject: Re: [Chicken-users] Help with problem involving GC mixing C/Scheme
Date: Mon, 9 May 2005 06:26:34 -0500
User-agent: Mutt/1.5.6+20040907i

> Since funccall may trigger a garbage collection, the value func in
> your run procedure may not be valid, once a GC occurred.  [...]
> 
> Here is an alternative version:
> 
> (use format)
> 
> (define-external (funccall (scheme-object func)) void (func))
> 
> (define run
>   (foreign-callback-lambda* void ((long n) (scheme-object func))
>     "void *r = CHICKEN_new_gc_root();"
>     "CHICKEN_gc_root_set(r, func);"
>     "while (n--) funccall(CHICKEN_gc_root_ref(r));"
>     "CHICKEN_delete_gc_root(r);") )
> 
> (run 1000000 (lambda () (format #t "~%")))

Excellent!

I'll make sure I document this in our unofficial manual.  :)

Thank you, Felix!

Alejo.
http://bachue.com/alejo

---=(  Comunidad de Usuarios de Software Libre en Colombia  )=---
---=(  http://bachue.com/colibri )=--=( address@hidden  )=---




reply via email to

[Prev in Thread] Current Thread [Next in Thread]