[racket] FFI: Casting pointers

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jan 23 09:12:34 EST 2012

Although discussion has moved on to better solutions...

At Sun, 22 Jan 2012 14:14:47 -0700, Michael W wrote:
> If I say:
> 
>    (cast
>     (malloc _OggVorbis_File)
>     _pointer _OggVorbis_File-pointer)
> 
> ...That's bad -- because I never keep the original pointer
> returned by the (malloc) call, the garbage collector reclaims
> that memory even though the _OggVorbis_File-pointer still points
> to it.

To fix this cast, use `_gcpointer' as the source type and `_gcable' on
the result pointer type:

    (cast
     (malloc _OggVorbis_File)
     _gcpointer
     (_gcable _OggVorbis_File-pointer))


Posted on the users mailing list.