On Tue, 2023-06-06 at 20:50 +0000, Mike Gran wrote:
> Hello Guile,

Hi Mike,

I'm sorry for "necrobumping" this thread; I wanted to reply back in
June but didn't have enough time to work through what I will explain
further below. In any case, I would very much like to see good Windows
64-bit support in Guile to make use of it in LilyPond.

> [...]
> 
> I'd be willing [1] to update the patches for MinGW support for
> review and inclusion into the main branch
> for 3.0.10 or 3.2 but, only if maintainers are open, in principle,
> to committing the most disruptive patch: the one where all
> long integers become intptr_t to deal with Window's stupid
> 4-byte longs on 64-bit OSs.  Without agreeing on that as a
> possibility, 64-bit Windows support is DOA.

For a long time, I wasn't really convinced by this argument until I
realized that the alternative would complicate cross-compilation and
move away from the simple {32-bit, 64-bit} x {little-endian, big-
endian} matrix for the bytecode.

> There are a couple of slightly outdated versions of janekke's 64-bit patch.
> Here, for example:
> 
> https://git.savannah.gnu.org/cgit/guile.git/commit/?h=wip-mingw&id=76950b4281c7dfff78b9ead6d3d62c070bbc1f13

If I understand correctly, one of the contentious points of this commit
(apart from being big and having many changes in one) is that it moves
GMP away from long. IIRC there was a statement somewhere that GMP will
not change their APIs, which basically means that Guile on Windows
would forever be stuck with a quite significantly patched mini-gmp.

I would like to propose a different approach: It turns out to be
possible to just define scm_t_inum as intptr_t, while leaving GMP
interfaces alone (be that mini-gmp or a full GMP). Instead, the
mismatch in type widths can be handled during the conversion to mpz.
For a practical implementation, see the fourth patch attached to this
message.

Afterwards, the fifth patch takes care of the hashes, which are
expected to have the same width as pointers. This is required because
(at least) hashes of symbols are stored into the bytecode. Taken
together, this seems to enable enough functionality to run LilyPond
with Guile 3 on Windows.

What do you and others think of this approach, would this be "more"
acceptable to land in main?

Jonas
From 996ddfa286434b242f89fae776241c196169a4a1 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <hah...@hahnjo.de>
Date: Wed, 30 Aug 2023 17:07:10 +0200
Subject: [PATCH 1/5] scm_i_divide2double: Refactor to use scm_to_mpz

* libguile/numbers.c (scm_i_divide2double): Refactor to use scm_to_mpz.
---
 libguile/numbers.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/libguile/numbers.c b/libguile/numbers.c
index 30a826f13..18fa21b6d 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -294,16 +294,11 @@ scm_i_divide2double (SCM n, SCM d)
           else
             return 0.0 / 0.0;
         }
-
-      mpz_init_set_si (dd, SCM_I_INUM (d));
     }
-  else
-    scm_integer_init_set_mpz_z (scm_bignum (d), dd);
 
-  if (SCM_I_INUMP (n))
-    mpz_init_set_si (nn, SCM_I_INUM (n));
-  else
-    scm_integer_init_set_mpz_z (scm_bignum (n), nn);
+  mpz_inits (nn, dd, lo, hi, x, NULL);
+  scm_to_mpz (d, dd);
+  scm_to_mpz (n, nn);
 
   neg = (mpz_sgn (nn) < 0) ^ (mpz_sgn (dd) < 0);
   mpz_abs (nn, nn);
@@ -351,7 +346,6 @@ scm_i_divide2double (SCM n, SCM d)
 
   /* Compute the initial values of lo, x, and hi
      based on the initial guess of e */
-  mpz_inits (lo, hi, x, NULL);
   mpz_mul_2exp (x, nn, 2 + ((e < 0) ? -e : 0));
   mpz_mul (lo, dd, scm_i_divide2double_lo2b);
   if (e > 0)
-- 
2.42.0

From 3b94097c6ce0d2c92a156dad5a0c7c43071f23d5 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <hah...@hahnjo.de>
Date: Wed, 30 Aug 2023 17:36:30 +0200
Subject: [PATCH 2/5] scm_integer_modulo_expt_nnn: Refactor to use scm_to_mpz

