Bogus :long-long alignment in Clozure CL

Bug #622339 reported by Luís Oliveira
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
CFFI
New
High
Unassigned

Bug Description

On Tue, Jun 1, 2010 at 7:55 AM, Helmut Eller <email address hidden> wrote:
> I think there is a bug in CFFI with CCL's 32-bit version:
>
> (cffi:defcunion foo-union
>  (int16    :int16  )
>  (uint64   :uint64 )
>  )
>
> (cffi:defcstruct bar-struct
>  (tag :uint8)
>  (val foo-union))
>
> (defun foo ()
>  (cffi:with-foreign-string (data "0123456789" :encoding :latin-1)
>    (- (cffi:pointer-address (cffi:foreign-slot-value data 'bar-struct 'val))
>       (cffi:pointer-address data))))
>
>
> FOO returns 4 in SBCL and Lispworks but with CCL it's 8.

Revision history for this message
Naofumi Honda (honda-c) wrote :

This happens with a recent ccl under linux 32 bits env, and not occure under linux 64, etc.
By this wrong alignment problem, for example, cl-gtk2's demo crashes.
The reason is very clear. As you know, gcc under linux 32 has 64 bits alignment for the long-long type. But
there is an exception that, in a struct or union, it becomes 32 bits alignment. However,
ccl:foreign-type-alignment always returns 64 for the long-long type (of course, it is theoretically true
and internally ccl uses proper alignment (=32) for the record type).

Therefore the following patch is needed:
*** ./src/cffi-openmcl.lisp.org 2012-09-25 00:48:14.000000000 +0900
--- ./src/cffi-openmcl.lisp 2012-09-25 00:51:09.000000000 +0900
***************
*** 222,227 ****
--- 222,231 ----
  ;; http://clozure.com/pipermail/openmcl-devel/2005-June/002777.html
  (defun %foreign-type-alignment (type-keyword)
    "Return the alignment in bytes of a foreign type."
+ #+32-bit-target <= please specify proper condition!
+ (case type-keyword
+ ((:double :long-long :unsigned-long-long)
+ (return-from %foreign-type-alignment 4)))
    (/ (ccl::foreign-type-alignment
        (ccl::parse-foreign-type
         (convert-foreign-type type-keyword))) 8))

Revision history for this message
Michał "phoe" Herda (phoe-krk) wrote :

Has ccl:foreign-type-alignment ever been patched in CCL32 to return 32 instead of 64 in that case?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.