chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] What happens to a (non-simple) Scheme object sent to


From: Tony Sidaway
Subject: Re: [Chicken-users] What happens to a (non-simple) Scheme object sent to a foreign function?
Date: Mon, 5 Feb 2007 08:09:50 +0000

On 2/5/07, felix winkelmann <address@hidden> wrote:
Another option would be to create a GC root (CHICKEN_new_gc_root)
and keep it on the C-side (you have to pass the argument string as
a scheme-object, then create the GC-root from it). Later, you can
access the gc root (CHICKEN_gc_root_ref) and use the string. The
gc root will be updated on every garbage collection. You just have
to make sure you free it eventually (or just reuse it).


I may try that, but at the moment I've opted for a solution managed on
the Scheme side.

It's something like this (in tinyclos)

(define-method (curl-evict (c <curl>) name)
 (let* ((obj (slot-ref c name))
        (evictee (object-evict obj)))
   (slot-set! c '%evictees (cons evictee (slot-ref c '%evictees)))
   evictee))

The slot %evictees is initially an empty list, and grows with each
eviction so that I can keep a tab on all objects formerly belonging to
the item that have been evicted.

The finalizer for the <curl> object is simply:

(define (curl-finalize! c)
 (map object-release (slot-ref c '%evictees)))

So now if I need to pass a string parameter to C I do this:

     (case type
       ...
        ((c-string) (curl-easy-set-option-c-string! rc key
            (curl-evict c name)))
       ...




reply via email to

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