* libguile/integers.c (scm_integer_modulo_expt_nnn): Refactor to use
scm_to_mpz.
(integer_init_mpz): Remove helper function.
---
 libguile/integers.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/libguile/integers.c b/libguile/integers.c
index cc62d1c78..81ee06206 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -2318,21 +2318,6 @@ scm_integer_expt_zi (struct scm_bignum *n, scm_t_inum k)
   return take_mpz (res);
 }
 
-static void
-integer_init_mpz (mpz_ptr z, SCM n)
-{
-  if (SCM_I_INUMP (n))
-    mpz_init_set_si (z, SCM_I_INUM (n));
-  else
-    {
-      ASSERT (SCM_BIGP (n));
-      mpz_t zn;
-      alias_bignum_to_mpz (scm_bignum (n), zn);
-      mpz_init_set (z, zn);
-      scm_remember_upto_here_1 (n);
-    }
-}
-
 SCM
 scm_integer_modulo_expt_nnn (SCM n, SCM k, SCM m)
 {
@@ -2341,9 +2326,16 @@ scm_integer_modulo_expt_nnn (SCM n, SCM k, SCM m)
 
   mpz_t n_tmp, k_tmp, m_tmp;
 
-  integer_init_mpz (n_tmp, n);
-  integer_init_mpz (k_tmp, k);
-  integer_init_mpz (m_tmp, m);
+#if (! HAVE_DECL_MPZ_INITS) || SCM_ENABLE_MINI_GMP
+  mpz_init (n_tmp);
+  mpz_init (k_tmp);
+  mpz_init (m_tmp);
+#else
+  mpz_inits (n_tmp, k_tmp, m_tmp, NULL);
+#endif
+  scm_to_mpz (n, n_tmp);
+  scm_to_mpz (k, k_tmp);
+  scm_to_mpz (m, m_tmp);
 
   /* if the exponent K is negative, and we simply call mpz_powm, we
      will get a divide-by-zero exception when an inverse 1/n mod m
-- 
2.42.0

From 5a6e65e166c4c32bcc255275df2b8276acca1e41 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <hah...@hahnjo.de>
Date: Sat, 2 Sep 2023 16:38:59 +0200
Subject: [PATCH 3/5] Rename functions that should accept scm_t_inum

* libguile/integers.c (long_to_bignum): Rename to inum_to_bignum.
(long_to_scm): Rename to scm_from_inum.
---
 libguile/integers.c | 52 ++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/libguile/integers.c b/libguile/integers.c
index 81ee06206..b4090e5bf 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -245,7 +245,7 @@ ulong_to_bignum (unsigned long u)
 };
 
 static struct scm_bignum *
-long_to_bignum (long i)
+inum_to_bignum (scm_t_inum i)
 {
   if (i > 0)
     return ulong_to_bignum (i);
@@ -260,11 +260,11 @@ scm_from_bignum (struct scm_bignum *x)
 }
 
 static SCM
-long_to_scm (long i)
+scm_from_inum (scm_t_inum i)
 {
   if (SCM_FIXABLE (i))
     return SCM_I_MAKINUM (i);
-  return scm_from_bignum (long_to_bignum (i));
+  return scm_from_bignum (inum_to_bignum (i));
 }
 
 static SCM
@@ -328,7 +328,7 @@ take_mpz (mpz_ptr mpz)
 {
   SCM ret;
   if (mpz_fits_slong_p (mpz))
-    ret = long_to_scm (mpz_get_si (mpz));
+    ret = scm_from_inum (mpz_get_si (mpz));
   else
     ret = scm_from_bignum (make_bignum_from_mpz (mpz));
   mpz_clear (mpz);
@@ -516,7 +516,7 @@ scm_integer_abs_i (scm_t_inum i)
   if (i >= 0)
     return SCM_I_MAKINUM (i);
 
-  return ulong_to_scm (long_magnitude (i));
+  return scm_from_inum (-i);
 }
 
 SCM
@@ -541,7 +541,7 @@ scm_integer_floor_quotient_ii (scm_t_inum x, scm_t_inum y)
   else if (x > 0)
     x = x - y - 1;
   scm_t_inum q = x / y;
-  return long_to_scm (q);
+  return scm_from_inum (q);
 }
 
 SCM
@@ -675,7 +675,7 @@ scm_integer_floor_divide_ii (scm_t_inum x, scm_t_inum y, SCM *qp, SCM *rp)
       q--;
     }
 
-  *qp = long_to_scm (q);
+  *qp = scm_from_inum (q);
   *rp = SCM_I_MAKINUM (r);
 }
 
@@ -768,7 +768,7 @@ scm_integer_ceiling_quotient_ii (scm_t_inum x, scm_t_inum y)
     x = x + y + 1;
   scm_t_inum q = x / y;
 
-  return long_to_scm (q);
+  return scm_from_inum (q);
 }
 
 SCM
@@ -935,7 +935,7 @@ scm_integer_ceiling_divide_ii (scm_t_inum x, scm_t_inum y, SCM *qp, SCM *rp)
           r -= y;
           q++;
         }
-      *qp = long_to_scm (q);
+      *qp = scm_from_inum (q);
       *rp = SCM_I_MAKINUM (r);
     }
 }
@@ -1034,7 +1034,7 @@ scm_integer_truncate_quotient_ii (scm_t_inum x, scm_t_inum y)
   else
     {
       scm_t_inum q = x / y;
-      return long_to_scm (q);
+      return scm_from_inum (q);
     }
 }
 
@@ -1096,7 +1096,7 @@ scm_integer_truncate_remainder_ii (scm_t_inum x, scm_t_inum y)
   else
     {
       scm_t_inum q = x % y;
-      return long_to_scm (q);
+      return scm_from_inum (q);
     }
 }
 
@@ -1150,7 +1150,7 @@ scm_integer_truncate_divide_ii (scm_t_inum x, scm_t_inum y, SCM *qp, SCM *rp)
     {
       scm_t_inum q = x / y;
       scm_t_inum r = x % y;
-      *qp = long_to_scm (q);
+      *qp = scm_from_inum (q);
       *rp = SCM_I_MAKINUM (r);
     }
 }
@@ -1284,13 +1284,13 @@ scm_integer_centered_quotient_ii (scm_t_inum x, scm_t_inum y)
             q++;
         }
     }
-  return long_to_scm (q);
+  return scm_from_inum (q);
 }
 
 SCM
 scm_integer_centered_quotient_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  return integer_centered_quotient_zz (long_to_bignum (x),
+  return integer_centered_quotient_zz (inum_to_bignum (x),
                                        y);
 }
 
@@ -1409,7 +1409,7 @@ scm_integer_centered_remainder_ii (scm_t_inum x, scm_t_inum y)
 SCM
 scm_integer_centered_remainder_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  return integer_centered_remainder_zz (long_to_bignum (x),
+  return integer_centered_remainder_zz (inum_to_bignum (x),
                                         y);
 }
 
@@ -1525,14 +1525,14 @@ scm_integer_centered_divide_ii (scm_t_inum x, scm_t_inum y, SCM *qp, SCM *rp)
             { q++; r -= y; }
         }
     }
-  *qp = long_to_scm (q);
+  *qp = scm_from_inum (q);
   *rp = SCM_I_MAKINUM (r);
 }
 
 void
 scm_integer_centered_divide_iz (scm_t_inum x, struct scm_bignum *y, SCM *qp, SCM *rp)
 {
-  integer_centered_divide_zz (long_to_bignum (x), y, qp, rp);
+  integer_centered_divide_zz (inum_to_bignum (x), y, qp, rp);
 }
 
 void
@@ -1643,13 +1643,13 @@ scm_integer_round_quotient_ii (scm_t_inum x, scm_t_inum y)
       else if (r2 < -ay)
         q--;
     }
-  return long_to_scm (q);
+  return scm_from_inum (q);
 }
 
 SCM
 scm_integer_round_quotient_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  return integer_round_quotient_zz (long_to_bignum (x), y);
+  return integer_round_quotient_zz (inum_to_bignum (x), y);
 }
 
 SCM
@@ -1789,7 +1789,7 @@ scm_integer_round_remainder_ii (scm_t_inum x, scm_t_inum y)
 SCM
 scm_integer_round_remainder_iz (scm_t_inum x, struct scm_bignum *y)
 {
-  return integer_round_remainder_zz (long_to_bignum (x), y);
+  return integer_round_remainder_zz (inum_to_bignum (x), y);
 }
 
 SCM
@@ -1902,14 +1902,14 @@ scm_integer_round_divide_ii (scm_t_inum x, scm_t_inum y, SCM *qp, SCM *rp)
       else if (r2 < -ay)
         { q--; r += y; }
     }
-  *qp = long_to_scm (q);
+  *qp = scm_from_inum (q);
   *rp = SCM_I_MAKINUM (r);
 }
 
 void
 scm_integer_round_divide_iz (scm_t_inum x, struct scm_bignum *y, SCM *qp, SCM *rp)
 {
-  integer_round_divide_zz (long_to_bignum (x), y, qp, rp);
+  integer_round_divide_zz (inum_to_bignum (x), y, qp, rp);
 }
 
 void
@@ -2004,7 +2004,7 @@ scm_integer_gcd_ii (scm_t_inum x, scm_t_inum y)
         }
       result = u << k;
     }
-  return ulong_to_scm (result);
+  return scm_from_inum (result);
 }
 
 SCM
@@ -2831,7 +2831,7 @@ scm_integer_from_double (double val)
 SCM
 scm_integer_add_ii (scm_t_inum x, scm_t_inum y)
 {
-  return long_to_scm (x + y);
+  return scm_from_inum (x + y);
 }
 
 static SCM
@@ -2949,7 +2949,7 @@ scm_integer_add_zz (struct scm_bignum *x, struct scm_bignum *y)
 SCM
 scm_integer_negate_i (scm_t_inum x)
 {
-  return long_to_scm (-x);
+  return scm_from_inum (-x);
 }
 
 SCM
@@ -3229,7 +3229,7 @@ scm_integer_from_int32 (int32_t n)
 {
   if (SCM_FIXABLE (n))
     return SCM_I_MAKINUM (n);
-  return scm_from_bignum (long_to_bignum (n));
+  return scm_from_bignum (inum_to_bignum (n));
 }
 
 SCM
-- 
2.42.0

From 54e47a5c63b7e6a85522b158ed514ddf931a556e Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <hah...@hahnjo.de>
Date: Sat, 2 Sep 2023 16:15:37 +0200
Subject: [PATCH 4/5] Decouple scm_t_inum from long datatype

Guile expects that scm_t_inum (a typedef to long before this patch)
has the same size as pointers to get compatible bytecode on different
platforms. This assumption breaks on 64-bit Windows where longs are
still 32 bit. Instead use intptr_t as the underlying datatype.

Unfortunately, this comes with an additional challenge because GMP
functions accept unsigned longs as arguments. So instead, in such
configurations where long < scm_t_inum, split the values into two
longs to convert to mpz.

* libguile/scm.h: Define SCM_INTPTR_T_BIT.
* libguile/numbers.h (scm_t_inum): Typedef to intptr_t. Update the
definitions of SCM_I_FIXNUM_BIT and SCM_MOST_NEGATIVE_FIXNUM.
* libguile/numbers.c: Update verify.
(scm_to_mpz): Implement if SCM_LONG_BIT < SCM_I_FIXNUM_BIT.
* libguile/integers.c (inum_to_bignum, scm_integer_gcd_zi): Implement
if SCM_LONG_BIT < SCM_I_FIXNUM_BIT.
---
 libguile/integers.c | 12 ++++++++++++
 libguile/numbers.c  | 25 ++++++++++++++++++++++---
 libguile/numbers.h  | 10 ++++------
 libguile/scm.h      |  2 ++
 4 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/libguile/integers.c b/libguile/integers.c
index b4090e5bf..23bd2c0d5 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -247,10 +247,14 @@ ulong_to_bignum (unsigned long u)
 static struct scm_bignum *
 inum_to_bignum (scm_t_inum i)
 {
+#if SCM_LONG_BIT >= SCM_I_FIXNUM_BIT
   if (i > 0)
     return ulong_to_bignum (i);
 
   return i == 0 ? make_bignum_0 () : make_bignum_1 (1, long_magnitude (i));
+#else
+  return make_bignum_from_int64 (i);
+#endif
 };
 
 static inline SCM
@@ -2015,6 +2019,14 @@ scm_integer_gcd_zi (struct scm_bignum *x, scm_t_inum y)
     return scm_integer_abs_z (x);
   if (y < 0)
     y = -y;
+#if SCM_I_FIXNUM_BIT > SCM_LONG_BIT
+  if (y > ULONG_MAX)
+    {
+      struct scm_bignum *y_bignum = inum_to_bignum (y);
+      return scm_integer_gcd_zz (x, y_bignum);
+    }
+#endif
+
   mpz_t zx;
   alias_bignum_to_mpz (x, zx);
   result = mpz_gcd_ui (NULL, zx, y);
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 18fa21b6d..92c202c83 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -94,10 +94,10 @@ verify (FLT_RADIX == 2);
 /* Make sure that scm_t_inum fits within a SCM value.  */
 verify (sizeof (scm_t_inum) <= sizeof (scm_t_bits));
 
-/* Several functions below assume that fixnums fit within a long, and
+/* Several functions below assume that fixnums fit within an intptr_t, 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'.  */
@@ -6857,7 +6857,26 @@ void
 scm_to_mpz (SCM val, mpz_t rop)
 {
   if (SCM_I_INUMP (val))
-    mpz_set_si (rop, SCM_I_INUM (val));
+    {
+      scm_t_inum inum = SCM_I_INUM (val);
+#if SCM_LONG_BIT >= SCM_I_FIXNUM_BIT
+      // Cast to long and directly pass to GMP.
+      mpz_set_si (rop, (long)inum);
+#elif (2 * SCM_LONG_BIT) > SCM_I_FIXNUM_BIT
+      scm_t_inum inum_abs = inum;
+      if (inum < 0)
+        inum_abs *= -1;
+      long high = inum_abs >> (SCM_LONG_BIT - 1);
+      long low = (long)(inum_abs & ((((scm_t_inum)1) << (SCM_LONG_BIT - 1)) - 1));
+      mpz_set_si (rop, high);
+      mpz_mul_2exp (rop, rop, SCM_LONG_BIT - 1);
+      mpz_add_ui (rop, rop, low);
+      if (inum < 0)
+        mpz_neg (rop, rop);
+#else
+#error Unknown configuration
+#endif
+    }
   else if (SCM_BIGP (val))
     scm_integer_set_mpz_z (scm_bignum (val), rop);
   else
diff --git a/libguile/numbers.h b/libguile/numbers.h
index 84ad5466f..8bc87829a 100644
--- a/libguile/numbers.h
+++ b/libguile/numbers.h
@@ -52,12 +52,10 @@ extern "C++" {
  *
  * Inums are exact integers that fit within an SCM word
  * (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)
-#define SCM_MOST_NEGATIVE_FIXNUM (-1L << (SCM_I_FIXNUM_BIT - 1))
+ */
+typedef intptr_t scm_t_inum;
+#define SCM_I_FIXNUM_BIT         (SCM_INTPTR_T_BIT - 2)
+#define SCM_MOST_NEGATIVE_FIXNUM (((scm_t_inum) -1) << (SCM_I_FIXNUM_BIT - 1))
 #define SCM_MOST_POSITIVE_FIXNUM (- (SCM_MOST_NEGATIVE_FIXNUM + 1))
 
 /* SCM_SRS (X, Y) is signed right shift, defined as floor (X / 2^Y),
diff --git a/libguile/scm.h b/libguile/scm.h
index 4d079b1a8..e053c9883 100644
--- a/libguile/scm.h
+++ b/libguile/scm.h
@@ -843,6 +843,8 @@ typedef struct scm_thread scm_thread;
 # define SCM_LONG_BIT (SCM_SIZEOF_LONG * 8)
 #endif
 
+#define SCM_INTPTR_T_BIT (SCM_SIZEOF_INTPTR_T * 8)
+
 
 
 /* Cast pointer through (void *) in order to avoid compiler warnings
-- 
2.42.0

From 639d9a53c883ec310783ba8ed9b43a485c0e5b61 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld <hah...@hahnjo.de>
Date: Tue, 24 Oct 2023 23:47:41 +0200
Subject: [PATCH 5/5] Store hashes as uintptr_t

As for scm_t_inum, Guile expects that hashes have the same size as
pointers to get compatible bytecode (with respect to interned symbols)
on different platforms. This assumption breaks on 64-bit Windows where
longs are still 32 bit. Instead use uintptr_t as the datatype.

Based on changes by Jan Nieuwenhuizen, Mike Gran, and Andy Wingo.

* libguile/hash.c:
* libguile/hash.h:
* libguile/strings.c:
* libguile/strings.h:
* libguile/symbols.c:
* libguile/symbols.h: Use uintptr_t to store hashes.
---
 libguile/hash.c    | 68 +++++++++++++++++++++++-----------------------
 libguile/hash.h    | 22 +++++++--------
 libguile/strings.c |  2 +-
 libguile/strings.h |  2 +-
 libguile/symbols.c | 24 ++++++++--------
 libguile/symbols.h |  6 ++--
 6 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/libguile/hash.c b/libguile/hash.c
index 5abdfe397..cfe14bf1d 100644
--- a/libguile/hash.c
+++ b/libguile/hash.c
@@ -112,31 +112,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);
@@ -148,13 +148,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)
@@ -164,11 +164,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.  */
@@ -219,8 +219,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;
 
@@ -228,16 +228,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);
 
@@ -257,7 +257,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)
@@ -283,7 +283,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))
@@ -301,7 +301,7 @@ scm_raw_ihash (SCM obj, size_t depth)
           SCM n = SCM_I_MAKINUM (SCM_MOST_POSITIVE_FIXNUM);
           if (scm_is_inexact (obj))
             obj = scm_inexact_to_exact (obj);
-          return scm_raw_ihashq (scm_to_ulong (scm_modulo (obj, n)));
+          return scm_raw_ihashq (scm_to_uintptr_t (scm_modulo (obj, n)));
         }
       else
         return scm_i_string_hash (scm_number_to_string (obj, scm_from_int (10)));
@@ -318,7 +318,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);
@@ -326,7 +326,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);
@@ -365,8 +365,8 @@ scm_raw_ihash (SCM obj, size_t depth)
 
 
 
-unsigned long
-scm_ihashq (SCM obj, unsigned long n)
+uintptr_t
+scm_ihashq (SCM obj, uintptr_t n)
 {
   return scm_raw_ihashq (SCM_UNPACK (obj)) % n;
 }
@@ -386,8 +386,8 @@ 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);
-  return scm_from_ulong (scm_ihashq (key, sz));
+  uintptr_t sz = scm_to_unsigned_integer (size, 1, UINTPTR_MAX);
+  return scm_from_unsigned_integer (scm_ihashq (key, sz));
 }
 #undef FUNC_NAME
 
@@ -395,8 +395,8 @@ SCM_DEFINE (scm_hashq, "hashq", 2, 0, 0,
 
 
 
-unsigned long
-scm_ihashv (SCM obj, unsigned long n)
+uintptr_t
+scm_ihashv (SCM obj, uintptr_t n)
 {
   if (SCM_NUMP(obj))
     return scm_raw_ihash (obj, 10) % n;
@@ -419,8 +419,8 @@ 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);
-  return scm_from_ulong (scm_ihashv (key, sz));
+  uintptr_t sz = scm_to_unsigned_integer (size, 1, UINTPTR_MAX);
+  return scm_from_unsigned_integer (scm_ihashv (key, sz));
 }
 #undef FUNC_NAME
 
