]> gitweb.factorcode.org Git - factor.git/commitdiff
Properly set bits in large bit arrays
authorSamuel Tardieu <sam@rfc1149.net>
Fri, 26 Dec 2008 19:58:45 +0000 (20:58 +0100)
committerSamuel Tardieu <sam@rfc1149.net>
Fri, 26 Dec 2008 19:58:45 +0000 (20:58 +0100)
Bit arrays were not properly manipulated by set-bits or clear-bits
if they were larger than 40 bits (one cell + one byte).

Moreover, the bug was likely to cause a bus error on architectures unable
to access unaligned words.

basis/bit-arrays/bit-arrays-tests.factor
basis/bit-arrays/bit-arrays.factor

index a5ae23dde69c049e4e59ad2e5387d0f542133424..24c27fa15bcfa45042c53ec674f3ea8e59ffae60 100644 (file)
@@ -76,3 +76,5 @@ IN: bit-arrays.tests
     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
 } bit-array>integer ] unit-test
+
+[ 49 ] [ 49 <bit-array> dup set-bits [ ] count ] unit-test
index 66c786f6bb11de62705847b6b926b7c2556c44af..18796fbfed44fb1bc84cffa150381db84ee1f0c5 100644 (file)
@@ -25,7 +25,7 @@ TUPLE: bit-array
 
 : (set-bits) ( bit-array n -- )
     [ [ length bits>cells ] keep ] dip swap underlying>>
-    '[ [ _ _ ] dip set-alien-unsigned-4 ] each ; inline
+    '[ 2 shift [ _ _ ] dip set-alien-unsigned-4 ] each ; inline
 
 PRIVATE>