summaryrefslogtreecommitdiff
path: root/libguile/vm-i-scheme.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2010-11-19 11:29:26 +0100
committerAndy Wingo <wingo@pobox.com>2010-11-19 15:22:43 +0100
commite25f37271acde5b9e3c34420ad9d0faa62b7503d (patch)
treeab77d62427c4c4fa717f3c62aa79765c7633d88e /libguile/vm-i-scheme.c
parentd2aed81f7cb8b703b000962a1b9dddc8de91212e (diff)
downloadguile-e25f37271acde5b9e3c34420ad9d0faa62b7503d.tar.gz
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.
Diffstat (limited to 'libguile/vm-i-scheme.c')
-rw-r--r--libguile/vm-i-scheme.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/libguile/vm-i-scheme.c b/libguile/vm-i-scheme.c
index ec226733a..19b48c59e 100644
--- a/libguile/vm-i-scheme.c
+++ b/libguile/vm-i-scheme.c
@@ -399,13 +399,13 @@ VM_DEFINE_FUNCTION (159, ash, "ash", 2)
else
/* Left shift. See comments in scm_ash. */
{
- long nn, bits_to_shift;
+ scm_t_signed_bits nn, bits_to_shift;
nn = SCM_I_INUM (x);
bits_to_shift = SCM_I_INUM (y);
if (bits_to_shift < SCM_I_FIXNUM_BIT-1
- && ((unsigned long)
+ && ((scm_t_bits)
(SCM_SRS (nn, (SCM_I_FIXNUM_BIT-1 - bits_to_shift)) + 1)
<= 1))
RETURN (SCM_I_MAKINUM (nn << bits_to_shift));
@@ -451,7 +451,7 @@ VM_DEFINE_FUNCTION (162, logxor, "logxor", 2)
VM_DEFINE_FUNCTION (163, vector_ref, "vector-ref", 2)
{
- long i = 0;
+ scm_t_signed_bits i = 0;
ARGS2 (vect, idx);
if (SCM_LIKELY (SCM_I_IS_NONWEAK_VECTOR (vect)
&& SCM_I_INUMP (idx)
@@ -467,7 +467,7 @@ VM_DEFINE_FUNCTION (163, vector_ref, "vector-ref", 2)
VM_DEFINE_INSTRUCTION (164, vector_set, "vector-set", 0, 3, 0)
{
- long i = 0;
+ scm_t_signed_bits i = 0;
SCM vect, idx, val;
POP (val); POP (idx); POP (vect);
if (SCM_LIKELY (SCM_I_IS_NONWEAK_VECTOR (vect)
@@ -570,6 +570,9 @@ VM_DEFINE_FUNCTION (169, struct_ref, "struct-ref", 2)
SCM vtable;
scm_t_bits index, len;
+ /* True, an inum is a signed value, but cast to unsigned it will
+ certainly be more than the length, so we will fall through if
+ index is negative. */
index = SCM_I_INUM (pos);
vtable = SCM_STRUCT_VTABLE (obj);
len = SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size);
@@ -599,6 +602,7 @@ VM_DEFINE_FUNCTION (170, struct_set, "struct-set", 3)
SCM vtable;
scm_t_bits index, len;
+ /* See above regarding index being >= 0. */
index = SCM_I_INUM (pos);
vtable = SCM_STRUCT_VTABLE (obj);
len = SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size);
@@ -627,6 +631,7 @@ VM_DEFINE_FUNCTION (171, class_of, "class-of", 1)
RETURN (scm_class_of (obj));
}
+/* FIXME: No checking whatsoever. */
VM_DEFINE_FUNCTION (172, slot_ref, "slot-ref", 2)
{
size_t slot;
@@ -635,6 +640,7 @@ VM_DEFINE_FUNCTION (172, slot_ref, "slot-ref", 2)
RETURN (SCM_PACK (SCM_STRUCT_DATA (instance) [slot]));
}
+/* FIXME: No checking whatsoever. */
VM_DEFINE_INSTRUCTION (173, slot_set, "slot-set", 0, 3, 0)
{
SCM instance, idx, val;
@@ -701,7 +707,7 @@ BV_REF_WITH_ENDIANNESS (f64, ieee_double)
#define BV_FIXABLE_INT_REF(stem, fn_stem, type, size) \
{ \
- long i; \
+ scm_t_signed_bits i; \
const scm_t_ ## type *int_ptr; \
ARGS2 (bv, idx); \
\
@@ -723,7 +729,7 @@ BV_REF_WITH_ENDIANNESS (f64, ieee_double)
#define BV_INT_REF(stem, type, size) \
{ \
- long i; \
+ scm_t_signed_bits i; \
const scm_t_ ## type *int_ptr; \
ARGS2 (bv, idx); \
\
@@ -754,7 +760,7 @@ BV_REF_WITH_ENDIANNESS (f64, ieee_double)
#define BV_FLOAT_REF(stem, fn_stem, type, size) \
{ \
- long i; \
+ scm_t_signed_bits i; \
const type *float_ptr; \
ARGS2 (bv, idx); \
\
@@ -841,7 +847,7 @@ BV_SET_WITH_ENDIANNESS (f64, ieee_double)
#define BV_FIXABLE_INT_SET(stem, fn_stem, type, min, max, size) \
{ \
- long i, j = 0; \
+ scm_t_signed_bits i, j = 0; \
SCM bv, idx, val; \
scm_t_ ## type *int_ptr; \
\
@@ -865,7 +871,7 @@ BV_SET_WITH_ENDIANNESS (f64, ieee_double)
#define BV_INT_SET(stem, type, size) \
{ \
- long i = 0; \
+ scm_t_signed_bits i = 0; \
SCM bv, idx, val; \
scm_t_ ## type *int_ptr; \
\
@@ -886,7 +892,7 @@ BV_SET_WITH_ENDIANNESS (f64, ieee_double)
#define BV_FLOAT_SET(stem, fn_stem, type, size) \
{ \
- long i = 0; \
+ scm_t_signed_bits i = 0; \
SCM bv, idx, val; \
type *float_ptr; \
\