From 5622c977f441a91a7482d5956df96e60d71d90f9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:25:04 +0900 Subject: remove dependency to SIZEOF_VOIDP --- include/mrbconf.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index d4802a5e7..81c19a121 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -27,7 +27,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 #define SIZEOF___INT64 0 -#define SIZEOF_VOIDP 4 #define SIZEOF_FLOAT 4 #define SIZEOF_DOUBLE 8 -- cgit v1.2.3 From 41bf311cd1997ad2d20d451fe627b241aed571d3 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:31:58 +0900 Subject: remove dependency to SIZEOF_INT --- include/mrbconf.h | 1 - include/mruby.h | 54 ------------------------------------------------------ src/numeric.c | 2 +- src/string.c | 6 +++--- src/transcode.c | 8 ++++---- 5 files changed, 8 insertions(+), 63 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 81c19a121..bc54de420 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,7 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_INT 4 #define SIZEOF_SHORT 2 #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 diff --git a/include/mruby.h b/include/mruby.h index 8084735bf..f1cf1ca01 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -560,60 +560,6 @@ void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t); #define ruby_setjmp(env) RUBY_SETJMP(env) #define ruby_longjmp(env,val) RUBY_LONGJMP(env,val) -#if defined PRIdPTR && !defined PRI_VALUE_PREFIX -#define PRIdVALUE PRIdPTR -#define PRIiVALUE PRIiPTR -#define PRIoVALUE PRIoPTR -#define PRIuVALUE PRIuPTR -#define PRIxVALUE PRIxPTR -#define PRIXVALUE PRIXPTR -#else -#define PRIdVALUE PRI_VALUE_PREFIX"d" -#define PRIiVALUE PRI_VALUE_PREFIX"i" -#define PRIoVALUE PRI_VALUE_PREFIX"o" -#define PRIuVALUE PRI_VALUE_PREFIX"u" -#define PRIxVALUE PRI_VALUE_PREFIX"x" -#define PRIXVALUE PRI_VALUE_PREFIX"X" -#endif -#ifndef PRI_VALUE_PREFIX -# define PRI_VALUE_PREFIX "" -#endif - -#if defined PRIdPTR -# define PRI_PTRDIFF_PREFIX "t" -#elif SIZEOF_PTRDIFF_T == SIZEOF_INT -# define PRI_PTRDIFF_PREFIX -#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG -# define PRI_PTRDIFF_PREFIX "l" -#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG -# define PRI_PTRDIFF_PREFIX "ll" -#else -# define PRI_PTRDIFF_PREFIX -#endif -#define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d" -#define PRIiPTRDIFF PRI_PTRDIFF_PREFIX"i" -#define PRIoPTRDIFF PRI_PTRDIFF_PREFIX"o" -#define PRIuPTRDIFF PRI_PTRDIFF_PREFIX"u" -#define PRIxPTRDIFF PRI_PTRDIFF_PREFIX"x" -#define PRIXPTRDIFF PRI_PTRDIFF_PREFIX"X" - -#if defined PRIdPTR -# define PRI_SIZE_PREFIX "z" -#elif SIZEOF_SIZE_T == SIZEOF_INT -# define PRI_SIZE_PREFIX -#elif SIZEOF_SIZE_T == SIZEOF_LONG -# define PRI_SIZE_PREFIX "l" -#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG -# define PRI_SIZE_PREFIX "ll" -#endif -#define PRIdSIZE PRI_SIZE_PREFIX"d" -#define PRIiSIZE PRI_SIZE_PREFIX"i" -#define PRIoSIZE PRI_SIZE_PREFIX"o" -#define PRIuSIZE PRI_SIZE_PREFIX"u" -#define PRIxSIZE PRI_SIZE_PREFIX"x" -#define PRIXSIZE PRI_SIZE_PREFIX"X" -#define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d" - #define KHASH 0 #define STHASH 1 #define BASICHASH 2 diff --git a/src/numeric.c b/src/numeric.c index ef4588f76..b03e57ce6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -985,7 +985,7 @@ mrb_num2fix(mrb_state *mrb, mrb_value val) v = mrb_num2long(mrb, val); if (!FIXABLE(v)) - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIdVALUE " out of range of fixnum", v); + mrb_raise(mrb, E_RANGE_ERROR, "integer %ld out of range of fixnum", v); return mrb_fixnum_value(v); } diff --git a/src/string.c b/src/string.c index 9556f93e8..6b8861ace 100644 --- a/src/string.c +++ b/src/string.c @@ -4833,9 +4833,9 @@ mrb_str_buf_cat_escaped_char(mrb_state *mrb, mrb_value result, unsigned int c, i char buf[CHAR_ESC_LEN + 1]; int l; -#if SIZEOF_INT > 4 - c &= 0xffffffff; -#endif + if (sizeof(c) > 4) { + c &= 0xffffffff; + } if (unicode_p) { if (c < 0x7F && ISPRINT(c)) { snprintf(buf, CHAR_ESC_LEN, "%c", c); diff --git a/src/transcode.c b/src/transcode.c index 05d2b05b1..66a4d4e42 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -1770,9 +1770,9 @@ mrb_econv_putbackable(mrb_econv_t *ec) { if (ec->num_trans == 0) return 0; -#if SIZEOF_SIZE_T > SIZEOF_INT - if (ec->elems[0].tc->readagain_len > INT_MAX) return INT_MAX; -#endif + if (sizeof(size_t) > sizeof(int)) { + if (ec->elems[0].tc->readagain_len > INT_MAX) return INT_MAX; + } return (int)ec->elems[0].tc->readagain_len; } @@ -2625,7 +2625,7 @@ str_transcode0(mrb_state *mrb, int argc, mrb_value *argv, mrb_value *self, int e transcode_loop(mrb, &fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, sname, dname, ecflags, ecopts); if (fromp != sp+slen) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp); + mrb_raise(mrb, E_ARGUMENT_ERROR, "not fully converted, %td bytes left", sp+slen-fromp); } buf = (unsigned char *)RSTRING_PTR(dest); *bp = '\0'; -- cgit v1.2.3 From 1f78ba77a2efb23f637e79a9b1120b5e316f870a Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:37:21 +0900 Subject: remove SIZEOF_SHORT --- include/mrbconf.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index bc54de420..6dccaccec 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,7 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_SHORT 2 #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 #define SIZEOF___INT64 0 -- cgit v1.2.3 From 0f0ad36c5f4b00781b96e2cae595672aa84e57c7 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:39:02 +0900 Subject: remove dependency to SIZEOF___INT64 --- include/mrbconf.h | 1 - src/numeric.c | 5 ----- 2 files changed, 6 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 6dccaccec..5d377e3e3 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -24,7 +24,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 -#define SIZEOF___INT64 0 #define SIZEOF_FLOAT 4 #define SIZEOF_DOUBLE 8 diff --git a/src/numeric.c b/src/numeric.c index b03e57ce6..113c9b062 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -90,11 +90,6 @@ #if SIZEOF_LONG_LONG > 0 # define LONG_LONG long long -#elif SIZEOF___INT64 > 0 -# define HAVE_LONG_LONG 1 -# define LONG_LONG __int64 -# undef SIZEOF_LONG_LONG -# define SIZEOF_LONG_LONG SIZEOF___INT64 #endif typedef uintptr_t VALUE; -- cgit v1.2.3 From 2c28d29cecaa1d007f89d3c233d0556345a8ff99 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:39:22 +0900 Subject: remove SIZEOF_FLOAT/DOUBLE --- include/mrbconf.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 5d377e3e3..96214a30b 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -24,8 +24,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 -#define SIZEOF_FLOAT 4 -#define SIZEOF_DOUBLE 8 #ifndef FALSE # define FALSE 0 -- cgit v1.2.3 From 3c1b3478343a7618dac7ac16953e77f45511f505 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:46:07 +0900 Subject: remove dependency to SIZEOF_LONG/LONG_LONG --- include/mrbconf.h | 3 --- src/numeric.c | 71 ++++--------------------------------------------------- src/regint.h | 4 ++-- 3 files changed, 6 insertions(+), 72 deletions(-) (limited to 'include/mrbconf.h') diff --git a/include/mrbconf.h b/include/mrbconf.h index 96214a30b..923558fd9 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,9 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_LONG 4 -#define SIZEOF_LONG_LONG 8 - #ifndef FALSE # define FALSE 0 #endif diff --git a/src/numeric.c b/src/numeric.c index 113c9b062..135691644 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -88,10 +88,6 @@ #define mrb_rational_raw1(x) mrb_rational_raw(x, INT2FIX(1)) -#if SIZEOF_LONG_LONG > 0 -# define LONG_LONG long long -#endif - typedef uintptr_t VALUE; typedef uintptr_t ID; #define SIGNED_VALUE intptr_t @@ -984,55 +980,6 @@ mrb_num2fix(mrb_state *mrb, mrb_value val) return mrb_fixnum_value(v); } -#if HAVE_LONG_LONG - -LONG_LONG -mrb_num2ll(mrb_state *mrb, mrb_value val) -{ - if (mrb_nil_p(val)) { - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from nil"); - } - - if (FIXNUM_P(val)) return (LONG_LONG)mrb_fixnum(val); - - switch (mrb_type(val)) { - case MRB_TT_FLOAT: - if (mrb_float(val) <= (double)LLONG_MAX - && mrb_float(val) >= (double)LLONG_MIN) { - return (LONG_LONG)(mrb_float(val)); - } - else { - char buf[24]; - char *s; - - snprintf(buf, sizeof(buf), "%-.10g", mrb_float(val)); - if ((s = strchr(buf, ' ')) != 0) *s = '\0'; - mrb_raise(mrb, E_RANGE_ERROR, "float %s out of range of long long", buf); - } - - case MRB_TT_STRING: - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from string"); - return mrb_nil_value(); /* not reached */ - - case MRB_TT_TRUE: - case MRB_TT_FALSE: - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from boolean"); - return mrb_nil_value(); /* not reached */ - - default: - val = mrb_to_int(mrb, val); - return NUM2LL(val); - } -} - -unsigned LONG_LONG -mrb_num2ull(mrb_state *mrb, mrb_value val) -{ - return (unsigned LONG_LONG)mrb_num2ll(mrb, val); -} - -#endif /* HAVE_LONG_LONG */ - /* * Document-class: Integer * @@ -1133,7 +1080,7 @@ rb_fix2str(mrb_state *mrb, mrb_value x, int base) return mrb_usascii_str_new2(mrb, b); } -#define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((SIZEOF_LONG*CHAR_BIT-1)/2)) +#define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((sizeof(intptr_t)*CHAR_BIT-1)/2)) /*tests if N*N would overflow*/ #define FIT_SQRT_LONG(n) (((n)=-SQRT_LONG_MAX)) @@ -1159,21 +1106,12 @@ fix_mul(mrb_state *mrb, mrb_value x) volatile #endif long a, b; -#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG - LONG_LONG d; -#else long c; mrb_value r; -#endif a = mrb_fixnum(x); b = mrb_fixnum(y); -#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG - d = (LONG_LONG)a * b; - if (FIXABLE(d)) return mrb_fixnum_value(d); - return mrb_nil_value();// rb_ll2inum(d); -#else if (FIT_SQRT_LONG(a) && FIT_SQRT_LONG(b)) return mrb_fixnum_value(a*b); c = a * b; @@ -1185,7 +1123,6 @@ fix_mul(mrb_state *mrb, mrb_value x) r = mrb_fixnum_value(a*b); } return r; -#endif } switch (mrb_type(y)) { case MRB_TT_FLOAT: @@ -1519,9 +1456,9 @@ mrb_fix_lshift(mrb_state *mrb, mrb_value x) static mrb_value fix_lshift(mrb_state *mrb, long val, unsigned long width) { - if (width > (SIZEOF_LONG*CHAR_BIT-1) - || ((unsigned long)abs(val))>>(SIZEOF_LONG*CHAR_BIT-1-width) > 0) { - mrb_raise(mrb, E_RANGE_ERROR, "width(%d) > (SIZEOF_LONG*CHAR_BIT-1)", width); + if (width > (sizeof(intptr_t)*CHAR_BIT-1) + || ((unsigned long)abs(val))>>(sizeof(intptr_t)*CHAR_BIT-1-width) > 0) { + mrb_raise(mrb, E_RANGE_ERROR, "width(%d) > (sizeof(intptr_t)*CHAR_BIT-1)", width); } val = val << width; return mrb_fixnum_value(val); diff --git a/src/regint.h b/src/regint.h index e86a95f27..bf19eee1a 100644 --- a/src/regint.h +++ b/src/regint.h @@ -246,11 +246,11 @@ } while(0) /* sizeof(OnigCodePoint) */ -#define WORD_ALIGNMENT_SIZE SIZEOF_LONG +#define WORD_ALIGNMENT_SIZE sizeof(uintptr_t) #define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\ (pad_size) = WORD_ALIGNMENT_SIZE \ - - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\ + - ((uintptr_t)(addr) % WORD_ALIGNMENT_SIZE);\ if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\ } while (0) -- cgit v1.2.3