[plt-scheme] FFI - Implicit binding of _int to the correct _int32 or _int64

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Sep 26 22:15:03 EDT 2007

On Sep 26, Ray Racine wrote:
> (define HMAC-SHA1/raw
>      (get-ffi-obj 'HMAC openssl-crypto
>                   (_fun [EVP_MD : _fpointer = (EVP_SHA1)]
>                         [key : _bytes]
>                         [key_len : _int = (bytes-length key)]
>                         [data : _bytes]
>                         [data_len : _int = (bytes-length data)]
>                         [md : _pointer = NULL]  
>                         [md_len : _pointer = NULL]
>                         ->
>                         _pointer)))

Yes, if `md_len' is not used, then you should use _pointer instead of
`(_ptr o ...)'.  The latter is for "output pointer" where you want its
value -- in the case of `(_ptr o _int)' it generates code that will
malloc an int before calling the function, and bind `md_len' to the
result of dereferencing that pointer later.

The above is therefore better (and fixes the size of `md'), but you
should use `#f' for NULL pointer values.

> works because I'm back to punning sizeof _int64 = sizeof _pointer.
> But I've lost generic 32/64 code.

(Not a good idea, but FWIW, if you wanted to fake a pointer as an
integer, you should have used `_long'.)

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

Posted on the users mailing list.