fix bug in ffi struct alignment

This commit is contained in:
Matthew Flatt 2010-10-28 08:42:58 -06:00
parent 3143192713
commit 58e1e37734
4 changed files with 8 additions and 4 deletions

View File

@ -1138,7 +1138,9 @@
(let loop ([ts types] [cur 0] [r '()])
(if (null? ts)
(reverse r)
(let* ([algn (or alignment (ctype-alignof (car ts)))]
(let* ([algn (if alignment
(min alignment (ctype-alignof (car ts)))
(ctype-alignof (car ts)))]
[pos (+ cur (modulo (- (modulo cur algn)) algn))])
(loop (cdr ts)
(+ pos (ctype-sizeof (car ts)))

View File

@ -136,8 +136,8 @@
(raise-type-error 'file-creator-and-type "bytes string of length 4" type))
(let ([fs (path->fsref path)]
[v (cast (malloc 256) _pointer _FSCatalogInfo-pointer)])
(get-info v fs path)
(let ([info (FSCatalogInfo-finderInfo v)])
(get-info v fs path)
(set-FileInfo-fileCreator! info (str->int creator))
(set-FileInfo-fileType! info (str->int type)))
(let ([r (FSSetCatalogInfo fs

View File

@ -1107,7 +1107,8 @@ static Scheme_Object *foreign_make_cstruct_type(int argc, Scheme_Object *argv[])
libffi_type = malloc(sizeof(ffi_type));
memcpy(libffi_type, elements[i], sizeof(ffi_type));
elements[i] = libffi_type;
elements[i]->alignment = with_alignment;
if (with_alignment < elements[i]->alignment)
elements[i]->alignment = with_alignment;
}
}
/* allocate the new libffi type object */

View File

@ -943,7 +943,8 @@ ffi_abi sym_to_abi(char *who, Scheme_Object *sym)
libffi_type = malloc(sizeof(ffi_type));
memcpy(libffi_type, elements[i], sizeof(ffi_type));
elements[i] = libffi_type;
elements[i]->alignment = with_alignment;
if (with_alignment < elements[i]->alignment)
elements[i]->alignment = with_alignment;
}
}
/* allocate the new libffi type object */