mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 12:20:20 +02:00
fix a number of assuptions that a long could hold an inum
* libguile/bytevectors.c: * libguile/goops.c: * libguile/instructions.c: * libguile/numbers.c: * libguile/random.c: * libguile/read.c: * libguile/vm-i-scheme.c: Fix a number of assumptions that a long could hold an inum. This is not the case on platforms whose void* is larger than their long. * libguile/numbers.c (scm_i_inum2big): New helper, only implemented for sizeof(void*) == sizeof(long); produces a compile error on other platforms. Basically gmp doesn't have a nice interface for converting between mpz values and intmax_t.
This commit is contained in:
parent
d2aed81f7c
commit
e25f37271a
7 changed files with 149 additions and 126 deletions
|
@ -392,16 +392,16 @@ SCM_DEFINE (scm_random, "random", 1, 1, 0,
|
|||
SCM_VALIDATE_RSTATE (2, state);
|
||||
if (SCM_I_INUMP (n))
|
||||
{
|
||||
unsigned long m = (unsigned long) SCM_I_INUM (n);
|
||||
scm_t_bits m = (scm_t_bits) SCM_I_INUM (n);
|
||||
SCM_ASSERT_RANGE (1, n, SCM_I_INUM (n) > 0);
|
||||
#if SCM_SIZEOF_UNSIGNED_LONG <= 4
|
||||
#if SCM_SIZEOF_UINTPTR_T <= 4
|
||||
return scm_from_uint32 (scm_c_random (SCM_RSTATE (state),
|
||||
(scm_t_uint32) m));
|
||||
#elif SCM_SIZEOF_UNSIGNED_LONG <= 8
|
||||
#elif SCM_SIZEOF_UINTPTR_T <= 8
|
||||
return scm_from_uint64 (scm_c_random64 (SCM_RSTATE (state),
|
||||
(scm_t_uint64) m));
|
||||
#else
|
||||
#error "Cannot deal with this platform's unsigned long size"
|
||||
#error "Cannot deal with this platform's scm_t_bits size"
|
||||
#endif
|
||||
}
|
||||
SCM_VALIDATE_NIM (1, n);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue