[racket] FFI Pointing to racket objects
Thanks Mattew, I suspected moving the value was causing the issue.
Just one more question: when implementing malloc-immobile-cell and free-immobile-cell, how do you check if a pointer has not yet been set? Doing things like:
(if (cpBody-data body1)
"I have some data"
"I have nothing")
Always shows "I have nothing". 'ptr-equal?' also doesn't seem to work. Is there some procedure like 'ptr-set?' I'm looking over in the manual? Or do I just set something in the beginning like (malloc-immobile-cell 'no-val-yet)?
-----Oorspronkelijk bericht-----
Van: Matthew Flatt [mailto:mflatt at cs.utah.edu]
Verzonden: maandag 4 maart 2013 14:59
Aan: Jay McCarthy
CC: Sam Vervaeck; users
Onderwerp: Re: [racket] FFI Pointing to racket objects
At Mon, 4 Mar 2013 06:35:03 -0700, Jay McCarthy wrote:
> My understanding is that in your version, the Racket object is only
> available via the Chipmunk/C data structure, which the GC views as
> opaque, so it is collected. If you want to put Racket things in C
> objects, you'll have to make sure they are retained on the Racket
> side, by (for example), also storing them in a hash table and
> monitoring access to the C objects.
Retaining a reference to the value from elsewhere won't be enough, usually. The GC might move the value, in which case the C data structure's field will point to the wrong place.
> On Sat, Mar 2, 2013 at 8:35 AM, Sam Vervaeck <vervaeck.sam at skynet.be> wrote:
> > I have looked into (malloc-immobile-cell
> > v) and (free-immobile-cell cptr) but I am not sure that fiddling
> > with the memory is such a good idea. Could you please give me any
> > guidelines or point me to a procedure I can use to provide this functionality?
The `malloc-immobile-cell' and `free-immobile-cell' functions really are the way to go.