unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Jan Nieuwenhuizen <janneke@gnu.org>
To: guile-devel@gnu.org
Subject: [PATCH] DRAFT Support for x86_64-w64-mingw32.
Date: Wed, 17 Mar 2021 17:42:22 +0100	[thread overview]
Message-ID: <87eegdratt.fsf@verum.com> (raw)

[-- 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

             reply	other threads:[~2021-03-17 16:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 16:42 Jan Nieuwenhuizen [this message]
2021-03-20 22:08 ` [PATCH v2] DRAFT Support for x86_64-w64-mingw32 Jan Nieuwenhuizen
2021-03-21 14:17   ` [PATCH v3] " Jan Nieuwenhuizen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eegdratt.fsf@verum.com \
    --to=janneke@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).