chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Safely holding on to a <procedure> reference in C


From: Felix
Subject: Re: [Chicken-users] Safely holding on to a <procedure> reference in C
Date: Tue, 22 Feb 2011 09:00:13 +0100 (CET)

From: Peter Bex <address@hidden>
Subject: Re: [Chicken-users] Safely holding on to a <procedure> reference in C
Date: Mon, 21 Feb 2011 09:19:54 +0100

> On Sun, Feb 20, 2011 at 08:55:24PM -0800, Naitik Shah wrote:
>> Hi,
>> 
>> I'm experimenting with Chicken and libevent using the bind extension to
>> build a event based webserver. I'm trying to figure out if there's a way to
>> have C code hold on to a <procedure> in a GC safe manner. The implementation
>> I have so far works for a few requests, but eventually fails. Based on what
>> I've learned so far it seems like this is because the GC is either throwing
>> away or moving the <procedure> making the pointer in C being held by
>> libevent invalid. Is it possible to hold on to a <procedure> like this?
> 
> I think you can use object-evict for that.  It's from unit lolevel, see
> http://wiki.call-cc.org/man/4/Unit%20lolevel#object-evict

I'm not sure eviction is the right thing to do here.

> 
> Alternatively, you can construct a new GC root with CHICKEN_new_gc_root()
> and put the procedure object in it with CHICKEN_gc_root_set():
> http://wiki.call-cc.org/man/4/Embedding#chicken_new_gc_root

Yes, that's the right thing.

> 
> I don't think there's a Scheme interface for that, though.

No, since this is intended to be used by C code. Alternatively,
one could declare a piece of C that creates and returns the
GC root and bind to this.


cheers,
felix



reply via email to

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