1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

get rid of implicit signedness conversions

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57152 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-12-22 20:58:55 +00:00
parent 2a6727b566
commit 353395f969
2 changed files with 102 additions and 88 deletions

View file

@ -429,10 +429,14 @@ enum ruby_special_consts {
RUBY_SPECIAL_SHIFT = 8 RUBY_SPECIAL_SHIFT = 8
}; };
#define Qfalse ((VALUE)RUBY_Qfalse) #define RUBY_Qfalse ((VALUE)RUBY_Qfalse)
#define Qtrue ((VALUE)RUBY_Qtrue) #define RUBY_Qtrue ((VALUE)RUBY_Qtrue)
#define Qnil ((VALUE)RUBY_Qnil) #define RUBY_Qnil ((VALUE)RUBY_Qnil)
#define Qundef ((VALUE)RUBY_Qundef) /* undefined value for placeholder */ #define RUBY_Qundef ((VALUE)RUBY_Qundef) /* undefined value for placeholder */
#define Qfalse RUBY_Qfalse
#define Qtrue RUBY_Qtrue
#define Qnil RUBY_Qnil
#define Qundef RUBY_Qundef
#define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK #define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK
#define FIXNUM_FLAG RUBY_FIXNUM_FLAG #define FIXNUM_FLAG RUBY_FIXNUM_FLAG
#if USE_FLONUM #if USE_FLONUM
@ -985,10 +989,6 @@ struct RString {
((ptrvar) = RSTRING(str)->as.ary, (lenvar) = RSTRING_EMBED_LEN(str)) : \ ((ptrvar) = RSTRING(str)->as.ary, (lenvar) = RSTRING_EMBED_LEN(str)) : \
((ptrvar) = RSTRING(str)->as.heap.ptr, (lenvar) = RSTRING(str)->as.heap.len)) ((ptrvar) = RSTRING(str)->as.heap.ptr, (lenvar) = RSTRING(str)->as.heap.len))
#define RARRAY_EMBED_FLAG RARRAY_EMBED_FLAG
#define RARRAY_EMBED_LEN_MASK RARRAY_EMBED_LEN_MASK
#define RARRAY_EMBED_LEN_MAX RARRAY_EMBED_LEN_MAX
#define RARRAY_EMBED_LEN_SHIFT RARRAY_EMBED_LEN_SHIFT
enum { enum {
RARRAY_EMBED_LEN_MAX = 3, RARRAY_EMBED_LEN_MAX = 3,
RARRAY_EMBED_FLAG = RUBY_FL_USER1, RARRAY_EMBED_FLAG = RUBY_FL_USER1,
@ -998,6 +998,10 @@ enum {
RARRAY_ENUM_END RARRAY_ENUM_END
}; };
#define RARRAY_EMBED_FLAG (VALUE)RARRAY_EMBED_FLAG
#define RARRAY_EMBED_LEN_MASK (VALUE)RARRAY_EMBED_LEN_MASK
#define RARRAY_EMBED_LEN_MAX RARRAY_EMBED_LEN_MAX
#define RARRAY_EMBED_LEN_SHIFT RARRAY_EMBED_LEN_SHIFT
struct RArray { struct RArray {
struct RBasic basic; struct RBasic basic;
union { union {
@ -1204,38 +1208,38 @@ int rb_big_sign(VALUE);
#define RTYPEDDATA(obj) (R_CAST(RTypedData)(obj)) #define RTYPEDDATA(obj) (R_CAST(RTypedData)(obj))
#define RFILE(obj) (R_CAST(RFile)(obj)) #define RFILE(obj) (R_CAST(RFile)(obj))
#define FL_SINGLETON RUBY_FL_SINGLETON #define FL_SINGLETON ((VALUE)RUBY_FL_SINGLETON)
#define FL_WB_PROTECTED RUBY_FL_WB_PROTECTED #define FL_WB_PROTECTED ((VALUE)RUBY_FL_WB_PROTECTED)
#define FL_PROMOTED0 RUBY_FL_PROMOTED0 #define FL_PROMOTED0 ((VALUE)RUBY_FL_PROMOTED0)
#define FL_PROMOTED1 RUBY_FL_PROMOTED1 #define FL_PROMOTED1 ((VALUE)RUBY_FL_PROMOTED1)
#define FL_FINALIZE RUBY_FL_FINALIZE #define FL_FINALIZE ((VALUE)RUBY_FL_FINALIZE)
#define FL_TAINT RUBY_FL_TAINT #define FL_TAINT ((VALUE)RUBY_FL_TAINT)
#define FL_UNTRUSTED RUBY_FL_UNTRUSTED #define FL_UNTRUSTED ((VALUE)RUBY_FL_UNTRUSTED)
#define FL_EXIVAR RUBY_FL_EXIVAR #define FL_EXIVAR ((VALUE)RUBY_FL_EXIVAR)
#define FL_FREEZE RUBY_FL_FREEZE #define FL_FREEZE ((VALUE)RUBY_FL_FREEZE)
#define FL_USHIFT RUBY_FL_USHIFT #define FL_USHIFT ((VALUE)RUBY_FL_USHIFT)
#define FL_USER0 RUBY_FL_USER0 #define FL_USER0 ((VALUE)RUBY_FL_USER0)
#define FL_USER1 RUBY_FL_USER1 #define FL_USER1 ((VALUE)RUBY_FL_USER1)
#define FL_USER2 RUBY_FL_USER2 #define FL_USER2 ((VALUE)RUBY_FL_USER2)
#define FL_USER3 RUBY_FL_USER3 #define FL_USER3 ((VALUE)RUBY_FL_USER3)
#define FL_USER4 RUBY_FL_USER4 #define FL_USER4 ((VALUE)RUBY_FL_USER4)
#define FL_USER5 RUBY_FL_USER5 #define FL_USER5 ((VALUE)RUBY_FL_USER5)
#define FL_USER6 RUBY_FL_USER6 #define FL_USER6 ((VALUE)RUBY_FL_USER6)
#define FL_USER7 RUBY_FL_USER7 #define FL_USER7 ((VALUE)RUBY_FL_USER7)
#define FL_USER8 RUBY_FL_USER8 #define FL_USER8 ((VALUE)RUBY_FL_USER8)
#define FL_USER9 RUBY_FL_USER9 #define FL_USER9 ((VALUE)RUBY_FL_USER9)
#define FL_USER10 RUBY_FL_USER10 #define FL_USER10 ((VALUE)RUBY_FL_USER10)
#define FL_USER11 RUBY_FL_USER11 #define FL_USER11 ((VALUE)RUBY_FL_USER11)
#define FL_USER12 RUBY_FL_USER12 #define FL_USER12 ((VALUE)RUBY_FL_USER12)
#define FL_USER13 RUBY_FL_USER13 #define FL_USER13 ((VALUE)RUBY_FL_USER13)
#define FL_USER14 RUBY_FL_USER14 #define FL_USER14 ((VALUE)RUBY_FL_USER14)
#define FL_USER15 RUBY_FL_USER15 #define FL_USER15 ((VALUE)RUBY_FL_USER15)
#define FL_USER16 RUBY_FL_USER16 #define FL_USER16 ((VALUE)RUBY_FL_USER16)
#define FL_USER17 RUBY_FL_USER17 #define FL_USER17 ((VALUE)RUBY_FL_USER17)
#define FL_USER18 RUBY_FL_USER18 #define FL_USER18 ((VALUE)RUBY_FL_USER18)
#define FL_USER19 RUBY_FL_USER19 #define FL_USER19 ((VALUE)RUBY_FL_USER19)
#define RB_SPECIAL_CONST_P(x) (RB_IMMEDIATE_P(x) || !RB_TEST(x)) #define RB_SPECIAL_CONST_P(x) (RB_IMMEDIATE_P(x) || !RB_TEST(x))
#define SPECIAL_CONST_P(x) RB_SPECIAL_CONST_P(x) #define SPECIAL_CONST_P(x) RB_SPECIAL_CONST_P(x)
@ -1249,7 +1253,7 @@ int rb_big_sign(VALUE);
#define RB_FL_ALL(x,f) (RB_FL_TEST((x),(f)) == (f)) #define RB_FL_ALL(x,f) (RB_FL_TEST((x),(f)) == (f))
#define RB_FL_SET_RAW(x,f) (void)(RBASIC(x)->flags |= (f)) #define RB_FL_SET_RAW(x,f) (void)(RBASIC(x)->flags |= (f))
#define RB_FL_SET(x,f) (RB_FL_ABLE(x) ? RB_FL_SET_RAW(x, f) : (void)0) #define RB_FL_SET(x,f) (RB_FL_ABLE(x) ? RB_FL_SET_RAW(x, f) : (void)0)
#define RB_FL_UNSET_RAW(x,f) (void)(RBASIC(x)->flags &= ~(f)) #define RB_FL_UNSET_RAW(x,f) (void)(RBASIC(x)->flags &= ~(VALUE)(f))
#define RB_FL_UNSET(x,f) (RB_FL_ABLE(x) ? RB_FL_UNSET_RAW(x, f) : (void)0) #define RB_FL_UNSET(x,f) (RB_FL_ABLE(x) ? RB_FL_UNSET_RAW(x, f) : (void)0)
#define RB_FL_REVERSE_RAW(x,f) (void)(RBASIC(x)->flags ^= (f)) #define RB_FL_REVERSE_RAW(x,f) (void)(RBASIC(x)->flags ^= (f))
#define RB_FL_REVERSE(x,f) (RB_FL_ABLE(x) ? RB_FL_REVERSE_RAW(x, f) : (void)0) #define RB_FL_REVERSE(x,f) (RB_FL_ABLE(x) ? RB_FL_REVERSE_RAW(x, f) : (void)0)
@ -1567,11 +1571,11 @@ rb_num2char_inline(VALUE x)
#define NUM2CHR(x) RB_NUM2CHR(x) #define NUM2CHR(x) RB_NUM2CHR(x)
#define CHR2FIX(x) RB_CHR2FIX(x) #define CHR2FIX(x) RB_CHR2FIX(x)
#define RB_ALLOC_N(type,n) ((type*)ruby_xmalloc2((n),sizeof(type))) #define RB_ALLOC_N(type,n) ((type*)ruby_xmalloc2((size_t)(n),sizeof(type)))
#define RB_ALLOC(type) ((type*)ruby_xmalloc(sizeof(type))) #define RB_ALLOC(type) ((type*)ruby_xmalloc(sizeof(type)))
#define RB_ZALLOC_N(type,n) ((type*)ruby_xcalloc((n),sizeof(type))) #define RB_ZALLOC_N(type,n) ((type*)ruby_xcalloc((size_t)(n),sizeof(type)))
#define RB_ZALLOC(type) (RB_ZALLOC_N(type,1)) #define RB_ZALLOC(type) (RB_ZALLOC_N(type,1))
#define RB_REALLOC_N(var,type,n) ((var)=(type*)ruby_xrealloc2((char*)(var),(n),sizeof(type))) #define RB_REALLOC_N(var,type,n) ((var)=(type*)ruby_xrealloc2((char*)(var),(size_t)(n),sizeof(type)))
#define ALLOC_N(type,n) RB_ALLOC_N(type,n) #define ALLOC_N(type,n) RB_ALLOC_N(type,n)
#define ALLOC(type) RB_ALLOC(type) #define ALLOC(type) RB_ALLOC(type)
@ -1637,8 +1641,8 @@ rb_alloc_tmp_buffer2(volatile VALUE *store, long count, size_t elsize)
rb_alloc_tmp_buffer(&(v), (n))) rb_alloc_tmp_buffer(&(v), (n)))
# define RB_ALLOCV_N(type, v, n) \ # define RB_ALLOCV_N(type, v, n) \
((type*)(((size_t)(n) < RUBY_ALLOCV_LIMIT / sizeof(type)) ? \ ((type*)(((size_t)(n) < RUBY_ALLOCV_LIMIT / sizeof(type)) ? \
(RB_GC_GUARD(v) = 0, alloca((n) * sizeof(type))) : \ (RB_GC_GUARD(v) = 0, alloca((size_t)(n) * sizeof(type))) : \
rb_alloc_tmp_buffer2(&(v), (n), sizeof(type)))) rb_alloc_tmp_buffer2(&(v), (long)(n), sizeof(type))))
#endif #endif
#define RB_ALLOCV_END(v) rb_free_tmp_buffer(&(v)) #define RB_ALLOCV_END(v) rb_free_tmp_buffer(&(v))
@ -1646,10 +1650,10 @@ rb_alloc_tmp_buffer2(volatile VALUE *store, long count, size_t elsize)
#define ALLOCV_N(type, v, n) RB_ALLOCV_N(type, v, n) #define ALLOCV_N(type, v, n) RB_ALLOCV_N(type, v, n)
#define ALLOCV_END(v) RB_ALLOCV_END(v) #define ALLOCV_END(v) RB_ALLOCV_END(v)
#define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n)) #define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(size_t)(n))
#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n)) #define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(size_t)(n))
#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n)) #define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(size_t)(n))
#define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(n)) #define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(size_t)(n))
void rb_obj_infect(VALUE,VALUE); void rb_obj_infect(VALUE,VALUE);

View file

@ -133,20 +133,20 @@ extern "C" {
# endif # endif
#endif #endif
static inline int static inline unsigned int
nlz_int(unsigned int x) nlz_int(unsigned int x)
{ {
#if defined(HAVE_BUILTIN___BUILTIN_CLZ) #if defined(HAVE_BUILTIN___BUILTIN_CLZ)
if (x == 0) return SIZEOF_INT * CHAR_BIT; if (x == 0) return SIZEOF_INT * CHAR_BIT;
return __builtin_clz(x); return (unsigned int)__builtin_clz(x);
#else #else
unsigned int y; unsigned int y;
# if 64 < SIZEOF_INT * CHAR_BIT # if 64 < SIZEOF_INT * CHAR_BIT
int n = 128; unsigned int n = 128;
# elif 32 < SIZEOF_INT * CHAR_BIT # elif 32 < SIZEOF_INT * CHAR_BIT
int n = 64; unsigned int n = 64;
# else # else
int n = 32; unsigned int n = 32;
# endif # endif
# if 64 < SIZEOF_INT * CHAR_BIT # if 64 < SIZEOF_INT * CHAR_BIT
y = x >> 64; if (y) {n -= 64; x = y;} y = x >> 64; if (y) {n -= 64; x = y;}
@ -159,24 +159,24 @@ nlz_int(unsigned int x)
y = x >> 4; if (y) {n -= 4; x = y;} y = x >> 4; if (y) {n -= 4; x = y;}
y = x >> 2; if (y) {n -= 2; x = y;} y = x >> 2; if (y) {n -= 2; x = y;}
y = x >> 1; if (y) {return n - 2;} y = x >> 1; if (y) {return n - 2;}
return (int)(n - x); return (unsigned int)(n - x);
#endif #endif
} }
static inline int static inline unsigned int
nlz_long(unsigned long x) nlz_long(unsigned long x)
{ {
#if defined(HAVE_BUILTIN___BUILTIN_CLZL) #if defined(HAVE_BUILTIN___BUILTIN_CLZL)
if (x == 0) return SIZEOF_LONG * CHAR_BIT; if (x == 0) return SIZEOF_LONG * CHAR_BIT;
return __builtin_clzl(x); return (unsigned int)__builtin_clzl(x);
#else #else
unsigned long y; unsigned long y;
# if 64 < SIZEOF_LONG * CHAR_BIT # if 64 < SIZEOF_LONG * CHAR_BIT
int n = 128; unsigned int n = 128;
# elif 32 < SIZEOF_LONG * CHAR_BIT # elif 32 < SIZEOF_LONG * CHAR_BIT
int n = 64; unsigned int n = 64;
# else # else
int n = 32; unsigned int n = 32;
# endif # endif
# if 64 < SIZEOF_LONG * CHAR_BIT # if 64 < SIZEOF_LONG * CHAR_BIT
y = x >> 64; if (y) {n -= 64; x = y;} y = x >> 64; if (y) {n -= 64; x = y;}
@ -189,25 +189,25 @@ nlz_long(unsigned long x)
y = x >> 4; if (y) {n -= 4; x = y;} y = x >> 4; if (y) {n -= 4; x = y;}
y = x >> 2; if (y) {n -= 2; x = y;} y = x >> 2; if (y) {n -= 2; x = y;}
y = x >> 1; if (y) {return n - 2;} y = x >> 1; if (y) {return n - 2;}
return (int)(n - x); return (unsigned int)(n - x);
#endif #endif
} }
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
static inline int static inline unsigned int
nlz_long_long(unsigned LONG_LONG x) nlz_long_long(unsigned LONG_LONG x)
{ {
#if defined(HAVE_BUILTIN___BUILTIN_CLZLL) #if defined(HAVE_BUILTIN___BUILTIN_CLZLL)
if (x == 0) return SIZEOF_LONG_LONG * CHAR_BIT; if (x == 0) return SIZEOF_LONG_LONG * CHAR_BIT;
return __builtin_clzll(x); return (unsigned int)__builtin_clzll(x);
#else #else
unsigned LONG_LONG y; unsigned LONG_LONG y;
# if 64 < SIZEOF_LONG_LONG * CHAR_BIT # if 64 < SIZEOF_LONG_LONG * CHAR_BIT
int n = 128; unsigned int n = 128;
# elif 32 < SIZEOF_LONG_LONG * CHAR_BIT # elif 32 < SIZEOF_LONG_LONG * CHAR_BIT
int n = 64; unsigned int n = 64;
# else # else
int n = 32; unsigned int n = 32;
# endif # endif
# if 64 < SIZEOF_LONG_LONG * CHAR_BIT # if 64 < SIZEOF_LONG_LONG * CHAR_BIT
y = x >> 64; if (y) {n -= 64; x = y;} y = x >> 64; if (y) {n -= 64; x = y;}
@ -220,17 +220,17 @@ nlz_long_long(unsigned LONG_LONG x)
y = x >> 4; if (y) {n -= 4; x = y;} y = x >> 4; if (y) {n -= 4; x = y;}
y = x >> 2; if (y) {n -= 2; x = y;} y = x >> 2; if (y) {n -= 2; x = y;}
y = x >> 1; if (y) {return n - 2;} y = x >> 1; if (y) {return n - 2;}
return (int)(n - x); return (unsigned int)(n - x);
#endif #endif
} }
#endif #endif
#ifdef HAVE_UINT128_T #ifdef HAVE_UINT128_T
static inline int static inline unsigned int
nlz_int128(uint128_t x) nlz_int128(uint128_t x)
{ {
uint128_t y; uint128_t y;
int n = 128; unsigned int n = 128;
y = x >> 64; if (y) {n -= 64; x = y;} y = x >> 64; if (y) {n -= 64; x = y;}
y = x >> 32; if (y) {n -= 32; x = y;} y = x >> 32; if (y) {n -= 32; x = y;}
y = x >> 16; if (y) {n -= 16; x = y;} y = x >> 16; if (y) {n -= 16; x = y;}
@ -238,12 +238,13 @@ nlz_int128(uint128_t x)
y = x >> 4; if (y) {n -= 4; x = y;} y = x >> 4; if (y) {n -= 4; x = y;}
y = x >> 2; if (y) {n -= 2; x = y;} y = x >> 2; if (y) {n -= 2; x = y;}
y = x >> 1; if (y) {return n - 2;} y = x >> 1; if (y) {return n - 2;}
return (int)(n - x); return (unsigned int)(n - x);
} }
#endif #endif
static inline int static inline unsigned int
nlz_intptr(uintptr_t x) { nlz_intptr(uintptr_t x)
{
#if SIZEOF_VOIDP == 8 #if SIZEOF_VOIDP == 8
return nlz_long_long(x); return nlz_long_long(x);
#elif SIZEOF_VOIDP == 4 #elif SIZEOF_VOIDP == 4
@ -251,10 +252,11 @@ nlz_intptr(uintptr_t x) {
#endif #endif
} }
static inline int static inline unsigned int
rb_popcount32(uint32_t x) { rb_popcount32(uint32_t x)
{
#ifdef HAVE_BUILTIN___BUILTIN_POPCOUNT #ifdef HAVE_BUILTIN___BUILTIN_POPCOUNT
return __builtin_popcount(x); return (unsigned int)__builtin_popcount(x);
#else #else
x = (x & 0x55555555) + (x >> 1 & 0x55555555); x = (x & 0x55555555) + (x >> 1 & 0x55555555);
x = (x & 0x33333333) + (x >> 2 & 0x33333333); x = (x & 0x33333333) + (x >> 2 & 0x33333333);
@ -265,7 +267,8 @@ rb_popcount32(uint32_t x) {
} }
static inline int static inline int
rb_popcount64(uint64_t x) { rb_popcount64(uint64_t x)
{
#ifdef HAVE_BUILTIN___BUILTIN_POPCOUNT #ifdef HAVE_BUILTIN___BUILTIN_POPCOUNT
return __builtin_popcountll(x); return __builtin_popcountll(x);
#else #else
@ -279,7 +282,8 @@ rb_popcount64(uint64_t x) {
} }
static inline int static inline int
rb_popcount_intptr(uintptr_t x) { rb_popcount_intptr(uintptr_t x)
{
#if SIZEOF_VOIDP == 8 #if SIZEOF_VOIDP == 8
return rb_popcount64(x); return rb_popcount64(x);
#elif SIZEOF_VOIDP == 4 #elif SIZEOF_VOIDP == 4
@ -288,7 +292,8 @@ rb_popcount_intptr(uintptr_t x) {
} }
static inline int static inline int
ntz_int32(uint32_t x) { ntz_int32(uint32_t x)
{
#ifdef HAVE_BUILTIN___BUILTIN_CTZ #ifdef HAVE_BUILTIN___BUILTIN_CTZ
return __builtin_ctz(x); return __builtin_ctz(x);
#else #else
@ -297,7 +302,8 @@ ntz_int32(uint32_t x) {
} }
static inline int static inline int
ntz_int64(uint64_t x) { ntz_int64(uint64_t x)
{
#ifdef HAVE_BUILTIN___BUILTIN_CTZLL #ifdef HAVE_BUILTIN___BUILTIN_CTZLL
return __builtin_ctzll(x); return __builtin_ctzll(x);
#else #else
@ -306,7 +312,8 @@ ntz_int64(uint64_t x) {
} }
static inline int static inline int
ntz_intptr(uintptr_t x) { ntz_intptr(uintptr_t x)
{
#if SIZEOF_VOIDP == 8 #if SIZEOF_VOIDP == 8
return ntz_int64(x); return ntz_int64(x);
#elif SIZEOF_VOIDP == 4 #elif SIZEOF_VOIDP == 4
@ -397,17 +404,20 @@ rb_fix_mod_fix(VALUE x, VALUE y)
#if defined(HAVE_UINT128_T) #if defined(HAVE_UINT128_T)
# define bit_length(x) \ # define bit_length(x) \
(unsigned int) \
(sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \ sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
sizeof(x) <= SIZEOF_LONG_LONG ? SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)) : \ sizeof(x) <= SIZEOF_LONG_LONG ? SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)) : \
SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x))) SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x)))
#elif defined(HAVE_LONG_LONG) #elif defined(HAVE_LONG_LONG)
# define bit_length(x) \ # define bit_length(x) \
(unsigned int) \
(sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \ sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x))) SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)))
#else #else
# define bit_length(x) \ # define bit_length(x) \
(unsigned int) \
(sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x))) SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)))
#endif #endif
@ -485,7 +495,7 @@ struct RBignum {
BDIGIT ary[BIGNUM_EMBED_LEN_MAX]; BDIGIT ary[BIGNUM_EMBED_LEN_MAX];
} as; } as;
}; };
#define BIGNUM_SIGN_BIT FL_USER1 #define BIGNUM_SIGN_BIT ((VALUE)FL_USER1)
/* sign: positive:1, negative:0 */ /* sign: positive:1, negative:0 */
#define BIGNUM_SIGN(b) ((RBASIC(b)->flags & BIGNUM_SIGN_BIT) != 0) #define BIGNUM_SIGN(b) ((RBASIC(b)->flags & BIGNUM_SIGN_BIT) != 0)
#define BIGNUM_SET_SIGN(b,sign) \ #define BIGNUM_SET_SIGN(b,sign) \
@ -495,13 +505,13 @@ struct RBignum {
#define BIGNUM_NEGATIVE_P(b) (!BIGNUM_SIGN(b)) #define BIGNUM_NEGATIVE_P(b) (!BIGNUM_SIGN(b))
#define BIGNUM_NEGATE(b) (RBASIC(b)->flags ^= BIGNUM_SIGN_BIT) #define BIGNUM_NEGATE(b) (RBASIC(b)->flags ^= BIGNUM_SIGN_BIT)
#define BIGNUM_EMBED_FLAG FL_USER2 #define BIGNUM_EMBED_FLAG ((VALUE)FL_USER2)
#define BIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3) #define BIGNUM_EMBED_LEN_MASK ((VALUE)(FL_USER5|FL_USER4|FL_USER3))
#define BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+BIGNUM_EMBED_LEN_NUMBITS) #define BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+BIGNUM_EMBED_LEN_NUMBITS)
#define BIGNUM_LEN(b) \ #define BIGNUM_LEN(b) \
((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
(long)((RBASIC(b)->flags >> BIGNUM_EMBED_LEN_SHIFT) & \ (size_t)((RBASIC(b)->flags >> BIGNUM_EMBED_LEN_SHIFT) & \
(BIGNUM_EMBED_LEN_MASK >> BIGNUM_EMBED_LEN_SHIFT)) : \ (BIGNUM_EMBED_LEN_MASK >> BIGNUM_EMBED_LEN_SHIFT)) : \
RBIGNUM(b)->as.heap.len) RBIGNUM(b)->as.heap.len)
/* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */ /* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */
#define BIGNUM_DIGITS(b) \ #define BIGNUM_DIGITS(b) \
@ -559,7 +569,7 @@ struct RHash {
#undef RHASH_SIZE #undef RHASH_SIZE
#define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev) #define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev)
#define RHASH_IFNONE(h) (RHASH(h)->ifnone) #define RHASH_IFNONE(h) (RHASH(h)->ifnone)
#define RHASH_SIZE(h) (RHASH(h)->ntbl ? (st_index_t)RHASH(h)->ntbl->num_entries : 0) #define RHASH_SIZE(h) (RHASH(h)->ntbl ? RHASH(h)->ntbl->num_entries : (st_index_t)0)
#endif #endif
/* missing/setproctitle.c */ /* missing/setproctitle.c */
@ -834,8 +844,8 @@ enum {
}; };
struct cmp_opt_data { struct cmp_opt_data {
int opt_methods; unsigned int opt_methods;
int opt_inited; unsigned int opt_inited;
}; };
#define NEW_CMP_OPT_MEMO(type, value) \ #define NEW_CMP_OPT_MEMO(type, value) \
@ -1214,7 +1224,7 @@ rb_float_flonum_value(VALUE v)
/* e: xx1... -> 011... */ /* e: xx1... -> 011... */
/* xx0... -> 100... */ /* xx0... -> 100... */
/* ^b63 */ /* ^b63 */
t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~0x03), 3); t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~(VALUE)0x03), 3);
return t.d; return t.d;
} }
#endif #endif