[plt-scheme] scheme/foreign, callbacks and NULL

From: Andreas Rottmann (a.rottmann at gmx.at)
Date: Thu Jan 1 09:08:26 EST 2009

Hi!

Writing an FFI compatiblity layer that targets Ikarus, PLT and Ypsilon,
I have run into this problem on PLT: I want to bind a C function that
takes a callback (function pointer) argument, and want to be able to
pass a NULL pointer as callback. Here's some example code, using GLib:

#lang scheme

(require scheme/foreign
         (only-in '#%foreign ffi-callback))

(unsafe!)

(define libglib (ffi-lib "libglib-2.0" '("0")))
(define g-idle-add-full% (get-ffi-obj "g_idle_add_full" libglib _fpointer))

(define g-idle-add-full
  (function-ptr g-idle-add-full%
                (_cprocedure (list _int _fpointer _pointer _fpointer) _uint)))

(define my-idle-callback
  (ffi-callback (lambda args
                  (printf "idle, args: ~s~n" args)
                  1)
                (list _pointer)
                _int))

(g-idle-add-full 200 my-idle-callback #f #f)
;; EOF

This causes the following error when run:
Scheme->C: expects argument of type <cpointer>; given #f

I'm using MzScheme v4.1.3.8 [3m] (recent build from SVN).

PS: I know one is not really supposed to use `ffi-callback' directly,
    but I need it to provide a compatible API across all
    implementations.

Regards, Rotty
-- 
Andreas Rottmann         | Rotty at ICQ      | 118634484 at ICQ | a.rottmann at gmx.at
http://rotty.uttx.net    | GnuPG Key: http://rotty.uttx.net/gpg.asc
Fingerprint              | C38A 39C5 16D7 B69F 33A3  6993 22C8 27F7 35A9 92E7
v2sw7MYChw5pr5OFma7u7Lw2m5g/l7Di6e6t5BSb7en6g3/5HZa2Xs6MSr1/2p7 hackerkey.com

Life is a sexually transmitted disease.


Posted on the users mailing list.