summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--include/ruby/ruby.h19
-rw-r--r--numeric.c20
-rw-r--r--struct.c6
-rw-r--r--version.h4
-rw-r--r--vm_eval.c8
-rw-r--r--vm_insnhelper.c2
7 files changed, 45 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 818288ccf8..f1951596d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu May 21 01:43:40 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/ruby.h (rb_long2int, RARRAY_LENINT): check long to
+ cast to int. [ruby-dev:38508]
+
+ * struct.c, vm_eval.c, vm_insnhelper.c: use RARRAY_LENINT.
+
Wed May 20 21:00:27 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* rb_enc_get_index: allows an arbitrary RData as the argument but not
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index a277bb2e9a..440bfe2ed1 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -663,6 +663,25 @@ struct RArray {
RARRAY(a)->as.ary : \
RARRAY(a)->as.heap.ptr)
+#if SIZEOF_INT < SIZEOF_VALUE
+NORETURN(void rb_out_of_int(SIGNED_VALUE num));
+#endif
+
+#if SIZEOF_INT < SIZEOF_LONG
+#define rb_long2int_internal(n, i) \
+ int i = (int)(n); \
+ if ((long)i != (n)) rb_out_of_int(n)
+#ifdef __GNUC__
+#define rb_long2int(i2l_n) ({rb_long2int_internal(i2l_n, i2l_i); i2l_i;})
+#else
+static inline int
+rb_long2int(long n) {rb_long2int_internal(n, i); return i;}
+#endif
+#else
+#define rb_long2int(n) ((int)(n))
+#endif
+#define RARRAY_LENINT(ary) rb_long2int(RARRAY_LEN(ary))
+
struct RRegexp {
struct RBasic basic;
struct re_pattern_buffer *ptr;
diff --git a/numeric.c b/numeric.c
index 5b051f1452..9da8e11784 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1630,21 +1630,19 @@ rb_num2ulong(VALUE val)
}
#if SIZEOF_INT < SIZEOF_VALUE
+void
+rb_out_of_int(SIGNED_VALUE num)
+{
+ rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too %s to convert to `int'",
+ num, num < 0 ? "small" : "big");
+}
+
static void
check_int(SIGNED_VALUE num)
{
- const char *s;
-
- if (num < INT_MIN) {
- s = "small";
- }
- else if (num > INT_MAX) {
- s = "big";
- }
- else {
- return;
+ if ((SIGNED_VALUE)(int)num != num) {
+ rb_out_of_int(num);
}
- rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too %s to convert to `int'", num, s);
}
static void
diff --git a/struct.c b/struct.c
index 2962d400ca..718add389f 100644
--- a/struct.c
+++ b/struct.c
@@ -378,7 +378,7 @@ rb_struct_initialize_m(int argc, VALUE *argv, VALUE self)
VALUE
rb_struct_initialize(VALUE self, VALUE values)
{
- return rb_struct_initialize_m(RARRAY_LEN(values), RARRAY_PTR(values), self);
+ return rb_struct_initialize_m(RARRAY_LENINT(values), RARRAY_PTR(values), self);
}
static VALUE
@@ -414,10 +414,10 @@ VALUE
rb_struct_new(VALUE klass, ...)
{
VALUE tmpargs[N_REF_FUNC], *mem = tmpargs;
- long size, i;
+ int size, i;
va_list args;
- size = num_members(klass);
+ size = rb_long2int(num_members(klass));
if (size > numberof(tmpargs)) {
tmpargs[0] = rb_ary_tmp_new(size);
mem = RARRAY_PTR(tmpargs[0]);
diff --git a/version.h b/version.h
index 4555e65a46..ad7cc3584d 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.2"
-#define RUBY_RELEASE_DATE "2009-05-20"
+#define RUBY_RELEASE_DATE "2009-05-21"
#define RUBY_PATCHLEVEL -1
#define RUBY_BRANCH_NAME "trunk"
@@ -8,7 +8,7 @@
#define RUBY_VERSION_TEENY 1
#define RUBY_RELEASE_YEAR 2009
#define RUBY_RELEASE_MONTH 5
-#define RUBY_RELEASE_DAY 20
+#define RUBY_RELEASE_DAY 21
#include "ruby/version.h"
diff --git a/vm_eval.c b/vm_eval.c
index 70bcd11ec8..b4db202e5e 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -398,7 +398,7 @@ rb_apply(VALUE recv, ID mid, VALUE args)
int argc;
VALUE *argv;
- argc = RARRAY_LEN(args); /* Assigns LONG, but argc is INT */
+ argc = RARRAY_LENINT(args);
argv = ALLOCA_N(VALUE, argc);
MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);
return rb_call(CLASS_OF(recv), recv, mid, argc, argv, CALL_FCALL);
@@ -552,7 +552,7 @@ rb_yield_splat(VALUE values)
if (NIL_P(tmp)) {
rb_raise(rb_eArgError, "not an array");
}
- v = rb_yield_0(RARRAY_LEN(tmp), RARRAY_PTR(tmp));
+ v = rb_yield_0(RARRAY_LENINT(tmp), RARRAY_PTR(tmp));
return v;
}
@@ -909,7 +909,7 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
PUSH_TAG();
rb_set_safe_level_force(level);
if ((state = EXEC_TAG()) == 0) {
- val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LEN(arg),
+ val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LENINT(arg),
RARRAY_PTR(arg));
}
POP_TAG();
@@ -951,7 +951,7 @@ yield_under(VALUE under, VALUE self, VALUE values)
return vm_yield_with_cref(th, 0, 0, cref);
}
else {
- return vm_yield_with_cref(th, RARRAY_LEN(values), RARRAY_PTR(values), cref);
+ return vm_yield_with_cref(th, RARRAY_LENINT(values), RARRAY_PTR(values), cref);
}
}
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 473a336117..bc196d83b3 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -774,7 +774,7 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
if (!(iseq->arg_simple & 0x02) && /* exclude {|a|} */
(m + iseq->arg_post_len) > 0 && /* this process is meaningful */
argc == 1 && !NIL_P(ary = rb_check_array_type(argv[0]))) { /* rhs is only an array */
- th->mark_stack_len = argc = RARRAY_LEN(ary);
+ th->mark_stack_len = argc = RARRAY_LENINT(ary);
CHECK_STACK_OVERFLOW(th->cfp, argc);