diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-28 07:45:00 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-28 07:45:00 +0000 |
commit | 790d6071c6d0d2c677b01779fecb891d64095ded (patch) | |
tree | 96f3b4d544d9ec2b12f12b477bfbdf81801cc7f9 /include | |
parent | 5e7101d3487846d83f8038856728ec77f931ecb6 (diff) |
* include/ruby/ruby.h ({RSTRING,RSTRUCT,RBIGNUM}_LENINT): check long
to cast to int.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r-- | include/ruby/ruby.h | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 20f45aee4e..a9fd974614 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -272,6 +272,24 @@ VALUE rb_ull2inum(unsigned LONG_LONG); # endif #endif +#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(n) __extension__ ({long i2l_n = (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 + #ifndef PIDT2NUM #define PIDT2NUM(v) LONG2NUM(v) #endif @@ -637,6 +655,7 @@ struct RString { ((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \ (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT))) : \ (RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len)) +#define RSTRING_LENINT(str) rb_long2int(RSTRING_LEN(str)) #define RARRAY_EMBED_LEN_MAX 3 struct RArray { @@ -666,24 +685,6 @@ struct RArray { ((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ? \ 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(n) __extension__ ({long i2l_n = (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 { @@ -822,6 +823,7 @@ struct RStruct { ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ RSTRUCT(st)->as.ary : \ RSTRUCT(st)->as.heap.ptr) +#define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st)) #define RBIGNUM_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(BDIGIT))) struct RBignum { @@ -856,6 +858,7 @@ struct RBignum { ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \ RBIGNUM(b)->as.ary : \ RBIGNUM(b)->as.heap.digits) +#define RBIGNUM_LENINT(b) rb_long2int(RBIGNUM_LEN(b)) #define R_CAST(st) (struct st*) #define RBASIC(obj) (R_CAST(RBasic)(obj)) |