[plt-scheme] Using SRFI-4 from C

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Mar 6 13:33:47 EST 2005

On Mar  6, Noel Welsh wrote:
> --- Eli Barzilay <eli at barzilay.org> wrote:
> > There is nothing to skip in C -- what happens is that you
> > do use plain
> > C vectors in C code, and these are used in Scheme via a
> > cpointer
> > object 
> 
> Ok, missing is, I think, the implicit use of the foreign.ss
> library.  I'm now using foreign.ss and get-ffi-obj is
> undefined:
> 
> Welcome to MzScheme version 299.32, Copyright (c) 2004-2005
> PLT Scheme, Inc.
> > (require (lib "foreign.ss"))
> > (define asmjump (ffi-lib "asmjump.so"))
> > (get-ffi-obj "jump" asmjump (_fun _u32vector -> _int))
> reference to undefined identifier: get-ffi-obj
> 
> Any suggestions?

By default you don't get any functionality that might make you crash &
burn, and this includes any kind of referencing, so you don't get
`get-ffi-obj'.  To get these things you need to use `(unsafe!)'.

The rational for this is that code that uses `(unsafe!)' has the same
responsibilities as C code: if you have bugs, then you might crash.
So what usually happen is that instead of writing a C interface you
write an unsafe Scheme interface that uses (unsafe!), and if your code
is behaved, then it should not provide any way to crash things.  (The
only exception where you provide such things from a well behaved
module is if your module provides functionality that is used to
provide more foreign-interaction tools, and you should use an
`unsafe!' like mechanism to protect dangerous bindings.)

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



Posted on the users mailing list.