summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-20 16:43:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-20 16:43:41 +0000
commit060f433f48ccb293ed21bc99a89b162a548d2e74 (patch)
treebeb1650b092b8a90fef0bf9b94288d0b38091117 /include
parentc573aaf73f68500ec482f756dd14508002714e61 (diff)
* 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
Diffstat (limited to 'include')
-rw-r--r--include/ruby/ruby.h19
1 files changed, 19 insertions, 0 deletions
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;