Steel Bank Common Lisp

alien alignment information not preserved during compilation

Reported by Stas Boukarev on 2012-07-24
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
High
Unassigned

Bug Description

(sb-alien:define-alien-type nil
    (sb-alien:struct type-b
                     (a sb-alien:unsigned-long :alignment 64)
                     (b sb-alien:unsigned-long :alignment 24)))

(defun test (a)
  (declare (type (sb-alien:alien (sb-alien:struct type-b)) a))
  a)

; in: DEFUN TEST
; (SB-INT:NAMED-LAMBDA TEST
; (A)
; (DECLARE (TYPE (ALIEN (STRUCT TYPE-B)) A))
; (BLOCK TEST A))
; --> SB-C::%FUNCALL MULTIPLE-VALUE-BIND LET UNLESS IF
; ==>
; (TYPEP #:G6 '(ALIEN (STRUCT TYPE-B (A (UNSIGNED 64)) (B (UNSIGNED 64)))))
;
; caught WARNING:
; illegal type specifier for TYPEP: (ALIEN
; (STRUCT TYPE-B (A (UNSIGNED 64))
; (B (UNSIGNED 64))))
;
; compilation unit finished
; caught 1 WARNING condition

And calling it:
(test 1)
  Incompatible alien record type definition
Old: (STRUCT TYPE-B (A (UNSIGNED 64)) (B (UNSIGNED 64)))
New: (STRUCT TYPE-B (A (UNSIGNED 64)) (B (UNSIGNED 64)))

(SB-ALIEN::PARSE-ALIEN-RECORD-TYPE :STRUCT TYPE-B ((A (UNSIGNED 64)) (B (UNSIGNED 64))) #<NULL-LEXENV>)
in the backtrace suggest that it doesn't save and pass alignment information.

Cyrus Harmon (ch-launchpad) wrote :

Not sure if this is the right thing, but the attached patch squirrels away the offset information in the alien type and uses this in parse-alien-record-fields to regenerate the type.

Stas Boukarev (stassats) on 2012-08-15
tags: added: review
Stas Boukarev (stassats) wrote :

commit c78d726af276ff97f8ec85eb42aa72cb31766284
Author: Cyrus Harmon <email address hidden>
Date: Sun Oct 14 23:12:58 2012 -0700

    alien type improvement: handle offsets in unparse-alien-record-type

    Previously, when recomputing the offset to struct fields we would
    ignore the offset and attempt to recompute it, occasionally getting it
    wrong. Now store the offset in uparse-alien-record-field and use in
    parse-alien-record-fields.

Changed in sbcl:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers