aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--bignum.c27
-rw-r--r--eval.c7
-rw-r--r--intern.h12
-rw-r--r--numeric.c38
-rw-r--r--ruby.h9
6 files changed, 65 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index 7670647dea..a6771897fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Tue Jul 11 15:29:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * bignum.c (rb_int2big): use SIGNED_VALUE. [ruby-dev:29019]
+
+ * bignum.c (rb_int2inum, rb_uint2inum): use VALUE sized integer.
+
+ * bignum.c (rb_big2long, rb_big2ulong): ditto.
+
+ * numeric.c (rb_num2long, rb_num2ulong): ditto.
+
+ * numeric.c (check_int, check_uint): ditto.
+
+ * bignum.c (rb_quad_pack): typo fixed.
+
Tue Jul 11 13:40:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* bignum.c (bignorm): sizeof(long) may be smaller than
diff --git a/bignum.c b/bignum.c
index c51f1613b5..8a5dd41782 100644
--- a/bignum.c
+++ b/bignum.c
@@ -192,7 +192,7 @@ rb_quad_pack(char *buf, VALUE val)
BDIGIT *ds;
if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) {
- len = SIZEOF_LONG/SIZEOF_BDIGITS;
+ len = SIZEOF_LONG_LONG/SIZEOF_BDIGITS;
}
ds = BDIGITS(val);
q = 0;
@@ -686,17 +686,17 @@ rb_big_to_s(int argc, VALUE *argv, VALUE x)
return rb_big2str(x, base);
}
-static unsigned long
+static VALUE
big2ulong(VALUE x, const char *type, int check)
{
long len = RBIGNUM(x)->len;
BDIGIT_DBL num;
BDIGIT *ds;
- if (len > SIZEOF_LONG/SIZEOF_BDIGITS) {
+ if (len > SIZEOF_VALUE/SIZEOF_BDIGITS) {
if (check)
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
- len = SIZEOF_LONG/SIZEOF_BDIGITS;
+ len = SIZEOF_VALUE/SIZEOF_BDIGITS;
}
ds = BDIGITS(x);
num = 0;
@@ -707,23 +707,23 @@ big2ulong(VALUE x, const char *type, int check)
return num;
}
-unsigned long
+VALUE
rb_big2ulong_pack(VALUE x)
{
- unsigned long num = big2ulong(x, "unsigned long", Qfalse);
+ VALUE num = big2ulong(x, "unsigned long", Qfalse);
if (!RBIGNUM(x)->sign) {
return -num;
}
return num;
}
-unsigned long
+VALUE
rb_big2ulong(VALUE x)
{
- unsigned long num = big2ulong(x, "unsigned long", Qtrue);
+ VALUE num = big2ulong(x, "unsigned long", Qtrue);
if (!RBIGNUM(x)->sign) {
- if ((long)num < 0) {
+ if ((SIGNED_VALUE)num < 0) {
rb_raise(rb_eRangeError, "bignum out of range of unsigned long");
}
return -num;
@@ -731,15 +731,16 @@ rb_big2ulong(VALUE x)
return num;
}
-long
+SIGNED_VALUE
rb_big2long(VALUE x)
{
- unsigned long num = big2ulong(x, "long", Qtrue);
+ VALUE num = big2ulong(x, "long", Qtrue);
- if ((long)num < 0 && (RBIGNUM(x)->sign || (long)num != LONG_MIN)) {
+ if ((SIGNED_VALUE)num < 0 &&
+ (RBIGNUM(x)->sign || (SIGNED_VALUE)num != LONG_MIN)) {
rb_raise(rb_eRangeError, "bignum too big to convert into `long'");
}
- if (!RBIGNUM(x)->sign) return -(long)num;
+ if (!RBIGNUM(x)->sign) return -(SIGNED_VALUE)num;
return num;
}
diff --git a/eval.c b/eval.c
index aa0010d927..ad976f4c2e 100644
--- a/eval.c
+++ b/eval.c
@@ -8555,10 +8555,13 @@ VALUE
rb_proc_yield(int argc, VALUE *argv, VALUE proc)
{
switch (argc) {
+ case 1:
+ if (!NIL_P(argv[0])) {
+ return proc_invoke(proc, argv[0], Qundef, 0, 0);
+ }
+ /* fall through */
case 0:
return proc_invoke(proc, Qundef, Qundef, 0, 0);
- case 1:
- return proc_invoke(proc, argv[0], Qundef, 0, 0);
default:
return proc_invoke(proc, rb_ary_new4(argc, argv), Qundef, 0, 0);
}
diff --git a/intern.h b/intern.h
index 1323427e0c..e393e0b940 100644
--- a/intern.h
+++ b/intern.h
@@ -72,18 +72,18 @@ VALUE rb_get_values_at(VALUE, long, int, VALUE*, VALUE(*)(VALUE,long));
VALUE rb_big_clone(VALUE);
void rb_big_2comp(VALUE);
VALUE rb_big_norm(VALUE);
-VALUE rb_uint2big(unsigned long);
-VALUE rb_int2big(long);
-VALUE rb_uint2inum(unsigned long);
-VALUE rb_int2inum(long);
+VALUE rb_uint2big(VALUE);
+VALUE rb_int2big(SIGNED_VALUE);
+VALUE rb_uint2inum(VALUE);
+VALUE rb_int2inum(SIGNED_VALUE);
VALUE rb_cstr_to_inum(const char*, int, int);
VALUE rb_str_to_inum(VALUE, int, int);
VALUE rb_cstr2inum(const char*, int);
VALUE rb_str2inum(VALUE, int);
VALUE rb_big2str(VALUE, int);
-long rb_big2long(VALUE);
+SIGNED_VALUE rb_big2long(VALUE);
#define rb_big2int(x) rb_big2long(x)
-unsigned long rb_big2ulong(VALUE);
+VALUE rb_big2ulong(VALUE);
#define rb_big2uint(x) rb_big2ulong(x)
#if HAVE_LONG_LONG
VALUE rb_ll2inum(LONG_LONG);
diff --git a/numeric.c b/numeric.c
index 2448cce894..1a2f779318 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1458,7 +1458,7 @@ num_step(int argc, VALUE *argv, VALUE from)
return from;
}
-long
+SIGNED_VALUE
rb_num2long(VALUE val)
{
if (NIL_P(val)) {
@@ -1471,7 +1471,7 @@ rb_num2long(VALUE val)
case T_FLOAT:
if (RFLOAT(val)->value <= (double)LONG_MAX
&& RFLOAT(val)->value >= (double)LONG_MIN) {
- return (long)(RFLOAT(val)->value);
+ return (SIGNED_VALUE)(RFLOAT(val)->value);
}
else {
char buf[24];
@@ -1491,19 +1491,18 @@ rb_num2long(VALUE val)
}
}
-unsigned long
+VALUE
rb_num2ulong(VALUE val)
{
if (TYPE(val) == T_BIGNUM) {
return rb_big2ulong(val);
}
- return (unsigned long)rb_num2long(val);
+ return (VALUE)rb_num2long(val);
}
-#if SIZEOF_INT < SIZEOF_LONG
+#if SIZEOF_INT < SIZEOF_VALUE
static void
-check_int(num)
- long num;
+check_int(SIGNED_VALUE num)
{
const char *s;
@@ -1516,21 +1515,27 @@ check_int(num)
else {
return;
}
+#if LONG_LONG_VALUE
+ rb_raise(rb_eRangeError, "integer %lld too %s to convert to `int'", num, s);
+#else
rb_raise(rb_eRangeError, "integer %ld too %s to convert to `int'", num, s);
+#endif
}
static void
-check_uint(num)
- unsigned long num;
+check_uint(VALUE num)
{
if (num > UINT_MAX) {
+#if LONG_LONG_VALUE
+ rb_raise(rb_eRangeError, "integer %llu too big to convert to `unsigned int'", num);
+#else
rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
+#endif
}
}
long
-rb_num2int(val)
- VALUE val;
+rb_num2int(VALUE val)
{
long num = rb_num2long(val);
@@ -1539,8 +1544,7 @@ rb_num2int(val)
}
long
-rb_fix2int(val)
- VALUE val;
+rb_fix2int(VALUE val)
{
long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2long(val);
@@ -1549,8 +1553,7 @@ rb_fix2int(val)
}
unsigned long
-rb_num2uint(val)
- VALUE val;
+rb_num2uint(VALUE val)
{
unsigned long num = rb_num2ulong(val);
@@ -1561,8 +1564,7 @@ rb_num2uint(val)
}
unsigned long
-rb_fix2uint(val)
- VALUE val;
+rb_fix2uint(VALUE val)
{
unsigned long num;
@@ -1837,7 +1839,7 @@ VALUE
rb_fix2str(VALUE x, int base)
{
extern const char ruby_digitmap[];
- char buf[SIZEOF_LONG*CHAR_BIT + 2], *b = buf + sizeof buf;
+ char buf[SIZEOF_VALUE*CHAR_BIT + 2], *b = buf + sizeof buf;
long val = FIX2LONG(x);
int neg = 0;
diff --git a/ruby.h b/ruby.h
index 3f773ed82b..b0a0e3e7b9 100644
--- a/ruby.h
+++ b/ruby.h
@@ -94,15 +94,18 @@ extern "C" {
typedef unsigned long VALUE;
typedef unsigned long ID;
# define SIGNED_VALUE long
+# define SIZEOF_VALUE SIZEOF_LONG
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
typedef unsigned LONG_LONG VALUE;
typedef unsigned LONG_LONG ID;
# define SIGNED_VALUE LONG_LONG
# define LONG_LONG_VALUE 1
+# define SIZEOF_VALUE SIZEOF_LONG_LONG
#else
# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
#endif
+
#ifdef __STDC__
# include <limits.h>
#else
@@ -273,8 +276,8 @@ RUBY_EXTERN int ruby_safe_level;
void rb_set_safe_level(int);
void rb_secure_update(VALUE);
-long rb_num2long(VALUE);
-unsigned long rb_num2ulong(VALUE);
+SIGNED_VALUE rb_num2long(VALUE);
+VALUE rb_num2ulong(VALUE);
#define NUM2LONG(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2long((VALUE)x))
#define NUM2ULONG(x) rb_num2ulong((VALUE)x)
#if SIZEOF_INT < SIZEOF_LONG
@@ -336,7 +339,7 @@ VALUE rb_newobj(void);
} while (0)
struct RBasic {
- unsigned long flags;
+ VALUE flags;
VALUE klass;
};