[gambit-list] Immutable foreign objects?

Julian Scheid julians37 at googlemail.com
Thu Oct 8 05:44:08 EDT 2009


On Thu, Oct 8, 2009 at 9:41 PM, Julian Scheid <julians37 at googlemail.com> wrote:
> http://www.iro.umontreal.ca/~gambit/doc/gambit-c.html#mapping-of-types says:
>
>> In the case of the struct, union and type types, the internal pointer
>> points to a copy of the C data type being represented. When an
>> instance of one of these types is converted from C to Scheme, a block
>> of memory is allocated from the C heap and initialized with the
>> instance and then a foreign object is allocated from the Scheme heap
>> and initialized with the pointer to this copy. [...]

I've made a test case that shows they are mutable when accessed by a
pointer. Does this mean the paragraph above only applies when
accessing a struct by value?

This also brings me to another question, I'm somewhat confused about
___alloc_rc.

James Long had an issue [1] that I could reproduce and was able to fix
by using __alloc_rc instead of malloc. Also, 4.5.2's gambit.h has
___USE_RC_ALLOCATION_FOR_FOREIGN defined.

At the same time, I have examples that seem to work fine with regular
new/malloc. Is that just a lucky accident?

If ___alloc_rc was indeed required, how could the FFI use foreign
objects that have been created outside of Gambit's control?

It would be great if someone could shed some light on this, thanks in advance.

[1] http://github.com/jlongster/gambit-iphone-example/blob/master/lib/ffi/osx.scm#L81


More information about the Gambit-list mailing list