@@ -428,10 +428,10 @@ SCM_DEFINE (scm_hashv, "hashv", 2, 0, 0,
 
 
 
-unsigned long
-scm_ihash (SCM obj, unsigned long n)
+uintptr_t
+scm_ihash (SCM obj, uintptr_t n)
 {
-  return (unsigned long) scm_raw_ihash (obj, 10) % n;
+  return scm_raw_ihash (obj, 10) % n;
 }
 
 SCM_DEFINE (scm_hash, "hash", 2, 0, 0,
@@ -442,8 +442,8 @@ 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);
-  return scm_from_ulong (scm_ihash (key, sz));
+  uintptr_t sz = scm_to_unsigned_integer (size, 1, UINTPTR_MAX);
+  return scm_from_unsigned_integer (scm_ihash (key, sz));
 }
 #undef FUNC_NAME
 
diff --git a/libguile/hash.h b/libguile/hash.h
index 0e82b4afc..580d2ce93 100644
--- a/libguile/hash.h
+++ b/libguile/hash.h
@@ -26,19 +26,19 @@
 
 
 
-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 unsigned long scm_i_string_hash (SCM str);
-SCM_API unsigned long scm_ihashq (SCM obj, unsigned long n);
+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 uintptr_t scm_i_string_hash (SCM str);
+SCM_API uintptr_t scm_ihashq (SCM obj, uintptr_t n);
 SCM_API SCM scm_hashq (SCM obj, SCM n);
