[cffi-devel] Cannot call function with char** arg

James Bielman jamesjb at jamesjb.com
Wed Apr 26 09:24:45 UTC 2006


Nikolai Nespor <nikolai.nespor at utanet.at> writes:

> rrd> (with-foreign-string-vector (argc argv '("create" "test.rrd" "--step=300" "DS:a:GAUGE:600:U:U" "DS:b:GAUGE:600:U:U" "RRA:AVERAGE:0.5:1:300"))
>        (rrd-create argc argv))
>
> I get this error:
>
> arithmetic error FLOATING-POINT-INVALID-OPERATION signalled
>    [Condition of type FLOATING-POINT-INVALID-OPERATION]

I've seen this happen in the glX libraries before.  As I understand
what's happening, SBCL enables floating point traps that are not
normally enabled in C programs, and this can mess things up when
calling foreign code.  What I used to get around this was:

;;; Execute BODY with floating-point traps disabled.  This seems to be
;;; necessary on (at least) Linux/x86-64 where SIGFPEs are signalled
;;; when creating making a GLX context active.
#+sbcl
(defmacro without-fp-traps (&body body)
  `(sb-int:with-float-traps-masked (:invalid :divide-by-zero)
     , at body))

;;; Do nothing on Lisps that don't need traps disabled.
#-sbcl
(defmacro without-fp-traps (&body body)
  `(progn
     , at body))

and a WITHOUT-FP-TRAPS form around the offending foreign function
calls.  I'm not enough of a floating-point wizard to know why you'd be
getting that particular trap though...

James



More information about the cffi-devel mailing list