ruby-changes:15619
From: nobu <ko1@a...>
Date: Wed, 28 Apr 2010 16:45:16 +0900 (JST)
Subject: [ruby-changes:15619] Ruby:r27528 (trunk): * include/ruby/ruby.h ({RSTRING,RSTRUCT,RBIGNUM}_LENINT): check long
nobu 2010-04-28 16:45:00 +0900 (Wed, 28 Apr 2010) New Revision: 27528 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27528 Log: * include/ruby/ruby.h ({RSTRING,RSTRUCT,RBIGNUM}_LENINT): check long to cast to int. Modified files: trunk/ChangeLog trunk/include/ruby/ruby.h Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 27527) +++ include/ruby/ruby.h (revision 27528) @@ -272,6 +272,24 @@ # 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 @@ ((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 @@ ((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 @@ ((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 @@ ((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)) Index: ChangeLog =================================================================== --- ChangeLog (revision 27527) +++ ChangeLog (revision 27528) @@ -1,3 +1,8 @@ +Wed Apr 28 16:44:58 2010 Nobuyoshi Nakada <nobu@r...> + + * include/ruby/ruby.h ({RSTRING,RSTRUCT,RBIGNUM}_LENINT): check long + to cast to int. + Wed Apr 28 16:28:51 2010 Nobuyoshi Nakada <nobu@r...> * ext/socket/unixsocket.c (sendmsg_blocking, recvmsg_blocking): -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/