diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-11-15 05:57:34 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-11-15 05:57:34 +0000 |
commit | fd5a7ee75cb372aaf15c8a3c95517ce228b94f04 (patch) | |
tree | c784d43a1642298ccba91cceba3d002c6377cb85 | |
parent | 3d85b0ff5a0ebe583235c99dfe17791d9d5d6587 (diff) | |
download | ruby-fd5a7ee75cb372aaf15c8a3c95517ce228b94f04.tar.gz |
* include/ruby/ruby.h(NUM2LONG, NUM2INT, NUM2SHORT, NUM2LL,
INT2NUM, UINT2NUM, LONG2NUM, ULONG2NUM, NUM2CHR): wrap by
macros.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | include/ruby/ruby.h | 36 |
2 files changed, 30 insertions, 14 deletions
@@ -1,3 +1,9 @@ +Tue Nov 15 14:45:15 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com> + + * include/ruby/ruby.h(NUM2LONG, NUM2INT, NUM2SHORT, NUM2LL, + INT2NUM, UINT2NUM, LONG2NUM, ULONG2NUM, NUM2CHR): wrap by + macros. + Tue Nov 15 13:38:14 2011 Naohisa Goto <ngotogenome@gmail.com> * include/ruby/defines.h (FLUSH_REGISTER_WINDOWS): move sparc asm code @@ -13,8 +19,6 @@ Tue Nov 15 13:11:35 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com> UINT2NUM(), LONG2NUM(), ULONG2NUM() and NUM2CHR() implementation. Because 1) They don't make any better code at all. 2) Inline function have a better debugger supoort. - 3) If they become to make better code in the future, they - might make cross compiler ABI compatibility issue. Tue Nov 15 09:58:25 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com> diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index be73b56252..7e534eb1ff 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -503,27 +503,30 @@ void rb_set_errinfo(VALUE); SIGNED_VALUE rb_num2long(VALUE); VALUE rb_num2ulong(VALUE); static inline long -NUM2LONG(VALUE x) +rb_num2long_inline(VALUE x) { if (FIXNUM_P(x)) return FIX2LONG(x); else return (long)rb_num2long(x); } -#define NUM2ULONG(x) rb_num2ulong((VALUE)(x)) +#define NUM2LONG(x) rb_num2long_inline(x) +#define NUM2ULONG(x) rb_num2ulong(x) #if SIZEOF_INT < SIZEOF_LONG long rb_num2int(VALUE); long rb_fix2int(VALUE); #define FIX2INT(x) ((int)rb_fix2int((VALUE)(x))) static inline int -NUM2INT(VALUE x) +rb_num2int_inline(VALUE x) { if (FIXNUM_P(x)) return FIX2INT(x); else return (int)rb_num2int(x); } +#define NUM2INT(x) rb_num2int_inline(x) + unsigned long rb_num2uint(VALUE); #define NUM2UINT(x) ((unsigned int)rb_num2uint(x)) unsigned long rb_fix2uint(VALUE); @@ -541,27 +544,30 @@ short rb_fix2short(VALUE); unsigned short rb_fix2ushort(VALUE); #define FIX2SHORT(x) (rb_fix2short((VALUE)(x))) static inline short -NUM2SHORT(VALUE x) +rb_num2short_inline(VALUE x) { if (FIXNUM_P(x)) return FIX2SHORT(x); else return rb_num2short(x); } -#define NUM2USHORT(x) rb_num2ushort((VALUE)(x)) + +#define NUM2SHORT(x) rb_num2short_inline(x) +#define NUM2USHORT(x) rb_num2ushort(x) #ifdef HAVE_LONG_LONG LONG_LONG rb_num2ll(VALUE); unsigned LONG_LONG rb_num2ull(VALUE); static inline LONG_LONG -NUM2LL(VALUE x) +rb_num2ll_inline(VALUE x) { if (FIXNUM_P(x)) return FIX2LONG(x); else return rb_num2ll(x); } -# define NUM2ULL(x) rb_num2ull((VALUE)(x)) +# define NUM2LL(x) rb_num2ll_inline(x) +# define NUM2ULL(x) rb_num2ull(x) #endif #if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T > SIZEOF_LONG @@ -982,50 +988,56 @@ struct RBignum { # define UINT2NUM(v) LONG2FIX((unsigned int)(v)) #else static inline VALUE -INT2NUM(int v) +rb_int2num_inline(int v) { if (FIXABLE(v)) return INT2FIX(v); else return rb_int2big(v); } +#define INT2NUM(x) rb_int2num_inline(x) static inline VALUE -UINT2NUM(unsigned int v) +rb_uint2num_inline(unsigned int v) { if (POSFIXABLE(v)) return LONG2FIX(v); else return rb_uint2big(v); } +#define UINT2NUM(x) rb_uint2num_inline(x) #endif static inline VALUE -LONG2NUM(long v) +rb_long2num_inline(long v) { if (FIXABLE(v)) return LONG2FIX(v); else return rb_int2big(v); } +#define LONG2NUM(x) rb_long2num_inline(x) static inline VALUE -ULONG2NUM(unsigned long v) +rb_ulong2num_inline(unsigned long v) { if (POSFIXABLE(v)) return LONG2FIX(v); else return rb_uint2big(v); } +#define ULONG2NUM(x) rb_ulong2num_inline(x) static inline char -NUM2CHR(VALUE x) +rb_num2char_inline(VALUE x) { if ((TYPE(x) == T_STRING) && (RSTRING_LEN(x)>=1)) return RSTRING_PTR(x)[0]; else return (char)(NUM2INT(x) & 0xff); } +#define NUM2CHR(x) rb_num2char_inline(x) + #define CHR2FIX(x) INT2FIX((long)((x)&0xff)) #define ALLOC_N(type,n) ((type*)xmalloc2((n),sizeof(type))) |