From: Chris Hanson <org/chris-hanson/cph> Date: Sat, 9 May 1987 04:51:32 +0000 (+0000) Subject: Fix two bugs: (1) `unsigned-integer->bit-string' was not clearing out X-Git-Tag: 20090517-FFI~13535 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=d20676724c118d6d9db8dfaacaf00f2af3e05cc3;p=mit-scheme.git Fix two bugs: (1) `unsigned-integer->bit-string' was not clearing out those parts of the result which were not filled in by copying from a bignum. (2) `bit-substring-find-next-set-bit' was not correctly advancing the scan pointer for the last word of a multi-word string. --- diff --git a/v7/src/microcode/bitstr.c b/v7/src/microcode/bitstr.c index 3f7f30830..35b1e91dd 100644 --- a/v7/src/microcode/bitstr.c +++ b/v7/src/microcode/bitstr.c @@ -30,7 +30,7 @@ Technology nor of any adaptation thereof in any advertising, promotional, or sales literature without prior written consent from MIT in each case. */ -/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.c,v 9.26 1987/04/25 20:25:54 cph Exp $ +/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.c,v 9.27 1987/05/09 04:50:56 cph Exp $ Bit string primitives. */ @@ -186,7 +186,7 @@ Built_In_Primitive (Prim_bit_string_length, 1, "BIT-STRING-LENGTH", 0xD4) Primitive_Error (ERR_ARG_2_BAD_RANGE); \ \ word = (index_to_word (Arg1, index)); \ - mask = (1 << (index % POINTER_LENGTH)); + mask = (1 << (index % POINTER_LENGTH)) /* (BIT-STRING-REF bit-string index) Returns the boolean value of the indexed bit. */ @@ -657,36 +657,40 @@ long_to_bit_string( length, number) } Pointer -bignum_to_bit_string( length, bignum) +bignum_to_bit_string (length, bignum) long length; Pointer bignum; { bigdigit *bigptr; long ndigits; - bigptr = BIGNUM( Get_Pointer( bignum)); - if (NEG_BIGNUM( bigptr)) - Primitive_Error( ERR_ARG_2_BAD_RANGE); - ndigits = LEN( bigptr); + bigptr = (BIGNUM (Get_Pointer (bignum))); + if (NEG_BIGNUM (bigptr)) + Primitive_Error (ERR_ARG_2_BAD_RANGE); + ndigits = (LEN (bigptr)); if (ndigits == 0) - zero_to_bit_string( length); + zero_to_bit_string (length); else { if (length < - (count_significant_bits( *(Bignum_Top( bigptr)), SHIFT) + (count_significant_bits ((*(Bignum_Top (bigptr))), SHIFT) + (SHIFT * (ndigits - 1)))) - Primitive_Error( ERR_ARG_2_BAD_RANGE) + Primitive_Error (ERR_ARG_2_BAD_RANGE) else { Pointer result; bigdigit *scan1, *scan2; + long extra; - result = allocate_bit_string( length); - scan1 = Bignum_Bottom( bigptr); - scan2 = ((bigdigit *) bit_string_end_ptr( result)); + result = (allocate_bit_string (length)); + scan1 = (Bignum_Bottom (bigptr)); + scan2 = ((bigdigit *) (bit_string_end_ptr (result))); + extra = (((length + (SHIFT - 1)) / SHIFT) - ndigits); for (; (ndigits > 0); ndigits -= 1) *--scan2 = *scan1++; - return result; + for (; (extra > 0); extra -= 1) + *--scan2 = 0; + return (result); } } } @@ -861,16 +865,15 @@ Built_In_Primitive (Prim_bit_substring_find_next_set_bit, 3, find_next_set_loop (bit); return (NIL); } - else if (((bit == 0) && *scan) - || (*scan & (any_mask ((POINTER_LENGTH - bit), bit)))) + else if (*scan & + ((bit == 0) ? ~0 : (any_mask ((POINTER_LENGTH - bit), bit)))) find_next_set_loop (bit); while (--word > end_word) if (*--scan) find_next_set_loop (0); - if (((end_bit == POINTER_LENGTH) && *scan) - || (*--scan & (low_mask (end_bit)))) + if (*--scan & ((end_bit == POINTER_LENGTH) ? ~0 : (low_mask (end_bit)))) find_next_set_loop (0); return (NIL); diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h index 31ff117e8..0b35296bd 100644 --- a/v7/src/microcode/version.h +++ b/v7/src/microcode/version.h @@ -30,7 +30,7 @@ Technology nor of any adaptation thereof in any advertising, promotional, or sales literature without prior written consent from MIT in each case. */ -/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 9.48 1987/04/30 22:56:49 cph Exp $ +/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 9.49 1987/05/09 04:51:32 cph Exp $ This file contains version information for the microcode. */ @@ -46,7 +46,7 @@ This file contains version information for the microcode. */ #define VERSION 9 #endif #ifndef SUBVERSION -#define SUBVERSION 48 +#define SUBVERSION 49 #endif #ifndef UCODE_TABLES_FILENAME diff --git a/v8/src/microcode/version.h b/v8/src/microcode/version.h index 0d2ff74dd..3e6b6f019 100644 --- a/v8/src/microcode/version.h +++ b/v8/src/microcode/version.h @@ -30,7 +30,7 @@ Technology nor of any adaptation thereof in any advertising, promotional, or sales literature without prior written consent from MIT in each case. */ -/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 9.48 1987/04/30 22:56:49 cph Exp $ +/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 9.49 1987/05/09 04:51:32 cph Exp $ This file contains version information for the microcode. */ @@ -46,7 +46,7 @@ This file contains version information for the microcode. */ #define VERSION 9 #endif #ifndef SUBVERSION -#define SUBVERSION 48 +#define SUBVERSION 49 #endif #ifndef UCODE_TABLES_FILENAME