ruby-changes:45436
From: nobu <ko1@a...>
Date: Fri, 3 Feb 2017 15:11:39 +0900 (JST)
Subject: [ruby-changes:45436] nobu:r57509 (trunk): internal.h: fix r57507
nobu 2017-02-03 15:11:32 +0900 (Fri, 03 Feb 2017) New Revision: 57509 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57509 Log: internal.h: fix r57507 * internal.h (rb_overflowed_fix_to_int): invert sign bit. should not set LSB of fixnum value, which is always set, to MSB. Modified files: trunk/internal.h Index: internal.h =================================================================== --- internal.h (revision 57508) +++ internal.h (revision 57509) @@ -348,10 +348,10 @@ VALUE rb_int128t2big(int128_t n); https://github.com/ruby/ruby/blob/trunk/internal.h#L348 #define ST2FIX(h) LONG2FIX((long)(h)) -static inline unsigned long -rb_ulong_rotate_right(unsigned long x) +static inline long +rb_overflowed_fix_to_int(long x) { - return (x >> 1) | (x << (SIZEOF_LONG * CHAR_BIT - 1)); + return (long)((unsigned long)(x >> 1) ^ (1LU << (SIZEOF_LONG * CHAR_BIT - 1))); } static inline VALUE @@ -368,7 +368,7 @@ rb_fix_plus_fix(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/internal.h#L368 * and it equals to `(z<<63)|(z>>1)` == `ror(z)`. */ if (__builtin_add_overflow((long)x, (long)y-1, &lz)) { - return rb_int2big(rb_ulong_rotate_right((unsigned long)lz)); + return rb_int2big(rb_overflowed_fix_to_int(lz)); } else { return (VALUE)lz; @@ -385,7 +385,7 @@ rb_fix_minus_fix(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/internal.h#L385 #ifdef HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW long lz; if (__builtin_sub_overflow((long)x, (long)y-1, &lz)) { - return rb_int2big(rb_ulong_rotate_right((unsigned long)lz)); + return rb_int2big(rb_overflowed_fix_to_int(lz)); } else { return (VALUE)lz; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/