From 58e1e377348c44372cf4da144a1e0a37482bf544 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 28 Oct 2010 08:42:58 -0600 Subject: [PATCH] fix bug in ffi struct alignment --- collects/ffi/unsafe.rkt | 4 +++- collects/mred/private/wx/cocoa/finfo.rkt | 2 +- src/foreign/foreign.c | 3 ++- src/foreign/foreign.rktc | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/collects/ffi/unsafe.rkt b/collects/ffi/unsafe.rkt index f1f0cb46ef..46c0351cb5 100644 --- a/collects/ffi/unsafe.rkt +++ b/collects/ffi/unsafe.rkt @@ -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))) diff --git a/collects/mred/private/wx/cocoa/finfo.rkt b/collects/mred/private/wx/cocoa/finfo.rkt index b1570bea44..b4090a9fe8 100644 --- a/collects/mred/private/wx/cocoa/finfo.rkt +++ b/collects/mred/private/wx/cocoa/finfo.rkt @@ -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 diff --git a/src/foreign/foreign.c b/src/foreign/foreign.c index a54113edea..5d7f2f8691 100644 --- a/src/foreign/foreign.c +++ b/src/foreign/foreign.c @@ -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 */ diff --git a/src/foreign/foreign.rktc b/src/foreign/foreign.rktc index 61c1eee040..3fff7490b1 100755 --- a/src/foreign/foreign.rktc +++ b/src/foreign/foreign.rktc @@ -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 */