unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] DRAFT Support for x86_64-w64-mingw32.
@ 2021-03-17 16:42 Jan Nieuwenhuizen
  2021-03-20 22:08 ` [PATCH v2] " Jan Nieuwenhuizen
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Nieuwenhuizen @ 2021-03-17 16:42 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 980 bytes --]

Hi!

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 mp_long and mp_ulong that
are defined to LONG LONG and UNSIGNED LONG LONG on this platform.

Because we do not always use mini-gmp, "numbers.h" now introcudes
SCM_I_UNUM NEXT to SCM_I_INUM.  Those are now used (almost) throughout
instead of LONG and UNSIGNED LONG.

As discussed on IRC, this patch also lives here

    https://gitlab.com/janneke/guile/-/commit/ac929750129cf396baee9cb45850d75ea9e7e1bd

You can build it by doing

   GUIX_PACKAGE_PATH=guix guix build --target=x86_64-w64-mingw32 guile-mingw

on that branch and using guile.cmd from the source tree, run something
like

   wine64 cmd /c guile -c '(display "hello\n")'

Greetings,
Janneke


[-- Attachment #2: 0001-DRAFT-Support-for-x86_64-w64-mingw32.patch --]
[-- Type: text/x-patch, Size: 65422 bytes --]

From ac929750129cf396baee9cb45850d75ea9e7e1bd Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
Date: Tue, 16 Mar 2021 12:10:36 +0100
Subject: [PATCH] DRAFT Support for x86_64-w64-mingw32.
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-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 mp_long and mp_ulong that
are defined to LONG LONG and UNSIGNED LONG LONG on this platform.

Because we do not always use mini-gmp, "numbers.h" now introcudes
SCM_I_UNUM NEXT to SCM_I_INUM.  Those are now used (almost) throughout
instead of LONG and UNSIGNED LONG.

* configure.ac: When x86_64-w64-mingw32, require mini-gmp.
* libguile/mini-gmp.h (MP_LONG_MAX, MP_LONG_MIN): New defines.
(mp_long, mp_ulong): New typedefs.  USe them throughout, replacing long
and unsigned long.
* libguile/mini-gmp.c: Likewise.
* libguile/scm.h (SCM_LONG_LONG_BIT): New define.
* libguile/numbers.h (SCM_FIXNUM_BIT)[__MINGW32__ && __x86_64__]: Use
it.
(SCM_SIZEOF_INUM, SCM_INUM_BIT, SCM_INUM_MIN, SCM_INUM_MAX,
SCM_UNUM_MAX): New defines.
(scm_t_unum): New typedef.
* libguile/numbers.c (L1): New macro.  Use it thoughout instead of 1L.
(verify): Use SCM_INUM_BIT.
(verify): Use SCM_INUM_MAX and SCM_INUM_MIN.
(scm_long2big): Rename to...
(scm_inum2big): ..this.
(scm_ulong2big): Rename to...
(scm_unum2big): ..this.  Use them throughout, together with scm_t_inum,
scm_t_unum instead of long and unsigned long.
* libguile/numbers.h (scm,inum2big,scm_unum2big): New declarations.
(scm_from_inum, scm_from_unum, scm_to_inum, scm_to_unum): New
defines.
* libguile/arrays.c (make-shared-array): Use scm_t_inum instead of long.
* libguile/bytevectors.c (twos_complement): Use scm_t_unum 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 scm_t_unum instead of unsigned long.
(scm_hashv, scm_hash): Use SCM_UNUM_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 scm_t_inum instead of long.
* libguile/strings.c (scm_i_make_symbol, (scm_i_c_make_symbol): Use
scm_t_unum instead of unsigned long.
* libguile/strings.h (scm_i_make_symbol, (scm_i_c_make_symbol): Update
declacations.
* libguile/srfi-60.c: Use scm_unum2big, scm_inum2big and variants
throughout.

Co-authored-by: Mike Gran <spk121@yahoo.com>
Co-authored-by: Andy Wingo <wingo@pobox.com>
---
 configure.ac               |   6 ++
 libguile/arrays.c          |   2 +-
 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        |  97 +++++++++++----------
 libguile/numbers.c         |  75 ++++++++--------
 libguile/numbers.h         |  40 ++++++++-
 libguile/scm.h             |   6 ++
 libguile/scmsigs.c         |  14 +--
 libguile/srfi-60.c         | 111 ++++++++++++------------
 libguile/strings.c         |  10 +--
 libguile/strings.h         |   7 +-
 16 files changed, 339 insertions(+), 283 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" = xyes || test "x$enable_mini_gmp" = xy; then
   SCM_I_GSC_ENABLE_MINI_GMP=1
 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 <gmp.h>], [mpz_import (0,0,0,0,0,0,0);])
   if test "x$HAVE_LIBGMP" != "xyes"; then
     AC_MSG_ERROR([GNU MP 4.1 or greater not found; either install it, or pass '--enable-mini-gmp' to use included less-optimal arbitrary-precision integer support.])
diff --git a/libguile/arrays.c b/libguile/arrays.c
index 0a919515b5..350bb29e2c 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;
+  scm_t_inum old_base, old_min, new_min, old_max, new_max;
   scm_t_array_dim *s;
 
   SCM_VALIDATE_REST_ARGUMENT (dims);
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index 2d6cbdb3e4..45d0d36172 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -810,14 +810,14 @@ SCM_DEFINE (scm_u8_list_to_bytevector, "u8-list->bytevector", 1, 0, 0,
 static inline void
 twos_complement (mpz_t value, size_t size)
 {
-  unsigned long bit_count;
+  scm_t_unum bit_count;
 
-  /* We expect BIT_COUNT to fit in a unsigned long thanks to the range
+  /* We expect BIT_COUNT to fit in a scm_t_unum thanks to the range
      checking on SIZE performed earlier.  */
-  bit_count = (unsigned long) size << 3UL;
+  bit_count = (scm_t_unum) size << 3ULL;
 
-  if (SCM_LIKELY (bit_count < sizeof (unsigned long)))
-    mpz_ui_sub (value, 1UL << bit_count, value);
+  if (SCM_LIKELY (bit_count < sizeof (scm_t_unum)))
+    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..9a9d822859 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 = mpz_get_si (SCM_I_BIG_MPZ (val));
+	      scm_t_inum n = mpz_get_si (SCM_I_BIG_MPZ (val));
 #if SIZEOF_TYPE != 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 >= LONG_MIN && val <= LONG_MAX)
-    return scm_i_long2big (val);
+  else if (val >= SCM_INUM_MIN && val <= SCM_INUM_MAX)
+    return scm_i_inum2big (val);
   else
     {
       SCM z = make_bignum ();
diff --git a/libguile/conv-uinteger.i.c b/libguile/conv-uinteger.i.c
index f9203771a0..cb56438304 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 = mpz_get_ui (SCM_I_BIG_MPZ (val));
+	      scm_t_unum n = mpz_get_ui (SCM_I_BIG_MPZ (val));
 #if SIZEOF_TYPE != 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 != 0 && SIZEOF_TYPE < SIZEOF_UINTPTR_T
+#if SIZEOF_TYPE != 0 && SIZEOF_TYPE < SCM_SIZEOF_INUM
   return SCM_I_MAKINUM (val);
 #else
   if (SCM_POSFIXABLE (val))
     return SCM_I_MAKINUM (val);
-  else if (val <= ULONG_MAX)
-    return scm_i_ulong2big (val);
+  else if (val <= SCM_UNUM_MAX)
+    return scm_i_unum2big (val);
   else
     {
       SCM z = make_bignum ();
diff --git a/libguile/hash.c b/libguile/hash.c
index 11a35c2cb8..ae985a791e 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) == 8)                                              \
-      ret = (((unsigned long) c) << 32) | b;                            \
+      ret = (((scm_t_unum) c) << 32) | b;                               \
     else                                                                \
       ret = c;                                                          \
   } while (0)
 
 
-static unsigned long
+static scm_t_unum
 narrow_string_hash (const uint8_t *str, size_t len)
 {
-  unsigned long ret;
+  scm_t_unum ret;
   JENKINS_LOOKUP3_HASHWORD2 (str, len, ret);
   ret >>= 2; /* Ensure that it fits in a fixnum.  */
   return ret;
 }
 
-static unsigned long
+static scm_t_unum
 wide_string_hash (const scm_t_wchar *str, size_t len)
 {
-  unsigned long ret;
+  scm_t_unum ret;
   JENKINS_LOOKUP3_HASHWORD2 (str, len, ret);
   ret >>= 2; /* Ensure that it fits in a fixnum.  */
   return ret;
 }
 
-unsigned long
+scm_t_unum
 scm_i_string_hash (SCM str)
 {
   size_t len = 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);
 }
 
-unsigned long 
+scm_t_unum
 scm_i_locale_string_hash (const char *str, size_t len)
 {
   return scm_i_string_hash (scm_from_locale_stringn (str, len));
 }
 
-unsigned long 
+scm_t_unum
 scm_i_latin1_string_hash (const char *str, size_t len)
 {
   if (len == (size_t) -1)
@@ -167,11 +167,11 @@ scm_i_latin1_string_hash (const char *str, size_t len)
 }
 
 /* A tricky optimization, but probably worth it.  */
-unsigned long 
+scm_t_unum
 scm_i_utf8_string_hash (const char *str, size_t len)
 {
   const uint8_t *end, *ustr = (const uint8_t *) str;
-  unsigned long ret;
+  scm_t_unum ret;
 
   /* 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)
 
   final (a, b, c);
 
-  if (sizeof (unsigned long) == 8)
-    ret = (((unsigned long) c) << 32) | b;
+  if (sizeof (scm_t_unum) == 8)
+    ret = (((scm_t_unum) c) << 32) | b;
   else
     ret = c;
 
@@ -231,16 +231,16 @@ scm_i_utf8_string_hash (const char *str, size_t len)
   return ret;
 }
 
-static unsigned long scm_raw_ihashq (scm_t_bits key);
-static unsigned long scm_raw_ihash (SCM obj, size_t depth);
+static scm_t_unum scm_raw_ihashq (scm_t_bits key);
+static scm_t_unum scm_raw_ihash (SCM obj, size_t depth);
 
 /* 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 scm_t_unum
 scm_i_struct_hash (SCM obj, size_t depth)
 {
   size_t struct_size, field_num;
-  unsigned long hash;
+  scm_t_unum hash;
 
   struct_size = SCM_STRUCT_SIZE (obj);
 
@@ -260,7 +260,7 @@ scm_i_struct_hash (SCM obj, size_t depth)
 
 /* Thomas Wang's integer hasher, from
    http://www.cris.com/~Ttwang/tech/inthash.htm.  */
-static unsigned long
+static scm_t_unum
 scm_raw_ihashq (scm_t_bits key)
 {
   if (sizeof (key) < 8)
@@ -286,7 +286,7 @@ scm_raw_ihashq (scm_t_bits key)
 }
 
 /* `depth' is used to limit recursion. */
-static unsigned long
+static scm_t_unum
 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 = SCM_SIMPLE_VECTOR_LENGTH (obj);
         size_t i = depth / 2;
-        unsigned long h = scm_raw_ihashq (SCM_CELL_WORD_0 (obj));
+        scm_t_unum h = scm_raw_ihashq (SCM_CELL_WORD_0 (obj));
         if (len)
           while (i--)
             h ^= 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;
+        scm_t_unum h;
         h = scm_raw_ihash (scm_syntax_expression (obj), depth);
         h ^= scm_raw_ihash (scm_syntax_wrap (obj), depth);
         h ^= 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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  scm_t_unum sz = scm_to_unsigned_integer (size, 1, SCM_UNUM_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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  scm_t_unum sz = scm_to_unsigned_integer (size, 1, SCM_UNUM_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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  scm_t_unum sz = scm_to_unsigned_integer (size, 1, SCM_UNUM_MAX);
   return scm_from_ulong (scm_ihash (key, sz));
 }
 #undef FUNC_NAME
diff --git a/libguile/hash.h b/libguile/hash.h
index 0e82b4afcb..c89923b5ed 100644
--- a/libguile/hash.h
+++ b/libguile/hash.h
@@ -23,17 +23,15 @@
 \f
 
 #include "libguile/scm.h"
+#include "libguile/numbers.h"
 
 \f
 
-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 scm_t_unum scm_i_locale_string_hash (const char *str, size_t len);
+SCM_INTERNAL scm_t_unum scm_i_latin1_string_hash (const  char *str, size_t len);
+SCM_INTERNAL scm_t_unum scm_i_utf8_string_hash (const char *str, size_t len);
 
-SCM_INTERNAL unsigned long scm_i_string_hash (SCM str);
+SCM_INTERNAL scm_t_unum 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..88e8c4b869 100644
--- a/libguile/mini-gmp.c
+++ b/libguile/mini-gmp.c
@@ -2,7 +2,7 @@
 
    Contributed to the GNU project by Niels Möller
 
-Copyright 1991-1997, 1999-2019 Free Software Foundation, Inc.
+Copyright 1991-1997, 1999-2019,2021 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -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)
 
-#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(mp_ulong) * CHAR_BIT)
+#define GMP_ULONG_HIGHBIT ((mp_ulong) 1 << (GMP_ULONG_BITS - 1))
 
 #define GMP_ABS(x) ((x) >= 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 >= 2 * GMP_LIMB_BITS)			\
       {									\
-	unsigned long int __ww = (unsigned long int) (u) * (v);		\
+	mp_ulong __ww = (mp_ulong) (u) * (v);		                \
 	w0 = (mp_limb_t) __ww;						\
 	w1 = (mp_limb_t) (__ww >> LOCAL_GMP_LIMB_BITS);			\
       }									\
@@ -1462,25 +1462,25 @@ mpz_realloc (mpz_t r, mp_size_t size)
 \f
 /* MPZ assignment and basic conversions. */
 void
-mpz_set_si (mpz_t r, signed long int x)
+mpz_set_si (mpz_t r, mp_long x)
 {
   if (x >= 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 (mp_ulong, x));
 	mpz_neg (r, r);
       }
   else
     {
       r->_mp_size = -1;
-      MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (unsigned long int, x);
+      MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (mp_ulong, x);
     }
 }
 
 void
-mpz_set_ui (mpz_t r, unsigned long int x)
+mpz_set_ui (mpz_t r, mp_ulong x)
 {
   if (x > 0)
     {
@@ -1518,14 +1518,14 @@ mpz_set (mpz_t r, const mpz_t x)
 }
 
 void
-mpz_init_set_si (mpz_t r, signed long int x)
+mpz_init_set_si (mpz_t r, mp_long x)
 {
   mpz_init (r);
   mpz_set_si (r, x);
 }
 
 void
-mpz_init_set_ui (mpz_t r, unsigned long int x)
+mpz_init_set_ui (mpz_t r, mp_ulong 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 == 0 || mpz_cmp_ui (u, LONG_MAX) <= 0) &&
-    mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, LONG_MIN)) <= 0;
+  return (MP_LONG_MAX + MP_LONG_MIN == 0 || mpz_cmp_ui (u, MP_LONG_MAX) <= 0) &&
+    mpz_cmpabs_ui (u, GMP_NEG_CAST (mp_ulong, MP_LONG_MIN)) <= 0;
 }
 
 static int
@@ -1565,26 +1565,26 @@ mpz_fits_ulong_p (const mpz_t u)
   return us >= 0 && mpn_absfits_ulong_p (u->_mp_d, us);
 }
 
-long int
+mp_long
 mpz_get_si (const mpz_t u)
 {
-  unsigned long r = mpz_get_ui (u);
-  unsigned long c = -LONG_MAX - LONG_MIN;
+  mp_ulong r = mpz_get_ui (u);
+  mp_ulong c = -MP_LONG_MAX - MP_LONG_MIN;
 
   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 -MP_LONG_MIN */
+    return -(mp_long) c - (mp_long) ((r - c) & MP_LONG_MAX);
   else
-    return (long) (r & LONG_MAX);
+    return (mp_long) (r & MP_LONG_MAX);
 }
 
-unsigned long int
+mp_ulong
 mpz_get_ui (const mpz_t u)
 {
   if (GMP_LIMB_BITS < GMP_ULONG_BITS)
     {
       int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;
-      unsigned long r = 0;
+      mp_ulong r = 0;
       mp_size_t n = GMP_ABS (u->_mp_size);
       n = GMP_MIN (n, 1 + (mp_size_t) (GMP_ULONG_BITS - 1) / GMP_LIMB_BITS);
       while (--n >= 0)
@@ -1827,7 +1827,7 @@ mpz_sgn (const mpz_t u)
 }
 
 int
-mpz_cmp_si (const mpz_t u, long v)
+mpz_cmp_si (const mpz_t u, mp_long v)
 {
   mp_size_t usize = u->_mp_size;
 
@@ -1836,11 +1836,11 @@ mpz_cmp_si (const mpz_t u, long v)
   else if (usize >= 0)
     return 1;
   else
-    return - mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, v));
+    return - mpz_cmpabs_ui (u, GMP_NEG_CAST (mp_ulong, v));
 }
 
 int
-mpz_cmp_ui (const mpz_t u, unsigned long v)
+mpz_cmp_ui (const mpz_t u, mp_ulong v)
 {
   mp_size_t usize = u->_mp_size;
 
@@ -1865,7 +1865,7 @@ mpz_cmp (const mpz_t a, const mpz_t b)
 }
 
 int
-mpz_cmpabs_ui (const mpz_t u, unsigned long v)
+mpz_cmpabs_ui (const mpz_t u, mp_ulong v)
 {
   mp_size_t un = GMP_ABS (u->_mp_size);
 
@@ -1873,7 +1873,7 @@ mpz_cmpabs_ui (const mpz_t u, unsigned long v)
     return 1;
   else
     {
-      unsigned long uu = mpz_get_ui (u);
+      mp_ulong uu = mpz_get_ui (u);
       return GMP_CMP(uu, v);
     }
 }
@@ -1912,7 +1912,7 @@ mpz_swap (mpz_t u, mpz_t v)
 
 
 void
-mpz_add_ui (mpz_t r, const mpz_t a, unsigned long b)
+mpz_add_ui (mpz_t r, const mpz_t a, mp_ulong 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)
 }
 
 void
-mpz_sub_ui (mpz_t r, const mpz_t a, unsigned long b)
+mpz_sub_ui (mpz_t r, const mpz_t a, mp_ulong b)
 {
   mpz_ui_sub (r, b, a);
   mpz_neg (r, r);
 }
 
 void
-mpz_ui_sub (mpz_t r, unsigned long a, const mpz_t b)
+mpz_ui_sub (mpz_t r, mp_ulong 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)
 \f
 /* 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, mp_long v)
 {
   if (v < 0)
     {
-      mpz_mul_ui (r, u, GMP_NEG_CAST (unsigned long int, v));
+      mpz_mul_ui (r, u, GMP_NEG_CAST (mp_ulong, v));
       mpz_neg (r, r);
     }
   else
@@ -2022,7 +2022,7 @@ mpz_mul_si (mpz_t r, const mpz_t u, long int v)
 }
 
 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, mp_ulong 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 bits)
 }
 
 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, mp_ulong 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)
 }
 
 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, mp_ulong 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, const mpz_t m)
   return res;
 }
 
-static unsigned long
+static mp_ulong
 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, mp_ulong d, enum mpz_div_round_mode mode)
 {
-  unsigned long ret;
+  mp_ulong ret;
   mpz_t rr, dd;
 
   mpz_init (rr);
@@ -2530,90 +2530,90 @@ mpz_div_qr_ui (mpz_t q, mpz_t r,
   return ret;
 }
 
-unsigned long
-mpz_cdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)
+mp_ulong
+mpz_cdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (q, r, n, d, GMP_DIV_CEIL);
 }
 
-unsigned long
-mpz_fdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)
+mp_ulong
+mpz_fdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (q, r, n, d, GMP_DIV_FLOOR);
 }
 
-unsigned long
-mpz_tdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, unsigned long d)
+mp_ulong
+mpz_tdiv_qr_ui (mpz_t q, mpz_t r, const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (q, r, n, d, GMP_DIV_TRUNC);
 }
 
-unsigned long
-mpz_cdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)
+mp_ulong
+mpz_cdiv_q_ui (mpz_t q, const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_CEIL);
 }
 
-unsigned long
-mpz_fdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)
+mp_ulong
+mpz_fdiv_q_ui (mpz_t q, const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_FLOOR);
 }
 
-unsigned long
-mpz_tdiv_q_ui (mpz_t q, const mpz_t n, unsigned long d)
+mp_ulong
+mpz_tdiv_q_ui (mpz_t q, const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_TRUNC);
 }
 
-unsigned long
-mpz_cdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)
+mp_ulong
+mpz_cdiv_r_ui (mpz_t r, const mpz_t n, mp_ulong 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)
+mp_ulong
+mpz_fdiv_r_ui (mpz_t r, const mpz_t n, mp_ulong 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)
+mp_ulong
+mpz_tdiv_r_ui (mpz_t r, const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_TRUNC);
 }
 
-unsigned long
-mpz_cdiv_ui (const mpz_t n, unsigned long d)
+mp_ulong
+mpz_cdiv_ui (const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_CEIL);
 }
 
-unsigned long
-mpz_fdiv_ui (const mpz_t n, unsigned long d)
+mp_ulong
+mpz_fdiv_ui (const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_FLOOR);
 }
 
-unsigned long
-mpz_tdiv_ui (const mpz_t n, unsigned long d)
+mp_ulong
+mpz_tdiv_ui (const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_TRUNC);
 }
 
-unsigned long
-mpz_mod_ui (mpz_t r, const mpz_t n, unsigned long d)
+mp_ulong
+mpz_mod_ui (mpz_t r, const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (NULL, r, n, d, GMP_DIV_FLOOR);
 }
 
 void
-mpz_divexact_ui (mpz_t q, const mpz_t n, unsigned long d)
+mpz_divexact_ui (mpz_t q, const mpz_t n, mp_ulong d)
 {
   gmp_assert_nocarry (mpz_div_qr_ui (q, NULL, n, d, GMP_DIV_TRUNC));
 }
 
 int
-mpz_divisible_ui_p (const mpz_t n, unsigned long d)
+mpz_divisible_ui_p (const mpz_t n, mp_ulong d)
 {
   return mpz_div_qr_ui (NULL, NULL, n, d, GMP_DIV_TRUNC) == 0;
 }
@@ -2663,8 +2663,8 @@ mpn_gcd_11 (mp_limb_t u, mp_limb_t v)
   return u << shift;
 }
 
-unsigned long
-mpz_gcd_ui (mpz_t g, const mpz_t u, unsigned long v)
+mp_ulong
+mpz_gcd_ui (mpz_t g, const mpz_t u, mp_ulong 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 == 0)
     {
       /* g = 0 u + sgn(v) v */
-      signed long sign = mpz_sgn (v);
+      mp_long sign = mpz_sgn (v);
       mpz_abs (g, v);
       if (s)
 	s->_mp_size = 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 == 0)
     {
       /* g = sgn(u) u + 0 v */
-      signed long sign = mpz_sgn (u);
+      mp_long sign = 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)
 }
 
 void
-mpz_lcm_ui (mpz_t r, const mpz_t u, unsigned long v)
+mpz_lcm_ui (mpz_t r, const mpz_t u, mp_ulong v)
 {
   if (v == 0 || u->_mp_size == 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) */
 
 void
-mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e)
+mpz_pow_ui (mpz_t r, const mpz_t b, mp_ulong e)
 {
-  unsigned long bit;
+  mp_ulong bit;
   mpz_t tr;
   mpz_init_set_ui (tr, 1);
 
@@ -3032,7 +3032,7 @@ mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e)
 }
 
 void
-mpz_ui_pow_ui (mpz_t r, unsigned long blimb, unsigned long e)
+mpz_ui_pow_ui (mpz_t r, mp_ulong blimb, mp_ulong e)
 {
   mpz_t b;
 
@@ -3147,7 +3147,7 @@ mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, const mpz_t m)
 }
 
 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, mp_ulong elimb, const mpz_t m)
 {
   mpz_t e;
 
@@ -3158,7 +3158,7 @@ mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long elimb, const mpz_t m)
 
 /* x=trunc(y^(1/z)), r=y-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, mp_ulong z)
 {
   int sgn;
   mpz_t t, u;
@@ -3218,7 +3218,7 @@ mpz_rootrem (mpz_t x, mpz_t r, const mpz_t y, unsigned long z)
 }
 
 int
-mpz_root (mpz_t x, const mpz_t y, unsigned long z)
+mpz_root (mpz_t x, const mpz_t y, mp_ulong z)
 {
   int res;
   mpz_t r;
@@ -3289,7 +3289,7 @@ mpn_sqrtrem (mp_ptr sp, mp_ptr rp, mp_srcptr p, mp_size_t n)
 /* Combinatorics */
 
 void
-mpz_mfac_uiui (mpz_t x, unsigned long n, unsigned long m)
+mpz_mfac_uiui (mpz_t x, mp_ulong n, mp_ulong m)
 {
   mpz_set_ui (x, n + (n == 0));
   if (m + 1 < 2) return;
@@ -3298,19 +3298,19 @@ mpz_mfac_uiui (mpz_t x, unsigned long n, unsigned long m)
 }
 
 void
-mpz_2fac_ui (mpz_t x, unsigned long n)
+mpz_2fac_ui (mpz_t x, mp_ulong n)
 {
   mpz_mfac_uiui (x, n, 2);
 }
 
 void
-mpz_fac_ui (mpz_t x, unsigned long n)
+mpz_fac_ui (mpz_t x, mp_ulong n)
 {
   mpz_mfac_uiui (x, n, 1);
 }
 
 void
-mpz_bin_uiui (mpz_t r, unsigned long n, unsigned long k)
+mpz_bin_uiui (mpz_t r, mp_ulong n, mp_ulong k)
 {
   mpz_t t;
 
@@ -3389,10 +3389,10 @@ gmp_lucas_step_k_2k (mpz_t V, mpz_t Qk, const mpz_t n)
 
 /* Computes V_k, Q^k (mod n) for the Lucas' sequence */
 /* with P=1, Q=Q; k = (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 mp_long */
 /* Returns (U_k == 0) and sets V=V_k and Qk=Q^k. */
 static int
-gmp_lucas_mod (mpz_t V, mpz_t Qk, long Q,
+gmp_lucas_mod (mpz_t V, mpz_t Qk, mp_long 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;
 
   assert (b0 > 0);
-  assert (Q <= - (LONG_MIN / 2));
-  assert (Q >= - (LONG_MAX / 2));
+  assert (Q <= - (MP_LONG_MIN / 2));
+  assert (Q >= - (MP_LONG_MAX / 2));
   assert (mpz_cmp_ui (n, 4) > 0);
   assert (mpz_odd_p (n));
 
@@ -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;
+  mp_long Q;
   mp_limb_t tl;
 
   /* Test on the absolute value. */
@@ -3490,7 +3490,7 @@ gmp_stronglucas (const mpz_t x, mpz_t Qk)
   b0 = mpz_scan0 (n, 0);
 
   /* D= P^2 - 4Q; P = 1; Q = (1-D)/4 */
-  Q = (D & 2) ? (long) (D >> 2) + 1 : -(long) (D >> 2);
+  Q = (D & 2) ? (mp_long) (D >> 2) + 1 : -(mp_long) (D >> 2);
 
   if (! gmp_lucas_mod (V, Qk, Q, b0, n))	/* If Ud != 0 */
     while (V->_mp_size != 0 && --b0 != 0)	/* while Vk != 0 */
@@ -3584,7 +3584,7 @@ mpz_probab_prime_p (const mpz_t n, int reps)
 
   for (j = 0; is_prime & (j < reps); j++)
     {
-      mpz_set_ui (y, (unsigned long) j*j+j+41);
+      mpz_set_ui (y, (mp_ulong) j*j+j+41);
       if (mpz_cmp (y, nm1) >= 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..6c5756a2aa 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.
 
-Copyright 2011-2015, 2017, 2019-2020 Free Software Foundation, Inc.
+Copyright 2011-2015, 2017, 2019-2021 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -54,7 +54,15 @@ void mp_get_memory_functions (void *(**) (size_t),
 			      void (**) (void *, size_t));
 
 #ifndef MINI_GMP_LIMB_TYPE
+#if !(__MINGW32__ && __x86_64__)
 #define MINI_GMP_LIMB_TYPE long
+#define MP_LONG_MAX LONG_MAX
+#define MP_LONG_MIN LONG_MIN
+#else /* __MINGW32__ && __x86_64__ */
+#define MINI_GMP_LIMB_TYPE long long
+#define MP_LONG_MAX LONG_LONG_MAX
+#define MP_LONG_MIN LONG_LONG_MIN
+#endif /* __MINGW32__ && __x86_64__ */
 #endif
 
 typedef unsigned MINI_GMP_LIMB_TYPE mp_limb_t;
@@ -64,6 +72,9 @@ typedef unsigned long mp_bitcnt_t;
 typedef mp_limb_t *mp_ptr;
 typedef const mp_limb_t *mp_srcptr;
 
+typedef MINI_GMP_LIMB_TYPE mp_long;
+typedef unsigned MINI_GMP_LIMB_TYPE mp_ulong;
+
 typedef struct
 {
   int _mp_alloc;		/* Number of *limbs* allocated and pointed
@@ -131,10 +142,10 @@ void mpz_clear (mpz_t);
 #define mpz_even_p(z)  (! mpz_odd_p (z))
 
 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, mp_long);
+int mpz_cmp_ui (const mpz_t, mp_ulong);
 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, mp_ulong);
 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 +154,19 @@ void mpz_abs (mpz_t, const mpz_t);
 void mpz_neg (mpz_t, const mpz_t);
 void mpz_swap (mpz_t, mpz_t);
 
-void mpz_add_ui (mpz_t, const mpz_t, unsigned long);
+void mpz_add_ui (mpz_t, const mpz_t, mp_ulong);
 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, mp_ulong);
+void mpz_ui_sub (mpz_t, mp_ulong, const mpz_t);
 void mpz_sub (mpz_t, const mpz_t, const mpz_t);
 
-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, mp_long);
+void mpz_mul_ui (mpz_t, const mpz_t, mp_ulong);
 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, mp_ulong);
 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, mp_ulong);
 void mpz_submul (mpz_t, const mpz_t, const mpz_t);
 
 void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
@@ -182,29 +193,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);
 
-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);
+mp_ulong mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_cdiv_q_ui (mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_fdiv_q_ui (mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_tdiv_q_ui (mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_cdiv_r_ui (mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_fdiv_r_ui (mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_tdiv_r_ui (mpz_t, const mpz_t, mp_ulong);
+mp_ulong mpz_cdiv_ui (const mpz_t, mp_ulong);
+mp_ulong mpz_fdiv_ui (const mpz_t, mp_ulong);
+mp_ulong mpz_tdiv_ui (const mpz_t, mp_ulong);
 
-unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long);
+mp_ulong mpz_mod_ui (mpz_t, const mpz_t, mp_ulong);
 
-void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long);
+void mpz_divexact_ui (mpz_t, const mpz_t, mp_ulong);
 
-int mpz_divisible_ui_p (const mpz_t, unsigned long);
+int mpz_divisible_ui_p (const mpz_t, mp_ulong);
 
-unsigned long mpz_gcd_ui (mpz_t, const mpz_t, unsigned long);
+mp_ulong mpz_gcd_ui (mpz_t, const mpz_t, mp_ulong);
 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, mp_ulong);
 void mpz_lcm (mpz_t, const mpz_t, const mpz_t);
 int mpz_invert (mpz_t, const mpz_t, const mpz_t);
 
@@ -212,18 +223,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);
 
-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, mp_ulong);
+void mpz_ui_pow_ui (mpz_t, mp_ulong, mp_ulong);
 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, mp_ulong, const mpz_t);
 
-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, mp_ulong);
+int mpz_root (mpz_t, const mpz_t, mp_ulong);
 
-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, mp_ulong);
+void mpz_2fac_ui (mpz_t, mp_ulong);
+void mpz_mfac_uiui (mpz_t, mp_ulong, mp_ulong);
+void mpz_bin_uiui (mpz_t, mp_ulong, mp_ulong);
 
 int mpz_probab_prime_p (const mpz_t, int);
 
@@ -244,8 +255,8 @@ mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);
 
 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);
+mp_long mpz_get_si (const mpz_t);
+mp_ulong 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 +270,13 @@ mpz_srcptr mpz_roinit_n (mpz_t, mp_srcptr, mp_size_t);
 
 #define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
 
-void mpz_set_si (mpz_t, signed long int);
-void mpz_set_ui (mpz_t, unsigned long int);
+void mpz_set_si (mpz_t, mp_long);
+void mpz_set_ui (mpz_t, mp_ulong);
 void mpz_set (mpz_t, const mpz_t);
 void mpz_set_d (mpz_t, double);
 
-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, mp_long);
+void mpz_init_set_ui (mpz_t, mp_ulong);
 void mpz_init_set (mpz_t, const mpz_t);
 void mpz_init_set_d (mpz_t, double);
 
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 0aa18e59ad..1ed79b5b19 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -91,24 +91,28 @@ verify (FLT_RADIX == 2);
 /* Make sure that scm_t_inum fits within a SCM value.  */
 verify (sizeof (scm_t_inum) <= sizeof (scm_t_bits));
 
+#if !(__MINGW32__ && __x86_64__)
+#define L1 1L
+#else /* (__MINGW32__ && __x86_64__) */
+#define L1 1LL
+#endif /* (__MINGW32__ && __x86_64__) */
+
 /* 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 <= SCM_LONG_BIT - 2);
+verify (SCM_I_FIXNUM_BIT <= SCM_INUM_BIT - 2);
 
 /* 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 <= (mp_limb_t) -1);
 
-#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 <= 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))
 
 #if (! HAVE_DECL_MPZ_INITS) || SCM_ENABLE_MINI_GMP
 
@@ -299,17 +303,8 @@ scm_i_mkbig ()
   return z;
 }
 
-static SCM
-scm_i_inum2big (scm_t_inum x)
-{
-  /* Return a newly created bignum initialized to X. */
-  SCM z = make_bignum ();
-  mpz_init_set_si (SCM_I_BIG_MPZ (z), x);
-  return z;
-}
-
 SCM
-scm_i_long2big (long x)
+scm_i_inum2big (scm_t_inum x)
 {
   /* Return a newly created bignum initialized to X. */
   SCM z = make_bignum ();
@@ -318,7 +313,7 @@ scm_i_long2big (long x)
 }
 
 SCM
-scm_i_ulong2big (unsigned long x)
+scm_i_unum2big (scm_t_unum x)
 {
   /* Return a newly created bignum initialized to X. */
   SCM z = make_bignum ();
@@ -742,7 +737,7 @@ SCM_PRIMITIVE_GENERIC (scm_odd_p, "odd?", 1, 0, 0,
   if (SCM_I_INUMP (n))
     {
       scm_t_inum val = SCM_I_INUM (n);
-      return scm_from_bool ((val & 1L) != 0);
+      return scm_from_bool ((val & L1) != 0);
     }
   else if (SCM_BIGP (n))
     {
@@ -776,7 +771,7 @@ SCM_PRIMITIVE_GENERIC (scm_even_p, "even?", 1, 0, 0,
   if (SCM_I_INUMP (n))
     {
       scm_t_inum val = SCM_I_INUM (n);
-      return scm_from_bool ((val & 1L) == 0);
+      return scm_from_bool ((val & L1) == 0);
     }
   else if (SCM_BIGP (n))
     {
@@ -2788,7 +2783,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "centered-quotient", 2, 0, 0,
 	{
 	  /* 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_inum2big (xx), y);
 	}
       else if (SCM_REALP (y))
 	return scm_i_inexact_centered_quotient (xx, SCM_REAL_VALUE (y));
@@ -3002,7 +2997,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_remainder, "centered-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_inum2big (xx), y);
 	}
       else if (SCM_REALP (y))
 	return scm_i_inexact_centered_remainder (xx, SCM_REAL_VALUE (y));
@@ -3238,7 +3233,7 @@ scm_centered_divide (SCM x, SCM y, SCM *qp, SCM *rp)
       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_inum2big (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))
@@ -3452,7 +3447,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quotient", 2, 0, 0,
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    qq++;
@@ -3476,7 +3471,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quotient", 2, 0, 0,
 	{
 	  /* 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_inum2big (xx), y);
 	}
       else if (SCM_REALP (y))
 	return scm_i_inexact_round_quotient (xx, SCM_REAL_VALUE (y));
@@ -3658,7 +3653,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-remainder", 2, 0, 0,
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    rr -= yy;
@@ -3680,7 +3675,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-remainder", 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_inum2big (xx), y);
 	}
       else if (SCM_REALP (y))
 	return scm_i_inexact_round_remainder (xx, SCM_REAL_VALUE (y));
@@ -3886,7 +3881,7 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp)
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    { qq++; rr -= yy; }
@@ -3910,7 +3905,7 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp)
       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_inum2big (SCM_I_INUM (x)), y, qp, rp);
       else if (SCM_REALP (y))
 	scm_i_inexact_round_divide (xx, SCM_REAL_VALUE (y), qp, rp);
       else if (SCM_FRACTIONP (y))
@@ -4457,7 +4452,7 @@ SCM scm_logior (SCM n1, SCM n2)
       nn1 = SCM_I_INUM (n1);
       if (SCM_I_INUMP (n2))
 	{
-	  long nn2 = SCM_I_INUM (n2);
+	  scm_t_inum nn2 = SCM_I_INUM (n2);
 	  return SCM_I_MAKINUM (nn1 | nn2);
 	}
       else if (SCM_BIGP (n2))
@@ -4683,7 +4678,7 @@ SCM_DEFINE (scm_logbit_p, "logbit?", 2, 0, 0,
 
   if (SCM_I_INUMP (j))
     {
-      if (iindex < SCM_LONG_BIT - 1)
+      if (iindex < SCM_INUM_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
@@ -4876,7 +4871,7 @@ SCM_DEFINE (scm_integer_expt, "integer-expt", 2, 0, 0,
   scm_t_inum i2 = 0;
   SCM z_i2 = SCM_BOOL_F;
   int i2_is_big = 0;
-  SCM acc = SCM_I_MAKINUM (1L);
+  SCM acc = SCM_I_MAKINUM (L1);
 
   /* 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,
 
   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,
@@ -5061,12 +5056,12 @@ round_right_shift_exact_integer (SCM n, long count)
           scm_t_inum nn = SCM_I_INUM (n);
           scm_t_inum qq = SCM_SRS (nn, count);
 
-          if (0 == (nn & (1L << (count-1))))
+          if (0 == (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)
 
 /* '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 >= LONG_MIN + 1
-        && SCM_MOST_POSITIVE_FIXNUM <= LONG_MAX);
+verify (SCM_MOST_NEGATIVE_FIXNUM >= SCM_INUM_MIN + 1
+        && SCM_MOST_POSITIVE_FIXNUM <= SCM_INUM_MAX);
 
 SCM_DEFINE (scm_ash, "ash", 2, 0, 0,
             (SCM n, SCM count),
@@ -5241,7 +5236,7 @@ SCM_DEFINE (scm_bit_extract, "bit-extract", 3, 0, 0,
 
       /* mask down to requisite bits */
       bits = 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))
     {
@@ -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
@@ -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 = mpz_get_si (SCM_I_BIG_MPZ (val));
+	      scm_t_inum n = mpz_get_si (SCM_I_BIG_MPZ (val));
 	      return n >= min && n <= max;
 	    }
 	  else
@@ -9758,7 +9753,7 @@ scm_is_unsigned_integer (SCM val, uintmax_t min, uintmax_t max)
 	{
 	  if (mpz_fits_ulong_p (SCM_I_BIG_MPZ (val)))
 	    {
-	      unsigned long n = mpz_get_ui (SCM_I_BIG_MPZ (val));
+	      scm_t_unum n = mpz_get_ui (SCM_I_BIG_MPZ (val));
 	      return n >= min && n <= max;
 	    }
 	  else
@@ -10307,7 +10302,7 @@ SCM_PRIMITIVE_GENERIC (scm_sqrt, "sqrt", 1, 0, 0,
           if (SCM_LIKELY (x >= 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 = sqrt (x);
 
diff --git a/libguile/numbers.h b/libguile/numbers.h
index df5c9110c1..37f4495626 100644
--- a/libguile/numbers.h
+++ b/libguile/numbers.h
@@ -54,10 +54,33 @@ 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.  */
+ * because that's what GMP's mpz_*_si functions accept.
+ *
+ * When using mini-gmp on x86_64-mingw, we use long long instead.
+ */
+
+#if !(__MINGW32__ && __x86_64__)
 typedef long scm_t_inum;
+typedef unsigned long scm_t_unum;
 #define SCM_I_FIXNUM_BIT         (SCM_LONG_BIT - 2)
 #define SCM_MOST_NEGATIVE_FIXNUM (-1L << (SCM_I_FIXNUM_BIT - 1))
+#define SCM_SIZEOF_INUM SIZEOF_LONG
+#define SCM_INUM_BIT SCM_LONG_BIT
+#define SCM_INUM_MIN LONG_MIN
+#define SCM_INUM_MAX LONG_MAX
+#define SCM_UNUM_MAX ULONG_MAX
+#else /* __MINGW32__ && __x86_64__ */
+typedef long long scm_t_inum;
+typedef unsigned long long scm_t_unum;
+#define SCM_I_FIXNUM_BIT         (SCM_LONG_LONG_BIT - 2)
+#define SCM_MOST_NEGATIVE_FIXNUM (-1LL << (SCM_I_FIXNUM_BIT - 1))
+#define SCM_SIZEOF_INUM SIZEOF_LONG_LONG
+#define SCM_INUM_BIT SCM_LONG_LONG_BIT
+#define SCM_INUM_MIN LONG_LONG_MIN
+#define SCM_INUM_MAX LONG_LONG_MAX
+#define SCM_UNUM_MAX ULONG_LONG_MAX
+#endif /* __MINGW32__ && __x86_64__ */
+
 #define SCM_MOST_POSITIVE_FIXNUM (- (SCM_MOST_NEGATIVE_FIXNUM + 1))
 
 /* SCM_SRS (X, Y) is signed right shift, defined as floor (X / 2^Y),
@@ -357,6 +380,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 same_sign_p);
 
+SCM scm_i_inum2big (scm_t_inum x);
+SCM scm_i_unum2big (scm_t_unum x);
+
+#if SIZEOF_INTPTR == 4
+#define scm_from_inum scm_from_int32
+#define scm_from_unum scm_from_uint32
+#define scm_to_inum scm_to_int32
+#define scm_to_unum scm_to_uint32
+#else
+#define scm_from_inum scm_from_int64
+#define scm_from_unum scm_from_uint64
+#define scm_to_inum scm_to_int64
+#define scm_to_unum 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..98571af8fc 100644
--- a/libguile/scm.h
+++ b/libguile/scm.h
@@ -843,6 +843,12 @@ typedef struct scm_thread scm_thread;
 # define SCM_LONG_BIT (SCM_SIZEOF_LONG * 8)
 #endif
 
+#ifdef LONG_LONG_BIT
+# define SCM_LONG_LONG_BIT LONG_LONG_BIT
+#else
+# define SCM_LONG_LONG_BIT (SCM_SIZEOF_LONG_LONG * 8)
+#endif
+
 \f
 
 /* Cast pointer through (void *) in order to avoid compiler warnings
diff --git a/libguile/scmsigs.c b/libguile/scmsigs.c
index c234c015a5..4806d53f59 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.
 
    This file is part of Guile.
@@ -414,9 +414,9 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
     query_only = 1;
   else if (scm_is_integer (handler))
     {
-      long handler_int = scm_to_long (handler);
+      scm_t_inum handler_int = scm_to_inum (handler);
 
-      if (handler_int == (long) SIG_DFL || handler_int == (long) SIG_IGN)
+      if (handler_int == (scm_t_inum) SIG_DFL || handler_int == (scm_t_inum) SIG_IGN)
 	{
 #ifdef HAVE_SIGACTION
 	  action.sa_handler = (SIGRETTYPE (*) (int)) handler_int;
@@ -512,7 +512,7 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
 	orig_handlers[csig] = old_action;
     }
   if (old_action.sa_handler == SIG_DFL || old_action.sa_handler == SIG_IGN)
-    old_handler = scm_from_long ((long) old_action.sa_handler);
+    old_handler = scm_from_inum ((scm_t_inum) old_action.sa_handler);
 
   scm_dynwind_end ();
 
@@ -533,7 +533,7 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
 	orig_handlers[csig] = old_chandler;
     }
   if (old_chandler == SIG_DFL || old_chandler == SIG_IGN)
-    old_handler = scm_from_long ((long) old_chandler);
+    old_handler = scm_from_inum ((scm_t_inum) old_chandler);
 
   scm_dynwind_end ();
 
@@ -803,8 +803,8 @@ scm_init_scmsigs ()
 #endif
 
   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_inum ((scm_t_inum) SIG_IGN));
+  scm_c_define ("SIG_DFL", scm_from_inum ((scm_t_inum) 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..68c75e9f26 100644
--- a/libguile/srfi-60.c
+++ b/libguile/srfi-60.c
@@ -1,6 +1,6 @@
 /* srfi-60.c --- Integers as Bits
 
-   Copyright 2005-2006,2008,2010,2014,2018
+   Copyright 2005-2006,2008,2010,2014,2018,2021
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -53,7 +53,7 @@ SCM_DEFINE (scm_srfi60_log2_binary_factors, "log2-binary-factors", 1, 0, 0,
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      scm_t_inum nn = SCM_I_INUM (n);
       if (nn == 0)
         return SCM_I_MAKINUM (-1);
       nn = 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;
+  scm_t_unum ii;
   int bb;
 
-  ii = scm_to_ulong (index);
+  ii = scm_to_unum (index);
   bb = scm_to_bool (newbit);
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      scm_t_inum nn = SCM_I_INUM (n);
 
-      /* can't set high bit ii==SCM_LONG_BIT-1, that would change the sign,
+      /* can't set high bit ii==SCM_INUM_BIT-1, that would change the sign,
          which is not what's wanted */
-      if (ii < SCM_LONG_BIT-1)
+      if (ii < SCM_INUM_BIT-1)
         {
           nn &= ~(1L << ii);  /* zap bit at index */
-          nn |= ((long) bb << ii);   /* insert desired bit */
-          return scm_from_long (nn);
+          nn |= ((scm_t_inum) bb << ii);   /* insert desired bit */
+          return scm_from_inum (nn);
         }
       else
         {
-          /* bits at ii==SCM_LONG_BIT-1 and above are all copies of the sign
+          /* bits at ii==SCM_INUM_BIT-1 and above are all copies of the sign
              bit, if this is already the desired "bit" value then no need to
              make a new bignum value */
           if (bb == (nn < 0))
             return n;
 
-          r = scm_i_long2big (nn);
+          r = scm_i_inum2big (nn);
           goto big;
         }
     }
@@ -152,9 +152,9 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
 	    "@end example")
 #define FUNC_NAME s_scm_srfi60_rotate_bit_field
 {
-  unsigned long ss = scm_to_ulong (start);
-  unsigned long ee = scm_to_ulong (end);
-  unsigned long ww, cc;
+  scm_t_unum ss = scm_to_unum (start);
+  scm_t_unum ee = scm_to_unum (end);
+  scm_t_unum ww, cc;
 
   SCM_ASSERT_RANGE (3, end, (ee >= ss));
   ww = ee - ss;
@@ -164,43 +164,44 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
   if (ww <= 1)
     cc = 0;
   else
-    cc = scm_to_ulong (scm_modulo (count, scm_difference (end, start)));
+    cc = scm_to_unum (scm_modulo (count, scm_difference (end, start)));
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      scm_t_inum nn = SCM_I_INUM (n);
 
-      if (ee <= SCM_LONG_BIT-1)
+      if (ee <= SCM_INUM_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 = nn;
-          unsigned long below = unn &  ((1UL << ss) - 1);  /* below start */
-          unsigned long above = unn & ~((1UL << ee) - 1);  /* above end */
-          unsigned long fmask = ((1UL << ww) - 1) << ss;   /* field mask */
-          unsigned long ff = unn & fmask;                  /* field */
-          unsigned long uresult = (above
+          /* Everything fits within a scm_t_inum.  To avoid undefined
+             behavior when shifting negative numbers, we do all
+             operations using unsigned values, and then convert to
+             signed at the end. */
+          scm_t_unum unn = nn;
+          scm_t_unum below = unn &  ((1UL << ss) - 1);  /* below start */
+          scm_t_unum above = unn & ~((1UL << ee) - 1);  /* above end */
+          scm_t_unum fmask = ((1UL << ww) - 1) << ss;   /* field mask */
+          scm_t_unum ff = unn & fmask;                  /* field */
+          scm_t_unum uresult = (above
                                    | ((ff << cc) & fmask)
                                    | ((ff >> (ww-cc)) & fmask)
                                    | below);
-          long result;
+          scm_t_inum result;
 
-          if (uresult > LONG_MAX)
+          if (uresult > SCM_INUM_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
+               and unsigned unums and thus convertible between them.  We
                cast that difference to a signed long and then substract
                it from -1. */
-            result = -1 - (long) ~uresult;
+            result = -1 - (scm_t_inum) ~uresult;
           else
-            result = (long) uresult;
+            result = (scm_t_inum) uresult;
 
-          return scm_from_long (result);
+          return scm_from_inum (result);
         }
       else
         {
@@ -208,7 +209,7 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
           if (cc == 0)
             return n;
 
-          n = scm_i_long2big (nn);
+          n = scm_i_inum2big (nn);
           goto big;
         }
     }
@@ -222,7 +223,7 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
         return n;
 
     big:
-      r = scm_i_ulong2big (0);
+      r = scm_i_unum2big (0);
       mpz_init (tmp);
 
       /* portion above end */
@@ -266,31 +267,31 @@ SCM_DEFINE (scm_srfi60_reverse_bit_field, "reverse-bit-field", 3, 0, 0,
 	    "@end example")
 #define FUNC_NAME s_scm_srfi60_reverse_bit_field
 {
-  long ss = scm_to_long (start);
-  long ee = scm_to_long (end);
-  long swaps = (ee - ss) / 2;  /* number of swaps */
+  scm_t_inum ss = scm_to_inum (start);
+  scm_t_inum ee = scm_to_inum (end);
+  scm_t_inum swaps = (ee - ss) / 2;  /* number of swaps */
   SCM b;
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      scm_t_inum nn = SCM_I_INUM (n);
 
-      if (ee <= SCM_LONG_BIT-1)
+      if (ee <= SCM_INUM_BIT-1)
         {
-          /* all within a long */
-          long smask = 1L << ss;
-          long emask = 1L << (ee-1);
+          /* all within a scm_t_inum */
+          scm_t_inum smask = 1L << ss;
+          scm_t_inum emask = 1L << (ee-1);
           for ( ; swaps > 0; swaps--)
             {
-              long sbit = nn & smask;
-              long ebit = nn & emask;
+              scm_t_inum sbit = nn & smask;
+              scm_t_inum ebit = nn & emask;
               nn ^= sbit ^ (ebit ? smask : 0)  /* zap sbit, put ebit value */
                 ^   ebit ^ (sbit ? emask : 0); /* zap ebit, put sbit value */
 
               smask <<= 1;
               emask >>= 1;
             }
-          return scm_from_long (nn);
+          return scm_from_inum (nn);
         }
       else
         {
@@ -298,7 +299,7 @@ SCM_DEFINE (scm_srfi60_reverse_bit_field, "reverse-bit-field", 3, 0, 0,
           if (ee - ss <= 1)
             return n;
 
-          b = scm_i_long2big (nn);
+          b = scm_i_inum2big (nn);
           goto big;
         }
     }
@@ -358,20 +359,20 @@ SCM_DEFINE (scm_srfi60_integer_to_list, "integer->list", 1, 1, 0,
 #define FUNC_NAME s_scm_srfi60_integer_to_list
 {
   SCM ret = SCM_EOL;
-  unsigned long ll, i;
+  scm_t_unum ll, i;
 
   if (SCM_UNBNDP (len))
     len = scm_integer_length (n);
-  ll = scm_to_ulong (len);
+  ll = scm_to_unum (len);
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      scm_t_inum nn = SCM_I_INUM (n);
       for (i = 0; i < ll; i++)
         {
-          unsigned long shift =
-	    (i < ((unsigned long) SCM_LONG_BIT-1)) 
-	    ? i : ((unsigned long) SCM_LONG_BIT-1);
+          scm_t_unum shift =
+	    (i < ((scm_t_unum) SCM_INUM_BIT-1))
+	    ? i : ((scm_t_unum) SCM_INUM_BIT-1);
           int bit = (nn >> shift) & 1;
           ret = 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;
+  scm_t_inum len;
 
   /* 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 <= SCM_I_FIXNUM_BIT - 1)
     {
       /* fits an inum (a positive inum) */
-      long n = 0;
+      scm_t_inum n = 0;
       while (scm_is_pair (lst))
         {
           n <<= 1;
@@ -428,7 +429,7 @@ SCM_DEFINE (scm_srfi60_list_to_integer, "list->integer", 1, 0, 0,
   else
     {
       /* need a bignum */
-      SCM n = scm_i_ulong2big (0);
+      SCM n = scm_i_unum2big (0);
       while (scm_is_pair (lst))
         {
           len--;
diff --git a/libguile/strings.c b/libguile/strings.c
index aab1044987..678f08d14b 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.
 
    This file is part of Guile.
@@ -761,7 +761,7 @@ scm_i_string_set_x (SCM str, size_t p, scm_t_wchar chr)
 
 SCM
 scm_i_make_symbol (SCM name, scm_t_bits flags,
-		   unsigned long hash, SCM props)
+		   scm_t_unum hash, SCM props)
 {
   SCM buf;
   size_t length = STRING_LENGTH (name);
@@ -774,7 +774,7 @@ scm_i_make_symbol (SCM name, scm_t_bits flags,
 
 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, scm_t_unum hash, SCM props)
 {
   SCM buf = 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;
+  scm_t_unum idx;
 
   SCM_VALIDATE_STRING (1, str);
 
@@ -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;
+  scm_t_unum idx;
 
   SCM_VALIDATE_STRING (1, str);
 
diff --git a/libguile/strings.h b/libguile/strings.h
index 3f92d8c894..c3d2c782ad 100644
--- a/libguile/strings.h
+++ b/libguile/strings.h
@@ -1,7 +1,7 @@
 #ifndef SCM_STRINGS_H
 #define SCM_STRINGS_H
 
-/* 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.
 
    This file is part of Guile.
@@ -26,6 +26,7 @@
 #include <libguile/error.h>
 #include "libguile/inline.h"
 #include <libguile/snarf.h>
+#include "libguile/numbers.h"
 
 \f
 
@@ -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. */
 
 SCM_INTERNAL SCM scm_i_make_symbol (SCM name, scm_t_bits flags,
-				    unsigned long hash, SCM props);
+				    scm_t_unum 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, scm_t_unum 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);
-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com


[-- Attachment #3: Type: text/plain, Size: 152 bytes --]


-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] DRAFT Support for x86_64-w64-mingw32.
  2021-03-17 16:42 [PATCH] DRAFT Support for x86_64-w64-mingw32 Jan Nieuwenhuizen
@ 2021-03-20 22:08 ` Jan Nieuwenhuizen
  2021-03-21 14:17   ` [PATCH v3] " Jan Nieuwenhuizen
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Nieuwenhuizen @ 2021-03-20 22:08 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 573 bytes --]

Jan Nieuwenhuizen writes:

Hello,

> To get around this, the x86-64-MinGW port now requires the use of
> mini-gmp.  Mini-gmp has been changed to use mp_long and mp_ulong that
> are defined to long long and unsigned long long on this platform.
>
> Because we do not always use mini-gmp, "numbers.h" now introcudes
> scm_t_unum next to scm_t_inum Those are now used (almost) throughout
> instead of long and unsigned long.

After discussing on IRC, we decided not to introduce these new types and
instead use intptr_t and uintptr_t.  New patch attached.

Greetinsg,
Janneke


[-- Attachment #2: v2-0001-DRAFT-Support-for-x86_64-w64-mingw32.patch --]
[-- Type: text/x-patch, Size: 103107 bytes --]

From 21b7969c3730bde876d4322eb3d898214cef0723 Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
Date: Tue, 16 Mar 2021 12:10:36 +0100
Subject: [PATCH v2] DRAFT Support for x86_64-w64-mingw32.
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-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 intptr_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 <spk121@yahoo.com>
Co-authored-by: Andy Wingo <wingo@pobox.com>
---
 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" = xyes || test "x$enable_mini_gmp" = xy; then
   SCM_I_GSC_ENABLE_MINI_GMP=1
 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 <gmp.h>], [mpz_import (0,0,0,0,0,0,0);])
   if test "x$HAVE_LIBGMP" != "xyes"; then
     AC_MSG_ERROR([GNU MP 4.1 or greater not found; either install it, or pass '--enable-mini-gmp' to use included less-optimal arbitrary-precision integer support.])
diff --git a/libguile/arrays.c b/libguile/arrays.c
index 0a919515b5..a49abcced3 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;
+  intptr_t old_base, old_min, new_min, old_max, new_max;
   scm_t_array_dim *s;
 
   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 != 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;
 	}
 
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->bytevector", 1, 0, 0,
 static inline void
 twos_complement (mpz_t value, size_t size)
 {
-  unsigned long bit_count;
+  uintptr_t bit_count;
 
-  /* 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 = (unsigned long) size << 3UL;
+  bit_count = (uintptr_t) size << 3ULL;
 
-  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 = mpz_get_si (SCM_I_BIG_MPZ (val));
+	      intptr_t n = mpz_get_si (SCM_I_BIG_MPZ (val));
 #if SIZEOF_TYPE != 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 >= LONG_MIN && val <= LONG_MAX)
-    return scm_i_long2big (val);
+  else if (val >= INTPTR_MIN && val <= INTPTR_MAX)
+    return scm_i_intptr2big (val);
   else
     {
       SCM z = 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 = mpz_get_ui (SCM_I_BIG_MPZ (val));
+	      uintptr_t n = mpz_get_ui (SCM_I_BIG_MPZ (val));
 #if SIZEOF_TYPE != 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 != 0 && SIZEOF_TYPE < SIZEOF_UINTPTR_T
+#if SIZEOF_TYPE != 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 <= ULONG_MAX)
-    return scm_i_ulong2big (val);
+  else if (val <= UINTPTR_MAX)
+    return scm_i_untptr2big (val);
   else
     {
       SCM z = 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) == 8)                                              \
-      ret = (((unsigned long) c) << 32) | b;                            \
+      ret = (((uintptr_t) c) << 32) | b;                               \
     else                                                                \
       ret = c;                                                          \
   } while (0)
 
 
-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 >>= 2; /* Ensure that it fits in a fixnum.  */
   return ret;
 }
 
-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 >>= 2; /* Ensure that it fits in a fixnum.  */
   return ret;
 }
 
-unsigned long
+uintptr_t
 scm_i_string_hash (SCM str)
 {
   size_t len = 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);
 }
 
-unsigned long 
+uintptr_t
 scm_i_locale_string_hash (const char *str, size_t len)
 {
   return scm_i_string_hash (scm_from_locale_stringn (str, len));
 }
 
-unsigned long 
+uintptr_t
 scm_i_latin1_string_hash (const char *str, size_t len)
 {
   if (len == (size_t) -1)
@@ -167,11 +167,11 @@ scm_i_latin1_string_hash (const char *str, size_t len)
 }
 
 /* A tricky optimization, but probably worth it.  */
-unsigned long 
+uintptr_t
 scm_i_utf8_string_hash (const char *str, size_t len)
 {
   const uint8_t *end, *ustr = (const uint8_t *) str;
-  unsigned long ret;
+  uintptr_t ret;
 
   /* 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)
 
   final (a, b, c);
 
-  if (sizeof (unsigned long) == 8)
-    ret = (((unsigned long) c) << 32) | b;
+  if (sizeof (uintptr_t) == 8)
+    ret = (((uintptr_t) c) << 32) | b;
   else
     ret = c;
 
@@ -231,16 +231,16 @@ scm_i_utf8_string_hash (const char *str, size_t len)
   return ret;
 }
 
-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);
 
 /* 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;
 
   struct_size = SCM_STRUCT_SIZE (obj);
 
@@ -260,7 +260,7 @@ scm_i_struct_hash (SCM obj, size_t depth)
 
 /* 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)
 }
 
 /* `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 = SCM_SIMPLE_VECTOR_LENGTH (obj);
         size_t i = depth / 2;
-        unsigned long h = scm_raw_ihashq (SCM_CELL_WORD_0 (obj));
+        uintptr_t h = scm_raw_ihashq (SCM_CELL_WORD_0 (obj));
         if (len)
           while (i--)
             h ^= 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 = scm_raw_ihash (scm_syntax_expression (obj), depth);
         h ^= scm_raw_ihash (scm_syntax_wrap (obj), depth);
         h ^= 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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  uintptr_t sz = 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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  uintptr_t sz = 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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  uintptr_t sz = 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 @@
 \f
 
 #include "libguile/scm.h"
+#include "libguile/numbers.h"
 
 \f
 
-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 len);
+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);
 
-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 @@
 
    Contributed to the GNU project by Niels Möller
 
-Copyright 1991-1997, 1999-2019 Free Software Foundation, Inc.
+Copyright 1991-1997, 1999-2019,2021 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -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)
 
-#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))
 
 #define GMP_ABS(x) ((x) >= 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 >= 2 * GMP_LIMB_BITS)			\
       {									\
-	unsigned long int __ww = (unsigned long int) (u) * (v);		\
+	uintptr_t __ww = (uintptr_t) (u) * (v);		                \
 	w0 = (mp_limb_t) __ww;						\
 	w1 = (mp_limb_t) (__ww >> LOCAL_GMP_LIMB_BITS);			\
       }									\
@@ -1462,25 +1462,25 @@ mpz_realloc (mpz_t r, mp_size_t size)
 \f
 /* 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 >= 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 = -1;
-      MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (unsigned long int, x);
+      MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (uintptr_t, x);
     }
 }
 
 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)
 }
 
 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);
 }
 
 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 == 0 || mpz_cmp_ui (u, LONG_MAX) <= 0) &&
-    mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, LONG_MIN)) <= 0;
+  return (INTPTR_MAX + INTPTR_MIN == 0 || mpz_cmp_ui (u, INTPTR_MAX) <= 0) &&
+    mpz_cmpabs_ui (u, GMP_NEG_CAST (uintptr_t, INTPTR_MIN)) <= 0;
 }
 
 static int
@@ -1565,26 +1565,26 @@ mpz_fits_ulong_p (const mpz_t u)
   return us >= 0 && mpn_absfits_ulong_p (u->_mp_d, us);
 }
 
-long int
+intptr_t
 mpz_get_si (const mpz_t u)
 {
-  unsigned long r = mpz_get_ui (u);
-  unsigned long c = -LONG_MAX - LONG_MIN;
+  uintptr_t r = mpz_get_ui (u);
+  uintptr_t c = -INTPTR_MAX - INTPTR_MIN;
 
   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);
 }
 
-unsigned long int
+uintptr_t
 mpz_get_ui (const mpz_t u)
 {
   if (GMP_LIMB_BITS < GMP_ULONG_BITS)
     {
       int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;
-      unsigned long r = 0;
+      uintptr_t r = 0;
       mp_size_t n = GMP_ABS (u->_mp_size);
       n = GMP_MIN (n, 1 + (mp_size_t) (GMP_ULONG_BITS - 1) / GMP_LIMB_BITS);
       while (--n >= 0)
@@ -1827,7 +1827,7 @@ mpz_sgn (const mpz_t u)
 }
 
 int
-mpz_cmp_si (const mpz_t u, long v)
+mpz_cmp_si (const mpz_t u, intptr_t v)
 {
   mp_size_t usize = u->_mp_size;
 
@@ -1836,11 +1836,11 @@ mpz_cmp_si (const mpz_t u, long v)
   else if (usize >= 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));
 }
 
 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 = u->_mp_size;
 
@@ -1865,7 +1865,7 @@ mpz_cmp (const mpz_t a, const mpz_t b)
 }
 
 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 = GMP_ABS (u->_mp_size);
 
@@ -1873,7 +1873,7 @@ mpz_cmpabs_ui (const mpz_t u, unsigned long v)
     return 1;
   else
     {
-      unsigned long uu = mpz_get_ui (u);
+      uintptr_t uu = mpz_get_ui (u);
       return GMP_CMP(uu, v);
     }
 }
@@ -1912,7 +1912,7 @@ mpz_swap (mpz_t u, mpz_t v)
 
 
 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)
 }
 
 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);
 }
 
 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)
 \f
 /* 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)
 }
 
 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 bits)
 }
 
 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)
 }
 
 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, const mpz_t m)
   return res;
 }
 
-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;
 
   mpz_init (rr);
@@ -2530,90 +2530,90 @@ mpz_div_qr_ui (mpz_t q, mpz_t r,
   return ret;
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
 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));
 }
 
 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) == 0;
 }
@@ -2663,8 +2663,8 @@ mpn_gcd_11 (mp_limb_t u, mp_limb_t v)
   return u << shift;
 }
 
-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 == 0)
     {
       /* g = 0 u + sgn(v) v */
-      signed long sign = mpz_sgn (v);
+      intptr_t sign = mpz_sgn (v);
       mpz_abs (g, v);
       if (s)
 	s->_mp_size = 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 == 0)
     {
       /* g = sgn(u) u + 0 v */
-      signed long sign = mpz_sgn (u);
+      intptr_t sign = 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)
 }
 
 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 == 0 || u->_mp_size == 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) */
 
 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);
 
@@ -3032,7 +3032,7 @@ mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e)
 }
 
 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;
 
@@ -3147,7 +3147,7 @@ mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, const mpz_t m)
 }
 
 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;
 
@@ -3158,7 +3158,7 @@ mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long elimb, const mpz_t m)
 
 /* x=trunc(y^(1/z)), r=y-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, unsigned long z)
 }
 
 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_size_t n)
 /* Combinatorics */
 
 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 == 0));
   if (m + 1 < 2) return;
@@ -3298,19 +3298,19 @@ mpz_mfac_uiui (mpz_t x, unsigned long n, unsigned long m)
 }
 
 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);
 }
 
 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);
 }
 
 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;
 
@@ -3389,10 +3389,10 @@ gmp_lucas_step_k_2k (mpz_t V, mpz_t Qk, const mpz_t n)
 
 /* Computes V_k, Q^k (mod n) for the Lucas' sequence */
 /* with P=1, Q=Q; k = (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 == 0) and sets V=V_k and Qk=Q^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;
 
   assert (b0 > 0);
-  assert (Q <= - (LONG_MIN / 2));
-  assert (Q >= - (LONG_MAX / 2));
+  assert (Q <= - (INTPTR_MIN / 2));
+  assert (Q >= - (INTPTR_MAX / 2));
   assert (mpz_cmp_ui (n, 4) > 0);
   assert (mpz_odd_p (n));
 
@@ -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;
 
   /* Test on the absolute value. */
@@ -3490,7 +3490,7 @@ gmp_stronglucas (const mpz_t x, mpz_t Qk)
   b0 = mpz_scan0 (n, 0);
 
   /* D= P^2 - 4Q; P = 1; Q = (1-D)/4 */
-  Q = (D & 2) ? (long) (D >> 2) + 1 : -(long) (D >> 2);
+  Q = (D & 2) ? (intptr_t) (D >> 2) + 1 : -(intptr_t) (D >> 2);
 
   if (! gmp_lucas_mod (V, Qk, Q, b0, n))	/* If Ud != 0 */
     while (V->_mp_size != 0 && --b0 != 0)	/* while Vk != 0 */
@@ -3584,7 +3584,7 @@ mpz_probab_prime_p (const mpz_t n, int reps)
 
   for (j = 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) >= 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.
 
-Copyright 2011-2015, 2017, 2019-2020 Free Software Foundation, Inc.
+Copyright 2011-2015, 2017, 2019-2021 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -53,17 +53,14 @@ void mp_get_memory_functions (void *(**) (size_t),
 			      void *(**) (void *, size_t, size_t),
 			      void (**) (void *, size_t));
 
-#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;
 
 typedef mp_limb_t *mp_ptr;
 typedef const mp_limb_t *mp_srcptr;
 
+
 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))
 
 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);
 
