* 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:
parent
c573aaf73f
commit
060f433f48
@ -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>
|
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
|
* 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.ary : \
|
||||||
RARRAY(a)->as.heap.ptr)
|
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 RRegexp {
|
||||||
struct RBasic basic;
|
struct RBasic basic;
|
||||||
struct re_pattern_buffer *ptr;
|
struct re_pattern_buffer *ptr;
|
||||||
|
20
numeric.c
20
numeric.c
@ -1630,21 +1630,19 @@ rb_num2ulong(VALUE val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if SIZEOF_INT < SIZEOF_VALUE
|
#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
|
static void
|
||||||
check_int(SIGNED_VALUE num)
|
check_int(SIGNED_VALUE num)
|
||||||
{
|
{
|
||||||
const char *s;
|
if ((SIGNED_VALUE)(int)num != num) {
|
||||||
|
rb_out_of_int(num);
|
||||||
if (num < INT_MIN) {
|
|
||||||
s = "small";
|
|
||||||
}
|
}
|
||||||
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
|
static void
|
||||||
|
6
struct.c
6
struct.c
@ -378,7 +378,7 @@ rb_struct_initialize_m(int argc, VALUE *argv, VALUE self)
|
|||||||
VALUE
|
VALUE
|
||||||
rb_struct_initialize(VALUE self, VALUE values)
|
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
|
static VALUE
|
||||||
@ -414,10 +414,10 @@ VALUE
|
|||||||
rb_struct_new(VALUE klass, ...)
|
rb_struct_new(VALUE klass, ...)
|
||||||
{
|
{
|
||||||
VALUE tmpargs[N_REF_FUNC], *mem = tmpargs;
|
VALUE tmpargs[N_REF_FUNC], *mem = tmpargs;
|
||||||
long size, i;
|
int size, i;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
size = num_members(klass);
|
size = rb_long2int(num_members(klass));
|
||||||
if (size > numberof(tmpargs)) {
|
if (size > numberof(tmpargs)) {
|
||||||
tmpargs[0] = rb_ary_tmp_new(size);
|
tmpargs[0] = rb_ary_tmp_new(size);
|
||||||
mem = RARRAY_PTR(tmpargs[0]);
|
mem = RARRAY_PTR(tmpargs[0]);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#define RUBY_VERSION "1.9.2"
|
#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_PATCHLEVEL -1
|
||||||
#define RUBY_BRANCH_NAME "trunk"
|
#define RUBY_BRANCH_NAME "trunk"
|
||||||
|
|
||||||
@ -8,7 +8,7 @@
|
|||||||
#define RUBY_VERSION_TEENY 1
|
#define RUBY_VERSION_TEENY 1
|
||||||
#define RUBY_RELEASE_YEAR 2009
|
#define RUBY_RELEASE_YEAR 2009
|
||||||
#define RUBY_RELEASE_MONTH 5
|
#define RUBY_RELEASE_MONTH 5
|
||||||
#define RUBY_RELEASE_DAY 20
|
#define RUBY_RELEASE_DAY 21
|
||||||
|
|
||||||
#include "ruby/version.h"
|
#include "ruby/version.h"
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ rb_apply(VALUE recv, ID mid, VALUE args)
|
|||||||
int argc;
|
int argc;
|
||||||
VALUE *argv;
|
VALUE *argv;
|
||||||
|
|
||||||
argc = RARRAY_LEN(args); /* Assigns LONG, but argc is INT */
|
argc = RARRAY_LENINT(args);
|
||||||
argv = ALLOCA_N(VALUE, argc);
|
argv = ALLOCA_N(VALUE, argc);
|
||||||
MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);
|
MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);
|
||||||
return rb_call(CLASS_OF(recv), recv, mid, argc, argv, CALL_FCALL);
|
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)) {
|
if (NIL_P(tmp)) {
|
||||||
rb_raise(rb_eArgError, "not an array");
|
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;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -909,7 +909,7 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
|
|||||||
PUSH_TAG();
|
PUSH_TAG();
|
||||||
rb_set_safe_level_force(level);
|
rb_set_safe_level_force(level);
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
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));
|
RARRAY_PTR(arg));
|
||||||
}
|
}
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
@ -951,7 +951,7 @@ yield_under(VALUE under, VALUE self, VALUE values)
|
|||||||
return vm_yield_with_cref(th, 0, 0, cref);
|
return vm_yield_with_cref(th, 0, 0, cref);
|
||||||
}
|
}
|
||||||
else {
|
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|} */
|
if (!(iseq->arg_simple & 0x02) && /* exclude {|a|} */
|
||||||
(m + iseq->arg_post_len) > 0 && /* this process is meaningful */
|
(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 */
|
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);
|
CHECK_STACK_OVERFLOW(th->cfp, argc);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user