1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 17:20:29 +02:00

Do not assume that sizeof (long) == sizeof (void *) == sizeof (SCM).

This assumption does not hold on systems that use the LLP64 data model.

Partially fixes <https://debbugs.gnu.org/22406>.
Reported by Peter TB Brett <peter@peter-b.co.uk>.

* libguile/numbers.h (scm_t_inum): Move here from numbers.c, and change
  to be equivalent to 'long' (formerly 'scm_t_signed_bits').
  (SCM_MOST_POSITIVE_FIXNUM, SCM_MOST_NEGATIVE_FIXNUM): Define based on
  SCM_I_FIXNUM_BIT instead of SCM_T_SIGNED_BITS_MAX.
  (SCM_I_INUM): Adjust definitions to return a 'scm_t_inum', and avoiding
  the assumption that SCM_UNPACK returns a 'long'.
* libguile/numbers.c (scm_t_inum): Move definition to numbers.h.
  Verify that 'scm_t_inum' fits within a SCM value.
  (scm_i_inum2big): Remove preprocessor code that forced a compile error
  unless sizeof (long) == sizeof (void *).
* libguile/vm-i-scheme.c (_CX): For fixnum assembly functions, choose
  the register size based on SCM_I_FIXNUM_BIT instead of SIZEOF_VOID_P.
  (ASM_MUL, "ash", "vector-ref", "vector-set", BV_FIXABLE_INT_REF)
  (BV_INT_REF, BV_FLOAT_REF, BV_FIXABLE_INT_SET, BV_INT_SET)
  (BV_FLOAT_SET): Use 'scm_t_inum' for fixnums instead of
  'scm_t_signed_bits'.
This commit is contained in:
Mark H Weaver 2016-04-06 17:36:57 -04:00
parent 1e86dc32a4
commit b0a702d773
3 changed files with 32 additions and 37 deletions

View file

@ -87,7 +87,9 @@
/* FIXME: We assume that FLT_RADIX is 2 */
verify (FLT_RADIX == 2);
typedef scm_t_signed_bits scm_t_inum;
/* Make sure that scm_t_inum fits within a SCM value. */
verify (sizeof (scm_t_inum) <= sizeof (scm_t_bits));
#define scm_from_inum(x) (scm_from_signed_integer (x))
/* Test an inum to see if it can be converted to a double without loss
@ -272,13 +274,7 @@ scm_i_inum2big (scm_t_inum x)
{
/* Return a newly created bignum initialized to X. */
SCM z = make_bignum ();
#if SIZEOF_VOID_P == SIZEOF_LONG
mpz_init_set_si (SCM_I_BIG_MPZ (z), x);
#else
/* Note that in this case, you'll also have to check all mpz_*_ui and
mpz_*_si invocations in Guile. */
#error creation of mpz not implemented for this inum size
#endif
return z;
}