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

Frederick LeMaster fred.lemaster at gmail.com
Tue Dec 24 10:08:05 EST 2013


If I'm not wrong you can take a similar approach to the one I took in
my OpenAL wrapper on the Dumping Grounds page of the Gambit Wiki
(http://dynamo.iro.umontreal.ca/wiki/images/2/2c/OpenAL.tar.gz). When
I allocate a foreign struct, I attach a will to the object and in the
will free the underlying C pointer when the foreign object is garbage
collected. The implementation is at the bottom of the file labelled
'foreign-macros.scm' in that tarball.

On Tue, Dec 24, 2013 at 2:06 PM, Estevo <euccastro at gmail.com> wrote:
>>> I've experimented in the past with making a macro that would generate the
>>> appropriate ffi code to create and manage c structs/unions/types.  The
>>> challenge was to handle references obtained from accessors to fields
>>> containing other structs/union/types within them in such a way that
>>> - no copying was necessary, and
>>> - the original structure wouldn't be released as long as derived
>>> references
>>> existed
>>
>> Anyone know what guile does?  If anything?
>>
>> -- hendrik
>
> Well, I was interested in how to make it work in Gambit as is.  If we
> consider modifications to Gambit, there is an easy solution: give foreign
> objects a 'data' field that holds a user-settable strong reference to a
> Scheme object.  Then, whenever you need to make sure that object A is not
> reclaimed while foreign object B is reachable, you just say
> (foreign-data-set! B A).
>
> Indeed, after having tried hard, my current impression is that the above
> can't be done in a way that is robust and seamless to the user without
> modifying Gambit.  I'd be very happy to be proven wrong in this!
>
> I have made a pull request proposing that change:
>
> https://github.com/feeley/gambit/pull/59
>
> but I don't know whether the cost of one extra pointer per foreign object is
> a showstopper here.
>
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>



More information about the Gambit-list mailing list