what is the length of a long (motivated by GSL2.1 and GSLL)

Stas Boukarev stassats at gmail.com
Mon Nov 23 08:35:45 UTC 2015


Mirko Vukovic <mirko.vukovic at gmail.com> writes:

> This message has two audiences:  One the general CFFI group, and second the
> GSL maintainer.
>
> This is using latest CCL and SBCL on 64-bit Windows 7, and MSYS2 running
> 64-bit MinGW and its GSL2.0 and 2.1.
>
> Running GSL 2.0 and 2.1 under GSLL resulted in exception violations.  I
> could eliminate them by specifying the length of an integer as 8 instead of
> 4 bytes.
>
> My question has to do with the origin of this specification, since it is
> derived from CFFI and GSLL, not hard-coded.
>
> Specifically, in GSLL, the following code in init/types.lisp:
> (case (cffi:foreign-type-size :long)
>   *(8 (push :int64 *features*))*
>   *(4 (push :int32 *features*))*)
>
> evaluates to 4, pushing :int32 into *features*.  Here is some additional
> output of cffi:foreign-type-size on my machine:
>
> GSL> (cffi:foreign-type-size :double)
> 8
> GSL> (cffi:foreign-type-size :long)
> 4
> GSL> (cffi:foreign-type-size :long-long)
> 8
> GSL> (cffi:foreign-type-size :int)
> 4
>
> This feature eventually makes its way to other code in GSLL.  In the Linear
> Algebra module, the function make-permutation (in data/permutation.lisp)
> has this line:
> (make-instance
>  'permutation
>  :element-type '(unsigned-byte *#+int64 64* *#+int32 32*)
>  :dimensions (if (typep n 'permutation) (grid:dimensions n) (list n)))))
>
> In my environment element type resulted in unsigned-byte 32.
>
> When I hard-coded my features to :int64 (and unsigned-byte 64), all the
> exception errors disappeared.
>
> I hope this gives enough background to fix this error (either in my setup,
> gsll, or cffi).
long on 64-bit windows is indeed 4-byte long, so it cannot be used to
determine word length.

I would suggest using (cffi:foreign-type-size :pointer) instead.
I would also suggest using DEFTYPE:
(deftype word ()
  `(unsigned-byte ,(* (cffi:foreign-type-size :pointer) 8)))

-- 
With best regards, Stas.



More information about the cffi-devel mailing list