From 1678c6aa47ad3d9517552face6a03c25fd230f61 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Wed, 26 Feb 2014 20:03:28 +0900 Subject: [PATCH] Fixing bit-set? on fixnums with larger than word-size index. Fixing some cases of arithmetic shift on bignums with zero modulo word-sized offset. --- lib/srfi/33/bit.c | 19 ++++++++++++------- tests/srfi-33-tests.scm | 6 ++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/srfi/33/bit.c b/lib/srfi/33/bit.c index 0546cc33..995d4da7 100644 --- a/lib/srfi/33/bit.c +++ b/lib/srfi/33/bit.c @@ -202,7 +202,8 @@ static sexp sexp_arithmetic_shift (sexp ctx, sexp self, sexp_sint_t n, sexp i, s for (j=tmp=0; j> tail_shift; + if (bit_shift != 0) + tmp = sexp_bignum_data(i)[j] >> tail_shift; } if (bit_shift != 0) sexp_bignum_data(res)[len+offset] = tmp; } @@ -286,20 +287,24 @@ static sexp sexp_integer_length (sexp ctx, sexp self, sexp_sint_t n, sexp x) { } static sexp sexp_bit_set_p (sexp ctx, sexp self, sexp_sint_t n, sexp i, sexp x) { + sexp_sint_t pos; #if SEXP_USE_BIGNUMS - sexp_uint_t pos; + sexp_sint_t rem; #endif if (! sexp_fixnump(i)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, i); + pos = sexp_unbox_fixnum(i); + if (pos < 0) + return sexp_xtype_exception(ctx, self, "index must be non-negative", i); if (sexp_fixnump(x)) { - return sexp_make_boolean(sexp_unbox_fixnum(x) & (1UL<