From 44570df893416922d80e087fc951f226caa99f59 Mon Sep 17 00:00:00 2001 From: "Guillermo J. Rozas" Date: Sun, 16 Aug 1992 23:16:30 +0000 Subject: [PATCH] Fix bug going to compilers where int != long. Handle - (1 << FIXNUM_DATUM_LENGTH) correctly. --- v7/src/microcode/psbtobin.c | 29 +++++++++++++++++++++++++---- v8/src/microcode/psbtobin.c | 29 +++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/v7/src/microcode/psbtobin.c b/v7/src/microcode/psbtobin.c index dd51b76ca..93526d596 100644 --- a/v7/src/microcode/psbtobin.c +++ b/v7/src/microcode/psbtobin.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/psbtobin.c,v 9.47 1992/02/11 21:14:23 mhwu Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/psbtobin.c,v 9.48 1992/08/16 23:16:30 jinx Exp $ Copyright (c) 1987-1992 Massachusetts Institute of Technology @@ -43,6 +43,9 @@ MIT in each case. */ #define portable_file input_file #define internal_file output_file +#undef HEAP_MALLOC +#define HEAP_MALLOC malloc + static Boolean band_p = false, allow_compiled_p = false, @@ -241,6 +244,7 @@ DEFUN (read_an_integer, (The_Type, To, Slot), if ((length_in_bits <= fixnum_to_bits) && (The_Type == TC_FIXNUM)) { + /* The most negative fixnum is handled in the bignum case */ fast long Value = 0; fast int Normalization; fast long ndigits; @@ -285,7 +289,9 @@ DEFUN (read_an_integer, (The_Type, To, Slot), ? length_in_bits : BIGNUM_DIGIT_LENGTH); fast int position = 0; - int hex_digit; + long original_length_in_bits = length_in_bits; + long hex_digit, low_digit; + while (length_in_bits > 0) { read_hex_digit (hex_digit); @@ -328,8 +334,23 @@ DEFUN (read_an_integer, (The_Type, To, Slot), } (*To) = (MAKE_OBJECT (TC_MANIFEST_NM_VECTOR, gc_length)); BIGNUM_SET_HEADER (bignum, length, negative); - (*Slot) = bignum; - return (To + gc_length + 1); + + /* The following test depends on BIGNUM_DIGITs being long */ + + low_digit = (- (BIGNUM_REF (bignum, 0))); + if (negative + && (The_Type == TC_FIXNUM) + && (original_length_in_bits == (fixnum_to_bits + 1)) + && (LONG_TO_FIXNUM_P (low_digit))) + { + *Slot = (LONG_TO_FIXNUM (low_digit)); + return (To); + } + else + { + *Slot = bignum; + return (To + gc_length + 1); + } } } diff --git a/v8/src/microcode/psbtobin.c b/v8/src/microcode/psbtobin.c index 9b29ebf55..13fa70a8a 100644 --- a/v8/src/microcode/psbtobin.c +++ b/v8/src/microcode/psbtobin.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/psbtobin.c,v 9.47 1992/02/11 21:14:23 mhwu Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/psbtobin.c,v 9.48 1992/08/16 23:16:30 jinx Exp $ Copyright (c) 1987-1992 Massachusetts Institute of Technology @@ -43,6 +43,9 @@ MIT in each case. */ #define portable_file input_file #define internal_file output_file +#undef HEAP_MALLOC +#define HEAP_MALLOC malloc + static Boolean band_p = false, allow_compiled_p = false, @@ -241,6 +244,7 @@ DEFUN (read_an_integer, (The_Type, To, Slot), if ((length_in_bits <= fixnum_to_bits) && (The_Type == TC_FIXNUM)) { + /* The most negative fixnum is handled in the bignum case */ fast long Value = 0; fast int Normalization; fast long ndigits; @@ -285,7 +289,9 @@ DEFUN (read_an_integer, (The_Type, To, Slot), ? length_in_bits : BIGNUM_DIGIT_LENGTH); fast int position = 0; - int hex_digit; + long original_length_in_bits = length_in_bits; + long hex_digit, low_digit; + while (length_in_bits > 0) { read_hex_digit (hex_digit); @@ -328,8 +334,23 @@ DEFUN (read_an_integer, (The_Type, To, Slot), } (*To) = (MAKE_OBJECT (TC_MANIFEST_NM_VECTOR, gc_length)); BIGNUM_SET_HEADER (bignum, length, negative); - (*Slot) = bignum; - return (To + gc_length + 1); + + /* The following test depends on BIGNUM_DIGITs being long */ + + low_digit = (- (BIGNUM_REF (bignum, 0))); + if (negative + && (The_Type == TC_FIXNUM) + && (original_length_in_bits == (fixnum_to_bits + 1)) + && (LONG_TO_FIXNUM_P (low_digit))) + { + *Slot = (LONG_TO_FIXNUM (low_digit)); + return (To); + } + else + { + *Slot = bignum; + return (To + gc_length + 1); + } } } -- 2.25.1