From c3ca13d2e1e75cc43399f8d290e5f8e6b8cdc08c Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Mon, 5 Jan 2009 08:55:20 +0000 Subject: [PATCH] 1.0.24.23: fix alien struct struct member offset bug No-one uses struct struct members, right? Well, academics are notoriously bad at keeping up to dat with good practice... --- NEWS | 2 ++ src/code/host-alieneval.lisp | 10 ++++++---- tests/foreign.test.sh | 15 +++++++++++++++ version.lisp-expr | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 7830d10..a9379b9 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ changes in sbcl-1.0.25 relative to 1.0.24: * optimization: CHAR-CODE type derivation has been improved, making TYPEP elimination on subtypes of CHARACTER work better. (reported by Tobias Rittweiler, patch by Paul Khuong) + * bug fix: setting alien structure fields of type struct by value now + computes the right offset for the memory copy. changes in sbcl-1.0.24 relative to 1.0.23: * new feature: ARRAY-STORAGE-VECTOR provides access to the underlying data diff --git a/src/code/host-alieneval.lisp b/src/code/host-alieneval.lisp index 29bb28f..920f616 100644 --- a/src/code/host-alieneval.lisp +++ b/src/code/host-alieneval.lisp @@ -869,13 +869,15 @@ (define-alien-type-method (mem-block :extract-gen) (type sap offset) (declare (ignore type)) - `(sap+ ,sap (/ ,offset sb!vm:n-byte-bits))) + `(sap+ ,sap (truncate ,offset sb!vm:n-byte-bits))) (define-alien-type-method (mem-block :deposit-gen) (type sap offset value) - (let ((bytes (truncate (alien-mem-block-type-bits type) sb!vm:n-byte-bits))) - (unless bytes + (let ((bits (alien-mem-block-type-bits type))) + (unless bits (error "can't deposit aliens of type ~S (unknown size)" type)) - `(sb!kernel:system-area-ub8-copy ,value 0 ,sap ,offset ',bytes))) + `(sb!kernel:system-area-ub8-copy ,value 0 ,sap + (truncate ,offset sb!vm:n-byte-bits) + ',(truncate bits sb!vm:n-byte-bits)))) ;;;; the ARRAY type diff --git a/tests/foreign.test.sh b/tests/foreign.test.sh index d34a900..9fff522 100644 --- a/tests/foreign.test.sh +++ b/tests/foreign.test.sh @@ -355,6 +355,21 @@ run_sbcl <