fixing bug reading SEXP_MIN_FIXNUM

This commit is contained in:
Alex Shinn 2010-04-15 22:25:35 +09:00
parent 53e538d5a3
commit 0299d42807
3 changed files with 13 additions and 8 deletions

View file

@ -848,7 +848,7 @@ SEXP_API sexp sexp_string_concatenate_op (sexp ctx sexp_api_params(self, n), sex
SEXP_API sexp sexp_intern (sexp ctx, const char *str, sexp_sint_t len); SEXP_API sexp sexp_intern (sexp ctx, const char *str, sexp_sint_t len);
SEXP_API sexp sexp_string_to_symbol_op (sexp ctx sexp_api_params(self, n), sexp str); SEXP_API sexp sexp_string_to_symbol_op (sexp ctx sexp_api_params(self, n), sexp str);
SEXP_API sexp sexp_string_to_number_op (sexp ctx sexp_api_params(self, n), sexp str, sexp b); SEXP_API sexp sexp_string_to_number_op (sexp ctx sexp_api_params(self, n), sexp str, sexp b);
SEXP_API sexp sexp_make_vector (sexp ctx, sexp len, sexp dflt); SEXP_API sexp sexp_make_vector_op (sexp ctx sexp_api_params(self, n), sexp len, sexp dflt);
SEXP_API sexp sexp_list_to_vector_op (sexp ctx sexp_api_params(self, n), sexp ls); SEXP_API sexp sexp_list_to_vector_op (sexp ctx sexp_api_params(self, n), sexp ls);
SEXP_API sexp sexp_make_cpointer (sexp ctx, sexp_uint_t type_id, void* value, sexp parent, int freep); SEXP_API sexp sexp_make_cpointer (sexp ctx, sexp_uint_t type_id, void* value, sexp parent, int freep);
SEXP_API sexp sexp_write_op (sexp ctx sexp_api_params(self, n), sexp obj, sexp out); SEXP_API sexp sexp_write_op (sexp ctx sexp_api_params(self, n), sexp obj, sexp out);
@ -915,6 +915,7 @@ SEXP_API sexp sexp_finalize_c_type (sexp ctx sexp_api_params(self, n), sexp obj)
#define sexp_nreverse(ctx, x) sexp_nreverse_op(ctx sexp_api_pass(NULL, 1), x) #define sexp_nreverse(ctx, x) sexp_nreverse_op(ctx sexp_api_pass(NULL, 1), x)
#define sexp_cons(ctx, a, b) sexp_cons_op(ctx sexp_api_pass(NULL, 2), a, b) #define sexp_cons(ctx, a, b) sexp_cons_op(ctx sexp_api_pass(NULL, 2), a, b)
#define sexp_append2(ctx, a, b) sexp_append2_op(ctx sexp_api_pass(NULL, 2), a, b) #define sexp_append2(ctx, a, b) sexp_append2_op(ctx sexp_api_pass(NULL, 2), a, b)
#define sexp_make_vector(ctx, a, b) sexp_make_vector_op(ctx sexp_api_pass(NULL, 2), a, b);
#define sexp_list_to_vector(ctx, x) sexp_list_to_vector_op(ctx sexp_api_pass(NULL, 1), x) #define sexp_list_to_vector(ctx, x) sexp_list_to_vector_op(ctx sexp_api_pass(NULL, 1), x)
#define sexp_exception_type(ctx, x) sexp_exception_type_op(ctx sexp_api_pass(NULL, 1), x) #define sexp_exception_type(ctx, x) sexp_exception_type_op(ctx sexp_api_pass(NULL, 1), x)
#define sexp_string_to_number(ctx, s, b) sexp_make_string_op(ctx sexp_api_pass(NULL, 2), s, b) #define sexp_string_to_number(ctx, s, b) sexp_make_string_op(ctx sexp_api_pass(NULL, 2), s, b)

View file

@ -27,7 +27,7 @@ sexp sexp_fixnum_to_bignum (sexp ctx, sexp a) {
sexp sexp_make_integer (sexp ctx, sexp_lsint_t x) { sexp sexp_make_integer (sexp ctx, sexp_lsint_t x) {
sexp res; sexp res;
if ((SEXP_MIN_FIXNUM < x) && (x < SEXP_MAX_FIXNUM)) { if ((SEXP_MIN_FIXNUM <= x) && (x <= SEXP_MAX_FIXNUM)) {
res = sexp_make_fixnum(x); res = sexp_make_fixnum(x);
} else { } else {
res = sexp_make_bignum(ctx, 1); res = sexp_make_bignum(ctx, 1);
@ -44,7 +44,7 @@ sexp sexp_make_integer (sexp ctx, sexp_lsint_t x) {
sexp sexp_make_unsigned_integer (sexp ctx, sexp_luint_t x) { sexp sexp_make_unsigned_integer (sexp ctx, sexp_luint_t x) {
sexp res; sexp res;
if (x < SEXP_MAX_FIXNUM) { if (x <= SEXP_MAX_FIXNUM) {
res = sexp_make_fixnum(x); res = sexp_make_fixnum(x);
} else { } else {
res = sexp_make_bignum(ctx, 1); res = sexp_make_bignum(ctx, 1);
@ -487,7 +487,7 @@ enum sexp_number_combs {
}; };
static int sexp_number_types[] = static int sexp_number_types[] =
{0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0}; {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0};
static int sexp_number_type (sexp a) { static int sexp_number_type (sexp a) {
return sexp_pointerp(a) ? sexp_number_types[sexp_pointer_tag(a)&15] return sexp_pointerp(a) ? sexp_number_types[sexp_pointer_tag(a)&15]

12
sexp.c
View file

@ -784,7 +784,7 @@ sexp sexp_string_to_symbol_op (sexp ctx sexp_api_params(self, n), sexp str) {
return sexp_intern(ctx, sexp_string_data(str), sexp_string_length(str)); return sexp_intern(ctx, sexp_string_data(str), sexp_string_length(str));
} }
sexp sexp_make_vector (sexp ctx, sexp len, sexp dflt) { sexp sexp_make_vector_op (sexp ctx sexp_api_params(self, n), sexp len, sexp dflt) {
sexp vec, *x; sexp vec, *x;
int i, clen = sexp_unbox_fixnum(len); int i, clen = sexp_unbox_fixnum(len);
if (! clen) return sexp_global(ctx, SEXP_G_EMPTY_VECTOR); if (! clen) return sexp_global(ctx, SEXP_G_EMPTY_VECTOR);
@ -1643,9 +1643,13 @@ sexp sexp_read_raw (sexp ctx, sexp in) {
else else
#endif #endif
#if SEXP_USE_BIGNUMS #if SEXP_USE_BIGNUMS
if (sexp_bignump(res)) if (sexp_bignump(res)) {
sexp_bignum_sign(res) = -sexp_bignum_sign(res); if ((sexp_bignum_hi(res) == 1)
else && sexp_bignum_data(res)[0] == SEXP_MAX_FIXNUM)
res = sexp_make_fixnum(-sexp_bignum_data(res)[0]);
else
sexp_bignum_sign(res) = -sexp_bignum_sign(res);
} else
#endif #endif
res = sexp_fx_mul(res, SEXP_NEG_ONE); res = sexp_fx_mul(res, SEXP_NEG_ONE);
} }