[gambit-list] Anyone else working in a schemey wrapper for c structs/unions/types?

Estevo euccastro at gmail.com
Wed Dec 25 11:18:11 EST 2013


>
> Is it that.. you find it tricky to get in place a particular sequence of C
> FFI structure release function invocation on their GC???
>

It's not tricky if you know what you're doing.  But if you are going to
publish a library that exposes C bindings, you really don't want to have to
be warning people against holding weak references to these foreign objects,
lest they get a segfault or memory corruption.


> Something along the lines that if you have a C structure A that contains
> in it a reference to another C structure B, and you want Gambit's GC to
> automatically take care of this relationship in the sense that it will not
> release B before A??
>

Yes, with the nuance that the C structure B is contained in A, not just
referenced from it.  So it doesn't make sense to free B at all.  Another
use case is that A is a union and B is another pointer to A's data.  You
want to free A only once.

But yes, the main point is that you want A to stick around while you have a
reference to B.  This kind of sanity you take for granted in the Scheme
world, thanks to garbage collection.  What I want is to be able to treat C
objects similarly, without having to do unnecessary copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20131225/ee1db8cb/attachment.htm>


More information about the Gambit-list mailing list