From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jan Nieuwenhuizen Newsgroups: gmane.lisp.guile.devel Subject: [PATCH v3] DRAFT Support for x86_64-w64-mingw32. Date: Sun, 21 Mar 2021 15:17:35 +0100 Organization: AvatarAcademy.nl Message-ID: <87lfag8ubk.fsf_-_@gnu.org> References: <87eegdratt.fsf@verum.com> <87mtuxwk9s.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14218"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sun Mar 21 15:18:04 2021 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNyu3-0003WQ-Hx for guile-devel@m.gmane-mx.org; Sun, 21 Mar 2021 15:18:03 +0100 Original-Received: from localhost ([::1]:40788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNyu2-0003hz-HM for guile-devel@m.gmane-mx.org; Sun, 21 Mar 2021 10:18:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNytf-0003hf-H1 for guile-devel@gnu.org; Sun, 21 Mar 2021 10:17:39 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:40301) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNytf-0007su-9l; Sun, 21 Mar 2021 10:17:39 -0400 Original-Received: from [2001:980:1b4f:1:42d2:832d:bb59:862] (port=44014 helo=dundal.janneke.lilypond.org) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lNyte-0006pJ-AY; Sun, 21 Mar 2021 10:17:39 -0400 X-Url: http://AvatarAcademy.nl In-Reply-To: <87mtuxwk9s.fsf@gnu.org> (Jan Nieuwenhuizen's message of "Sat, 20 Mar 2021 23:08:31 +0100") X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20713 Archived-At: --=-=-= Content-Type: text/plain Jan Nieuwenhuizen writes: > Andy Wingo started a new discussion on libguile/bytevectors.c: > > 810 810 static inline void > 811 811 twos_complement (mpz_t value, size_t size) > 812 812 { > 813 - unsigned long bit_count; > 813 + scm_t_unum bit_count; > > Given that we require in-memory addressability for array elements, > let's use ssize_t for this. That makes some sense, but using ssize_t would change it from unsigned to signed, are you sure we shouldn't choose size_t? New patch attached using size_t, also up at https://gitlab.com/janneke/guile/-/commit/b587e04e6b0e0fe37cb8774609a51ac7e04127a5 Greetings, Janneke --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=v3-0001-DRAFT-Support-for-x86_64-w64-mingw32.patch Content-Transfer-Encoding: quoted-printable >From b587e04e6b0e0fe37cb8774609a51ac7e04127a5 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 16 Mar 2021 12:10:36 +0100 Subject: [PATCH v3] DRAFT Support for x86_64-w64-mingw32. Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=3DUTF-8 On x86-64-MinGW the size of long is 4. as long is used for SCM_FIXNUM_BIT, that would mean incompatible .go files, and waste of cell space. So we would like to use long long, but the GMP interface uses long. to get around this, the x86-64-MinGW port now requires the use of mini-gmp. Mini-gmp has been changed to use intptr_t and uintptr_t. Likewise, "numbers.h" now uses intptr_t instead of scm_inum_t and uintptr_t instead of unsigned long. This patch is still keeping SCM_I_INUM and SCM_I_INUMP, we could do sed -i s/SCM_I_INUM/SCM_I_INTPTR/g $(find . -name '*.c' -o -name '*.h') but hmm...WDYT? * configure.ac: When x86_64-w64-mingw32, require mini-gmp. * libguile/mini-gmp.h: Use intptr_t instead of long, uintptr_t instead of unsigned long throughout. * libguile/mini-gmp.c: Likewise. * libguile/scm.h (SCM_INTPTR_T_BIT): New define. * libguile/numbers.h (SCM_FIXNUM_BIT): Use it. * libguile/numbers.c (L1): New macro. Use it thoughout instead of 1L. (verify): Use SCM_INTPTR_T_BIT. (verify): Use SCM_INTPTR_T_MAX and SCM_INTPTR_T_MIN. (scm_long2big): Rename to... (scm_intptr2big): ..this. (scm_ulong2big): Rename to... (scm_uintptr2big): ..this. Use them throughout, together with intptr_t, uintptr_t instead of long and unsigned long. * libguile/numbers.h (scm_intptr2big,scm_uintptr2big): New declarations. (scm_from_intptr, scm_from_uintptr, scm_to_intptr, scm_to_uintptr): New defines. * libguile/arrays.c (make-shared-array): Use ssize_t instead of long. * libguile/bytevectors.c (twos_complement): Use uintptr_t instead of unsigned long. * libguile/conv-integer.i.c (SCM_TO_TYPE_PROTO): Likewise. * libguile/conv-uinteger.i.c (SCM_FROM_TYPE_PROTO): Likewise. * libguile/hash.c (JENKINS_LOOKUP3_HASHWORD2): Likewise. (narrow_string_hash, wide_string_hash, scm_i_string_hash, scm_i_locale_string_hash, scm_i_latin1_string_hash, scm_i_utf8_string_hash, scm_i_struct_hash, scm_raw_ihashq, scm_raw_ihash): Use and return uintptr_t instead of unsigned long. (scm_hashv, scm_hash): Use SCM_UINTPTR_T_MAX. * libguile/hash.h (scm_i_locale_string_hash, scm_i_latin1_string_hash, scm_i_utf8_string_hash): update prototypes. * libguile/scmsigs.c (sigaction): Use intptr_t instead of long. * libguile/strings.c (scm_i_make_symbol, (scm_i_c_make_symbol): Use uintptr_t instead of unsigned long. * libguile/strings.h (scm_i_make_symbol, (scm_i_c_make_symbol): Update declacations. * libguile/srfi-60.c: Use scm_uintptr2big, scm_intptr and variants throughout. Co-authored-by: Mike Gran Co-authored-by: Andy Wingo ssizet --- configure.ac | 6 + libguile/arrays.c | 6 +- libguile/bytevectors.c | 10 +- libguile/conv-integer.i.c | 6 +- libguile/conv-uinteger.i.c | 8 +- libguile/hash.c | 46 ++-- libguile/hash.h | 12 +- libguile/mini-gmp.c | 172 +++++++-------- libguile/mini-gmp.h | 93 ++++---- libguile/numbers.c | 441 ++++++++++++++++++------------------- libguile/numbers.h | 34 ++- libguile/scm.h | 6 +- libguile/scmsigs.c | 14 +- libguile/srfi-60.c | 113 +++++----- libguile/strings.c | 10 +- libguile/strings.h | 7 +- 16 files changed, 501 insertions(+), 483 deletions(-) diff --git a/configure.ac b/configure.ac index bd49bf162f..3129c0e50a 100644 --- a/configure.ac +++ b/configure.ac @@ -658,6 +658,12 @@ AC_ARG_ENABLE(mini-gmp, if test "x$enable_mini_gmp" =3D xyes || test "x$enable_mini_gmp" =3D xy; t= hen SCM_I_GSC_ENABLE_MINI_GMP=3D1 else + case $host in + x86_64-*-mingw*) + AC_MSG_ERROR([mini-gmp is required; use --enable-mini-gmp]) + ;; + *) ;; + esac AC_LIB_HAVE_LINKFLAGS([gmp],[],[#include ], [mpz_import (0,0,0,0,= 0,0,0);]) if test "x$HAVE_LIBGMP" !=3D "xyes"; then AC_MSG_ERROR([GNU MP 4.1 or greater not found; either install it, or p= ass '--enable-mini-gmp' to use included less-optimal arbitrary-precision in= teger support.]) diff --git a/libguile/arrays.c b/libguile/arrays.c index 0a919515b5..da8e1a72d0 100644 --- a/libguile/arrays.c +++ b/libguile/arrays.c @@ -342,7 +342,7 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array",= 2, 0, 1, SCM imap; size_t k; ssize_t i; - long old_base, old_min, new_min, old_max, new_max; + ssize_t old_base, old_min, new_min, old_max, new_max; scm_t_array_dim *s; =20 SCM_VALIDATE_REST_ARGUMENT (dims); @@ -747,8 +747,8 @@ SCM_DEFINE (scm_array_contents, "array-contents", 1, 1,= 0, return SCM_BOOL_F; if (scm_is_bitvector (SCM_I_ARRAY_V (ra)) && (len !=3D scm_c_bitvector_length (SCM_I_ARRAY_V (ra)) || - SCM_I_ARRAY_BASE (ra) % SCM_LONG_BIT || - len % SCM_LONG_BIT)) + SCM_I_ARRAY_BASE (ra) % SCM_INTPTR_T_BIT || + len % SCM_INTPTR_T_BIT)) return SCM_BOOL_F; } =20 diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c index 2d6cbdb3e4..3df8ff835c 100644 --- a/libguile/bytevectors.c +++ b/libguile/bytevectors.c @@ -810,14 +810,14 @@ SCM_DEFINE (scm_u8_list_to_bytevector, "u8-list->byte= vector", 1, 0, 0, static inline void twos_complement (mpz_t value, size_t size) { - unsigned long bit_count; + uintptr_t bit_count; =20 - /* We expect BIT_COUNT to fit in a unsigned long thanks to the range + /* We expect BIT_COUNT to fit in a uintptr_t thanks to the range checking on SIZE performed earlier. */ - bit_count =3D (unsigned long) size << 3UL; + bit_count =3D (uintptr_t) size << 3ULL; =20 - if (SCM_LIKELY (bit_count < sizeof (unsigned long))) - mpz_ui_sub (value, 1UL << bit_count, value); + if (SCM_LIKELY (bit_count < sizeof (uintptr_t))) + mpz_ui_sub (value, 1ULL << bit_count, value); else { mpz_t max; diff --git a/libguile/conv-integer.i.c b/libguile/conv-integer.i.c index 7d6bd347e7..8ff1645e2f 100644 --- a/libguile/conv-integer.i.c +++ b/libguile/conv-integer.i.c @@ -49,7 +49,7 @@ SCM_TO_TYPE_PROTO (SCM val) { if (mpz_fits_slong_p (SCM_I_BIG_MPZ (val))) { - long n =3D mpz_get_si (SCM_I_BIG_MPZ (val)); + intptr_t n =3D mpz_get_si (SCM_I_BIG_MPZ (val)); #if SIZEOF_TYPE !=3D 0 && SIZEOF_TYPE > SCM_SIZEOF_LONG return n; #else @@ -118,8 +118,8 @@ SCM_FROM_TYPE_PROTO (TYPE val) #else if (SCM_FIXABLE (val)) return SCM_I_MAKINUM (val); - else if (val >=3D LONG_MIN && val <=3D LONG_MAX) - return scm_i_long2big (val); + else if (val >=3D INTPTR_MIN && val <=3D INTPTR_MAX) + return scm_i_intptr2big (val); else { SCM z =3D make_bignum (); diff --git a/libguile/conv-uinteger.i.c b/libguile/conv-uinteger.i.c index f9203771a0..54afd040bd 100644 --- a/libguile/conv-uinteger.i.c +++ b/libguile/conv-uinteger.i.c @@ -49,7 +49,7 @@ SCM_TO_TYPE_PROTO (SCM val) { if (mpz_fits_ulong_p (SCM_I_BIG_MPZ (val))) { - unsigned long n =3D mpz_get_ui (SCM_I_BIG_MPZ (val)); + uintptr_t n =3D mpz_get_ui (SCM_I_BIG_MPZ (val)); #if SIZEOF_TYPE !=3D 0 && SIZEOF_TYPE > SCM_SIZEOF_LONG return n; #else @@ -95,13 +95,13 @@ SCM_TO_TYPE_PROTO (SCM val) SCM SCM_FROM_TYPE_PROTO (TYPE val) { -#if SIZEOF_TYPE !=3D 0 && SIZEOF_TYPE < SIZEOF_UINTPTR_T +#if SIZEOF_TYPE !=3D 0 && SIZEOF_TYPE < SCM_SIZEOF_INTPTR_T return SCM_I_MAKINUM (val); #else if (SCM_POSFIXABLE (val)) return SCM_I_MAKINUM (val); - else if (val <=3D ULONG_MAX) - return scm_i_ulong2big (val); + else if (val <=3D UINTPTR_MAX) + return scm_i_untptr2big (val); else { SCM z =3D make_bignum (); diff --git a/libguile/hash.c b/libguile/hash.c index 11a35c2cb8..caf7f2b3cd 100644 --- a/libguile/hash.c +++ b/libguile/hash.c @@ -115,31 +115,31 @@ extern double floor(); the hash on a 64-bit system are equal to the hash on a 32-bit \ system. The low 32 bits just add more entropy. */ \ if (sizeof (ret) =3D=3D 8) = \ - ret =3D (((unsigned long) c) << 32) | b; \ + ret =3D (((uintptr_t) c) << 32) | b; \ else \ ret =3D c; \ } while (0) =20 =20 -static unsigned long +static uintptr_t narrow_string_hash (const uint8_t *str, size_t len) { - unsigned long ret; + uintptr_t ret; JENKINS_LOOKUP3_HASHWORD2 (str, len, ret); ret >>=3D 2; /* Ensure that it fits in a fixnum. */ return ret; } =20 -static unsigned long +static uintptr_t wide_string_hash (const scm_t_wchar *str, size_t len) { - unsigned long ret; + uintptr_t ret; JENKINS_LOOKUP3_HASHWORD2 (str, len, ret); ret >>=3D 2; /* Ensure that it fits in a fixnum. */ return ret; } =20 -unsigned long +uintptr_t scm_i_string_hash (SCM str) { size_t len =3D scm_i_string_length (str); @@ -151,13 +151,13 @@ scm_i_string_hash (SCM str) return wide_string_hash (scm_i_string_wide_chars (str), len); } =20 -unsigned long=20 +uintptr_t scm_i_locale_string_hash (const char *str, size_t len) { return scm_i_string_hash (scm_from_locale_stringn (str, len)); } =20 -unsigned long=20 +uintptr_t scm_i_latin1_string_hash (const char *str, size_t len) { if (len =3D=3D (size_t) -1) @@ -167,11 +167,11 @@ scm_i_latin1_string_hash (const char *str, size_t len) } =20 /* A tricky optimization, but probably worth it. */ -unsigned long=20 +uintptr_t scm_i_utf8_string_hash (const char *str, size_t len) { const uint8_t *end, *ustr =3D (const uint8_t *) str; - unsigned long ret; + uintptr_t ret; =20 /* The length of the string in characters. This name corresponds to Jenkins' original name. */ @@ -222,8 +222,8 @@ scm_i_utf8_string_hash (const char *str, size_t len) =20 final (a, b, c); =20 - if (sizeof (unsigned long) =3D=3D 8) - ret =3D (((unsigned long) c) << 32) | b; + if (sizeof (uintptr_t) =3D=3D 8) + ret =3D (((uintptr_t) c) << 32) | b; else ret =3D c; =20 @@ -231,16 +231,16 @@ scm_i_utf8_string_hash (const char *str, size_t len) return ret; } =20 -static unsigned long scm_raw_ihashq (scm_t_bits key); -static unsigned long scm_raw_ihash (SCM obj, size_t depth); +static uintptr_t scm_raw_ihashq (scm_t_bits key); +static uintptr_t scm_raw_ihash (SCM obj, size_t depth); =20 /* Return the hash of struct OBJ. Traverse OBJ's fields to compute the result, unless DEPTH is zero. Assumes that OBJ is a struct. */ -static unsigned long +static uintptr_t scm_i_struct_hash (SCM obj, size_t depth) { size_t struct_size, field_num; - unsigned long hash; + uintptr_t hash; =20 struct_size =3D SCM_STRUCT_SIZE (obj); =20 @@ -260,7 +260,7 @@ scm_i_struct_hash (SCM obj, size_t depth) =20 /* Thomas Wang's integer hasher, from http://www.cris.com/~Ttwang/tech/inthash.htm. */ -static unsigned long +static uintptr_t scm_raw_ihashq (scm_t_bits key) { if (sizeof (key) < 8) @@ -286,7 +286,7 @@ scm_raw_ihashq (scm_t_bits key) } =20 /* `depth' is used to limit recursion. */ -static unsigned long +static uintptr_t scm_raw_ihash (SCM obj, size_t depth) { if (SCM_IMP (obj)) @@ -321,7 +321,7 @@ scm_raw_ihash (SCM obj, size_t depth) { size_t len =3D SCM_SIMPLE_VECTOR_LENGTH (obj); size_t i =3D depth / 2; - unsigned long h =3D scm_raw_ihashq (SCM_CELL_WORD_0 (obj)); + uintptr_t h =3D scm_raw_ihashq (SCM_CELL_WORD_0 (obj)); if (len) while (i--) h ^=3D scm_raw_ihash (scm_c_vector_ref (obj, h % len), i); @@ -329,7 +329,7 @@ scm_raw_ihash (SCM obj, size_t depth) } case scm_tc7_syntax: { - unsigned long h; + uintptr_t h; h =3D scm_raw_ihash (scm_syntax_expression (obj), depth); h ^=3D scm_raw_ihash (scm_syntax_wrap (obj), depth); h ^=3D scm_raw_ihash (scm_syntax_module (obj), depth); @@ -389,7 +389,7 @@ SCM_DEFINE (scm_hashq, "hashq", 2, 0, 0, "different values, since @code{foo} will be garbage collected.") #define FUNC_NAME s_scm_hashq { - unsigned long sz =3D scm_to_unsigned_integer (size, 1, ULONG_MAX); + uintptr_t sz =3D scm_to_unsigned_integer (size, 1, UINTPTR_MAX); return scm_from_ulong (scm_ihashq (key, sz)); } #undef FUNC_NAME @@ -422,7 +422,7 @@ SCM_DEFINE (scm_hashv, "hashv", 2, 0, 0, "different values, since @code{foo} will be garbage collected.") #define FUNC_NAME s_scm_hashv { - unsigned long sz =3D scm_to_unsigned_integer (size, 1, ULONG_MAX); + uintptr_t sz =3D scm_to_unsigned_integer (size, 1, UINTPTR_MAX); return scm_from_ulong (scm_ihashv (key, sz)); } #undef FUNC_NAME @@ -445,7 +445,7 @@ SCM_DEFINE (scm_hash, "hash", 2, 0, 0, "integer in the range 0 to @var{size} - 1.") #define FUNC_NAME s_scm_hash { - unsigned long sz =3D scm_to_unsigned_integer (size, 1, ULONG_MAX); + uintptr_t sz =3D scm_to_unsigned_integer (size, 1, UINTPTR_MAX); return scm_from_ulong (scm_ihash (key, sz)); } #undef FUNC_NAME diff --git a/libguile/hash.h b/libguile/hash.h index 0e82b4afcb..985d5360f9 100644 --- a/libguile/hash.h +++ b/libguile/hash.h @@ -23,17 +23,15 @@ =20 #include "libguile/scm.h" +#include "libguile/numbers.h" =20 =20 -SCM_INTERNAL unsigned long scm_i_locale_string_hash (const char *str, - size_t len); -SCM_INTERNAL unsigned long scm_i_latin1_string_hash (const char *str, - size_t len); -SCM_INTERNAL unsigned long scm_i_utf8_string_hash (const char *str, - size_t len); +SCM_INTERNAL uintptr_t scm_i_locale_string_hash (const char *str, size_t l= en); +SCM_INTERNAL uintptr_t scm_i_latin1_string_hash (const char *str, size_t = len); +SCM_INTERNAL uintptr_t scm_i_utf8_string_hash (const char *str, size_t len= ); =20 -SCM_INTERNAL unsigned long scm_i_string_hash (SCM str); +SCM_INTERNAL uintptr_t scm_i_string_hash (SCM str); SCM_API unsigned long scm_ihashq (SCM obj, unsigned long n); SCM_API SCM scm_hashq (SCM obj, SCM n); SCM_API unsigned long scm_ihashv (SCM obj, unsigned long n); diff --git a/libguile/mini-gmp.c b/libguile/mini-gmp.c index 48ce1072ba..fed5bbd7e2 100644 --- a/libguile/mini-gmp.c +++ b/libguile/mini-gmp.c @@ -2,7 +2,7 @@ =20 Contributed to the GNU project by Niels M=C3=B6ller =20 -Copyright 1991-1997, 1999-2019 Free Software Foundation, Inc. +Copyright 1991-1997, 1999-2019,2021 Free Software Foundation, Inc. =20 This file is part of the GNU MP Library. =20 @@ -64,8 +64,8 @@ see https://www.gnu.org/licenses/. */ #define GMP_HLIMB_BIT ((mp_limb_t) 1 << (GMP_LIMB_BITS / 2)) #define GMP_LLIMB_MASK (GMP_HLIMB_BIT - 1) =20 -#define GMP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT) -#define GMP_ULONG_HIGHBIT ((unsigned long) 1 << (GMP_ULONG_BITS - 1)) +#define GMP_ULONG_BITS (sizeof(uintptr_t) * CHAR_BIT) +#define GMP_ULONG_HIGHBIT ((uintptr_t) 1 << (GMP_ULONG_BITS - 1)) =20 #define GMP_ABS(x) ((x) >=3D 0 ? (x) : -(x)) #define GMP_NEG_CAST(T,x) (-((T)((x) + 1) - 1)) @@ -140,7 +140,7 @@ see https://www.gnu.org/licenses/. */ } \ else if (GMP_ULONG_BITS >=3D 2 * GMP_LIMB_BITS) \ { \ - unsigned long int __ww =3D (unsigned long int) (u) * (v); \ + uintptr_t __ww =3D (uintptr_t) (u) * (v); \ w0 =3D (mp_limb_t) __ww; \ w1 =3D (mp_limb_t) (__ww >> LOCAL_GMP_LIMB_BITS); \ } \ @@ -1462,25 +1462,25 @@ mpz_realloc (mpz_t r, mp_size_t size) /* MPZ assignment and basic conversions. */ void -mpz_set_si (mpz_t r, signed long int x) +mpz_set_si (mpz_t r, intptr_t x) { if (x >=3D 0) mpz_set_ui (r, x); else /* (x < 0) */ if (GMP_LIMB_BITS < GMP_ULONG_BITS) { - mpz_set_ui (r, GMP_NEG_CAST (unsigned long int, x)); + mpz_set_ui (r, GMP_NEG_CAST (uintptr_t, x)); mpz_neg (r, r); } else { r->_mp_size =3D -1; - MPZ_REALLOC (r, 1)[0] =3D GMP_NEG_CAST (unsigned long int, x); + MPZ_REALLOC (r, 1)[0] =3D GMP_NEG_CAST (uintptr_t, x); } } =20 void -mpz_set_ui (mpz_t r, unsigned long int x) +mpz_set_ui (mpz_t r, uintptr_t x) { if (x > 0) { @@ -1518,14 +1518,14 @@ mpz_set (mpz_t r, const mpz_t x) } =20 void -mpz_init_set_si (mpz_t r, signed long int x) +mpz_init_set_si (mpz_t r, intptr_t x) { mpz_init (r); mpz_set_si (r, x); } =20 void -mpz_init_set_ui (mpz_t r, unsigned long int x) +mpz_init_set_ui (mpz_t r, uintptr_t x) { mpz_init (r); mpz_set_ui (r, x); @@ -1541,8 +1541,8 @@ mpz_init_set (mpz_t r, const mpz_t x) int mpz_fits_slong_p (const mpz_t u) { - return (LONG_MAX + LONG_MIN =3D=3D 0 || mpz_cmp_ui (u, LONG_MAX) <=3D 0)= && - mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, LONG_MIN)) <=3D 0; + return (INTPTR_MAX + INTPTR_MIN =3D=3D 0 || mpz_cmp_ui (u, INTPTR_MAX) <= =3D 0) && + mpz_cmpabs_ui (u, GMP_NEG_CAST (uintptr_t, INTPTR_MIN)) <=3D 0; } =20 static int @@ -1565,26 +1565,26 @@ mpz_fits_ulong_p (const mpz_t u) return us >=3D 0 && mpn_absfits_ulong_p (u->_mp_d, us); } =20 -long int +intptr_t mpz_get_si (const mpz_t u) { - unsigned long r =3D mpz_get_ui (u); - unsigned long c =3D -LONG_MAX - LONG_MIN; + uintptr_t r =3D mpz_get_ui (u); + uintptr_t c =3D -INTPTR_MAX - INTPTR_MIN; =20 if (u->_mp_size < 0) - /* This expression is necessary to properly handle -LONG_MIN */ - return -(long) c - (long) ((r - c) & LONG_MAX); + /* This expression is necessary to properly handle -INTPTR_MIN */ + return -(intptr_t) c - (intptr_t) ((r - c) & INTPTR_MAX); else - return (long) (r & LONG_MAX); + return (intptr_t) (r & INTPTR_MAX); } =20 -unsigned long int +uintptr_t mpz_get_ui (const mpz_t u) { if (GMP_LIMB_BITS < GMP_ULONG_BITS) { int LOCAL_GMP_LIMB_BITS =3D GMP_LIMB_BITS; - unsigned long r =3D 0; + uintptr_t r =3D 0; mp_size_t n =3D GMP_ABS (u->_mp_size); n =3D GMP_MIN (n, 1 + (mp_size_t) (GMP_ULONG_BITS - 1) / GMP_LIMB_BI= TS); while (--n >=3D 0) @@ -1827,7 +1827,7 @@ mpz_sgn (const mpz_t u) } =20 int -mpz_cmp_si (const mpz_t u, long v) +mpz_cmp_si (const mpz_t u, intptr_t v) { mp_size_t usize =3D u->_mp_size; =20 @@ -1836,11 +1836,11 @@ mpz_cmp_si (const mpz_t u, long v) else if (usize >=3D 0) return 1; else - return - mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, v)); + return - mpz_cmpabs_ui (u, GMP_NEG_CAST (uintptr_t, v)); } =20 int -mpz_cmp_ui (const mpz_t u, unsigned long v) +mpz_cmp_ui (const mpz_t u, uintptr_t v) { mp_size_t usize =3D u->_mp_size; =20 @@ -1865,7 +1865,7 @@ mpz_cmp (const mpz_t a, const mpz_t b) } =20 int -mpz_cmpabs_ui (const mpz_t u, unsigned long v) +mpz_cmpabs_ui (const mpz_t u, uintptr_t v) { mp_size_t un =3D GMP_ABS (u->_mp_size); =20 @@ -1873,7 +1873,7 @@ mpz_cmpabs_ui (const mpz_t u, unsigned long v) return 1; else { - unsigned long uu =3D mpz_get_ui (u); + uintptr_t uu =3D mpz_get_ui (u); return GMP_CMP(uu, v); } } @@ -1912,7 +1912,7 @@ mpz_swap (mpz_t u, mpz_t v) =20 =20 void -mpz_add_ui (mpz_t r, const mpz_t a, unsigned long b) +mpz_add_ui (mpz_t r, const mpz_t a, uintptr_t b) { mpz_t bb; mpz_init_set_ui (bb, b); @@ -1921,14 +1921,14 @@ mpz_add_ui (mpz_t r, const mpz_t a, unsigned long b) } =20 void -mpz_sub_ui (mpz_t r, const mpz_t a, unsigned long b) +mpz_sub_ui (mpz_t r, const mpz_t a, uintptr_t b) { mpz_ui_sub (r, b, a); mpz_neg (r, r); } =20 void -mpz_ui_sub (mpz_t r, unsigned long a, const mpz_t b) +mpz_ui_sub (mpz_t r, uintptr_t a, const mpz_t b) { mpz_neg (r, b); mpz_add_ui (r, r, a); @@ -2010,11 +2010,11 @@ mpz_sub (mpz_t r, const mpz_t a, const mpz_t b) /* MPZ multiplication */ void -mpz_mul_si (mpz_t r, const mpz_t u, long int v) +mpz_mul_si (mpz_t r, const mpz_t u, intptr_t v) { if (v < 0) { - mpz_mul_ui (r, u, GMP_NEG_CAST (unsigned long int, v)); + mpz_mul_ui (r, u, GMP_NEG_CAST (uintptr_t, v)); mpz_neg (r, r); } else @@ -2022,7 +2022,7 @@ mpz_mul_si (mpz_t r, const mpz_t u, long int v) } =20 void -mpz_mul_ui (mpz_t r, const mpz_t u, unsigned long int v) +mpz_mul_ui (mpz_t r, const mpz_t u, uintptr_t v) { mpz_t vv; mpz_init_set_ui (vv, v); @@ -2104,7 +2104,7 @@ mpz_mul_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t bit= s) } =20 void -mpz_addmul_ui (mpz_t r, const mpz_t u, unsigned long int v) +mpz_addmul_ui (mpz_t r, const mpz_t u, uintptr_t v) { mpz_t t; mpz_init_set_ui (t, v); @@ -2114,7 +2114,7 @@ mpz_addmul_ui (mpz_t r, const mpz_t u, unsigned long = int v) } =20 void -mpz_submul_ui (mpz_t r, const mpz_t u, unsigned long int v) +mpz_submul_ui (mpz_t r, const mpz_t u, uintptr_t v) { mpz_t t; mpz_init_set_ui (t, v); @@ -2510,11 +2510,11 @@ mpz_congruent_p (const mpz_t a, const mpz_t b, cons= t mpz_t m) return res; } =20 -static unsigned long +static uintptr_t mpz_div_qr_ui (mpz_t q, mpz_t r, - const mpz_t n, unsigned long d, enum mpz_div_round_mode mode) + const mpz_t n, uintptr_t d, enum mpz_div_round_mode mode) { - unsigned long ret; + uintptr_t ret; mpz_t rr, dd; =20 mpz_init (rr); @@ -2530,90 +2530,90 @@ mpz_div_qr_ui (mpz_t q, mpz_t r, return ret; } =20 -unsigned long -mpz_cdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d) +uintptr_t +mpz_cdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (q, r, n, d, GMP_DIV_CEIL); } =20 -unsigned long -mpz_fdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d) +uintptr_t +mpz_fdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (q, r, n, d, GMP_DIV_FLOOR); } =20 -unsigned long -mpz_tdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d) +uintptr_t +mpz_tdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (q, r, n, d, GMP_DIV_TRUNC); } =20 -unsigned long -mpz_cdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d) +uintptr_t +mpz_cdiv_q_ui (mpz_t q, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_CEIL); } =20 -unsigned long -mpz_fdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d) +uintptr_t +mpz_fdiv_q_ui (mpz_t q, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_FLOOR); } =20 -unsigned long -mpz_tdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d) +uintptr_t +mpz_tdiv_q_ui (mpz_t q, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_TRUNC); } =20 -unsigned long -mpz_cdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d) +uintptr_t +mpz_cdiv_r_ui (mpz_t r, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_CEIL); } -unsigned long -mpz_fdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d) +uintptr_t +mpz_fdiv_r_ui (mpz_t r, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_FLOOR); } -unsigned long -mpz_tdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d) +uintptr_t +mpz_tdiv_r_ui (mpz_t r, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_TRUNC); } =20 -unsigned long -mpz_cdiv_ui (const mpz_t n, unsigned long d) +uintptr_t +mpz_cdiv_ui (const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_CEIL); } =20 -unsigned long -mpz_fdiv_ui (const mpz_t n, unsigned long d) +uintptr_t +mpz_fdiv_ui (const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_FLOOR); } =20 -unsigned long -mpz_tdiv_ui (const mpz_t n, unsigned long d) +uintptr_t +mpz_tdiv_ui (const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_TRUNC); } =20 -unsigned long -mpz_mod_ui (mpz_t r, const mpz_t n, unsigned long d) +uintptr_t +mpz_mod_ui (mpz_t r, const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_FLOOR); } =20 void -mpz_divexact_ui (mpz_t q, const mpz_t n, unsigned long d) +mpz_divexact_ui (mpz_t q, const mpz_t n, uintptr_t d) { gmp_assert_nocarry (mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_TRUNC)); } =20 int -mpz_divisible_ui_p (const mpz_t n, unsigned long d) +mpz_divisible_ui_p (const mpz_t n, uintptr_t d) { return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_TRUNC) =3D=3D 0; } @@ -2663,8 +2663,8 @@ mpn_gcd_11 (mp_limb_t u, mp_limb_t v) return u << shift; } =20 -unsigned long -mpz_gcd_ui (mpz_t g, const mpz_t u, unsigned long v) +uintptr_t +mpz_gcd_ui (mpz_t g, const mpz_t u, uintptr_t v) { mpz_t t; mpz_init_set_ui(t, v); @@ -2766,7 +2766,7 @@ mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u,= const mpz_t v) if (u->_mp_size =3D=3D 0) { /* g =3D 0 u + sgn(v) v */ - signed long sign =3D mpz_sgn (v); + intptr_t sign =3D mpz_sgn (v); mpz_abs (g, v); if (s) s->_mp_size =3D 0; @@ -2778,7 +2778,7 @@ mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u,= const mpz_t v) if (v->_mp_size =3D=3D 0) { /* g =3D sgn(u) u + 0 v */ - signed long sign =3D mpz_sgn (u); + intptr_t sign =3D mpz_sgn (u); mpz_abs (g, u); if (s) mpz_set_si (s, sign); @@ -2961,7 +2961,7 @@ mpz_lcm (mpz_t r, const mpz_t u, const mpz_t v) } =20 void -mpz_lcm_ui (mpz_t r, const mpz_t u, unsigned long v) +mpz_lcm_ui (mpz_t r, const mpz_t u, uintptr_t v) { if (v =3D=3D 0 || u->_mp_size =3D=3D 0) { @@ -3011,9 +3011,9 @@ mpz_invert (mpz_t r, const mpz_t u, const mpz_t m) /* Higher level operations (sqrt, pow and root) */ =20 void -mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e) +mpz_pow_ui (mpz_t r, const mpz_t b, uintptr_t e) { - unsigned long bit; + uintptr_t bit; mpz_t tr; mpz_init_set_ui (tr, 1); =20 @@ -3032,7 +3032,7 @@ mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e) } =20 void -mpz_ui_pow_ui (mpz_t r, unsigned long blimb, unsigned long e) +mpz_ui_pow_ui (mpz_t r, uintptr_t blimb, uintptr_t e) { mpz_t b; =20 @@ -3147,7 +3147,7 @@ mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, cons= t mpz_t m) } =20 void -mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long elimb, const mpz_t m) +mpz_powm_ui (mpz_t r, const mpz_t b, uintptr_t elimb, const mpz_t m) { mpz_t e; =20 @@ -3158,7 +3158,7 @@ mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long el= imb, const mpz_t m) =20 /* x=3Dtrunc(y^(1/z)), r=3Dy-x^z */ void -mpz_rootrem (mpz_t x, mpz_t r, const mpz_t y, unsigned long z) +mpz_rootrem (mpz_t x, mpz_t r, const mpz_t y, uintptr_t z) { int sgn; mpz_t t, u; @@ -3218,7 +3218,7 @@ mpz_rootrem (mpz_t x, mpz_t r, const mpz_t y, unsigne= d long z) } =20 int -mpz_root (mpz_t x, const mpz_t y, unsigned long z) +mpz_root (mpz_t x, const mpz_t y, uintptr_t z) { int res; mpz_t r; @@ -3289,7 +3289,7 @@ mpn_sqrtrem (mp_ptr sp, mp_ptr rp, mp_srcptr p, mp_si= ze_t n) /* Combinatorics */ =20 void -mpz_mfac_uiui (mpz_t x, unsigned long n, unsigned long m) +mpz_mfac_uiui (mpz_t x, uintptr_t n, uintptr_t m) { mpz_set_ui (x, n + (n =3D=3D 0)); if (m + 1 < 2) return; @@ -3298,19 +3298,19 @@ mpz_mfac_uiui (mpz_t x, unsigned long n, unsigned l= ong m) } =20 void -mpz_2fac_ui (mpz_t x, unsigned long n) +mpz_2fac_ui (mpz_t x, uintptr_t n) { mpz_mfac_uiui (x, n, 2); } =20 void -mpz_fac_ui (mpz_t x, unsigned long n) +mpz_fac_ui (mpz_t x, uintptr_t n) { mpz_mfac_uiui (x, n, 1); } =20 void -mpz_bin_uiui (mpz_t r, unsigned long n, unsigned long k) +mpz_bin_uiui (mpz_t r, uintptr_t n, uintptr_t k) { mpz_t t; =20 @@ -3389,10 +3389,10 @@ gmp_lucas_step_k_2k (mpz_t V, mpz_t Qk, const mpz_t= n) =20 /* Computes V_k, Q^k (mod n) for the Lucas' sequence */ /* with P=3D1, Q=3DQ; k =3D (n>>b0)|1. */ -/* Requires an odd n > 4; b0 > 0; -2*Q must not overflow a long */ +/* Requires an odd n > 4; b0 > 0; -2*Q must not overflow a intptr_t */ /* Returns (U_k =3D=3D 0) and sets V=3DV_k and Qk=3DQ^k. */ static int -gmp_lucas_mod (mpz_t V, mpz_t Qk, long Q, +gmp_lucas_mod (mpz_t V, mpz_t Qk, intptr_t Q, mp_bitcnt_t b0, const mpz_t n) { mp_bitcnt_t bs; @@ -3400,8 +3400,8 @@ gmp_lucas_mod (mpz_t V, mpz_t Qk, long Q, int res; =20 assert (b0 > 0); - assert (Q <=3D - (LONG_MIN / 2)); - assert (Q >=3D - (LONG_MAX / 2)); + assert (Q <=3D - (INTPTR_MIN / 2)); + assert (Q >=3D - (INTPTR_MAX / 2)); assert (mpz_cmp_ui (n, 4) > 0); assert (mpz_odd_p (n)); =20 @@ -3455,7 +3455,7 @@ gmp_stronglucas (const mpz_t x, mpz_t Qk) mp_bitcnt_t b0; mpz_t V, n; mp_limb_t maxD, D; /* The absolute value is stored. */ - long Q; + intptr_t Q; mp_limb_t tl; =20 /* Test on the absolute value. */ @@ -3490,7 +3490,7 @@ gmp_stronglucas (const mpz_t x, mpz_t Qk) b0 =3D mpz_scan0 (n, 0); =20 /* D=3D P^2 - 4Q; P =3D 1; Q =3D (1-D)/4 */ - Q =3D (D & 2) ? (long) (D >> 2) + 1 : -(long) (D >> 2); + Q =3D (D & 2) ? (intptr_t) (D >> 2) + 1 : -(intptr_t) (D >> 2); =20 if (! gmp_lucas_mod (V, Qk, Q, b0, n)) /* If Ud !=3D 0 */ while (V->_mp_size !=3D 0 && --b0 !=3D 0) /* while Vk !=3D 0 */ @@ -3584,7 +3584,7 @@ mpz_probab_prime_p (const mpz_t n, int reps) =20 for (j =3D 0; is_prime & (j < reps); j++) { - mpz_set_ui (y, (unsigned long) j*j+j+41); + mpz_set_ui (y, (uintptr_t) j*j+j+41); if (mpz_cmp (y, nm1) >=3D 0) { /* Don't try any further bases. This "early" break does not affect diff --git a/libguile/mini-gmp.h b/libguile/mini-gmp.h index d575f7d132..feb53f78eb 100644 --- a/libguile/mini-gmp.h +++ b/libguile/mini-gmp.h @@ -1,6 +1,6 @@ /* mini-gmp, a minimalistic implementation of a GNU GMP subset. =20 -Copyright 2011-2015, 2017, 2019-2020 Free Software Foundation, Inc. +Copyright 2011-2015, 2017, 2019-2021 Free Software Foundation, Inc. =20 This file is part of the GNU MP Library. =20 @@ -53,17 +53,14 @@ void mp_get_memory_functions (void *(**) (size_t), void *(**) (void *, size_t, size_t), void (**) (void *, size_t)); =20 -#ifndef MINI_GMP_LIMB_TYPE -#define MINI_GMP_LIMB_TYPE long -#endif - -typedef unsigned MINI_GMP_LIMB_TYPE mp_limb_t; +typedef uintptr_t mp_limb_t; typedef long mp_size_t; typedef unsigned long mp_bitcnt_t; =20 typedef mp_limb_t *mp_ptr; typedef const mp_limb_t *mp_srcptr; =20 + typedef struct { int _mp_alloc; /* Number of *limbs* allocated and pointed @@ -131,10 +128,10 @@ void mpz_clear (mpz_t); #define mpz_even_p(z) (! mpz_odd_p (z)) =20 int mpz_sgn (const mpz_t); -int mpz_cmp_si (const mpz_t, long); -int mpz_cmp_ui (const mpz_t, unsigned long); +int mpz_cmp_si (const mpz_t, intptr_t); +int mpz_cmp_ui (const mpz_t, uintptr_t); int mpz_cmp (const mpz_t, const mpz_t); -int mpz_cmpabs_ui (const mpz_t, unsigned long); +int mpz_cmpabs_ui (const mpz_t, uintptr_t); int mpz_cmpabs (const mpz_t, const mpz_t); int mpz_cmp_d (const mpz_t, double); int mpz_cmpabs_d (const mpz_t, double); @@ -143,19 +140,19 @@ void mpz_abs (mpz_t, const mpz_t); void mpz_neg (mpz_t, const mpz_t); void mpz_swap (mpz_t, mpz_t); =20 -void mpz_add_ui (mpz_t, const mpz_t, unsigned long); +void mpz_add_ui (mpz_t, const mpz_t, uintptr_t); void mpz_add (mpz_t, const mpz_t, const mpz_t); -void mpz_sub_ui (mpz_t, const mpz_t, unsigned long); -void mpz_ui_sub (mpz_t, unsigned long, const mpz_t); +void mpz_sub_ui (mpz_t, const mpz_t, uintptr_t); +void mpz_ui_sub (mpz_t, uintptr_t, const mpz_t); void mpz_sub (mpz_t, const mpz_t, const mpz_t); =20 -void mpz_mul_si (mpz_t, const mpz_t, long int); -void mpz_mul_ui (mpz_t, const mpz_t, unsigned long int); +void mpz_mul_si (mpz_t, const mpz_t, intptr_t); +void mpz_mul_ui (mpz_t, const mpz_t, uintptr_t); void mpz_mul (mpz_t, const mpz_t, const mpz_t); void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t); -void mpz_addmul_ui (mpz_t, const mpz_t, unsigned long int); +void mpz_addmul_ui (mpz_t, const mpz_t, uintptr_t); void mpz_addmul (mpz_t, const mpz_t, const mpz_t); -void mpz_submul_ui (mpz_t, const mpz_t, unsigned long int); +void mpz_submul_ui (mpz_t, const mpz_t, uintptr_t); void mpz_submul (mpz_t, const mpz_t, const mpz_t); =20 void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t); @@ -182,29 +179,29 @@ void mpz_divexact (mpz_t, const mpz_t, const mpz_t); int mpz_divisible_p (const mpz_t, const mpz_t); int mpz_congruent_p (const mpz_t, const mpz_t, const mpz_t); =20 -unsigned long mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); -unsigned long mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); -unsigned long mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); -unsigned long mpz_cdiv_q_ui (mpz_t, const mpz_t, unsigned long); -unsigned long mpz_fdiv_q_ui (mpz_t, const mpz_t, unsigned long); -unsigned long mpz_tdiv_q_ui (mpz_t, const mpz_t, unsigned long); -unsigned long mpz_cdiv_r_ui (mpz_t, const mpz_t, unsigned long); -unsigned long mpz_fdiv_r_ui (mpz_t, const mpz_t, unsigned long); -unsigned long mpz_tdiv_r_ui (mpz_t, const mpz_t, unsigned long); -unsigned long mpz_cdiv_ui (const mpz_t, unsigned long); -unsigned long mpz_fdiv_ui (const mpz_t, unsigned long); -unsigned long mpz_tdiv_ui (const mpz_t, unsigned long); +uintptr_t mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_cdiv_q_ui (mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_fdiv_q_ui (mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_tdiv_q_ui (mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_cdiv_r_ui (mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_fdiv_r_ui (mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_tdiv_r_ui (mpz_t, const mpz_t, uintptr_t); +uintptr_t mpz_cdiv_ui (const mpz_t, uintptr_t); +uintptr_t mpz_fdiv_ui (const mpz_t, uintptr_t); +uintptr_t mpz_tdiv_ui (const mpz_t, uintptr_t); =20 -unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long); +uintptr_t mpz_mod_ui (mpz_t, const mpz_t, uintptr_t); =20 -void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long); +void mpz_divexact_ui (mpz_t, const mpz_t, uintptr_t); =20 -int mpz_divisible_ui_p (const mpz_t, unsigned long); +int mpz_divisible_ui_p (const mpz_t, uintptr_t); =20 -unsigned long mpz_gcd_ui (mpz_t, const mpz_t, unsigned long); +uintptr_t mpz_gcd_ui (mpz_t, const mpz_t, uintptr_t); void mpz_gcd (mpz_t, const mpz_t, const mpz_t); void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t); -void mpz_lcm_ui (mpz_t, const mpz_t, unsigned long); +void mpz_lcm_ui (mpz_t, const mpz_t, uintptr_t); void mpz_lcm (mpz_t, const mpz_t, const mpz_t); int mpz_invert (mpz_t, const mpz_t, const mpz_t); =20 @@ -212,18 +209,18 @@ void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t); void mpz_sqrt (mpz_t, const mpz_t); int mpz_perfect_square_p (const mpz_t); =20 -void mpz_pow_ui (mpz_t, const mpz_t, unsigned long); -void mpz_ui_pow_ui (mpz_t, unsigned long, unsigned long); +void mpz_pow_ui (mpz_t, const mpz_t, uintptr_t); +void mpz_ui_pow_ui (mpz_t, uintptr_t, uintptr_t); void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t); -void mpz_powm_ui (mpz_t, const mpz_t, unsigned long, const mpz_t); +void mpz_powm_ui (mpz_t, const mpz_t, uintptr_t, const mpz_t); =20 -void mpz_rootrem (mpz_t, mpz_t, const mpz_t, unsigned long); -int mpz_root (mpz_t, const mpz_t, unsigned long); +void mpz_rootrem (mpz_t, mpz_t, const mpz_t, uintptr_t); +int mpz_root (mpz_t, const mpz_t, uintptr_t); =20 -void mpz_fac_ui (mpz_t, unsigned long); -void mpz_2fac_ui (mpz_t, unsigned long); -void mpz_mfac_uiui (mpz_t, unsigned long, unsigned long); -void mpz_bin_uiui (mpz_t, unsigned long, unsigned long); +void mpz_fac_ui (mpz_t, uintptr_t); +void mpz_2fac_ui (mpz_t, uintptr_t); +void mpz_mfac_uiui (mpz_t, uintptr_t, uintptr_t); +void mpz_bin_uiui (mpz_t, uintptr_t, uintptr_t); =20 int mpz_probab_prime_p (const mpz_t, int); =20 @@ -244,8 +241,8 @@ mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t); =20 int mpz_fits_slong_p (const mpz_t); int mpz_fits_ulong_p (const mpz_t); -long int mpz_get_si (const mpz_t); -unsigned long int mpz_get_ui (const mpz_t); +intptr_t mpz_get_si (const mpz_t); +uintptr_t mpz_get_ui (const mpz_t); double mpz_get_d (const mpz_t); size_t mpz_size (const mpz_t); mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t); @@ -259,13 +256,13 @@ mpz_srcptr mpz_roinit_n (mpz_t, mp_srcptr, mp_size_t); =20 #define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }} =20 -void mpz_set_si (mpz_t, signed long int); -void mpz_set_ui (mpz_t, unsigned long int); +void mpz_set_si (mpz_t, intptr_t); +void mpz_set_ui (mpz_t, uintptr_t); void mpz_set (mpz_t, const mpz_t); void mpz_set_d (mpz_t, double); =20 -void mpz_init_set_si (mpz_t, signed long int); -void mpz_init_set_ui (mpz_t, unsigned long int); +void mpz_init_set_si (mpz_t, intptr_t); +void mpz_init_set_ui (mpz_t, uintptr_t); void mpz_init_set (mpz_t, const mpz_t); void mpz_init_set_d (mpz_t, double); =20 diff --git a/libguile/numbers.c b/libguile/numbers.c index 0aa18e59ad..9660785d24 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -88,27 +88,31 @@ /* FIXME: We assume that FLT_RADIX is 2 */ verify (FLT_RADIX =3D=3D 2); =20 -/* Make sure that scm_t_inum fits within a SCM value. */ -verify (sizeof (scm_t_inum) <=3D sizeof (scm_t_bits)); +/* Make sure that intptr_t fits within a SCM value. */ +verify (sizeof (intptr_t) <=3D sizeof (scm_t_bits)); + +#if !(__MINGW32__ && __x86_64__) +#define L1 1L +#else /* (__MINGW32__ && __x86_64__) */ +#define L1 1LL +#endif /* (__MINGW32__ && __x86_64__) */ =20 /* Several functions below assume that fixnums fit within a long, and furthermore that there is some headroom to spare for other operations without overflowing. */ -verify (SCM_I_FIXNUM_BIT <=3D SCM_LONG_BIT - 2); +verify (SCM_I_FIXNUM_BIT <=3D SCM_INTPTR_T_BIT - 2); =20 /* Some functions that use GMP's mpn functions assume that a non-negative fixnum will always fit in a 'mp_limb_t'. */ verify (SCM_MOST_POSITIVE_FIXNUM <=3D (mp_limb_t) -1); =20 -#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 of precision. Note that this will sometimes return 0 even when 1 could have been returned, e.g. for large powers of 2. It is designed to be a fast check to optimize common cases. */ #define INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE(n) \ (SCM_I_FIXNUM_BIT-1 <=3D DBL_MANT_DIG \ - || ((n) ^ ((n) >> (SCM_I_FIXNUM_BIT-1))) < (1L << DBL_MANT_DIG)) + || ((n) ^ ((n) >> (SCM_I_FIXNUM_BIT-1))) < (L1 << DBL_MANT_DIG)) =20 #if (! HAVE_DECL_MPZ_INITS) || SCM_ENABLE_MINI_GMP =20 @@ -299,17 +303,8 @@ scm_i_mkbig () return z; } =20 -static SCM -scm_i_inum2big (scm_t_inum x) -{ - /* Return a newly created bignum initialized to X. */ - SCM z =3D make_bignum (); - mpz_init_set_si (SCM_I_BIG_MPZ (z), x); - return z; -} - SCM -scm_i_long2big (long x) +scm_i_intptr2big (intptr_t x) { /* Return a newly created bignum initialized to X. */ SCM z =3D make_bignum (); @@ -318,7 +313,7 @@ scm_i_long2big (long x) } =20 SCM -scm_i_ulong2big (unsigned long x) +scm_i_untptr2big (uintptr_t x) { /* Return a newly created bignum initialized to X. */ SCM z =3D make_bignum (); @@ -377,7 +372,7 @@ scm_i_dbl2num (double u) =20 if (u < (double) (SCM_MOST_POSITIVE_FIXNUM+1) && u >=3D (double) SCM_MOST_NEGATIVE_FIXNUM) - return SCM_I_MAKINUM ((scm_t_inum) u); + return SCM_I_MAKINUM ((intptr_t) u); else return scm_i_dbl2big (u); } @@ -445,7 +440,7 @@ scm_i_normbig (SCM b) /* presume b is a bignum */ if (mpz_fits_slong_p (SCM_I_BIG_MPZ (b))) { - scm_t_inum val =3D mpz_get_si (SCM_I_BIG_MPZ (b)); + intptr_t val =3D mpz_get_si (SCM_I_BIG_MPZ (b)); if (SCM_FIXABLE (val)) b =3D SCM_I_MAKINUM (val); } @@ -458,7 +453,7 @@ scm_i_mpz2num (mpz_t b) /* convert a mpz number to a SCM number. */ if (mpz_fits_slong_p (b)) { - scm_t_inum val =3D mpz_get_si (b); + intptr_t val =3D mpz_get_si (b); if (SCM_FIXABLE (val)) return SCM_I_MAKINUM (val); } @@ -741,8 +736,8 @@ SCM_PRIMITIVE_GENERIC (scm_odd_p, "odd?", 1, 0, 0, { if (SCM_I_INUMP (n)) { - scm_t_inum val =3D SCM_I_INUM (n); - return scm_from_bool ((val & 1L) !=3D 0); + intptr_t val =3D SCM_I_INUM (n); + return scm_from_bool ((val & L1) !=3D 0); } else if (SCM_BIGP (n)) { @@ -775,8 +770,8 @@ SCM_PRIMITIVE_GENERIC (scm_even_p, "even?", 1, 0, 0, { if (SCM_I_INUMP (n)) { - scm_t_inum val =3D SCM_I_INUM (n); - return scm_from_bool ((val & 1L) =3D=3D 0); + intptr_t val =3D SCM_I_INUM (n); + return scm_from_bool ((val & L1) =3D=3D 0); } else if (SCM_BIGP (n)) { @@ -932,13 +927,13 @@ SCM_PRIMITIVE_GENERIC (scm_abs, "abs", 1, 0, 0, { if (SCM_I_INUMP (x)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (xx >=3D 0) return x; else if (SCM_POSFIXABLE (-xx)) return SCM_I_MAKINUM (-xx); else - return scm_i_inum2big (-xx); + return scm_i_intptr2big (-xx); } else if (SCM_LIKELY (SCM_REALP (x))) { @@ -1044,19 +1039,19 @@ scm_exact_integer_quotient (SCM n, SCM d) { if (SCM_LIKELY (SCM_I_INUMP (n))) { - scm_t_inum nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); if (SCM_LIKELY (SCM_I_INUMP (d))) { - scm_t_inum dd =3D SCM_I_INUM (d); + intptr_t dd =3D SCM_I_INUM (d); if (SCM_UNLIKELY (dd =3D=3D 0)) scm_num_overflow ("exact-integer-quotient"); else { - scm_t_inum qq =3D nn / dd; + intptr_t qq =3D nn / dd; if (SCM_LIKELY (SCM_FIXABLE (qq))) return SCM_I_MAKINUM (qq); else - return scm_i_inum2big (qq); + return scm_i_intptr2big (qq); } } else if (SCM_LIKELY (SCM_BIGP (d))) @@ -1076,7 +1071,7 @@ scm_exact_integer_quotient (SCM n, SCM d) { if (SCM_LIKELY (SCM_I_INUMP (d))) { - scm_t_inum dd =3D SCM_I_INUM (d); + intptr_t dd =3D SCM_I_INUM (d); if (SCM_UNLIKELY (dd =3D=3D 0)) scm_num_overflow ("exact-integer-quotient"); else if (SCM_UNLIKELY (dd =3D=3D 1)) @@ -1228,12 +1223,12 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, "floor-q= uotient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); - scm_t_inum xx1 =3D xx; - scm_t_inum qq; + intptr_t yy =3D SCM_I_INUM (y); + intptr_t xx1 =3D xx; + intptr_t qq; if (SCM_LIKELY (yy > 0)) { if (SCM_UNLIKELY (xx < 0)) @@ -1247,7 +1242,7 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, "floor-quo= tient", 2, 0, 0, if (SCM_LIKELY (SCM_FIXABLE (qq))) return SCM_I_MAKINUM (qq); else - return scm_i_inum2big (qq); + return scm_i_intptr2big (qq); } else if (SCM_BIGP (y)) { @@ -1270,7 +1265,7 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, "floor-quo= tient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_floor_quotient); else if (SCM_UNLIKELY (yy =3D=3D 1)) @@ -1371,15 +1366,15 @@ SCM_PRIMITIVE_GENERIC (scm_floor_remainder, "floor-= remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_floor_remainder); else { - scm_t_inum rr =3D xx % yy; + intptr_t rr =3D xx % yy; int needs_adjustment; =20 if (SCM_LIKELY (yy > 0)) @@ -1430,12 +1425,12 @@ SCM_PRIMITIVE_GENERIC (scm_floor_remainder, "floor-= remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_floor_remainder); else { - scm_t_inum rr; + intptr_t rr; if (yy > 0) rr =3D mpz_fdiv_ui (SCM_I_BIG_MPZ (x), yy); else @@ -1552,16 +1547,16 @@ scm_floor_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_floor_divide); else { - scm_t_inum qq =3D xx / yy; - scm_t_inum rr =3D xx % yy; + intptr_t qq =3D xx / yy; + intptr_t rr =3D xx % yy; int needs_adjustment; =20 if (SCM_LIKELY (yy > 0)) @@ -1578,7 +1573,7 @@ scm_floor_divide (SCM x, SCM y, SCM *qp, SCM *rp) if (SCM_LIKELY (SCM_FIXABLE (qq))) *qp =3D SCM_I_MAKINUM (qq); else - *qp =3D scm_i_inum2big (qq); + *qp =3D scm_i_intptr2big (qq); *rp =3D SCM_I_MAKINUM (rr); } } @@ -1628,7 +1623,7 @@ scm_floor_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_floor_divide); else @@ -1739,16 +1734,16 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_quotient, "ceili= ng-quotient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_ceiling_quotient); else { - scm_t_inum xx1 =3D xx; - scm_t_inum qq; + intptr_t xx1 =3D xx; + intptr_t qq; if (SCM_LIKELY (yy > 0)) { if (SCM_LIKELY (xx >=3D 0)) @@ -1760,7 +1755,7 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_quotient, "ceiling= -quotient", 2, 0, 0, if (SCM_LIKELY (SCM_FIXABLE (qq))) return SCM_I_MAKINUM (qq); else - return scm_i_inum2big (qq); + return scm_i_intptr2big (qq); } } else if (SCM_BIGP (y)) @@ -1799,7 +1794,7 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_quotient, "ceiling= -quotient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_ceiling_quotient); else if (SCM_UNLIKELY (yy =3D=3D 1)) @@ -1900,15 +1895,15 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_remainder, "ceil= ing-remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_ceiling_remainder); else { - scm_t_inum rr =3D xx % yy; + intptr_t rr =3D xx % yy; int needs_adjustment; =20 if (SCM_LIKELY (yy > 0)) @@ -1969,12 +1964,12 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_remainder, "ceil= ing-remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_ceiling_remainder); else { - scm_t_inum rr; + intptr_t rr; if (yy > 0) rr =3D -mpz_cdiv_ui (SCM_I_BIG_MPZ (x), yy); else @@ -2090,16 +2085,16 @@ scm_ceiling_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_ceiling_divide); else { - scm_t_inum qq =3D xx / yy; - scm_t_inum rr =3D xx % yy; + intptr_t qq =3D xx / yy; + intptr_t rr =3D xx % yy; int needs_adjustment; =20 if (SCM_LIKELY (yy > 0)) @@ -2115,7 +2110,7 @@ scm_ceiling_divide (SCM x, SCM y, SCM *qp, SCM *rp) if (SCM_LIKELY (SCM_FIXABLE (qq))) *qp =3D SCM_I_MAKINUM (qq); else - *qp =3D scm_i_inum2big (qq); + *qp =3D scm_i_intptr2big (qq); *rp =3D SCM_I_MAKINUM (rr); } } @@ -2176,7 +2171,7 @@ scm_ceiling_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_ceiling_divide); else @@ -2287,19 +2282,19 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_quotient, "trun= cate-quotient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_truncate_quotient); else { - scm_t_inum qq =3D xx / yy; + intptr_t qq =3D xx / yy; if (SCM_LIKELY (SCM_FIXABLE (qq))) return SCM_I_MAKINUM (qq); else - return scm_i_inum2big (qq); + return scm_i_intptr2big (qq); } } else if (SCM_BIGP (y)) @@ -2327,7 +2322,7 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_quotient, "trunca= te-quotient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_truncate_quotient); else if (SCM_UNLIKELY (yy =3D=3D 1)) @@ -2428,10 +2423,10 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_remainder, "tru= ncate-remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_truncate_remainder); else @@ -2462,12 +2457,12 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_remainder, "tru= ncate-remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_truncate_remainder); else { - scm_t_inum rr =3D (mpz_tdiv_ui (SCM_I_BIG_MPZ (x), + intptr_t rr =3D (mpz_tdiv_ui (SCM_I_BIG_MPZ (x), (yy > 0) ? yy : -yy) * mpz_sgn (SCM_I_BIG_MPZ (x))); scm_remember_upto_here_1 (x); @@ -2581,20 +2576,20 @@ scm_truncate_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_truncate_divide); else { - scm_t_inum qq =3D xx / yy; - scm_t_inum rr =3D xx % yy; + intptr_t qq =3D xx / yy; + intptr_t rr =3D xx % yy; if (SCM_LIKELY (SCM_FIXABLE (qq))) *qp =3D SCM_I_MAKINUM (qq); else - *qp =3D scm_i_inum2big (qq); + *qp =3D scm_i_intptr2big (qq); *rp =3D SCM_I_MAKINUM (rr); } } @@ -2627,13 +2622,13 @@ scm_truncate_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_truncate_divide); else { SCM q =3D scm_i_mkbig (); - scm_t_inum rr; + intptr_t rr; if (yy > 0) rr =3D mpz_tdiv_q_ui (SCM_I_BIG_MPZ (q), SCM_I_BIG_MPZ (x), yy); @@ -2742,16 +2737,16 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "cent= ered-quotient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_centered_quotient); else { - scm_t_inum qq =3D xx / yy; - scm_t_inum rr =3D xx % yy; + intptr_t qq =3D xx / yy; + intptr_t rr =3D xx % yy; if (SCM_LIKELY (xx > 0)) { if (SCM_LIKELY (yy > 0)) @@ -2781,14 +2776,14 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "cent= ered-quotient", 2, 0, 0, if (SCM_LIKELY (SCM_FIXABLE (qq))) return SCM_I_MAKINUM (qq); else - return scm_i_inum2big (qq); + return scm_i_intptr2big (qq); } } else if (SCM_BIGP (y)) { /* Pass a denormalized bignum version of x (even though it can fit in a fixnum) to scm_i_bigint_centered_quotient */ - return scm_i_bigint_centered_quotient (scm_i_long2big (xx), y); + return scm_i_bigint_centered_quotient (scm_i_intptr2big (xx), y); } else if (SCM_REALP (y)) return scm_i_inexact_centered_quotient (xx, SCM_REAL_VALUE (y)); @@ -2802,7 +2797,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "center= ed-quotient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_centered_quotient); else if (SCM_UNLIKELY (yy =3D=3D 1)) @@ -2810,7 +2805,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "center= ed-quotient", 2, 0, 0, else { SCM q =3D scm_i_mkbig (); - scm_t_inum rr; + intptr_t rr; /* Arrange for rr to initially be non-positive, because that simplifies the test to see if it is within the needed bounds. */ @@ -2960,15 +2955,15 @@ SCM_PRIMITIVE_GENERIC (scm_centered_remainder, "cen= tered-remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_centered_remainder); else { - scm_t_inum rr =3D xx % yy; + intptr_t rr =3D xx % yy; if (SCM_LIKELY (xx > 0)) { if (SCM_LIKELY (yy > 0)) @@ -3002,7 +2997,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_remainder, "cente= red-remainder", 2, 0, 0, { /* Pass a denormalized bignum version of x (even though it can fit in a fixnum) to scm_i_bigint_centered_remainder */ - return scm_i_bigint_centered_remainder (scm_i_long2big (xx), y); + return scm_i_bigint_centered_remainder (scm_i_intptr2big (xx), y); } else if (SCM_REALP (y)) return scm_i_inexact_centered_remainder (xx, SCM_REAL_VALUE (y)); @@ -3016,12 +3011,12 @@ SCM_PRIMITIVE_GENERIC (scm_centered_remainder, "cen= tered-remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_centered_remainder); else { - scm_t_inum rr; + intptr_t rr; /* Arrange for rr to initially be non-positive, because that simplifies the test to see if it is within the needed bounds. */ @@ -3192,16 +3187,16 @@ scm_centered_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_centered_divide); else { - scm_t_inum qq =3D xx / yy; - scm_t_inum rr =3D xx % yy; + intptr_t qq =3D xx / yy; + intptr_t rr =3D xx % yy; if (SCM_LIKELY (xx > 0)) { if (SCM_LIKELY (yy > 0)) @@ -3231,14 +3226,14 @@ scm_centered_divide (SCM x, SCM y, SCM *qp, SCM *rp) if (SCM_LIKELY (SCM_FIXABLE (qq))) *qp =3D SCM_I_MAKINUM (qq); else - *qp =3D scm_i_inum2big (qq); + *qp =3D scm_i_intptr2big (qq); *rp =3D SCM_I_MAKINUM (rr); } } else if (SCM_BIGP (y)) /* Pass a denormalized bignum version of x (even though it can fit in a fixnum) to scm_i_bigint_centered_divide */ - scm_i_bigint_centered_divide (scm_i_long2big (xx), y, qp, rp); + scm_i_bigint_centered_divide (scm_i_intptr2big (xx), y, qp, rp); else if (SCM_REALP (y)) scm_i_inexact_centered_divide (xx, SCM_REAL_VALUE (y), qp, rp); else if (SCM_FRACTIONP (y)) @@ -3251,13 +3246,13 @@ scm_centered_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_centered_divide); else { SCM q =3D scm_i_mkbig (); - scm_t_inum rr; + intptr_t rr; /* Arrange for rr to initially be non-positive, because that simplifies the test to see if it is within the needed bounds. */ @@ -3433,18 +3428,18 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-q= uotient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_round_quotient); else { - scm_t_inum qq =3D xx / yy; - scm_t_inum rr =3D xx % yy; - scm_t_inum ay =3D yy; - scm_t_inum r2 =3D 2 * rr; + intptr_t qq =3D xx / yy; + intptr_t rr =3D xx % yy; + intptr_t ay =3D yy; + intptr_t r2 =3D 2 * rr; =20 if (SCM_LIKELY (yy < 0)) { @@ -3452,7 +3447,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quo= tient", 2, 0, 0, r2 =3D -r2; } =20 - if (qq & 1L) + if (qq & L1) { if (r2 >=3D ay) qq++; @@ -3469,14 +3464,14 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-q= uotient", 2, 0, 0, if (SCM_LIKELY (SCM_FIXABLE (qq))) return SCM_I_MAKINUM (qq); else - return scm_i_inum2big (qq); + return scm_i_intptr2big (qq); } } else if (SCM_BIGP (y)) { /* Pass a denormalized bignum version of x (even though it can fit in a fixnum) to scm_i_bigint_round_quotient */ - return scm_i_bigint_round_quotient (scm_i_long2big (xx), y); + return scm_i_bigint_round_quotient (scm_i_intptr2big (xx), y); } else if (SCM_REALP (y)) return scm_i_inexact_round_quotient (xx, SCM_REAL_VALUE (y)); @@ -3490,7 +3485,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quo= tient", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_round_quotient); else if (SCM_UNLIKELY (yy =3D=3D 1)) @@ -3498,7 +3493,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quo= tient", 2, 0, 0, else { SCM q =3D scm_i_mkbig (); - scm_t_inum rr; + intptr_t rr; int needs_adjustment; =20 if (yy > 0) @@ -3639,18 +3634,18 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-= remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_round_remainder); else { - scm_t_inum qq =3D xx / yy; - scm_t_inum rr =3D xx % yy; - scm_t_inum ay =3D yy; - scm_t_inum r2 =3D 2 * rr; + intptr_t qq =3D xx / yy; + intptr_t rr =3D xx % yy; + intptr_t ay =3D yy; + intptr_t r2 =3D 2 * rr; =20 if (SCM_LIKELY (yy < 0)) { @@ -3658,7 +3653,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-re= mainder", 2, 0, 0, r2 =3D -r2; } =20 - if (qq & 1L) + if (qq & L1) { if (r2 >=3D ay) rr -=3D yy; @@ -3680,7 +3675,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-re= mainder", 2, 0, 0, /* Pass a denormalized bignum version of x (even though it can fit in a fixnum) to scm_i_bigint_round_remainder */ return scm_i_bigint_round_remainder - (scm_i_long2big (xx), y); + (scm_i_intptr2big (xx), y); } else if (SCM_REALP (y)) return scm_i_inexact_round_remainder (xx, SCM_REAL_VALUE (y)); @@ -3694,13 +3689,13 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-= remainder", 2, 0, 0, { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_round_remainder); else { SCM q =3D scm_i_mkbig (); - scm_t_inum rr; + intptr_t rr; int needs_adjustment; =20 if (yy > 0) @@ -3867,18 +3862,18 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_round_divide); else { - scm_t_inum qq =3D xx / yy; - scm_t_inum rr =3D xx % yy; - scm_t_inum ay =3D yy; - scm_t_inum r2 =3D 2 * rr; + intptr_t qq =3D xx / yy; + intptr_t rr =3D xx % yy; + intptr_t ay =3D yy; + intptr_t r2 =3D 2 * rr; =20 if (SCM_LIKELY (yy < 0)) { @@ -3886,7 +3881,7 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp) r2 =3D -r2; } =20 - if (qq & 1L) + if (qq & L1) { if (r2 >=3D ay) { qq++; rr -=3D yy; } @@ -3903,14 +3898,14 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp) if (SCM_LIKELY (SCM_FIXABLE (qq))) *qp =3D SCM_I_MAKINUM (qq); else - *qp =3D scm_i_inum2big (qq); + *qp =3D scm_i_intptr2big (qq); *rp =3D SCM_I_MAKINUM (rr); } } else if (SCM_BIGP (y)) /* Pass a denormalized bignum version of x (even though it can fit in a fixnum) to scm_i_bigint_round_divide */ - scm_i_bigint_round_divide (scm_i_long2big (SCM_I_INUM (x)), y, qp,= rp); + scm_i_bigint_round_divide (scm_i_intptr2big (SCM_I_INUM (x)), y, q= p, rp); else if (SCM_REALP (y)) scm_i_inexact_round_divide (xx, SCM_REAL_VALUE (y), qp, rp); else if (SCM_FRACTIONP (y)) @@ -3923,13 +3918,13 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp) { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (SCM_UNLIKELY (yy =3D=3D 0)) scm_num_overflow (s_scm_round_divide); else { SCM q =3D scm_i_mkbig (); - scm_t_inum rr; + intptr_t rr; int needs_adjustment; =20 if (yy > 0) @@ -4090,11 +4085,11 @@ scm_gcd (SCM x, SCM y) { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum xx =3D SCM_I_INUM (x); - scm_t_inum yy =3D SCM_I_INUM (y); - scm_t_inum u =3D xx < 0 ? -xx : xx; - scm_t_inum v =3D yy < 0 ? -yy : yy; - scm_t_inum result; + intptr_t xx =3D SCM_I_INUM (x); + intptr_t yy =3D SCM_I_INUM (y); + intptr_t u =3D xx < 0 ? -xx : xx; + intptr_t v =3D yy < 0 ? -yy : yy; + intptr_t result; if (SCM_UNLIKELY (xx =3D=3D 0)) result =3D v; else if (SCM_UNLIKELY (yy =3D=3D 0)) @@ -4138,7 +4133,7 @@ scm_gcd (SCM x, SCM y) } return (SCM_POSFIXABLE (result) ? SCM_I_MAKINUM (result) - : scm_i_inum2big (result)); + : scm_i_intptr2big (result)); } else if (SCM_BIGP (y)) { @@ -4155,7 +4150,7 @@ scm_gcd (SCM x, SCM y) if (SCM_I_INUMP (y)) { scm_t_bits result; - scm_t_inum yy; + intptr_t yy; big_inum: yy =3D SCM_I_INUM (y); if (yy =3D=3D 0) @@ -4238,7 +4233,7 @@ scm_lcm (SCM n1, SCM n2) inumbig: { SCM result =3D scm_i_mkbig (); - scm_t_inum nn1 =3D SCM_I_INUM (n1); + intptr_t nn1 =3D SCM_I_INUM (n1); if (nn1 =3D=3D 0) return SCM_INUM0; if (nn1 < 0) nn1 =3D - nn1; mpz_lcm_ui (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (n2), nn1); @@ -4350,7 +4345,7 @@ SCM_DEFINE (scm_i_logand, "logand", 0, 2, 1, SCM scm_logand (SCM n1, SCM n2) #define FUNC_NAME s_scm_logand { - scm_t_inum nn1; + intptr_t nn1; =20 if (SCM_UNBNDP (n2)) { @@ -4369,7 +4364,7 @@ SCM scm_logand (SCM n1, SCM n2) nn1 =3D SCM_I_INUM (n1); if (SCM_I_INUMP (n2)) { - scm_t_inum nn2 =3D SCM_I_INUM (n2); + intptr_t nn2 =3D SCM_I_INUM (n2); return SCM_I_MAKINUM (nn1 & nn2); } else if SCM_BIGP (n2) @@ -4440,7 +4435,7 @@ SCM_DEFINE (scm_i_logior, "logior", 0, 2, 1, SCM scm_logior (SCM n1, SCM n2) #define FUNC_NAME s_scm_logior { - scm_t_inum nn1; + intptr_t nn1; =20 if (SCM_UNBNDP (n2)) { @@ -4457,7 +4452,7 @@ SCM scm_logior (SCM n1, SCM n2) nn1 =3D SCM_I_INUM (n1); if (SCM_I_INUMP (n2)) { - long nn2 =3D SCM_I_INUM (n2); + intptr_t nn2 =3D SCM_I_INUM (n2); return SCM_I_MAKINUM (nn1 | nn2); } else if (SCM_BIGP (n2)) @@ -4530,7 +4525,7 @@ SCM_DEFINE (scm_i_logxor, "logxor", 0, 2, 1, SCM scm_logxor (SCM n1, SCM n2) #define FUNC_NAME s_scm_logxor { - scm_t_inum nn1; + intptr_t nn1; =20 if (SCM_UNBNDP (n2)) { @@ -4547,7 +4542,7 @@ SCM scm_logxor (SCM n1, SCM n2) nn1 =3D SCM_I_INUM (n1); if (SCM_I_INUMP (n2)) { - scm_t_inum nn2 =3D SCM_I_INUM (n2); + intptr_t nn2 =3D SCM_I_INUM (n2); return SCM_I_MAKINUM (nn1 ^ nn2); } else if (SCM_BIGP (n2)) @@ -4605,14 +4600,14 @@ SCM_DEFINE (scm_logtest, "logtest", 2, 0, 0, "@end lisp") #define FUNC_NAME s_scm_logtest { - scm_t_inum nj; + intptr_t nj; =20 if (SCM_I_INUMP (j)) { nj =3D SCM_I_INUM (j); if (SCM_I_INUMP (k)) { - scm_t_inum nk =3D SCM_I_INUM (k); + intptr_t nk =3D SCM_I_INUM (k); return scm_from_bool (nj & nk); } else if (SCM_BIGP (k)) @@ -4683,7 +4678,7 @@ SCM_DEFINE (scm_logbit_p, "logbit?", 2, 0, 0, =20 if (SCM_I_INUMP (j)) { - if (iindex < SCM_LONG_BIT - 1) + if (iindex < SCM_INTPTR_T_BIT - 1) /* Arrange for the number to be converted to unsigned before checking the bit, to ensure that we're testing the bit in a two's complement representation (regardless of the native @@ -4873,10 +4868,10 @@ SCM_DEFINE (scm_integer_expt, "integer-expt", 2, 0,= 0, "@end lisp") #define FUNC_NAME s_scm_integer_expt { - scm_t_inum i2 =3D 0; + intptr_t i2 =3D 0; SCM z_i2 =3D SCM_BOOL_F; int i2_is_big =3D 0; - SCM acc =3D SCM_I_MAKINUM (1L); + SCM acc =3D SCM_I_MAKINUM (L1); =20 /* Specifically refrain from checking the type of the first argument. This allows us to exponentiate any object that can be multiplied. @@ -4887,7 +4882,7 @@ SCM_DEFINE (scm_integer_expt, "integer-expt", 2, 0, 0, =20 if (SCM_UNLIKELY (scm_is_eq (k, SCM_INUM0))) return SCM_INUM1; /* n^(exact0) is exact 1, regardless of n */ - else if (SCM_UNLIKELY (scm_is_eq (n, SCM_I_MAKINUM (-1L)))) + else if (SCM_UNLIKELY (scm_is_eq (n, SCM_I_MAKINUM (-L1)))) return scm_is_false (scm_even_p (k)) ? n : SCM_INUM1; /* The next check is necessary only because R6RS specifies different behavior for 0^(-k) than for (/ 0). If n is not a scheme number, @@ -4985,7 +4980,7 @@ left_shift_exact_integer (SCM n, long count) { if (SCM_I_INUMP (n)) { - scm_t_inum nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); =20 /* Left shift of count >=3D SCM_I_FIXNUM_BIT-1 will almost[*] always overflow a non-zero fixnum. For smaller shifts we check the @@ -5004,7 +4999,7 @@ left_shift_exact_integer (SCM n, long count) return SCM_I_MAKINUM (nn < 0 ? -(-nn << count) : (nn << count)); else { - SCM result =3D scm_i_inum2big (nn); + SCM result =3D scm_i_intptr2big (nn); mpz_mul_2exp (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (result), count); return scm_i_normbig (result); @@ -5028,7 +5023,7 @@ floor_right_shift_exact_integer (SCM n, long count) { if (SCM_I_INUMP (n)) { - scm_t_inum nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); =20 if (count >=3D SCM_I_FIXNUM_BIT) return (nn >=3D 0 ? SCM_INUM0 : SCM_I_MAKINUM (-1)); @@ -5058,15 +5053,15 @@ round_right_shift_exact_integer (SCM n, long count) return SCM_INUM0; else { - scm_t_inum nn =3D SCM_I_INUM (n); - scm_t_inum qq =3D SCM_SRS (nn, count); + intptr_t nn =3D SCM_I_INUM (n); + intptr_t qq =3D SCM_SRS (nn, count); =20 - if (0 =3D=3D (nn & (1L << (count-1)))) + if (0 =3D=3D (nn & (L1 << (count-1)))) return SCM_I_MAKINUM (qq); /* round down */ - else if (nn & ((1L << (count-1)) - 1)) + else if (nn & ((L1 << (count-1)) - 1)) return SCM_I_MAKINUM (qq + 1); /* round up */ else - return SCM_I_MAKINUM ((~1L) & (qq + 1)); /* round to even */ + return SCM_I_MAKINUM ((~L1) & (qq + 1)); /* round to even */ } } else if (SCM_BIGP (n)) @@ -5087,8 +5082,8 @@ round_right_shift_exact_integer (SCM n, long count) =20 /* 'scm_ash' and 'scm_round_ash' assume that fixnums fit within a long, and moreover that they can be negated without overflow. */ -verify (SCM_MOST_NEGATIVE_FIXNUM >=3D LONG_MIN + 1 - && SCM_MOST_POSITIVE_FIXNUM <=3D LONG_MAX); +verify (SCM_MOST_NEGATIVE_FIXNUM >=3D INTPTR_MIN + 1 + && SCM_MOST_POSITIVE_FIXNUM <=3D INTPTR_MAX); =20 SCM_DEFINE (scm_ash, "ash", 2, 0, 0, (SCM n, SCM count), @@ -5221,7 +5216,7 @@ SCM_DEFINE (scm_bit_extract, "bit-extract", 3, 0, 0, =20 if (SCM_I_INUMP (n)) { - scm_t_inum in =3D SCM_I_INUM (n); + intptr_t in =3D SCM_I_INUM (n); =20 /* When istart>=3DSCM_I_FIXNUM_BIT we can just limit the shift to SCM_I_FIXNUM_BIT-1 to get either 0 or -1 per the sign of "in". */ @@ -5233,7 +5228,7 @@ SCM_DEFINE (scm_bit_extract, "bit-extract", 3, 0, 0, * special case requires us to produce a result that has * more bits than can be stored in a fixnum. */ - SCM result =3D scm_i_inum2big (in); + SCM result =3D scm_i_intptr2big (in); mpz_fdiv_r_2exp (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (result), bits); return result; @@ -5241,7 +5236,7 @@ SCM_DEFINE (scm_bit_extract, "bit-extract", 3, 0, 0, =20 /* mask down to requisite bits */ bits =3D MIN (bits, SCM_I_FIXNUM_BIT); - return SCM_I_MAKINUM (in & ((1L << bits) - 1)); + return SCM_I_MAKINUM (in & ((L1 << bits) - 1)); } else if (SCM_BIGP (n)) { @@ -5293,7 +5288,7 @@ SCM_DEFINE (scm_logcount, "logcount", 1, 0, 0, if (SCM_I_INUMP (n)) { unsigned long c =3D 0; - scm_t_inum nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); if (nn < 0) nn =3D -1 - nn; while (nn) @@ -5342,7 +5337,7 @@ SCM_DEFINE (scm_integer_length, "integer-length", 1, = 0, 0, { unsigned long c =3D 0; unsigned int l =3D 4; - scm_t_inum nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); if (nn < 0) nn =3D -1 - nn; while (nn) @@ -6847,10 +6842,10 @@ scm_less_p (SCM x, SCM y) again: if (SCM_I_INUMP (x)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_I_INUMP (y)) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); return scm_from_bool (xx < yy); } else if (SCM_BIGP (y)) @@ -6877,7 +6872,7 @@ scm_less_p (SCM x, SCM y) return SCM_BOOL_F; else /* yy is a finite integer that fits in an inum. */ - return scm_from_bool (xx < (scm_t_inum) yy); + return scm_from_bool (xx < (intptr_t) yy); } else if (SCM_FRACTIONP (y)) { @@ -6940,7 +6935,7 @@ scm_less_p (SCM x, SCM y) return SCM_BOOL_F; else /* xx is a finite integer that fits in an inum. */ - return scm_from_bool ((scm_t_inum) xx < SCM_I_INUM (y)); + return scm_from_bool ((intptr_t) xx < SCM_I_INUM (y)); } else if (SCM_BIGP (y)) { @@ -7222,10 +7217,10 @@ scm_max (SCM x, SCM y) =20=20=20 if (SCM_I_INUMP (x)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_I_INUMP (y)) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); return (xx < yy) ? y : x; } else if (SCM_BIGP (y)) @@ -7292,7 +7287,7 @@ scm_max (SCM x, SCM y) { if (SCM_I_INUMP (y)) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); double xxd =3D SCM_REAL_VALUE (x); double yyd =3D yy; =20 @@ -7402,10 +7397,10 @@ scm_min (SCM x, SCM y) =20=20=20 if (SCM_I_INUMP (x)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_I_INUMP (y)) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); return (xx < yy) ? x : y; } else if (SCM_BIGP (y)) @@ -7561,10 +7556,10 @@ scm_sum (SCM x, SCM y) { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum xx =3D SCM_I_INUM (x); - scm_t_inum yy =3D SCM_I_INUM (y); - scm_t_inum z =3D xx + yy; - return SCM_FIXABLE (z) ? SCM_I_MAKINUM (z) : scm_i_inum2big (z); + intptr_t xx =3D SCM_I_INUM (x); + intptr_t yy =3D SCM_I_INUM (y); + intptr_t z =3D xx + yy; + return SCM_FIXABLE (z) ? SCM_I_MAKINUM (z) : scm_i_intptr2big (z= ); } else if (SCM_BIGP (y)) { @@ -7573,12 +7568,12 @@ scm_sum (SCM x, SCM y) } else if (SCM_REALP (y)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); return scm_i_from_double (xx + SCM_REAL_VALUE (y)); } else if (SCM_COMPLEXP (y)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); return scm_c_make_rectangular (xx + SCM_COMPLEX_REAL (y), SCM_COMPLEX_IMAG (y)); } @@ -7593,7 +7588,7 @@ scm_sum (SCM x, SCM y) { if (SCM_I_INUMP (y)) { - scm_t_inum inum; + intptr_t inum; int bigsgn; add_big_inum: inum =3D SCM_I_INUM (y);=20=20=20=20=20=20 @@ -7767,11 +7762,11 @@ scm_difference (SCM x, SCM y) else=20 if (SCM_I_INUMP (x)) { - scm_t_inum xx =3D -SCM_I_INUM (x); + intptr_t xx =3D -SCM_I_INUM (x); if (SCM_FIXABLE (xx)) return SCM_I_MAKINUM (xx); else - return scm_i_inum2big (xx); + return scm_i_intptr2big (xx); } else if (SCM_BIGP (x)) /* Must scm_i_normbig here because -SCM_MOST_NEGATIVE_FIXNUM is a @@ -7794,18 +7789,18 @@ scm_difference (SCM x, SCM y) { if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum xx =3D SCM_I_INUM (x); - scm_t_inum yy =3D SCM_I_INUM (y); - scm_t_inum z =3D xx - yy; + intptr_t xx =3D SCM_I_INUM (x); + intptr_t yy =3D SCM_I_INUM (y); + intptr_t z =3D xx - yy; if (SCM_FIXABLE (z)) return SCM_I_MAKINUM (z); else - return scm_i_inum2big (z); + return scm_i_intptr2big (z); } else if (SCM_BIGP (y)) { /* inum-x - big-y */ - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); =20 if (xx =3D=3D 0) { @@ -7837,7 +7832,7 @@ scm_difference (SCM x, SCM y) } else if (SCM_REALP (y)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); =20 /* * We need to handle x =3D=3D exact 0 @@ -7857,7 +7852,7 @@ scm_difference (SCM x, SCM y) } else if (SCM_COMPLEXP (y)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); =20 /* We need to handle x =3D=3D exact 0 specially. See the comment above (for SCM_REALP (y)) */ @@ -7881,13 +7876,13 @@ scm_difference (SCM x, SCM y) if (SCM_I_INUMP (y)) { /* big-x - inum-y */ - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); int sgn_x =3D mpz_sgn (SCM_I_BIG_MPZ (x)); =20 scm_remember_upto_here_1 (x); if (sgn_x =3D=3D 0) return (SCM_FIXABLE (-yy) ? - SCM_I_MAKINUM (-yy) : scm_from_inum (-yy)); + SCM_I_MAKINUM (-yy) : scm_from_intptr (-yy)); else { SCM result =3D scm_i_mkbig (); @@ -8049,7 +8044,7 @@ scm_product (SCM x, SCM y) if (SCM_UNLIKELY (SCM_UNBNDP (y))) { if (SCM_UNBNDP (x)) - return SCM_I_MAKINUM (1L); + return SCM_I_MAKINUM (L1); else if (SCM_NUMBERP (x)) return x; else @@ -8058,7 +8053,7 @@ scm_product (SCM x, SCM y) =20=20=20 if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx; + intptr_t xx; =20 xinum: xx =3D SCM_I_INUM (x); @@ -8092,20 +8087,20 @@ scm_product (SCM x, SCM y) =20 if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); #if SCM_I_FIXNUM_BIT < 32 && SCM_HAVE_T_INT64 int64_t kk =3D xx * (int64_t) yy; if (SCM_FIXABLE (kk)) return SCM_I_MAKINUM (kk); #else - scm_t_inum axx =3D (xx > 0) ? xx : -xx; - scm_t_inum ayy =3D (yy > 0) ? yy : -yy; + intptr_t axx =3D (xx > 0) ? xx : -xx; + intptr_t ayy =3D (yy > 0) ? yy : -yy; if (SCM_MOST_POSITIVE_FIXNUM / axx >=3D ayy) return SCM_I_MAKINUM (xx * yy); #endif else { - SCM result =3D scm_i_inum2big (xx); + SCM result =3D scm_i_intptr2big (xx); mpz_mul_si (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (result), yy); return scm_i_normbig (result); } @@ -8321,7 +8316,7 @@ scm_divide (SCM x, SCM y) return scm_wta_dispatch_0 (g_divide, s_divide); else if (SCM_I_INUMP (x)) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (xx =3D=3D 1 || xx =3D=3D -1) return x; #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO @@ -8369,10 +8364,10 @@ scm_divide (SCM x, SCM y) =20 if (SCM_LIKELY (SCM_I_INUMP (x))) { - scm_t_inum xx =3D SCM_I_INUM (x); + intptr_t xx =3D SCM_I_INUM (x); if (SCM_LIKELY (SCM_I_INUMP (y))) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (yy =3D=3D 0) { #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO @@ -8385,11 +8380,11 @@ scm_divide (SCM x, SCM y) return scm_i_make_ratio (x, y); else { - scm_t_inum z =3D xx / yy; + intptr_t z =3D xx / yy; if (SCM_FIXABLE (z)) return SCM_I_MAKINUM (z); else - return scm_i_inum2big (z); + return scm_i_intptr2big (z); } } else if (SCM_BIGP (y)) @@ -8403,7 +8398,7 @@ scm_divide (SCM x, SCM y) else #endif /* FIXME: Precision may be lost here due to: - (1) The cast from 'scm_t_inum' to 'double' + (1) The cast from 'intptr_t' to 'double' (2) Double rounding */ return scm_i_from_double ((double) xx / yy); } @@ -8439,7 +8434,7 @@ scm_divide (SCM x, SCM y) { if (SCM_I_INUMP (y)) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); if (yy =3D=3D 0) { #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO @@ -8462,7 +8457,7 @@ scm_divide (SCM x, SCM y) middle ground: test, then if divisible, use the faster div func. */ =20 - scm_t_inum abs_yy =3D yy < 0 ? -yy : yy; + intptr_t abs_yy =3D yy < 0 ? -yy : yy; int divisible_p =3D mpz_divisible_ui_p (SCM_I_BIG_MPZ (x), abs_yy); =20 if (divisible_p) @@ -8522,14 +8517,14 @@ scm_divide (SCM x, SCM y) double rx =3D SCM_REAL_VALUE (x); if (SCM_I_INUMP (y)) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO if (yy =3D=3D 0) scm_num_overflow (s_divide); else #endif /* FIXME: Precision may be lost here due to: - (1) The cast from 'scm_t_inum' to 'double' + (1) The cast from 'intptr_t' to 'double' (2) Double rounding */ return scm_i_from_double (rx / (double) yy); } @@ -8568,7 +8563,7 @@ scm_divide (SCM x, SCM y) double ix =3D SCM_COMPLEX_IMAG (x); if (SCM_I_INUMP (y)) { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO if (yy =3D=3D 0) scm_num_overflow (s_divide); @@ -8576,7 +8571,7 @@ scm_divide (SCM x, SCM y) #endif { /* FIXME: Precision may be lost here due to: - (1) The conversion from 'scm_t_inum' to double + (1) The conversion from 'intptr_t' to double (2) Double rounding */ double d =3D yy; return scm_c_make_rectangular (rx / d, ix / d); @@ -8633,7 +8628,7 @@ scm_divide (SCM x, SCM y) { if (SCM_I_INUMP (y))=20 { - scm_t_inum yy =3D SCM_I_INUM (y); + intptr_t yy =3D SCM_I_INUM (y); #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO if (yy =3D=3D 0) scm_num_overflow (s_divide); @@ -9307,13 +9302,13 @@ SCM_PRIMITIVE_GENERIC (scm_magnitude, "magnitude", = 1, 0, 0, { if (SCM_I_INUMP (z)) { - scm_t_inum zz =3D SCM_I_INUM (z); + intptr_t zz =3D SCM_I_INUM (z); if (zz >=3D 0) return z; else if (SCM_POSFIXABLE (-zz)) return SCM_I_MAKINUM (-zz); else - return scm_i_inum2big (-zz); + return scm_i_intptr2big (-zz); } else if (SCM_BIGP (z)) { @@ -9700,7 +9695,7 @@ scm_is_signed_integer (SCM val, intmax_t min, intmax_= t max) { if (mpz_fits_slong_p (SCM_I_BIG_MPZ (val))) { - long n =3D mpz_get_si (SCM_I_BIG_MPZ (val)); + intptr_t n =3D mpz_get_si (SCM_I_BIG_MPZ (val)); return n >=3D min && n <=3D max; } else @@ -9758,7 +9753,7 @@ scm_is_unsigned_integer (SCM val, uintmax_t min, uint= max_t max) { if (mpz_fits_ulong_p (SCM_I_BIG_MPZ (val))) { - unsigned long n =3D mpz_get_ui (SCM_I_BIG_MPZ (val)); + uintptr_t n =3D mpz_get_ui (SCM_I_BIG_MPZ (val)); return n >=3D min && n <=3D max; } else @@ -10302,19 +10297,19 @@ SCM_PRIMITIVE_GENERIC (scm_sqrt, "sqrt", 1, 0, 0, { if (SCM_I_INUMP (z)) { - scm_t_inum x =3D SCM_I_INUM (z); + intptr_t x =3D SCM_I_INUM (z); =20 if (SCM_LIKELY (x >=3D 0)) { if (SCM_LIKELY (SCM_I_FIXNUM_BIT < DBL_MANT_DIG - || x < (1L << (DBL_MANT_DIG - 1)))) + || x < (L1 << (DBL_MANT_DIG - 1)))) { double root =3D sqrt (x); =20 /* If 0 <=3D x < 2^(DBL_MANT_DIG-1) and sqrt(x) is an integer, then the result is exact. */ if (root =3D=3D floor (root)) - return SCM_I_MAKINUM ((scm_t_inum) root); + return SCM_I_MAKINUM ((intptr_t) root); else return scm_i_from_double (root); } diff --git a/libguile/numbers.h b/libguile/numbers.h index df5c9110c1..a0b2790bda 100644 --- a/libguile/numbers.h +++ b/libguile/numbers.h @@ -54,10 +54,17 @@ extern "C++" { * (along with two tagging bits). * * In the current implementation, Inums must also fit within a long - * because that's what GMP's mpz_*_si functions accept. */ -typedef long scm_t_inum; -#define SCM_I_FIXNUM_BIT (SCM_LONG_BIT - 2) + * because that's what GMP's mpz_*_si functions accept. + * + * When using mini-gmp on x86_64-mingw, we use long long instead. + */ + +#define SCM_I_FIXNUM_BIT (SCM_INTPTR_T_BIT - 2) +#if !(__MINGW32__ && __x86_64__) #define SCM_MOST_NEGATIVE_FIXNUM (-1L << (SCM_I_FIXNUM_BIT - 1)) +#else /* __MINGW32__ && __x86_64__ */ +#define SCM_MOST_NEGATIVE_FIXNUM (-1LL << (SCM_I_FIXNUM_BIT - 1)) +#endif /* __MINGW32__ && __x86_64__ */ #define SCM_MOST_POSITIVE_FIXNUM (- (SCM_MOST_NEGATIVE_FIXNUM + 1)) =20 /* SCM_SRS (X, Y) is signed right shift, defined as floor (X / 2^Y), @@ -85,12 +92,12 @@ typedef long scm_t_inum; =20 NOTE: X must not perform side effects. */ #ifdef __GNUC__ -# define SCM_I_INUM(x) (SCM_SRS ((scm_t_inum) SCM_UNPACK (x), 2)) +# define SCM_I_INUM(x) (SCM_SRS ((intptr_t) SCM_UNPACK (x), 2)) #else # define SCM_I_INUM(x) \ (SCM_UNPACK (x) > SCM_T_SIGNED_BITS_MAX \ - ? -1 - (scm_t_inum) (~SCM_UNPACK (x) >> 2) \ - : (scm_t_inum) (SCM_UNPACK (x) >> 2)) + ? -1 - (intptr_t) (~SCM_UNPACK (x) >> 2) \ + : (intptr_t) (SCM_UNPACK (x) >> 2)) #endif =20 #define SCM_I_INUMP(x) (2 & SCM_UNPACK (x)) @@ -357,6 +364,21 @@ SCM_API /* FIXME: not internal */ SCM scm_i_long2big (= long n); SCM_API /* FIXME: not internal */ SCM scm_i_ulong2big (unsigned long n); SCM_API /* FIXME: not internal */ SCM scm_i_clonebig (SCM src_big, int sam= e_sign_p); =20 +SCM scm_i_intptr2big (intptr_t x); +SCM scm_i_untptr2big (uintptr_t x); + +#if SIZEOF_INTPTR =3D=3D 4 +#define scm_from_intptr scm_from_int32 +#define scm_from_uintptr scm_from_uint32 +#define scm_to_intptr scm_to_int32 +#define scm_to_uintptr scm_to_uint32 +#else +#define scm_from_intptr scm_from_int64 +#define scm_from_uintptr scm_from_uint64 +#define scm_to_intptr scm_to_int64 +#define scm_to_uintptr scm_to_uint64 +#endif + /* ratio functions */ SCM_API SCM scm_rationalize (SCM x, SCM err); SCM_API SCM scm_numerator (SCM z); diff --git a/libguile/scm.h b/libguile/scm.h index e69552893b..7ffc85c53d 100644 --- a/libguile/scm.h +++ b/libguile/scm.h @@ -837,10 +837,8 @@ typedef struct scm_thread scm_thread; # define SCM_CHAR_BIT 8 #endif =20 -#ifdef LONG_BIT -# define SCM_LONG_BIT LONG_BIT -#else -# define SCM_LONG_BIT (SCM_SIZEOF_LONG * 8) +#ifndef INTPTR_T_BIT +# define SCM_INTPTR_T_BIT (SCM_SIZEOF_INTPTR_T * 8) #endif =20 diff --git a/libguile/scmsigs.c b/libguile/scmsigs.c index c234c015a5..562871d499 100644 --- a/libguile/scmsigs.c +++ b/libguile/scmsigs.c @@ -1,4 +1,4 @@ -/* Copyright 1995-2002,2004,2006-2009,2011,2013-2014,2017-2018 +/* Copyright 1995-2002,2004,2006-2009,2011,2013-2014,2017-2018,2021 Free Software Foundation, Inc. =20 This file is part of Guile. @@ -414,9 +414,9 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3= , 0, query_only =3D 1; else if (scm_is_integer (handler)) { - long handler_int =3D scm_to_long (handler); + intptr_t handler_int =3D scm_to_intptr (handler); =20 - if (handler_int =3D=3D (long) SIG_DFL || handler_int =3D=3D (long) S= IG_IGN) + if (handler_int =3D=3D (intptr_t) SIG_DFL || handler_int =3D=3D (int= ptr_t) SIG_IGN) { #ifdef HAVE_SIGACTION action.sa_handler =3D (SIGRETTYPE (*) (int)) handler_int; @@ -512,7 +512,7 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3= , 0, orig_handlers[csig] =3D old_action; } if (old_action.sa_handler =3D=3D SIG_DFL || old_action.sa_handler =3D=3D= SIG_IGN) - old_handler =3D scm_from_long ((long) old_action.sa_handler); + old_handler =3D scm_from_intptr ((intptr_t) old_action.sa_handler); =20 scm_dynwind_end (); =20 @@ -533,7 +533,7 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3= , 0, orig_handlers[csig] =3D old_chandler; } if (old_chandler =3D=3D SIG_DFL || old_chandler =3D=3D SIG_IGN) - old_handler =3D scm_from_long ((long) old_chandler); + old_handler =3D scm_from_intptr ((intptr_t) old_chandler); =20 scm_dynwind_end (); =20 @@ -803,8 +803,8 @@ scm_init_scmsigs () #endif =20 scm_c_define ("NSIG", scm_from_long (NSIG)); - scm_c_define ("SIG_IGN", scm_from_long ((long) SIG_IGN)); - scm_c_define ("SIG_DFL", scm_from_long ((long) SIG_DFL)); + scm_c_define ("SIG_IGN", scm_from_intptr ((intptr_t) SIG_IGN)); + scm_c_define ("SIG_DFL", scm_from_intptr ((intptr_t) SIG_DFL)); #ifdef SA_NOCLDSTOP scm_c_define ("SA_NOCLDSTOP", scm_from_long (SA_NOCLDSTOP)); #endif diff --git a/libguile/srfi-60.c b/libguile/srfi-60.c index 578106e8e7..07fcf8751b 100644 --- a/libguile/srfi-60.c +++ b/libguile/srfi-60.c @@ -1,6 +1,6 @@ /* srfi-60.c --- Integers as Bits =20 - Copyright 2005-2006,2008,2010,2014,2018 + Copyright 2005-2006,2008,2010,2014,2018,2021 Free Software Foundation, Inc. =20 This file is part of Guile. @@ -53,7 +53,7 @@ SCM_DEFINE (scm_srfi60_log2_binary_factors, "log2-binary-= factors", 1, 0, 0, =20 if (SCM_I_INUMP (n)) { - long nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); if (nn =3D=3D 0) return SCM_I_MAKINUM (-1); nn =3D nn ^ (nn-1); /* 1 bits for each low 0 and lowest 1 */ @@ -86,33 +86,33 @@ SCM_DEFINE (scm_srfi60_copy_bit, "copy-bit", 3, 0, 0, #define FUNC_NAME s_scm_srfi60_copy_bit { SCM r; - unsigned long ii; + uintptr_t ii; int bb; =20 - ii =3D scm_to_ulong (index); + ii =3D scm_to_uintptr (index); bb =3D scm_to_bool (newbit); =20 if (SCM_I_INUMP (n)) { - long nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); =20 - /* can't set high bit ii=3D=3DSCM_LONG_BIT-1, that would change the = sign, + /* can't set high bit ii=3D=3DSCM_INTPTR_T_BIT-1, that would change = the sign, which is not what's wanted */ - if (ii < SCM_LONG_BIT-1) + if (ii < SCM_INTPTR_T_BIT-1) { nn &=3D ~(1L << ii); /* zap bit at index */ - nn |=3D ((long) bb << ii); /* insert desired bit */ - return scm_from_long (nn); + nn |=3D ((intptr_t) bb << ii); /* insert desired bit */ + return scm_from_intptr (nn); } else { - /* bits at ii=3D=3DSCM_LONG_BIT-1 and above are all copies of th= e sign + /* bits at ii=3D=3DSCM_INTPTR_T_BIT-1 and above are all copies o= f the sign bit, if this is already the desired "bit" value then no need = to make a new bignum value */ if (bb =3D=3D (nn < 0)) return n; =20 - r =3D scm_i_long2big (nn); + r =3D scm_i_intptr2big (nn); goto big; } } @@ -152,9 +152,9 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-fi= eld", 4, 0, 0, "@end example") #define FUNC_NAME s_scm_srfi60_rotate_bit_field { - unsigned long ss =3D scm_to_ulong (start); - unsigned long ee =3D scm_to_ulong (end); - unsigned long ww, cc; + uintptr_t ss =3D scm_to_uintptr (start); + uintptr_t ee =3D scm_to_uintptr (end); + uintptr_t ww, cc; =20 SCM_ASSERT_RANGE (3, end, (ee >=3D ss)); ww =3D ee - ss; @@ -164,43 +164,44 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-= field", 4, 0, 0, if (ww <=3D 1) cc =3D 0; else - cc =3D scm_to_ulong (scm_modulo (count, scm_difference (end, start))); + cc =3D scm_to_uintptr (scm_modulo (count, scm_difference (end, start))= ); =20 if (SCM_I_INUMP (n)) { - long nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); =20 - if (ee <=3D SCM_LONG_BIT-1) + if (ee <=3D SCM_INTPTR_T_BIT-1) { - /* Everything fits within a long. To avoid undefined behavior - when shifting negative numbers, we do all operations using - unsigned values, and then convert to signed at the end. */ - unsigned long unn =3D nn; - unsigned long below =3D unn & ((1UL << ss) - 1); /* below star= t */ - unsigned long above =3D unn & ~((1UL << ee) - 1); /* above end = */ - unsigned long fmask =3D ((1UL << ww) - 1) << ss; /* field mask= */ - unsigned long ff =3D unn & fmask; /* field */ - unsigned long uresult =3D (above + /* Everything fits within a intptr_t. To avoid undefined + behavior when shifting negative numbers, we do all + operations using unsigned values, and then convert to + signed at the end. */ + uintptr_t unn =3D nn; + uintptr_t below =3D unn & ((1UL << ss) - 1); /* below start */ + uintptr_t above =3D unn & ~((1UL << ee) - 1); /* above end */ + uintptr_t fmask =3D ((1UL << ww) - 1) << ss; /* field mask */ + uintptr_t ff =3D unn & fmask; /* field */ + uintptr_t uresult =3D (above | ((ff << cc) & fmask) | ((ff >> (ww-cc)) & fmask) | below); - long result; + intptr_t result; =20 - if (uresult > LONG_MAX) + if (uresult > INTPTR_MAX) /* The high bit is set in uresult, so the result is negative. We have to handle the conversion to signed integer carefully, to avoid undefined behavior. First we compute ~uresult, equivalent to (ULONG_MAX - uresult), which will be between 0 and LONG_MAX (inclusive): exactly - the set of numbers that can be represented as both signed - and unsigned longs and thus convertible between them. We + the set of numbers that can be represented as both intptr_t + and uintptr_p and thus convertible between them. We cast that difference to a signed long and then substract it from -1. */ - result =3D -1 - (long) ~uresult; + result =3D -1 - (intptr_t) ~uresult; else - result =3D (long) uresult; + result =3D (intptr_t) uresult; =20 - return scm_from_long (result); + return scm_from_intptr (result); } else { @@ -208,7 +209,7 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-fi= eld", 4, 0, 0, if (cc =3D=3D 0) return n; =20 - n =3D scm_i_long2big (nn); + n =3D scm_i_intptr2big (nn); goto big; } } @@ -222,7 +223,7 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-fi= eld", 4, 0, 0, return n; =20 big: - r =3D scm_i_ulong2big (0); + r =3D scm_i_untptr2big (0); mpz_init (tmp); =20 /* portion above end */ @@ -266,31 +267,31 @@ SCM_DEFINE (scm_srfi60_reverse_bit_field, "reverse-bi= t-field", 3, 0, 0, "@end example") #define FUNC_NAME s_scm_srfi60_reverse_bit_field { - long ss =3D scm_to_long (start); - long ee =3D scm_to_long (end); - long swaps =3D (ee - ss) / 2; /* number of swaps */ + intptr_t ss =3D scm_to_intptr (start); + intptr_t ee =3D scm_to_intptr (end); + intptr_t swaps =3D (ee - ss) / 2; /* number of swaps */ SCM b; =20 if (SCM_I_INUMP (n)) { - long nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); =20 - if (ee <=3D SCM_LONG_BIT-1) + if (ee <=3D SCM_INTPTR_T_BIT-1) { - /* all within a long */ - long smask =3D 1L << ss; - long emask =3D 1L << (ee-1); + /* all within a intptr_t */ + intptr_t smask =3D 1L << ss; + intptr_t emask =3D 1L << (ee-1); for ( ; swaps > 0; swaps--) { - long sbit =3D nn & smask; - long ebit =3D nn & emask; + intptr_t sbit =3D nn & smask; + intptr_t ebit =3D nn & emask; nn ^=3D sbit ^ (ebit ? smask : 0) /* zap sbit, put ebit val= ue */ ^ ebit ^ (sbit ? emask : 0); /* zap ebit, put sbit value= */ =20 smask <<=3D 1; emask >>=3D 1; } - return scm_from_long (nn); + return scm_from_intptr (nn); } else { @@ -298,7 +299,7 @@ SCM_DEFINE (scm_srfi60_reverse_bit_field, "reverse-bit-= field", 3, 0, 0, if (ee - ss <=3D 1) return n; =20 - b =3D scm_i_long2big (nn); + b =3D scm_i_intptr2big (nn); goto big; } } @@ -358,20 +359,20 @@ SCM_DEFINE (scm_srfi60_integer_to_list, "integer->lis= t", 1, 1, 0, #define FUNC_NAME s_scm_srfi60_integer_to_list { SCM ret =3D SCM_EOL; - unsigned long ll, i; + uintptr_t ll, i; =20 if (SCM_UNBNDP (len)) len =3D scm_integer_length (n); - ll =3D scm_to_ulong (len); + ll =3D scm_to_uintptr (len); =20 if (SCM_I_INUMP (n)) { - long nn =3D SCM_I_INUM (n); + intptr_t nn =3D SCM_I_INUM (n); for (i =3D 0; i < ll; i++) { - unsigned long shift =3D - (i < ((unsigned long) SCM_LONG_BIT-1))=20 - ? i : ((unsigned long) SCM_LONG_BIT-1); + uintptr_t shift =3D + (i < ((uintptr_t) SCM_INTPTR_T_BIT-1)) + ? i : ((uintptr_t) SCM_INTPTR_T_BIT-1); int bit =3D (nn >> shift) & 1; ret =3D scm_cons (scm_from_bool (bit), ret); } @@ -403,7 +404,7 @@ SCM_DEFINE (scm_srfi60_list_to_integer, "list->integer"= , 1, 0, 0, "@end example") #define FUNC_NAME s_scm_srfi60_list_to_integer { - long len; + intptr_t len; =20 /* strip high zero bits from lst; after this the length tells us whether an inum or bignum is required */ @@ -415,7 +416,7 @@ SCM_DEFINE (scm_srfi60_list_to_integer, "list->integer"= , 1, 0, 0, if (len <=3D SCM_I_FIXNUM_BIT - 1) { /* fits an inum (a positive inum) */ - long n =3D 0; + intptr_t n =3D 0; while (scm_is_pair (lst)) { n <<=3D 1; @@ -428,7 +429,7 @@ SCM_DEFINE (scm_srfi60_list_to_integer, "list->integer"= , 1, 0, 0, else { /* need a bignum */ - SCM n =3D scm_i_ulong2big (0); + SCM n =3D scm_i_untptr2big (0); while (scm_is_pair (lst)) { len--; diff --git a/libguile/strings.c b/libguile/strings.c index aab1044987..2cc9865b27 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -1,4 +1,4 @@ -/* Copyright 1995-1996,1998,2000-2001,2004,2006,2008-2016,2018-2019 +/* Copyright 1995-1996,1998,2000-2001,2004,2006,2008-2016,2018-2019,2021 Free Software Foundation, Inc. =20 This file is part of Guile. @@ -761,7 +761,7 @@ scm_i_string_set_x (SCM str, size_t p, scm_t_wchar chr) =20 SCM scm_i_make_symbol (SCM name, scm_t_bits flags, - unsigned long hash, SCM props) + uintptr_t hash, SCM props) { SCM buf; size_t length =3D STRING_LENGTH (name); @@ -774,7 +774,7 @@ scm_i_make_symbol (SCM name, scm_t_bits flags, =20 SCM scm_i_c_make_symbol (const char *name, size_t len, - scm_t_bits flags, unsigned long hash, SCM props) + scm_t_bits flags, uintptr_t hash, SCM props) { SCM buf =3D make_stringbuf (len); memcpy (STRINGBUF_CHARS (buf), name, len); @@ -1221,7 +1221,7 @@ SCM_DEFINE (scm_string_ref, "string-ref", 2, 0, 0, #define FUNC_NAME s_scm_string_ref { size_t len; - unsigned long idx; + uintptr_t idx; =20 SCM_VALIDATE_STRING (1, str); =20 @@ -1258,7 +1258,7 @@ SCM_DEFINE (scm_string_set_x, "string-set!", 3, 0, 0, #define FUNC_NAME s_scm_string_set_x { size_t len; - unsigned long idx; + uintptr_t idx; =20 SCM_VALIDATE_STRING (1, str); =20 diff --git a/libguile/strings.h b/libguile/strings.h index 3f92d8c894..e9ebd255aa 100644 --- a/libguile/strings.h +++ b/libguile/strings.h @@ -1,7 +1,7 @@ #ifndef SCM_STRINGS_H #define SCM_STRINGS_H =20 -/* Copyright 1995-1998,2000-2001,2004-2006,2008-2011,2013,2015-2019 +/* Copyright 1995-1998,2000-2001,2004-2006,2008-2011,2013,2015-2019,2021 Free Software Foundation, Inc. =20 This file is part of Guile. @@ -26,6 +26,7 @@ #include #include "libguile/inline.h" #include +#include "libguile/numbers.h" =20 =20 @@ -250,10 +251,10 @@ SCM_INTERNAL void scm_i_string_set_x (SCM str, size_t= p, scm_t_wchar chr); /* internal functions related to symbols. */ =20 SCM_INTERNAL SCM scm_i_make_symbol (SCM name, scm_t_bits flags, - unsigned long hash, SCM props); + uintptr_t hash, SCM props); SCM_INTERNAL SCM scm_i_c_make_symbol (const char *name, size_t len, - scm_t_bits flags, unsigned long hash, SCM props); + scm_t_bits flags, uintptr_t hash, SCM props); SCM_INTERNAL const char *scm_i_symbol_chars (SCM sym); SCM_INTERNAL const scm_t_wchar *scm_i_symbol_wide_chars (SCM sym); SCM_INTERNAL size_t scm_i_symbol_length (SCM sym); --=20 Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar=C2=AE http://AvatarAcademy.com --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar=C2=AE http://AvatarAcademy.com --=-=-=--