[racket] FFI questions

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Oct 6 01:22:35 EDT 2010

15 minutes ago, Neil Toronto wrote:
> Eli Barzilay wrote:
> > (I don't see why, either way you need some pointer going to some
> > data.)
> It looks like this:
> (struct bigfloat (mpfr-value)
>          #:property prop:custom-write ...)
> I have a struct type with just one field. Every time I'm forced into 
> doing that, it seems like a pointless indirection. (It's *only* an 
> indirection; I'm not aggregating anything.) But if that's the only way, 
> I'm fine with it.

(You can think about this as packing up a C pointer with a racket
struct type.)  If you're doing a language, you can also play with the
display/write handlers.

> > Why aren't you using a byte string directly?
> Let me sum up.
> The C library provides gimme_string (actually something with a more
> complex type signature), which allocates a char* in some special way
> and returns it. The library also provides special_free, which takes
> a char* and frees it in a special way.
> I need to call gimme_string and use the return value as a string,
> but also have the return value as a pointer so I can pass it to
> special_free. If I get gimme_string with (_fun -> _string)

Remember that there's a step here that converts the char* string into
a racket string (in ucs-4).

> or (_fun -> _bytes), I don't get a pointer, I get a string? or a
> bytes?.

A byte string can be used as a pointer.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.