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

From: Ray Racine (ray.racine at comcast.net)
Date: Wed Sep 26 20:40:07 EDT 2007

YIKES!!!   <sigh> and Google never forgets!

On Wed, 2007-09-26 at 17:14 -0600, Matthew Flatt wrote:

> I think `int' normally means 32 bits on both 32-bt and 64-bit machines.
> So, if a C prototype says `int', I'd expect `_int' to be the right FFI
> choice. Unlike `int', the `long' type's size normally varies.

yes... I don't know _what_ my pea brain was doing.

> After looking at "hmac.h" on my machine, I wonder whether the problem
> is that the md_len argument is supposed to be a pointer to an integer,
> not an integer?

yes...

man hmac
 #include <openssl/hmac.h>

        unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
                      int key_len, const unsigned char *d, int n,
                      unsigned char *md, unsigned int *md_len);

Changing back to _int and using (_ptr o _int) the following is working
for me.  Am I using (_ptr o _int) appropriately here?

  (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 : _int = 0]
                       [md_len : (_ptr o _int)]
                       ->
                       _pointer)))






Posted on the users mailing list.