-SCM_API unsigned long scm_ihashv (SCM obj, unsigned long n);
+SCM_API uintptr_t scm_ihashv (SCM obj, uintptr_t n);
 SCM_API SCM scm_hashv (SCM obj, SCM n);
-SCM_API unsigned long scm_ihash (SCM obj, unsigned long n);
+SCM_API uintptr_t scm_ihash (SCM obj, uintptr_t n);
 SCM_API SCM scm_hash (SCM obj, SCM n);
 SCM_INTERNAL void scm_init_hash (void);
 
diff --git a/libguile/strings.c b/libguile/strings.c
index 5eebb3300..572c554c3 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -760,7 +760,7 @@ scm_i_string_set_x (SCM str, size_t p, scm_t_wchar chr)
 #define SYMBOL_STRINGBUF SCM_CELL_OBJECT_1
 
 SCM
-scm_i_make_symbol (SCM name, scm_t_bits flags, unsigned long hash)
+scm_i_make_symbol (SCM name, scm_t_bits flags, uintptr_t hash)
 {
   SCM buf, symbol;
   size_t start, length = STRING_LENGTH (name);
diff --git a/libguile/strings.h b/libguile/strings.h
index f28ef3246..aa6a601be 100644
--- a/libguile/strings.h
+++ b/libguile/strings.h
@@ -250,7 +250,7 @@ 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);
+                                    uintptr_t hash);
 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);