-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);
 
-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);
 
 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);
 
-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);
 
-unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long);
+uintptr_t mpz_mod_ui (mpz_t, const mpz_t, uintptr_t);
 
-void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long);
+void mpz_divexact_ui (mpz_t, const mpz_t, uintptr_t);
 
-int mpz_divisible_ui_p (const mpz_t, unsigned long);
+int mpz_divisible_ui_p (const mpz_t, uintptr_t);
 
-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);
 
@@ -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);
 
-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);
 
-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);
 
-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);
 
 int mpz_probab_prime_p (const mpz_t, int);
 
@@ -244,8 +241,8 @@ mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);
 
 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);
 
 #define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
 
-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);
 
-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);
 
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 == 2);
 
-/* Make sure that scm_t_inum fits within a SCM value.  */
-verify (sizeof (scm_t_inum) <= sizeof (scm_t_bits));
+/* Make sure that intptr_t fits within a SCM value.  */
+verify (sizeof (intptr_t) <= sizeof (scm_t_bits));
+
+#if !(__MINGW32__ && __x86_64__)
+#define L1 1L
+#else /* (__MINGW32__ && __x86_64__) */
+#define L1 1LL
+#endif /* (__MINGW32__ && __x86_64__) */
 
 /* 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 <= SCM_LONG_BIT - 2);
+verify (SCM_I_FIXNUM_BIT <= SCM_INTPTR_T_BIT - 2);
 
 /* 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 <= (mp_limb_t) -1);
 
-#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 <= 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))
 
 #if (! HAVE_DECL_MPZ_INITS) || SCM_ENABLE_MINI_GMP
 
@@ -299,17 +303,8 @@ scm_i_mkbig ()
   return z;
 }
 
-static SCM
-scm_i_inum2big (scm_t_inum x)
-{
-  /* Return a newly created bignum initialized to X. */
-  SCM z = 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 = make_bignum ();
@@ -318,7 +313,7 @@ scm_i_long2big (long x)
 }
 
 SCM
