Hi all !

I wrote the following code to test unix fork(using cffi):

(load "~/quicklisp/setup.lisp")
(ql:quickload "cffi")

(defpackage :testfork
    (:use :common-lisp :cffi))
(in-package :testfork)

(defcvar "errno" :int)  
(cffi:defcfun ("getpid" unix-getpid) :int)
(cffi:defcfun ("getuid" unix-getuid) :int)
(cffi:defcfun ("getgid" unix-getgid) :int)
(cffi:defcfun ("fork" unix-fork) :int)
(cffi:defcfun ("exit" unix-exit) :void (code :int))
(cffi:defcfun ("wait" unix-wait) :int (statloc :pointer))

(when (zerop (unix-fork))
(with-foreign-pointer-as-string (str 6 str-size :encoding :ascii)
         (lisp-string-to-foreign "Hello, foreign world!" str str-size))
(unix-exit 0))

  (format t "I'm parent, Pid=~A~%" (unix-getpid))
  (format t "one child claimed!~A~%" (unix-wait (cffi:null-pointer)))

When I add two lines using with-foreign-pointer-as-string and lisp-string-to-foreign, my SBCL always crashes, and tell me

" fatal error encountered in SBCL pid XXXX:
Unhandled memory fault. "

So I remove lisp-string-to-foreign, the problem is still there. I have tried other memory allocation macros, I get the same result. But if I remove them, the program runs and exits normally.

Later I switch to ccl, it runs without any problem.

So I expand the macro in SBCL , and get:

  (LET ((#:SIZE960 6) (STR (SB-ALIEN:ALIEN-SAP #:ALIEN961)))

My environment is : OSX 10.8.3 Processor Intel Core i7,SBCL 1.1.4(installed using brew), cffi_0.10.7.1 installed from quicklisp

Thank you very much!