From: Paul Khuong Date: Mon, 20 May 2013 03:47:13 +0000 (-0400) Subject: Take bitwidth into account in BOOLEAN alien type X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=14dde89d91420d03a37e6b03f2e41e830218b736;p=sbcl.git Take bitwidth into account in BOOLEAN alien type Some ABIs (x86/x86-64) allow garbage in unused upper bits of return values; take that into account when converting BOOLEAN return types to CL BOOLEANs. --- diff --git a/NEWS b/NEWS index 2b413ca..dd9b144 100644 --- a/NEWS +++ b/NEWS @@ -55,6 +55,8 @@ changes relative to sbcl-1.1.7: modular arithemtic (mostly to exploit fixnum-width VOPs). (lp#1026634) * bug fix: a combination of inlined local function with &optional and recursion no longer causes undescriptive compiler errors. (lp#1180992) + * bug fix: sub-word BOOLEAN alien types now disregard higher order bits + when testing for non-zero-ness. * optimization: faster ISQRT on fixnums and small bignums * optimization: faster and smaller INTEGER-LENGTH on fixnums on x86-64. * optimization: On x86-64, the number of multi-byte NOP instructions used diff --git a/src/code/host-alieneval.lisp b/src/code/host-alieneval.lisp index 8e61909..c78853f 100644 --- a/src/code/host-alieneval.lisp +++ b/src/code/host-alieneval.lisp @@ -666,8 +666,10 @@ `(member t nil)) (define-alien-type-method (boolean :naturalize-gen) (type alien) - (declare (ignore type)) - `(not (zerop ,alien))) + (let ((bits (alien-boolean-type-bits type))) + (if (= bits sb!vm:n-word-bits) + `(not (zerop ,alien)) + `(logtest ,alien ,(ldb (byte bits 0) -1))))) (define-alien-type-method (boolean :deport-gen) (type value) (declare (ignore type))