-scm_i_ulong2big (unsigned long x)
+scm_i_untptr2big (uintptr_t x)
 {
   /* Return a newly created bignum initialized to X. */
   SCM z = make_bignum ();
@@ -377,7 +372,7 @@ scm_i_dbl2num (double u)
 
   if (u < (double) (SCM_MOST_POSITIVE_FIXNUM+1)
       && u >= (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 = mpz_get_si (SCM_I_BIG_MPZ (b));
+      intptr_t val = mpz_get_si (SCM_I_BIG_MPZ (b));
       if (SCM_FIXABLE (val))
         b = 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 = mpz_get_si (b);
+      intptr_t val = 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 = SCM_I_INUM (n);
-      return scm_from_bool ((val & 1L) != 0);
+      intptr_t val = SCM_I_INUM (n);
+      return scm_from_bool ((val & L1) != 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 = SCM_I_INUM (n);
-      return scm_from_bool ((val & 1L) == 0);
+      intptr_t val = SCM_I_INUM (n);
+      return scm_from_bool ((val & L1) == 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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (xx >= 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 = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       if (SCM_LIKELY (SCM_I_INUMP (d)))
 	{
-	  scm_t_inum dd = SCM_I_INUM (d);
+	  intptr_t dd = SCM_I_INUM (d);
 	  if (SCM_UNLIKELY (dd == 0))
 	    scm_num_overflow ("exact-integer-quotient");
 	  else
 	    {
-	      scm_t_inum qq = nn / dd;
+	      intptr_t qq = 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 = SCM_I_INUM (d);
+	  intptr_t dd = SCM_I_INUM (d);
 	  if (SCM_UNLIKELY (dd == 0))
 	    scm_num_overflow ("exact-integer-quotient");
 	  else if (SCM_UNLIKELY (dd == 1))
@@ -1228,12 +1223,12 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, "floor-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
-	  scm_t_inum xx1 = xx;
-	  scm_t_inum qq;
+	  intptr_t yy = SCM_I_INUM (y);
+	  intptr_t xx1 = 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-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))
 	{
@@ -1270,7 +1265,7 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, "floor-quotient", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_quotient);
 	  else if (SCM_UNLIKELY (yy == 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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_remainder);
 	  else
 	    {
-	      scm_t_inum rr = xx % yy;
+	      intptr_t rr = xx % yy;
 	      int needs_adjustment;
 
 	      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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_remainder);
 	  else
 	    {
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      if (yy > 0)
 		rr = 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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
 	      int needs_adjustment;
 
 	      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 = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_divide);
 	  else
@@ -1739,16 +1734,16 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_quotient, "ceiling-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_quotient);
 	  else
 	    {
-	      scm_t_inum xx1 = xx;
-	      scm_t_inum qq;
+	      intptr_t xx1 = xx;
+	      intptr_t qq;
 	      if (SCM_LIKELY (yy > 0))
 		{
 		  if (SCM_LIKELY (xx >= 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_quotient);
 	  else if (SCM_UNLIKELY (yy == 1))
@@ -1900,15 +1895,15 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_remainder, "ceiling-remainder", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_remainder);
 	  else
 	    {
-	      scm_t_inum rr = xx % yy;
+	      intptr_t rr = xx % yy;
 	      int needs_adjustment;
 
 	      if (SCM_LIKELY (yy > 0))
@@ -1969,12 +1964,12 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_remainder, "ceiling-remainder", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_remainder);
 	  else
 	    {
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      if (yy > 0)
 		rr = -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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
 	      int needs_adjustment;
 
 	      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 = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_divide);
 	  else
@@ -2287,19 +2282,19 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_quotient, "truncate-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_quotient);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
+	      intptr_t qq = 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, "truncate-quotient", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_quotient);
 	  else if (SCM_UNLIKELY (yy == 1))
@@ -2428,10 +2423,10 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_remainder, "truncate-remainder", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_remainder);
 	  else
@@ -2462,12 +2457,12 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_remainder, "truncate-remainder", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_remainder);
 	  else
 	    {
-	      scm_t_inum rr = (mpz_tdiv_ui (SCM_I_BIG_MPZ (x),
+	      intptr_t rr = (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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
 	      if (SCM_LIKELY (SCM_FIXABLE (qq)))
 		*qp = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_divide);
 	  else
 	    {
 	      SCM q = scm_i_mkbig ();
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      if (yy > 0)
 		rr = 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, "centered-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_quotient);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
 	      if (SCM_LIKELY (xx > 0))
 		{
 		  if (SCM_LIKELY (yy > 0))
@@ -2781,14 +2776,14 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "centered-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, "centered-quotient", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_quotient);
 	  else if (SCM_UNLIKELY (yy == 1))
@@ -2810,7 +2805,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "centered-quotient", 2, 0, 0,
 	  else
 	    {
 	      SCM q = 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, "centered-remainder", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_remainder);
 	  else
 	    {
-	      scm_t_inum rr = xx % yy;
+	      intptr_t rr = xx % yy;
 	      if (SCM_LIKELY (xx > 0))
 		{
 		  if (SCM_LIKELY (yy > 0))
@@ -3002,7 +2997,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_remainder, "centered-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, "centered-remainder", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = 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 = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_divide);
 	  else
 	    {
 	      SCM q = 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-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_quotient);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
-	      scm_t_inum ay = yy;
-	      scm_t_inum r2 = 2 * rr;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
+	      intptr_t ay = yy;
+	      intptr_t r2 = 2 * rr;
 
 	      if (SCM_LIKELY (yy < 0))
 		{
@@ -3452,7 +3447,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quotient", 2, 0, 0,
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    qq++;
@@ -3469,14 +3464,14 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-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_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-quotient", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_quotient);
 	  else if (SCM_UNLIKELY (yy == 1))
@@ -3498,7 +3493,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quotient", 2, 0, 0,
 	  else
 	    {
 	      SCM q = scm_i_mkbig ();
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      int needs_adjustment;
 
 	      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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_remainder);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
-	      scm_t_inum ay = yy;
-	      scm_t_inum r2 = 2 * rr;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
+	      intptr_t ay = yy;
+	      intptr_t r2 = 2 * rr;
 
 	      if (SCM_LIKELY (yy < 0))
 		{
@@ -3658,7 +3653,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-remainder", 2, 0, 0,
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    rr -= yy;
@@ -3680,7 +3675,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-remainder", 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_remainder);
 	  else
 	    {
 	      SCM q = scm_i_mkbig ();
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      int needs_adjustment;
 
 	      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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
-	      scm_t_inum ay = yy;
-	      scm_t_inum r2 = 2 * rr;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
+	      intptr_t ay = yy;
+	      intptr_t r2 = 2 * rr;
 
 	      if (SCM_LIKELY (yy < 0))
 		{
@@ -3886,7 +3881,7 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp)
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    { qq++; rr -= yy; }
@@ -3903,14 +3898,14 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp)
 	      if (SCM_LIKELY (SCM_FIXABLE (qq)))
 		*qp = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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, qp, 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_divide);
 	  else
 	    {
 	      SCM q = scm_i_mkbig ();
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      int needs_adjustment;
 
 	      if (yy > 0)
@@ -4090,11 +4085,11 @@ scm_gcd (SCM x, SCM y)
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
         {
-          scm_t_inum xx = SCM_I_INUM (x);
-          scm_t_inum yy = SCM_I_INUM (y);
-          scm_t_inum u = xx < 0 ? -xx : xx;
-          scm_t_inum v = yy < 0 ? -yy : yy;
-          scm_t_inum result;
+          intptr_t xx = SCM_I_INUM (x);
+          intptr_t yy = SCM_I_INUM (y);
+          intptr_t u = xx < 0 ? -xx : xx;
+          intptr_t v = yy < 0 ? -yy : yy;
+          intptr_t result;
           if (SCM_UNLIKELY (xx == 0))
 	    result = v;
 	  else if (SCM_UNLIKELY (yy == 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 = SCM_I_INUM (y);
           if (yy == 0)
@@ -4238,7 +4233,7 @@ scm_lcm (SCM n1, SCM n2)
         inumbig:
           {
             SCM result = scm_i_mkbig ();
-            scm_t_inum nn1 = SCM_I_INUM (n1);
+            intptr_t nn1 = SCM_I_INUM (n1);
             if (nn1 == 0) return SCM_INUM0;
             if (nn1 < 0) nn1 = - 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;
 
   if (SCM_UNBNDP (n2))
     {
@@ -4369,7 +4364,7 @@ SCM scm_logand (SCM n1, SCM n2)
       nn1 = SCM_I_INUM (n1);
       if (SCM_I_INUMP (n2))
 	{
-	  scm_t_inum nn2 = SCM_I_INUM (n2);
+	  intptr_t nn2 = 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;
 
   if (SCM_UNBNDP (n2))
     {
@@ -4457,7 +4452,7 @@ SCM scm_logior (SCM n1, SCM n2)
       nn1 = SCM_I_INUM (n1);
       if (SCM_I_INUMP (n2))
 	{
-	  long nn2 = SCM_I_INUM (n2);
+	  intptr_t nn2 = 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;
 
   if (SCM_UNBNDP (n2))
     {
@@ -4547,7 +4542,7 @@ SCM scm_logxor (SCM n1, SCM n2)
       nn1 = SCM_I_INUM (n1);
       if (SCM_I_INUMP (n2))
 	{
-	  scm_t_inum nn2 = SCM_I_INUM (n2);
+	  intptr_t nn2 = 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;
 
   if (SCM_I_INUMP (j))
     {
       nj = SCM_I_INUM (j);
       if (SCM_I_INUMP (k))
 	{
-	  scm_t_inum nk = SCM_I_INUM (k);
+	  intptr_t nk = 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,
 
   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 = 0;
+  intptr_t i2 = 0;
   SCM z_i2 = SCM_BOOL_F;
   int i2_is_big = 0;
-  SCM acc = SCM_I_MAKINUM (1L);
+  SCM acc = SCM_I_MAKINUM (L1);
 
   /* 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,
 
   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 = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
       /* Left shift of count >= 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 = scm_i_inum2big (nn);
+          SCM result = 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 = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
       if (count >= SCM_I_FIXNUM_BIT)
         return (nn >= 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 = SCM_I_INUM (n);
-          scm_t_inum qq = SCM_SRS (nn, count);
+          intptr_t nn = SCM_I_INUM (n);
+          intptr_t qq = SCM_SRS (nn, count);
 
-          if (0 == (nn & (1L << (count-1))))
+          if (0 == (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)
 
 /* '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 >= LONG_MIN + 1
-        && SCM_MOST_POSITIVE_FIXNUM <= LONG_MAX);
+verify (SCM_MOST_NEGATIVE_FIXNUM >= INTPTR_MIN + 1
+        && SCM_MOST_POSITIVE_FIXNUM <= INTPTR_MAX);
 
 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,
 
   if (SCM_I_INUMP (n))
     {
-      scm_t_inum in = SCM_I_INUM (n);
+      intptr_t in = SCM_I_INUM (n);
 
       /* When istart>=SCM_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 = scm_i_inum2big (in);
+          SCM result = 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,
 
       /* mask down to requisite bits */
       bits = 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 = 0;
-      scm_t_inum nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       if (nn < 0)
         nn = -1 - nn;
       while (nn)
@@ -5342,7 +5337,7 @@ SCM_DEFINE (scm_integer_length, "integer-length", 1, 0, 0,
     {
       unsigned long c = 0;
       unsigned int l = 4;
-      scm_t_inum nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       if (nn < 0)
 	nn = -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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = 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)
   
   if (SCM_I_INUMP (x))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  double xxd = SCM_REAL_VALUE (x);
 	  double yyd = yy;
 
@@ -7402,10 +7397,10 @@ scm_min (SCM x, SCM y)
   
   if (SCM_I_INUMP (x))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = 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 = SCM_I_INUM (x);
-          scm_t_inum yy = SCM_I_INUM (y);
-          scm_t_inum z = xx + yy;
-          return SCM_FIXABLE (z) ? SCM_I_MAKINUM (z) : scm_i_inum2big (z);
+          intptr_t xx = SCM_I_INUM (x);
+          intptr_t yy = SCM_I_INUM (y);
+          intptr_t z = 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 = SCM_I_INUM (x);
+          intptr_t xx = SCM_I_INUM (x);
           return scm_i_from_double (xx + SCM_REAL_VALUE (y));
         }
       else if (SCM_COMPLEXP (y))
         {
-          scm_t_inum xx = SCM_I_INUM (x);
+          intptr_t xx = 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 = SCM_I_INUM (y);      
@@ -7767,11 +7762,11 @@ scm_difference (SCM x, SCM y)
       else 
         if (SCM_I_INUMP (x))
           {
-            scm_t_inum xx = -SCM_I_INUM (x);
+            intptr_t xx = -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 = SCM_I_INUM (x);
-	  scm_t_inum yy = SCM_I_INUM (y);
-	  scm_t_inum z = xx - yy;
+	  intptr_t xx = SCM_I_INUM (x);
+	  intptr_t yy = SCM_I_INUM (y);
+	  intptr_t z = 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 = SCM_I_INUM (x);
+	  intptr_t xx = SCM_I_INUM (x);
 
 	  if (xx == 0)
 	    {
@@ -7837,7 +7832,7 @@ scm_difference (SCM x, SCM y)
 	}
       else if (SCM_REALP (y))
 	{
-	  scm_t_inum xx = SCM_I_INUM (x);
+	  intptr_t xx = SCM_I_INUM (x);
 
 	  /*
 	   * We need to handle x == exact 0
@@ -7857,7 +7852,7 @@ scm_difference (SCM x, SCM y)
 	}
       else if (SCM_COMPLEXP (y))
 	{
-	  scm_t_inum xx = SCM_I_INUM (x);
+	  intptr_t xx = SCM_I_INUM (x);
 
 	  /* We need to handle x == 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  int sgn_x = mpz_sgn (SCM_I_BIG_MPZ (x));
 
 	  scm_remember_upto_here_1 (x);
 	  if (sgn_x == 0)
 	    return (SCM_FIXABLE (-yy) ?
-		    SCM_I_MAKINUM (-yy) : scm_from_inum (-yy));
+		    SCM_I_MAKINUM (-yy) : scm_from_intptr (-yy));
 	  else
 	    {
 	      SCM result = 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)
   
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx;
+      intptr_t xx;
 
     xinum:
       xx = SCM_I_INUM (x);
@@ -8092,20 +8087,20 @@ scm_product (SCM x, SCM y)
 
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 #if SCM_I_FIXNUM_BIT < 32 && SCM_HAVE_T_INT64
           int64_t kk = xx * (int64_t) yy;
           if (SCM_FIXABLE (kk))
             return SCM_I_MAKINUM (kk);
 #else
-          scm_t_inum axx = (xx > 0) ? xx : -xx;
-          scm_t_inum ayy = (yy > 0) ? yy : -yy;
+          intptr_t axx = (xx > 0) ? xx : -xx;
+          intptr_t ayy = (yy > 0) ? yy : -yy;
           if (SCM_MOST_POSITIVE_FIXNUM / axx >= ayy)
             return SCM_I_MAKINUM (xx * yy);
 #endif
 	  else
 	    {
-	      SCM result = scm_i_inum2big (xx);
+	      SCM result = 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 = SCM_I_INUM (x);
+	  intptr_t xx = SCM_I_INUM (x);
 	  if (xx == 1 || xx == -1)
 	    return x;
 #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO
@@ -8369,10 +8364,10 @@ scm_divide (SCM x, SCM y)
 
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (yy == 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 = xx / yy;
+	      intptr_t z = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (yy == 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. */
 
-	      scm_t_inum abs_yy = yy < 0 ? -yy : yy;
+	      intptr_t abs_yy = yy < 0 ? -yy : yy;
 	      int divisible_p = mpz_divisible_ui_p (SCM_I_BIG_MPZ (x), abs_yy);
 
 	      if (divisible_p)
@@ -8522,14 +8517,14 @@ scm_divide (SCM x, SCM y)
       double rx = SCM_REAL_VALUE (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO
 	  if (yy == 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 = SCM_COMPLEX_IMAG (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO
 	  if (yy == 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 = 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)) 
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO
 	  if (yy == 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 = SCM_I_INUM (z);
+      intptr_t zz = SCM_I_INUM (z);
       if (zz >= 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 = mpz_get_si (SCM_I_BIG_MPZ (val));
+	      intptr_t n = mpz_get_si (SCM_I_BIG_MPZ (val));
 	      return n >= min && n <= max;
 	    }
 	  else
@@ -9758,7 +9753,7 @@ scm_is_unsigned_integer (SCM val, uintmax_t min, uintmax_t max)
 	{
 	  if (mpz_fits_ulong_p (SCM_I_BIG_MPZ (val)))
 	    {
-	      unsigned long n = mpz_get_ui (SCM_I_BIG_MPZ (val));
+	      uintptr_t n = mpz_get_ui (SCM_I_BIG_MPZ (val));
 	      return n >= min && n <= max;
 	    }
 	  else
@@ -10302,19 +10297,19 @@ SCM_PRIMITIVE_GENERIC (scm_sqrt, "sqrt", 1, 0, 0,
     {
       if (SCM_I_INUMP (z))
         {
-          scm_t_inum x = SCM_I_INUM (z);
+          intptr_t x = SCM_I_INUM (z);
 
           if (SCM_LIKELY (x >= 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 = sqrt (x);
 
                   /* If 0 <= x < 2^(DBL_MANT_DIG-1) and sqrt(x) is an
                      integer, then the result is exact. */
                   if (root == 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))
 
 /* SCM_SRS (X, Y) is signed right shift, defined as floor (X / 2^Y),
@@ -85,12 +92,12 @@ typedef long scm_t_inum;
 
    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
 
 #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 same_sign_p);
 
+SCM scm_i_intptr2big (intptr_t x);
+SCM scm_i_untptr2big (uintptr_t x);
+
+#if SIZEOF_INTPTR == 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
 
-#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
 
 \f
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.
 
    This file is part of Guile.
@@ -414,9 +414,9 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
     query_only = 1;
   else if (scm_is_integer (handler))
     {
-      long handler_int = scm_to_long (handler);
+      intptr_t handler_int = scm_to_intptr (handler);
 
-      if (handler_int == (long) SIG_DFL || handler_int == (long) SIG_IGN)
+      if (handler_int == (intptr_t) SIG_DFL || handler_int == (intptr_t) SIG_IGN)
 	{
 #ifdef HAVE_SIGACTION
 	  action.sa_handler = (SIGRETTYPE (*) (int)) handler_int;
@@ -512,7 +512,7 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
 	orig_handlers[csig] = old_action;
     }
   if (old_action.sa_handler == SIG_DFL || old_action.sa_handler == SIG_IGN)
-    old_handler = scm_from_long ((long) old_action.sa_handler);
+    old_handler = scm_from_intptr ((intptr_t) old_action.sa_handler);
 
   scm_dynwind_end ();
 
@@ -533,7 +533,7 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
 	orig_handlers[csig] = old_chandler;
     }
   if (old_chandler == SIG_DFL || old_chandler == SIG_IGN)
-    old_handler = scm_from_long ((long) old_chandler);
+    old_handler = scm_from_intptr ((intptr_t) old_chandler);
 
   scm_dynwind_end ();
 
@@ -803,8 +803,8 @@ scm_init_scmsigs ()
 #endif
 
   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
 
-   Copyright 2005-2006,2008,2010,2014,2018
+   Copyright 2005-2006,2008,2010,2014,2018,2021
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -53,7 +53,7 @@ SCM_DEFINE (scm_srfi60_log2_binary_factors, "log2-binary-factors", 1, 0, 0,
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       if (nn == 0)
         return SCM_I_MAKINUM (-1);
       nn = 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;
 
-  ii = scm_to_ulong (index);
+  ii = scm_to_uintptr (index);
   bb = scm_to_bool (newbit);
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
-      /* can't set high bit ii==SCM_LONG_BIT-1, that would change the sign,
+      /* can't set high bit ii==SCM_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 &= ~(1L << ii);  /* zap bit at index */
-          nn |= ((long) bb << ii);   /* insert desired bit */
-          return scm_from_long (nn);
+          nn |= ((intptr_t) bb << ii);   /* insert desired bit */
+          return scm_from_intptr (nn);
         }
       else
         {
-          /* bits at ii==SCM_LONG_BIT-1 and above are all copies of the sign
+          /* bits at ii==SCM_INTPTR_T_BIT-1 and above are all copies of the sign
              bit, if this is already the desired "bit" value then no need to
              make a new bignum value */
           if (bb == (nn < 0))
             return n;
 
-          r = scm_i_long2big (nn);
+          r = scm_i_intptr2big (nn);
           goto big;
         }
     }
@@ -152,9 +152,9 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
 	    "@end example")
 #define FUNC_NAME s_scm_srfi60_rotate_bit_field
 {
-  unsigned long ss = scm_to_ulong (start);
-  unsigned long ee = scm_to_ulong (end);
-  unsigned long ww, cc;
+  uintptr_t ss = scm_to_uintptr (start);
+  uintptr_t ee = scm_to_uintptr (end);
+  uintptr_t ww, cc;
 
   SCM_ASSERT_RANGE (3, end, (ee >= ss));
   ww = ee - ss;
@@ -164,43 +164,44 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
   if (ww <= 1)
     cc = 0;
   else
-    cc = scm_to_ulong (scm_modulo (count, scm_difference (end, start)));
+    cc = scm_to_uintptr (scm_modulo (count, scm_difference (end, start)));
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
-      if (ee <= SCM_LONG_BIT-1)
+      if (ee <= 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 = nn;
-          unsigned long below = unn &  ((1UL << ss) - 1);  /* below start */
-          unsigned long above = unn & ~((1UL << ee) - 1);  /* above end */
-          unsigned long fmask = ((1UL << ww) - 1) << ss;   /* field mask */
-          unsigned long ff = unn & fmask;                  /* field */
-          unsigned long uresult = (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 = nn;
+          uintptr_t below = unn &  ((1UL << ss) - 1);  /* below start */
+          uintptr_t above = unn & ~((1UL << ee) - 1);  /* above end */
+          uintptr_t fmask = ((1UL << ww) - 1) << ss;   /* field mask */
+          uintptr_t ff = unn & fmask;                  /* field */
+          uintptr_t uresult = (above
                                    | ((ff << cc) & fmask)
                                    | ((ff >> (ww-cc)) & fmask)
                                    | below);
-          long result;
+          intptr_t result;
 
-          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 = -1 - (long) ~uresult;
+            result = -1 - (intptr_t) ~uresult;
           else
-            result = (long) uresult;
+            result = (intptr_t) uresult;
 
-          return scm_from_long (result);
+          return scm_from_intptr (result);
         }
       else
         {
@@ -208,7 +209,7 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
           if (cc == 0)
             return n;
 
-          n = scm_i_long2big (nn);
+          n = scm_i_intptr2big (nn);
           goto big;
         }
     }
@@ -222,7 +223,7 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
         return n;
 
     big:
-      r = scm_i_ulong2big (0);
+      r = scm_i_untptr2big (0);
       mpz_init (tmp);
 
       /* portion above end */
@@ -266,31 +267,31 @@ SCM_DEFINE (scm_srfi60_reverse_bit_field, "reverse-bit-field", 3, 0, 0,
 	    "@end example")
 #define FUNC_NAME s_scm_srfi60_reverse_bit_field
 {
-  long ss = scm_to_long (start);
-  long ee = scm_to_long (end);
-  long swaps = (ee - ss) / 2;  /* number of swaps */
+  intptr_t ss = scm_to_intptr (start);
+  intptr_t ee = scm_to_intptr (end);
+  intptr_t swaps = (ee - ss) / 2;  /* number of swaps */
   SCM b;
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
-      if (ee <= SCM_LONG_BIT-1)
+      if (ee <= SCM_INTPTR_T_BIT-1)
         {
-          /* all within a long */
-          long smask = 1L << ss;
-          long emask = 1L << (ee-1);
+          /* all within a intptr_t */
+          intptr_t smask = 1L << ss;
+          intptr_t emask = 1L << (ee-1);
           for ( ; swaps > 0; swaps--)
             {
-              long sbit = nn & smask;
-              long ebit = nn & emask;
+              intptr_t sbit = nn & smask;
+              intptr_t ebit = nn & emask;
               nn ^= sbit ^ (ebit ? smask : 0)  /* zap sbit, put ebit value */
                 ^   ebit ^ (sbit ? emask : 0); /* zap ebit, put sbit value */
 
               smask <<= 1;
               emask >>= 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 <= 1)
             return n;
 
-          b = scm_i_long2big (nn);
+          b = scm_i_intptr2big (nn);
           goto big;
         }
     }
@@ -358,20 +359,20 @@ SCM_DEFINE (scm_srfi60_integer_to_list, "integer->list", 1, 1, 0,
 #define FUNC_NAME s_scm_srfi60_integer_to_list
 {
   SCM ret = SCM_EOL;
-  unsigned long ll, i;
+  uintptr_t ll, i;
 
   if (SCM_UNBNDP (len))
     len = scm_integer_length (n);
-  ll = scm_to_ulong (len);
+  ll = scm_to_uintptr (len);
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       for (i = 0; i < ll; i++)
         {
-          unsigned long shift =
-	    (i < ((unsigned long) SCM_LONG_BIT-1)) 
-	    ? i : ((unsigned long) SCM_LONG_BIT-1);
+          uintptr_t shift =
+	    (i < ((uintptr_t) SCM_INTPTR_T_BIT-1))
+	    ? i : ((uintptr_t) SCM_INTPTR_T_BIT-1);
           int bit = (nn >> shift) & 1;
           ret = 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;
 
   /* 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 <= SCM_I_FIXNUM_BIT - 1)
     {
       /* fits an inum (a positive inum) */
-      long n = 0;
+      intptr_t n = 0;
       while (scm_is_pair (lst))
         {
           n <<= 1;
@@ -428,7 +429,7 @@ SCM_DEFINE (scm_srfi60_list_to_integer, "list->integer", 1, 0, 0,
   else
     {
       /* need a bignum */
-      SCM n = scm_i_ulong2big (0);
+      SCM n = 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.
 
    This file is part of Guile.
@@ -761,7 +761,7 @@ scm_i_string_set_x (SCM str, size_t p, scm_t_wchar chr)
 
 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 = STRING_LENGTH (name);
@@ -774,7 +774,7 @@ scm_i_make_symbol (SCM name, scm_t_bits flags,
 
 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 = 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;
 
   SCM_VALIDATE_STRING (1, str);
 
@@ -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;
 
   SCM_VALIDATE_STRING (1, str);
 
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
 
-/* 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.
 
    This file is part of Guile.
@@ -26,6 +26,7 @@
 #include <libguile/error.h>
 #include "libguile/inline.h"
 #include <libguile/snarf.h>
+#include "libguile/numbers.h"
 
 \f
 
@@ -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. */
 
 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);
-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com


[-- Attachment #3: Type: text/plain, Size: 152 bytes --]


-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v3] DRAFT Support for x86_64-w64-mingw32.
  2021-03-20 22:08 ` [PATCH v2] " Jan Nieuwenhuizen
@ 2021-03-21 14:17   ` Jan Nieuwenhuizen
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Nieuwenhuizen @ 2021-03-21 14:17 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 671 bytes --]

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


[-- Attachment #2: v3-0001-DRAFT-Support-for-x86_64-w64-mingw32.patch --]
[-- Type: text/x-patch, Size: 103115 bytes --]

From b587e04e6b0e0fe37cb8774609a51ac7e04127a5 Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
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=UTF-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 <spk121@yahoo.com>
Co-authored-by: Andy Wingo <wingo@pobox.com>

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" = xyes || test "x$enable_mini_gmp" = xy; then
   SCM_I_GSC_ENABLE_MINI_GMP=1
 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 <gmp.h>], [mpz_import (0,0,0,0,0,0,0);])
   if test "x$HAVE_LIBGMP" != "xyes"; then
     AC_MSG_ERROR([GNU MP 4.1 or greater not found; either install it, or pass '--enable-mini-gmp' to use included less-optimal arbitrary-precision integer 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;
 
   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 != 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;
 	}
 
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->bytevector", 1, 0, 0,
 static inline void
 twos_complement (mpz_t value, size_t size)
 {
-  unsigned long bit_count;
+  uintptr_t bit_count;
 
-  /* 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 = (unsigned long) size << 3UL;
+  bit_count = (uintptr_t) size << 3ULL;
 
-  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 = mpz_get_si (SCM_I_BIG_MPZ (val));
+	      intptr_t n = mpz_get_si (SCM_I_BIG_MPZ (val));
 #if SIZEOF_TYPE != 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 >= LONG_MIN && val <= LONG_MAX)
-    return scm_i_long2big (val);
+  else if (val >= INTPTR_MIN && val <= INTPTR_MAX)
+    return scm_i_intptr2big (val);
   else
     {
       SCM z = 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 = mpz_get_ui (SCM_I_BIG_MPZ (val));
+	      uintptr_t n = mpz_get_ui (SCM_I_BIG_MPZ (val));
 #if SIZEOF_TYPE != 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 != 0 && SIZEOF_TYPE < SIZEOF_UINTPTR_T
+#if SIZEOF_TYPE != 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 <= ULONG_MAX)
-    return scm_i_ulong2big (val);
+  else if (val <= UINTPTR_MAX)
+    return scm_i_untptr2big (val);
   else
     {
       SCM z = 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) == 8)                                              \
-      ret = (((unsigned long) c) << 32) | b;                            \
+      ret = (((uintptr_t) c) << 32) | b;                               \
     else                                                                \
       ret = c;                                                          \
   } while (0)
 
 
-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 >>= 2; /* Ensure that it fits in a fixnum.  */
   return ret;
 }
 
-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 >>= 2; /* Ensure that it fits in a fixnum.  */
   return ret;
 }
 
-unsigned long
+uintptr_t
 scm_i_string_hash (SCM str)
 {
   size_t len = 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);
 }
 
-unsigned long 
+uintptr_t
 scm_i_locale_string_hash (const char *str, size_t len)
 {
   return scm_i_string_hash (scm_from_locale_stringn (str, len));
 }
 
-unsigned long 
+uintptr_t
 scm_i_latin1_string_hash (const char *str, size_t len)
 {
   if (len == (size_t) -1)
@@ -167,11 +167,11 @@ scm_i_latin1_string_hash (const char *str, size_t len)
 }
 
 /* A tricky optimization, but probably worth it.  */
-unsigned long 
+uintptr_t
 scm_i_utf8_string_hash (const char *str, size_t len)
 {
   const uint8_t *end, *ustr = (const uint8_t *) str;
-  unsigned long ret;
+  uintptr_t ret;
 
   /* 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)
 
   final (a, b, c);
 
-  if (sizeof (unsigned long) == 8)
-    ret = (((unsigned long) c) << 32) | b;
+  if (sizeof (uintptr_t) == 8)
+    ret = (((uintptr_t) c) << 32) | b;
   else
     ret = c;
 
@@ -231,16 +231,16 @@ scm_i_utf8_string_hash (const char *str, size_t len)
   return ret;
 }
 
-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);
 
 /* 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;
 
   struct_size = SCM_STRUCT_SIZE (obj);
 
@@ -260,7 +260,7 @@ scm_i_struct_hash (SCM obj, size_t depth)
 
 /* 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)
 }
 
 /* `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 = SCM_SIMPLE_VECTOR_LENGTH (obj);
         size_t i = depth / 2;
-        unsigned long h = scm_raw_ihashq (SCM_CELL_WORD_0 (obj));
+        uintptr_t h = scm_raw_ihashq (SCM_CELL_WORD_0 (obj));
         if (len)
           while (i--)
             h ^= 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 = scm_raw_ihash (scm_syntax_expression (obj), depth);
         h ^= scm_raw_ihash (scm_syntax_wrap (obj), depth);
         h ^= 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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  uintptr_t sz = 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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  uintptr_t sz = 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 = scm_to_unsigned_integer (size, 1, ULONG_MAX);
+  uintptr_t sz = 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 @@
 \f
 
 #include "libguile/scm.h"
+#include "libguile/numbers.h"
 
 \f
 
-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 len);
+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);
 
-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 @@
 
    Contributed to the GNU project by Niels Möller
 
-Copyright 1991-1997, 1999-2019 Free Software Foundation, Inc.
+Copyright 1991-1997, 1999-2019,2021 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -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)
 
-#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))
 
 #define GMP_ABS(x) ((x) >= 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 >= 2 * GMP_LIMB_BITS)			\
       {									\
-	unsigned long int __ww = (unsigned long int) (u) * (v);		\
+	uintptr_t __ww = (uintptr_t) (u) * (v);		                \
 	w0 = (mp_limb_t) __ww;						\
 	w1 = (mp_limb_t) (__ww >> LOCAL_GMP_LIMB_BITS);			\
       }									\
@@ -1462,25 +1462,25 @@ mpz_realloc (mpz_t r, mp_size_t size)
 \f
 /* 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 >= 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 = -1;
-      MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (unsigned long int, x);
+      MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (uintptr_t, x);
     }
 }
 
 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)
 }
 
 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);
 }
 
 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 == 0 || mpz_cmp_ui (u, LONG_MAX) <= 0) &&
-    mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, LONG_MIN)) <= 0;
+  return (INTPTR_MAX + INTPTR_MIN == 0 || mpz_cmp_ui (u, INTPTR_MAX) <= 0) &&
+    mpz_cmpabs_ui (u, GMP_NEG_CAST (uintptr_t, INTPTR_MIN)) <= 0;
 }
 
 static int
@@ -1565,26 +1565,26 @@ mpz_fits_ulong_p (const mpz_t u)
   return us >= 0 && mpn_absfits_ulong_p (u->_mp_d, us);
 }
 
-long int
+intptr_t
 mpz_get_si (const mpz_t u)
 {
-  unsigned long r = mpz_get_ui (u);
-  unsigned long c = -LONG_MAX - LONG_MIN;
+  uintptr_t r = mpz_get_ui (u);
+  uintptr_t c = -INTPTR_MAX - INTPTR_MIN;
 
   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);
 }
 
-unsigned long int
+uintptr_t
 mpz_get_ui (const mpz_t u)
 {
   if (GMP_LIMB_BITS < GMP_ULONG_BITS)
     {
       int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;
-      unsigned long r = 0;
+      uintptr_t r = 0;
       mp_size_t n = GMP_ABS (u->_mp_size);
       n = GMP_MIN (n, 1 + (mp_size_t) (GMP_ULONG_BITS - 1) / GMP_LIMB_BITS);
       while (--n >= 0)
@@ -1827,7 +1827,7 @@ mpz_sgn (const mpz_t u)
 }
 
 int
-mpz_cmp_si (const mpz_t u, long v)
+mpz_cmp_si (const mpz_t u, intptr_t v)
 {
   mp_size_t usize = u->_mp_size;
 
@@ -1836,11 +1836,11 @@ mpz_cmp_si (const mpz_t u, long v)
   else if (usize >= 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));
 }
 
 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 = u->_mp_size;
 
@@ -1865,7 +1865,7 @@ mpz_cmp (const mpz_t a, const mpz_t b)
 }
 
 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 = GMP_ABS (u->_mp_size);
 
@@ -1873,7 +1873,7 @@ mpz_cmpabs_ui (const mpz_t u, unsigned long v)
     return 1;
   else
     {
-      unsigned long uu = mpz_get_ui (u);
+      uintptr_t uu = mpz_get_ui (u);
       return GMP_CMP(uu, v);
     }
 }
@@ -1912,7 +1912,7 @@ mpz_swap (mpz_t u, mpz_t v)
 
 
 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)
 }
 
 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);
 }
 
 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)
 \f
 /* 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)
 }
 
 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 bits)
 }
 
 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)
 }
 
 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, const mpz_t m)
   return res;
 }
 
-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;
 
   mpz_init (rr);
@@ -2530,90 +2530,90 @@ mpz_div_qr_ui (mpz_t q, mpz_t r,
   return ret;
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
-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);
 }
 
 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));
 }
 
 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) == 0;
 }
@@ -2663,8 +2663,8 @@ mpn_gcd_11 (mp_limb_t u, mp_limb_t v)
   return u << shift;
 }
 
-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 == 0)
     {
       /* g = 0 u + sgn(v) v */
-      signed long sign = mpz_sgn (v);
+      intptr_t sign = mpz_sgn (v);
       mpz_abs (g, v);
       if (s)
 	s->_mp_size = 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 == 0)
     {
       /* g = sgn(u) u + 0 v */
-      signed long sign = mpz_sgn (u);
+      intptr_t sign = 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)
 }
 
 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 == 0 || u->_mp_size == 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) */
 
 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);
 
@@ -3032,7 +3032,7 @@ mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e)
 }
 
 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;
 
@@ -3147,7 +3147,7 @@ mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, const mpz_t m)
 }
 
 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;
 
@@ -3158,7 +3158,7 @@ mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long elimb, const mpz_t m)
 
 /* x=trunc(y^(1/z)), r=y-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, unsigned long z)
 }
 
 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_size_t n)
 /* Combinatorics */
 
 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 == 0));
   if (m + 1 < 2) return;
@@ -3298,19 +3298,19 @@ mpz_mfac_uiui (mpz_t x, unsigned long n, unsigned long m)
 }
 
 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);
 }
 
 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);
 }
 
 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;
 
@@ -3389,10 +3389,10 @@ gmp_lucas_step_k_2k (mpz_t V, mpz_t Qk, const mpz_t n)
 
 /* Computes V_k, Q^k (mod n) for the Lucas' sequence */
 /* with P=1, Q=Q; k = (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 == 0) and sets V=V_k and Qk=Q^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;
 
   assert (b0 > 0);
-  assert (Q <= - (LONG_MIN / 2));
-  assert (Q >= - (LONG_MAX / 2));
+  assert (Q <= - (INTPTR_MIN / 2));
+  assert (Q >= - (INTPTR_MAX / 2));
   assert (mpz_cmp_ui (n, 4) > 0);
   assert (mpz_odd_p (n));
 
@@ -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;
 
   /* Test on the absolute value. */
@@ -3490,7 +3490,7 @@ gmp_stronglucas (const mpz_t x, mpz_t Qk)
   b0 = mpz_scan0 (n, 0);
 
   /* D= P^2 - 4Q; P = 1; Q = (1-D)/4 */
-  Q = (D & 2) ? (long) (D >> 2) + 1 : -(long) (D >> 2);
+  Q = (D & 2) ? (intptr_t) (D >> 2) + 1 : -(intptr_t) (D >> 2);
 
   if (! gmp_lucas_mod (V, Qk, Q, b0, n))	/* If Ud != 0 */
     while (V->_mp_size != 0 && --b0 != 0)	/* while Vk != 0 */
@@ -3584,7 +3584,7 @@ mpz_probab_prime_p (const mpz_t n, int reps)
 
   for (j = 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) >= 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.
 
-Copyright 2011-2015, 2017, 2019-2020 Free Software Foundation, Inc.
+Copyright 2011-2015, 2017, 2019-2021 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -53,17 +53,14 @@ void mp_get_memory_functions (void *(**) (size_t),
 			      void *(**) (void *, size_t, size_t),
 			      void (**) (void *, size_t));
 
-#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;
 
 typedef mp_limb_t *mp_ptr;
 typedef const mp_limb_t *mp_srcptr;
 
+
 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))
 
 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);
 
-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);
 
-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);
 
 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);
 
-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);
 
-unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long);
+uintptr_t mpz_mod_ui (mpz_t, const mpz_t, uintptr_t);
 
-void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long);
+void mpz_divexact_ui (mpz_t, const mpz_t, uintptr_t);
 
-int mpz_divisible_ui_p (const mpz_t, unsigned long);
+int mpz_divisible_ui_p (const mpz_t, uintptr_t);
 
-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);
 
@@ -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);
 
-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);
 
-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);
 
-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);
 
 int mpz_probab_prime_p (const mpz_t, int);
 
@@ -244,8 +241,8 @@ mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);
 
 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);
 
 #define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
 
-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);
 
-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);
 
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 == 2);
 
-/* Make sure that scm_t_inum fits within a SCM value.  */
-verify (sizeof (scm_t_inum) <= sizeof (scm_t_bits));
+/* Make sure that intptr_t fits within a SCM value.  */
+verify (sizeof (intptr_t) <= sizeof (scm_t_bits));
+
+#if !(__MINGW32__ && __x86_64__)
+#define L1 1L
+#else /* (__MINGW32__ && __x86_64__) */
+#define L1 1LL
+#endif /* (__MINGW32__ && __x86_64__) */
 
 /* 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 <= SCM_LONG_BIT - 2);
+verify (SCM_I_FIXNUM_BIT <= SCM_INTPTR_T_BIT - 2);
 
 /* 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 <= (mp_limb_t) -1);
 
-#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 <= 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))
 
 #if (! HAVE_DECL_MPZ_INITS) || SCM_ENABLE_MINI_GMP
 
@@ -299,17 +303,8 @@ scm_i_mkbig ()
   return z;
 }
 
-static SCM
-scm_i_inum2big (scm_t_inum x)
-{
-  /* Return a newly created bignum initialized to X. */
-  SCM z = 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 = make_bignum ();
@@ -318,7 +313,7 @@ scm_i_long2big (long x)
 }
 
 SCM
-scm_i_ulong2big (unsigned long x)
+scm_i_untptr2big (uintptr_t x)
 {
   /* Return a newly created bignum initialized to X. */
   SCM z = make_bignum ();
@@ -377,7 +372,7 @@ scm_i_dbl2num (double u)
 
   if (u < (double) (SCM_MOST_POSITIVE_FIXNUM+1)
       && u >= (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 = mpz_get_si (SCM_I_BIG_MPZ (b));
+      intptr_t val = mpz_get_si (SCM_I_BIG_MPZ (b));
       if (SCM_FIXABLE (val))
         b = 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 = mpz_get_si (b);
+      intptr_t val = 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 = SCM_I_INUM (n);
-      return scm_from_bool ((val & 1L) != 0);
+      intptr_t val = SCM_I_INUM (n);
+      return scm_from_bool ((val & L1) != 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 = SCM_I_INUM (n);
-      return scm_from_bool ((val & 1L) == 0);
+      intptr_t val = SCM_I_INUM (n);
+      return scm_from_bool ((val & L1) == 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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (xx >= 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 = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       if (SCM_LIKELY (SCM_I_INUMP (d)))
 	{
-	  scm_t_inum dd = SCM_I_INUM (d);
+	  intptr_t dd = SCM_I_INUM (d);
 	  if (SCM_UNLIKELY (dd == 0))
 	    scm_num_overflow ("exact-integer-quotient");
 	  else
 	    {
-	      scm_t_inum qq = nn / dd;
+	      intptr_t qq = 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 = SCM_I_INUM (d);
+	  intptr_t dd = SCM_I_INUM (d);
 	  if (SCM_UNLIKELY (dd == 0))
 	    scm_num_overflow ("exact-integer-quotient");
 	  else if (SCM_UNLIKELY (dd == 1))
@@ -1228,12 +1223,12 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, "floor-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
-	  scm_t_inum xx1 = xx;
-	  scm_t_inum qq;
+	  intptr_t yy = SCM_I_INUM (y);
+	  intptr_t xx1 = 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-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))
 	{
@@ -1270,7 +1265,7 @@ SCM_PRIMITIVE_GENERIC (scm_floor_quotient, "floor-quotient", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_quotient);
 	  else if (SCM_UNLIKELY (yy == 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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_remainder);
 	  else
 	    {
-	      scm_t_inum rr = xx % yy;
+	      intptr_t rr = xx % yy;
 	      int needs_adjustment;
 
 	      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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_remainder);
 	  else
 	    {
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      if (yy > 0)
 		rr = 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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
 	      int needs_adjustment;
 
 	      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 = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_floor_divide);
 	  else
@@ -1739,16 +1734,16 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_quotient, "ceiling-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_quotient);
 	  else
 	    {
-	      scm_t_inum xx1 = xx;
-	      scm_t_inum qq;
+	      intptr_t xx1 = xx;
+	      intptr_t qq;
 	      if (SCM_LIKELY (yy > 0))
 		{
 		  if (SCM_LIKELY (xx >= 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_quotient);
 	  else if (SCM_UNLIKELY (yy == 1))
@@ -1900,15 +1895,15 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_remainder, "ceiling-remainder", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_remainder);
 	  else
 	    {
-	      scm_t_inum rr = xx % yy;
+	      intptr_t rr = xx % yy;
 	      int needs_adjustment;
 
 	      if (SCM_LIKELY (yy > 0))
@@ -1969,12 +1964,12 @@ SCM_PRIMITIVE_GENERIC (scm_ceiling_remainder, "ceiling-remainder", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_remainder);
 	  else
 	    {
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      if (yy > 0)
 		rr = -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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
 	      int needs_adjustment;
 
 	      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 = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_ceiling_divide);
 	  else
@@ -2287,19 +2282,19 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_quotient, "truncate-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_quotient);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
+	      intptr_t qq = 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, "truncate-quotient", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_quotient);
 	  else if (SCM_UNLIKELY (yy == 1))
@@ -2428,10 +2423,10 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_remainder, "truncate-remainder", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_remainder);
 	  else
@@ -2462,12 +2457,12 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_remainder, "truncate-remainder", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_remainder);
 	  else
 	    {
-	      scm_t_inum rr = (mpz_tdiv_ui (SCM_I_BIG_MPZ (x),
+	      intptr_t rr = (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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
 	      if (SCM_LIKELY (SCM_FIXABLE (qq)))
 		*qp = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_truncate_divide);
 	  else
 	    {
 	      SCM q = scm_i_mkbig ();
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      if (yy > 0)
 		rr = 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, "centered-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_quotient);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
 	      if (SCM_LIKELY (xx > 0))
 		{
 		  if (SCM_LIKELY (yy > 0))
@@ -2781,14 +2776,14 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "centered-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, "centered-quotient", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_quotient);
 	  else if (SCM_UNLIKELY (yy == 1))
@@ -2810,7 +2805,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quotient, "centered-quotient", 2, 0, 0,
 	  else
 	    {
 	      SCM q = 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, "centered-remainder", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_remainder);
 	  else
 	    {
-	      scm_t_inum rr = xx % yy;
+	      intptr_t rr = xx % yy;
 	      if (SCM_LIKELY (xx > 0))
 		{
 		  if (SCM_LIKELY (yy > 0))
@@ -3002,7 +2997,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_remainder, "centered-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, "centered-remainder", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = 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 = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_centered_divide);
 	  else
 	    {
 	      SCM q = 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-quotient", 2, 0, 0,
 {
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_quotient);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
-	      scm_t_inum ay = yy;
-	      scm_t_inum r2 = 2 * rr;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
+	      intptr_t ay = yy;
+	      intptr_t r2 = 2 * rr;
 
 	      if (SCM_LIKELY (yy < 0))
 		{
@@ -3452,7 +3447,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quotient", 2, 0, 0,
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    qq++;
@@ -3469,14 +3464,14 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-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_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-quotient", 2, 0, 0,
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_quotient);
 	  else if (SCM_UNLIKELY (yy == 1))
@@ -3498,7 +3493,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_quotient, "round-quotient", 2, 0, 0,
 	  else
 	    {
 	      SCM q = scm_i_mkbig ();
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      int needs_adjustment;
 
 	      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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_remainder);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
-	      scm_t_inum ay = yy;
-	      scm_t_inum r2 = 2 * rr;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
+	      intptr_t ay = yy;
+	      intptr_t r2 = 2 * rr;
 
 	      if (SCM_LIKELY (yy < 0))
 		{
@@ -3658,7 +3653,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-remainder", 2, 0, 0,
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    rr -= yy;
@@ -3680,7 +3675,7 @@ SCM_PRIMITIVE_GENERIC (scm_round_remainder, "round-remainder", 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_remainder);
 	  else
 	    {
 	      SCM q = scm_i_mkbig ();
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      int needs_adjustment;
 
 	      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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_divide);
 	  else
 	    {
-	      scm_t_inum qq = xx / yy;
-	      scm_t_inum rr = xx % yy;
-	      scm_t_inum ay = yy;
-	      scm_t_inum r2 = 2 * rr;
+	      intptr_t qq = xx / yy;
+	      intptr_t rr = xx % yy;
+	      intptr_t ay = yy;
+	      intptr_t r2 = 2 * rr;
 
 	      if (SCM_LIKELY (yy < 0))
 		{
@@ -3886,7 +3881,7 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp)
 		  r2 = -r2;
 		}
 
-	      if (qq & 1L)
+	      if (qq & L1)
 		{
 		  if (r2 >= ay)
 		    { qq++; rr -= yy; }
@@ -3903,14 +3898,14 @@ scm_round_divide (SCM x, SCM y, SCM *qp, SCM *rp)
 	      if (SCM_LIKELY (SCM_FIXABLE (qq)))
 		*qp = SCM_I_MAKINUM (qq);
 	      else
-		*qp = scm_i_inum2big (qq);
+		*qp = scm_i_intptr2big (qq);
 	      *rp = 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, qp, 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (SCM_UNLIKELY (yy == 0))
 	    scm_num_overflow (s_scm_round_divide);
 	  else
 	    {
 	      SCM q = scm_i_mkbig ();
-	      scm_t_inum rr;
+	      intptr_t rr;
 	      int needs_adjustment;
 
 	      if (yy > 0)
@@ -4090,11 +4085,11 @@ scm_gcd (SCM x, SCM y)
     {
       if (SCM_LIKELY (SCM_I_INUMP (y)))
         {
-          scm_t_inum xx = SCM_I_INUM (x);
-          scm_t_inum yy = SCM_I_INUM (y);
-          scm_t_inum u = xx < 0 ? -xx : xx;
-          scm_t_inum v = yy < 0 ? -yy : yy;
-          scm_t_inum result;
+          intptr_t xx = SCM_I_INUM (x);
+          intptr_t yy = SCM_I_INUM (y);
+          intptr_t u = xx < 0 ? -xx : xx;
+          intptr_t v = yy < 0 ? -yy : yy;
+          intptr_t result;
           if (SCM_UNLIKELY (xx == 0))
 	    result = v;
 	  else if (SCM_UNLIKELY (yy == 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 = SCM_I_INUM (y);
           if (yy == 0)
@@ -4238,7 +4233,7 @@ scm_lcm (SCM n1, SCM n2)
         inumbig:
           {
             SCM result = scm_i_mkbig ();
-            scm_t_inum nn1 = SCM_I_INUM (n1);
+            intptr_t nn1 = SCM_I_INUM (n1);
             if (nn1 == 0) return SCM_INUM0;
             if (nn1 < 0) nn1 = - 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;
 
   if (SCM_UNBNDP (n2))
     {
@@ -4369,7 +4364,7 @@ SCM scm_logand (SCM n1, SCM n2)
       nn1 = SCM_I_INUM (n1);
       if (SCM_I_INUMP (n2))
 	{
-	  scm_t_inum nn2 = SCM_I_INUM (n2);
+	  intptr_t nn2 = 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;
 
   if (SCM_UNBNDP (n2))
     {
@@ -4457,7 +4452,7 @@ SCM scm_logior (SCM n1, SCM n2)
       nn1 = SCM_I_INUM (n1);
       if (SCM_I_INUMP (n2))
 	{
-	  long nn2 = SCM_I_INUM (n2);
+	  intptr_t nn2 = 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;
 
   if (SCM_UNBNDP (n2))
     {
@@ -4547,7 +4542,7 @@ SCM scm_logxor (SCM n1, SCM n2)
       nn1 = SCM_I_INUM (n1);
       if (SCM_I_INUMP (n2))
 	{
-	  scm_t_inum nn2 = SCM_I_INUM (n2);
+	  intptr_t nn2 = 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;
 
   if (SCM_I_INUMP (j))
     {
       nj = SCM_I_INUM (j);
       if (SCM_I_INUMP (k))
 	{
-	  scm_t_inum nk = SCM_I_INUM (k);
+	  intptr_t nk = 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,
 
   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 = 0;
+  intptr_t i2 = 0;
   SCM z_i2 = SCM_BOOL_F;
   int i2_is_big = 0;
-  SCM acc = SCM_I_MAKINUM (1L);
+  SCM acc = SCM_I_MAKINUM (L1);
 
   /* 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,
 
   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 = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
       /* Left shift of count >= 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 = scm_i_inum2big (nn);
+          SCM result = 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 = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
       if (count >= SCM_I_FIXNUM_BIT)
         return (nn >= 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 = SCM_I_INUM (n);
-          scm_t_inum qq = SCM_SRS (nn, count);
+          intptr_t nn = SCM_I_INUM (n);
+          intptr_t qq = SCM_SRS (nn, count);
 
-          if (0 == (nn & (1L << (count-1))))
+          if (0 == (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)
 
 /* '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 >= LONG_MIN + 1
-        && SCM_MOST_POSITIVE_FIXNUM <= LONG_MAX);
+verify (SCM_MOST_NEGATIVE_FIXNUM >= INTPTR_MIN + 1
+        && SCM_MOST_POSITIVE_FIXNUM <= INTPTR_MAX);
 
 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,
 
   if (SCM_I_INUMP (n))
     {
-      scm_t_inum in = SCM_I_INUM (n);
+      intptr_t in = SCM_I_INUM (n);
 
       /* When istart>=SCM_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 = scm_i_inum2big (in);
+          SCM result = 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,
 
       /* mask down to requisite bits */
       bits = 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 = 0;
-      scm_t_inum nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       if (nn < 0)
         nn = -1 - nn;
       while (nn)
@@ -5342,7 +5337,7 @@ SCM_DEFINE (scm_integer_length, "integer-length", 1, 0, 0,
     {
       unsigned long c = 0;
       unsigned int l = 4;
-      scm_t_inum nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       if (nn < 0)
 	nn = -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 = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = 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)
   
   if (SCM_I_INUMP (x))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  double xxd = SCM_REAL_VALUE (x);
 	  double yyd = yy;
 
@@ -7402,10 +7397,10 @@ scm_min (SCM x, SCM y)
   
   if (SCM_I_INUMP (x))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = 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 = SCM_I_INUM (x);
-          scm_t_inum yy = SCM_I_INUM (y);
-          scm_t_inum z = xx + yy;
-          return SCM_FIXABLE (z) ? SCM_I_MAKINUM (z) : scm_i_inum2big (z);
+          intptr_t xx = SCM_I_INUM (x);
+          intptr_t yy = SCM_I_INUM (y);
+          intptr_t z = 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 = SCM_I_INUM (x);
+          intptr_t xx = SCM_I_INUM (x);
           return scm_i_from_double (xx + SCM_REAL_VALUE (y));
         }
       else if (SCM_COMPLEXP (y))
         {
-          scm_t_inum xx = SCM_I_INUM (x);
+          intptr_t xx = 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 = SCM_I_INUM (y);      
@@ -7767,11 +7762,11 @@ scm_difference (SCM x, SCM y)
       else 
         if (SCM_I_INUMP (x))
           {
-            scm_t_inum xx = -SCM_I_INUM (x);
+            intptr_t xx = -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 = SCM_I_INUM (x);
-	  scm_t_inum yy = SCM_I_INUM (y);
-	  scm_t_inum z = xx - yy;
+	  intptr_t xx = SCM_I_INUM (x);
+	  intptr_t yy = SCM_I_INUM (y);
+	  intptr_t z = 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 = SCM_I_INUM (x);
+	  intptr_t xx = SCM_I_INUM (x);
 
 	  if (xx == 0)
 	    {
@@ -7837,7 +7832,7 @@ scm_difference (SCM x, SCM y)
 	}
       else if (SCM_REALP (y))
 	{
-	  scm_t_inum xx = SCM_I_INUM (x);
+	  intptr_t xx = SCM_I_INUM (x);
 
 	  /*
 	   * We need to handle x == exact 0
@@ -7857,7 +7852,7 @@ scm_difference (SCM x, SCM y)
 	}
       else if (SCM_COMPLEXP (y))
 	{
-	  scm_t_inum xx = SCM_I_INUM (x);
+	  intptr_t xx = SCM_I_INUM (x);
 
 	  /* We need to handle x == 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  int sgn_x = mpz_sgn (SCM_I_BIG_MPZ (x));
 
 	  scm_remember_upto_here_1 (x);
 	  if (sgn_x == 0)
 	    return (SCM_FIXABLE (-yy) ?
-		    SCM_I_MAKINUM (-yy) : scm_from_inum (-yy));
+		    SCM_I_MAKINUM (-yy) : scm_from_intptr (-yy));
 	  else
 	    {
 	      SCM result = 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)
   
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx;
+      intptr_t xx;
 
     xinum:
       xx = SCM_I_INUM (x);
@@ -8092,20 +8087,20 @@ scm_product (SCM x, SCM y)
 
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 #if SCM_I_FIXNUM_BIT < 32 && SCM_HAVE_T_INT64
           int64_t kk = xx * (int64_t) yy;
           if (SCM_FIXABLE (kk))
             return SCM_I_MAKINUM (kk);
 #else
-          scm_t_inum axx = (xx > 0) ? xx : -xx;
-          scm_t_inum ayy = (yy > 0) ? yy : -yy;
+          intptr_t axx = (xx > 0) ? xx : -xx;
+          intptr_t ayy = (yy > 0) ? yy : -yy;
           if (SCM_MOST_POSITIVE_FIXNUM / axx >= ayy)
             return SCM_I_MAKINUM (xx * yy);
 #endif
 	  else
 	    {
-	      SCM result = scm_i_inum2big (xx);
+	      SCM result = 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 = SCM_I_INUM (x);
+	  intptr_t xx = SCM_I_INUM (x);
 	  if (xx == 1 || xx == -1)
 	    return x;
 #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO
@@ -8369,10 +8364,10 @@ scm_divide (SCM x, SCM y)
 
   if (SCM_LIKELY (SCM_I_INUMP (x)))
     {
-      scm_t_inum xx = SCM_I_INUM (x);
+      intptr_t xx = SCM_I_INUM (x);
       if (SCM_LIKELY (SCM_I_INUMP (y)))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (yy == 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 = xx / yy;
+	      intptr_t z = 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 = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 	  if (yy == 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. */
 
-	      scm_t_inum abs_yy = yy < 0 ? -yy : yy;
+	      intptr_t abs_yy = yy < 0 ? -yy : yy;
 	      int divisible_p = mpz_divisible_ui_p (SCM_I_BIG_MPZ (x), abs_yy);
 
 	      if (divisible_p)
@@ -8522,14 +8517,14 @@ scm_divide (SCM x, SCM y)
       double rx = SCM_REAL_VALUE (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO
 	  if (yy == 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 = SCM_COMPLEX_IMAG (x);
       if (SCM_I_INUMP (y))
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO
 	  if (yy == 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 = 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)) 
 	{
-	  scm_t_inum yy = SCM_I_INUM (y);
+	  intptr_t yy = SCM_I_INUM (y);
 #ifndef ALLOW_DIVIDE_BY_EXACT_ZERO
 	  if (yy == 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 = SCM_I_INUM (z);
+      intptr_t zz = SCM_I_INUM (z);
       if (zz >= 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 = mpz_get_si (SCM_I_BIG_MPZ (val));
+	      intptr_t n = mpz_get_si (SCM_I_BIG_MPZ (val));
 	      return n >= min && n <= max;
 	    }
 	  else
@@ -9758,7 +9753,7 @@ scm_is_unsigned_integer (SCM val, uintmax_t min, uintmax_t max)
 	{
 	  if (mpz_fits_ulong_p (SCM_I_BIG_MPZ (val)))
 	    {
-	      unsigned long n = mpz_get_ui (SCM_I_BIG_MPZ (val));
+	      uintptr_t n = mpz_get_ui (SCM_I_BIG_MPZ (val));
 	      return n >= min && n <= max;
 	    }
 	  else
@@ -10302,19 +10297,19 @@ SCM_PRIMITIVE_GENERIC (scm_sqrt, "sqrt", 1, 0, 0,
     {
       if (SCM_I_INUMP (z))
         {
-          scm_t_inum x = SCM_I_INUM (z);
+          intptr_t x = SCM_I_INUM (z);
 
           if (SCM_LIKELY (x >= 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 = sqrt (x);
 
                   /* If 0 <= x < 2^(DBL_MANT_DIG-1) and sqrt(x) is an
                      integer, then the result is exact. */
                   if (root == 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))
 
 /* SCM_SRS (X, Y) is signed right shift, defined as floor (X / 2^Y),
@@ -85,12 +92,12 @@ typedef long scm_t_inum;
 
    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
 
 #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 same_sign_p);
 
+SCM scm_i_intptr2big (intptr_t x);
+SCM scm_i_untptr2big (uintptr_t x);
+
+#if SIZEOF_INTPTR == 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
 
-#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
 
 \f
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.
 
    This file is part of Guile.
@@ -414,9 +414,9 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
     query_only = 1;
   else if (scm_is_integer (handler))
     {
-      long handler_int = scm_to_long (handler);
+      intptr_t handler_int = scm_to_intptr (handler);
 
-      if (handler_int == (long) SIG_DFL || handler_int == (long) SIG_IGN)
+      if (handler_int == (intptr_t) SIG_DFL || handler_int == (intptr_t) SIG_IGN)
 	{
 #ifdef HAVE_SIGACTION
 	  action.sa_handler = (SIGRETTYPE (*) (int)) handler_int;
@@ -512,7 +512,7 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
 	orig_handlers[csig] = old_action;
     }
   if (old_action.sa_handler == SIG_DFL || old_action.sa_handler == SIG_IGN)
-    old_handler = scm_from_long ((long) old_action.sa_handler);
+    old_handler = scm_from_intptr ((intptr_t) old_action.sa_handler);
 
   scm_dynwind_end ();
 
@@ -533,7 +533,7 @@ SCM_DEFINE (scm_sigaction_for_thread, "sigaction", 1, 3, 0,
 	orig_handlers[csig] = old_chandler;
     }
   if (old_chandler == SIG_DFL || old_chandler == SIG_IGN)
-    old_handler = scm_from_long ((long) old_chandler);
+    old_handler = scm_from_intptr ((intptr_t) old_chandler);
 
   scm_dynwind_end ();
 
@@ -803,8 +803,8 @@ scm_init_scmsigs ()
 #endif
 
   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
 
-   Copyright 2005-2006,2008,2010,2014,2018
+   Copyright 2005-2006,2008,2010,2014,2018,2021
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -53,7 +53,7 @@ SCM_DEFINE (scm_srfi60_log2_binary_factors, "log2-binary-factors", 1, 0, 0,
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       if (nn == 0)
         return SCM_I_MAKINUM (-1);
       nn = 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;
 
-  ii = scm_to_ulong (index);
+  ii = scm_to_uintptr (index);
   bb = scm_to_bool (newbit);
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
-      /* can't set high bit ii==SCM_LONG_BIT-1, that would change the sign,
+      /* can't set high bit ii==SCM_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 &= ~(1L << ii);  /* zap bit at index */
-          nn |= ((long) bb << ii);   /* insert desired bit */
-          return scm_from_long (nn);
+          nn |= ((intptr_t) bb << ii);   /* insert desired bit */
+          return scm_from_intptr (nn);
         }
       else
         {
-          /* bits at ii==SCM_LONG_BIT-1 and above are all copies of the sign
+          /* bits at ii==SCM_INTPTR_T_BIT-1 and above are all copies of the sign
              bit, if this is already the desired "bit" value then no need to
              make a new bignum value */
           if (bb == (nn < 0))
             return n;
 
-          r = scm_i_long2big (nn);
+          r = scm_i_intptr2big (nn);
           goto big;
         }
     }
@@ -152,9 +152,9 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
 	    "@end example")
 #define FUNC_NAME s_scm_srfi60_rotate_bit_field
 {
-  unsigned long ss = scm_to_ulong (start);
-  unsigned long ee = scm_to_ulong (end);
-  unsigned long ww, cc;
+  uintptr_t ss = scm_to_uintptr (start);
+  uintptr_t ee = scm_to_uintptr (end);
+  uintptr_t ww, cc;
 
   SCM_ASSERT_RANGE (3, end, (ee >= ss));
   ww = ee - ss;
@@ -164,43 +164,44 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
   if (ww <= 1)
     cc = 0;
   else
-    cc = scm_to_ulong (scm_modulo (count, scm_difference (end, start)));
+    cc = scm_to_uintptr (scm_modulo (count, scm_difference (end, start)));
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
-      if (ee <= SCM_LONG_BIT-1)
+      if (ee <= 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 = nn;
-          unsigned long below = unn &  ((1UL << ss) - 1);  /* below start */
-          unsigned long above = unn & ~((1UL << ee) - 1);  /* above end */
-          unsigned long fmask = ((1UL << ww) - 1) << ss;   /* field mask */
-          unsigned long ff = unn & fmask;                  /* field */
-          unsigned long uresult = (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 = nn;
+          uintptr_t below = unn &  ((1UL << ss) - 1);  /* below start */
+          uintptr_t above = unn & ~((1UL << ee) - 1);  /* above end */
+          uintptr_t fmask = ((1UL << ww) - 1) << ss;   /* field mask */
+          uintptr_t ff = unn & fmask;                  /* field */
+          uintptr_t uresult = (above
                                    | ((ff << cc) & fmask)
                                    | ((ff >> (ww-cc)) & fmask)
                                    | below);
-          long result;
+          intptr_t result;
 
-          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 = -1 - (long) ~uresult;
+            result = -1 - (intptr_t) ~uresult;
           else
-            result = (long) uresult;
+            result = (intptr_t) uresult;
 
-          return scm_from_long (result);
+          return scm_from_intptr (result);
         }
       else
         {
@@ -208,7 +209,7 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
           if (cc == 0)
             return n;
 
-          n = scm_i_long2big (nn);
+          n = scm_i_intptr2big (nn);
           goto big;
         }
     }
@@ -222,7 +223,7 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
         return n;
 
     big:
-      r = scm_i_ulong2big (0);
+      r = scm_i_untptr2big (0);
       mpz_init (tmp);
 
       /* portion above end */
@@ -266,31 +267,31 @@ SCM_DEFINE (scm_srfi60_reverse_bit_field, "reverse-bit-field", 3, 0, 0,
 	    "@end example")
 #define FUNC_NAME s_scm_srfi60_reverse_bit_field
 {
-  long ss = scm_to_long (start);
-  long ee = scm_to_long (end);
-  long swaps = (ee - ss) / 2;  /* number of swaps */
+  intptr_t ss = scm_to_intptr (start);
+  intptr_t ee = scm_to_intptr (end);
+  intptr_t swaps = (ee - ss) / 2;  /* number of swaps */
   SCM b;
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
 
-      if (ee <= SCM_LONG_BIT-1)
+      if (ee <= SCM_INTPTR_T_BIT-1)
         {
-          /* all within a long */
-          long smask = 1L << ss;
-          long emask = 1L << (ee-1);
+          /* all within a intptr_t */
+          intptr_t smask = 1L << ss;
+          intptr_t emask = 1L << (ee-1);
           for ( ; swaps > 0; swaps--)
             {
-              long sbit = nn & smask;
-              long ebit = nn & emask;
+              intptr_t sbit = nn & smask;
+              intptr_t ebit = nn & emask;
               nn ^= sbit ^ (ebit ? smask : 0)  /* zap sbit, put ebit value */
                 ^   ebit ^ (sbit ? emask : 0); /* zap ebit, put sbit value */
 
               smask <<= 1;
               emask >>= 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 <= 1)
             return n;
 
-          b = scm_i_long2big (nn);
+          b = scm_i_intptr2big (nn);
           goto big;
         }
     }
@@ -358,20 +359,20 @@ SCM_DEFINE (scm_srfi60_integer_to_list, "integer->list", 1, 1, 0,
 #define FUNC_NAME s_scm_srfi60_integer_to_list
 {
   SCM ret = SCM_EOL;
-  unsigned long ll, i;
+  uintptr_t ll, i;
 
   if (SCM_UNBNDP (len))
     len = scm_integer_length (n);
-  ll = scm_to_ulong (len);
+  ll = scm_to_uintptr (len);
 
   if (SCM_I_INUMP (n))
     {
-      long nn = SCM_I_INUM (n);
+      intptr_t nn = SCM_I_INUM (n);
       for (i = 0; i < ll; i++)
         {
-          unsigned long shift =
-	    (i < ((unsigned long) SCM_LONG_BIT-1)) 
-	    ? i : ((unsigned long) SCM_LONG_BIT-1);
+          uintptr_t shift =
+	    (i < ((uintptr_t) SCM_INTPTR_T_BIT-1))
+	    ? i : ((uintptr_t) SCM_INTPTR_T_BIT-1);
           int bit = (nn >> shift) & 1;
           ret = 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;
 
   /* 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 <= SCM_I_FIXNUM_BIT - 1)
     {
       /* fits an inum (a positive inum) */
-      long n = 0;
+      intptr_t n = 0;
       while (scm_is_pair (lst))
         {
           n <<= 1;
@@ -428,7 +429,7 @@ SCM_DEFINE (scm_srfi60_list_to_integer, "list->integer", 1, 0, 0,
   else
     {
       /* need a bignum */
-      SCM n = scm_i_ulong2big (0);
+      SCM n = 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.
 
    This file is part of Guile.
@@ -761,7 +761,7 @@ scm_i_string_set_x (SCM str, size_t p, scm_t_wchar chr)
 
 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 = STRING_LENGTH (name);
@@ -774,7 +774,7 @@ scm_i_make_symbol (SCM name, scm_t_bits flags,
 
 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 = 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;
 
   SCM_VALIDATE_STRING (1, str);
 
@@ -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;
 
   SCM_VALIDATE_STRING (1, str);
 
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
 
-/* 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.
 
    This file is part of Guile.
@@ -26,6 +26,7 @@
 #include <libguile/error.h>
 #include "libguile/inline.h"
 #include <libguile/snarf.h>
+#include "libguile/numbers.h"
 
 \f
 
@@ -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. */
 
 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);
-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com


[-- Attachment #3: Type: text/plain, Size: 152 bytes --]


-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-21 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 16:42 [PATCH] DRAFT Support for x86_64-w64-mingw32 Jan Nieuwenhuizen
2021-03-20 22:08 ` [PATCH v2] " Jan Nieuwenhuizen
2021-03-21 14:17   ` [PATCH v3] " Jan Nieuwenhuizen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).