Fix more bugs in bit_string_to_bignum.
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Thu, 14 Jun 1990 19:54:00 +0000 (19:54 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Thu, 14 Jun 1990 19:54:00 +0000 (19:54 +0000)
v7/src/microcode/bitstr.c

index bca8d0f29636bc1d84b8134a45d779a4d4ff1f5a..2195f560c269ef6ce1b8094e73bcea3fb7ea6750 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.c,v 9.43 1990/06/14 17:30:32 jinx Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.c,v 9.44 1990/06/14 19:54:00 jinx Exp $
 
 Copyright (c) 1987, 1988, 1989, 1990 Massachusetts Institute of Technology
 
@@ -713,27 +713,41 @@ bit_string_to_bignum (nbits, bitstr)
 {
   static unsigned int bstb_producer ();
   struct bitstr_to_bignm_context context;
+  int ndigits, skip;
+
+  ndigits = ((nbits + (CHAR_BIT - 1)) / CHAR_BIT);
 
-  context.source_ptr =
-    ((unsigned char *) (BIT_STRING_HIGH_PTR (bitstr)));
   context.mask = (LOW_MASK (((nbits - 1) % (CHAR_BIT)) + 1));
+  context.source_ptr =
+    ((unsigned char *)
+     (MEMORY_LOC (bitstr, (BIT_STRING_INDEX_TO_WORD (bitstr, (nbits - 1))))));
+
+  if (ndigits != 0)
+  {
+    skip = ((sizeof (SCHEME_OBJECT)) -
+           (((ndigits - 1) % (sizeof (SCHEME_OBJECT))) + 1));
+    while ((--skip) >= 0)
+    {
+      DEC_BIT_STRING_PTR (context.source_ptr);
+    }
+  }
 
   return
-    (digit_stream_to_bignum
-     (((nbits + (CHAR_BIT - 1)) / CHAR_BIT),
-      bstb_producer, (&context),
-      (1 << CHAR_BIT), 0));
+    (digit_stream_to_bignum (ndigits, bstb_producer,
+                            (&context), (1 << CHAR_BIT),
+                            0));
 }
 
 static unsigned int
 bstb_producer (context)
      struct bitstr_to_bignm_context *context;
 {
-  unsigned int mask;
+  unsigned int result;
 
-  mask = context->mask;
+  result = (context->mask & (BIT_STRING_WORD (context->source_ptr)));
   context->mask = (LOW_MASK (CHAR_BIT));
-  return (mask & (* (DEC_BIT_STRING_PTR (context->source_ptr))));
+  DEC_BIT_STRING_PTR (context->source_ptr);
+  return (result);
 }
 \f
 /* (UNSIGNED-INTEGER->BIT-STRING length integer)