* 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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-05-20 16:43:41 +00:00
Родитель c573aaf73f
Коммит 060f433f48
7 изменённых файлов: 45 добавлений и 21 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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";
if ((SIGNED_VALUE)(int)num != num) {
rb_out_of_int(num);
}
else if (num > INT_MAX) {
s = "big";
}
else {
return;
}
rb_raise(rb_eRangeError, "integer %"PRIdVALUE " too %s to convert to `int'", num, s);
}
static void

Просмотреть файл

@ -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]);

Просмотреть файл

@ -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"

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);