diff --git a/libguile/symbols.c b/libguile/symbols.c
index 292941e9d..b3ddab67d 100644
--- a/libguile/symbols.c
+++ b/libguile/symbols.c
@@ -71,8 +71,8 @@ SCM_DEFINE (scm_sys_symbols, "%symbols", 0, 0, 0,
 /* {Symbols}
  */
 
-unsigned long
-scm_i_hash_symbol (SCM obj, unsigned long n, void *closure)
+uintptr_t
+scm_i_hash_symbol (SCM obj, uintptr_t n, void *closure)
 {
   return scm_i_symbol_hash (obj) % n;
 }
@@ -80,7 +80,7 @@ scm_i_hash_symbol (SCM obj, unsigned long n, void *closure)
 struct string_lookup_data
 {
   SCM string;
-  unsigned long string_hash;
+  uintptr_t string_hash;
 };
 
 static int
@@ -102,7 +102,7 @@ string_lookup_predicate_fn (SCM sym, void *closure)
 }
 
 static SCM
-lookup_interned_symbol (SCM name, unsigned long raw_hash)
+lookup_interned_symbol (SCM name, uintptr_t raw_hash)
 {
   struct string_lookup_data data;
 
@@ -118,7 +118,7 @@ struct latin1_lookup_data
 {
   const char *str;
   size_t len;
-  unsigned long string_hash;
+  uintptr_t string_hash;
 };
 
 static int
@@ -134,7 +134,7 @@ latin1_lookup_predicate_fn (SCM sym, void *closure)
 
 static SCM
 lookup_interned_latin1_symbol (const char *str, size_t len,
-                               unsigned long raw_hash)
+                               uintptr_t raw_hash)
 {
   struct latin1_lookup_data data;
 
@@ -151,7 +151,7 @@ struct utf8_lookup_data
 {
   const char *str;
   size_t len;
-  unsigned long string_hash;
+  uintptr_t string_hash;
 };
 
 static int
@@ -201,7 +201,7 @@ utf8_lookup_predicate_fn (SCM sym, void *closure)
 
 static SCM
 lookup_interned_utf8_symbol (const char *str, size_t len,
-                             unsigned long raw_hash)
+                             uintptr_t raw_hash)
 {
   struct utf8_lookup_data data;
 
@@ -239,7 +239,7 @@ static SCM
 scm_i_str2symbol (SCM str)
 {
   SCM symbol;
-  unsigned long raw_hash = scm_i_string_hash (str);
+  uintptr_t raw_hash = scm_i_string_hash (str);
 
   symbol = lookup_interned_symbol (str, raw_hash);
   if (scm_is_true (symbol))
@@ -261,7 +261,7 @@ scm_i_str2symbol (SCM str)
 static SCM
 scm_i_str2uninterned_symbol (SCM str)
 {
-  unsigned long raw_hash = scm_i_string_hash (str);
+  uintptr_t raw_hash = scm_i_string_hash (str);
 
   return scm_i_make_symbol (str, SCM_I_F_SYMBOL_UNINTERNED, raw_hash);
 }
@@ -416,7 +416,7 @@ scm_from_latin1_symbol (const char *sym)
 SCM
 scm_from_latin1_symboln (const char *sym, size_t len)
 {
-  unsigned long hash;
+  uintptr_t hash;
   SCM ret;
 
   if (len == (size_t) -1)
@@ -442,7 +442,7 @@ scm_from_utf8_symbol (const char *sym)
 SCM
 scm_from_utf8_symboln (const char *sym, size_t len)
 {
-  unsigned long hash;
+  uintptr_t hash;
   SCM ret;
 
   if (len == (size_t) -1)
diff --git a/libguile/symbols.h b/libguile/symbols.h
index e8bc3346f..f541f5126 100644
--- a/libguile/symbols.h
+++ b/libguile/symbols.h
@@ -31,7 +31,7 @@
 
 
 #define scm_is_symbol(x)            (SCM_HAS_TYP7 (x, scm_tc7_symbol))
-#define scm_i_symbol_hash(x)        ((unsigned long) SCM_CELL_WORD_2 (x))
+#define scm_i_symbol_hash(x)        ((uintptr_t) SCM_CELL_WORD_2 (x))
 #define scm_i_symbol_is_interned(x) \
   (!(SCM_CELL_WORD_0 (x) & SCM_I_F_SYMBOL_UNINTERNED))
 
@@ -122,8 +122,8 @@ SCM_API SCM scm_take_utf8_symboln (char *sym, size_t len);
 
 /* internal functions. */
 
-SCM_INTERNAL unsigned long scm_i_hash_symbol (SCM obj, unsigned long n,
-                                              void *closure);
+SCM_INTERNAL uintptr_t scm_i_hash_symbol (SCM obj, uintptr_t n,
+                                          void *closure);
 
 SCM_INTERNAL void scm_symbols_prehistory (void);
 SCM_INTERNAL void scm_init_symbols (void);
-- 
2.42.0

Attachment: signature.asc
Description: This is a digitally signed message part

  • Guile 64-bit Wind... Mike Gran
    • Re: Guile 64... Jean Abou Samra
    • [EXT] Guile ... Thompson, David
    • Re: Guile 64... Maxime Devos
    • Re: Guile 64... Developers list for Guile, the GNU extensibility library
      • Re: Guil... Developers list for Guile, the GNU extensibility library
        • Re: ... Dr. Arne Babenhauserheide
        • Re: ... Developers list for Guile, the GNU extensibility library
          • ... Dr. Arne Babenhauserheide
          • ... Thompson, David
            • ... Developers list for Guile, the GNU extensibility library
              • ... Thompson, David
                • ... Developers list for Guile, the GNU extensibility library
                • ... Developers list for Guile, the GNU extensibility library
                • ... Thompson, David

Reply via email to