mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
remove dependency to SIZEOF_LONG/LONG_LONG
This commit is contained in:
@@ -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
|
||||
|
||||
+4
-67
@@ -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)&&((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);
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user