* bignum.c (rb_int2big): use SIGNED_VALUE. [ruby-dev:29019]
* bignum.c (rb_int2inum, rb_uint2inum): use VALUE sized integer. * bignum.c (rb_big2long, rb_big2ulong): ditto. * numeric.c (rb_num2long, rb_num2ulong): ditto. * numeric.c (check_int, check_uint): ditto. * bignum.c (rb_quad_pack): typo fixed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4bacdc1e46
commit
1db0db3ba0
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
|||||||
|
Tue Jul 11 15:29:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* bignum.c (rb_int2big): use SIGNED_VALUE. [ruby-dev:29019]
|
||||||
|
|
||||||
|
* bignum.c (rb_int2inum, rb_uint2inum): use VALUE sized integer.
|
||||||
|
|
||||||
|
* bignum.c (rb_big2long, rb_big2ulong): ditto.
|
||||||
|
|
||||||
|
* numeric.c (rb_num2long, rb_num2ulong): ditto.
|
||||||
|
|
||||||
|
* numeric.c (check_int, check_uint): ditto.
|
||||||
|
|
||||||
|
* bignum.c (rb_quad_pack): typo fixed.
|
||||||
|
|
||||||
Tue Jul 11 13:40:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Tue Jul 11 13:40:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* bignum.c (bignorm): sizeof(long) may be smaller than
|
* bignum.c (bignorm): sizeof(long) may be smaller than
|
||||||
|
27
bignum.c
27
bignum.c
@ -192,7 +192,7 @@ rb_quad_pack(char *buf, VALUE val)
|
|||||||
BDIGIT *ds;
|
BDIGIT *ds;
|
||||||
|
|
||||||
if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) {
|
if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) {
|
||||||
len = SIZEOF_LONG/SIZEOF_BDIGITS;
|
len = SIZEOF_LONG_LONG/SIZEOF_BDIGITS;
|
||||||
}
|
}
|
||||||
ds = BDIGITS(val);
|
ds = BDIGITS(val);
|
||||||
q = 0;
|
q = 0;
|
||||||
@ -686,17 +686,17 @@ rb_big_to_s(int argc, VALUE *argv, VALUE x)
|
|||||||
return rb_big2str(x, base);
|
return rb_big2str(x, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long
|
static VALUE
|
||||||
big2ulong(VALUE x, const char *type, int check)
|
big2ulong(VALUE x, const char *type, int check)
|
||||||
{
|
{
|
||||||
long len = RBIGNUM(x)->len;
|
long len = RBIGNUM(x)->len;
|
||||||
BDIGIT_DBL num;
|
BDIGIT_DBL num;
|
||||||
BDIGIT *ds;
|
BDIGIT *ds;
|
||||||
|
|
||||||
if (len > SIZEOF_LONG/SIZEOF_BDIGITS) {
|
if (len > SIZEOF_VALUE/SIZEOF_BDIGITS) {
|
||||||
if (check)
|
if (check)
|
||||||
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
|
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
|
||||||
len = SIZEOF_LONG/SIZEOF_BDIGITS;
|
len = SIZEOF_VALUE/SIZEOF_BDIGITS;
|
||||||
}
|
}
|
||||||
ds = BDIGITS(x);
|
ds = BDIGITS(x);
|
||||||
num = 0;
|
num = 0;
|
||||||
@ -707,23 +707,23 @@ big2ulong(VALUE x, const char *type, int check)
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
VALUE
|
||||||
rb_big2ulong_pack(VALUE x)
|
rb_big2ulong_pack(VALUE x)
|
||||||
{
|
{
|
||||||
unsigned long num = big2ulong(x, "unsigned long", Qfalse);
|
VALUE num = big2ulong(x, "unsigned long", Qfalse);
|
||||||
if (!RBIGNUM(x)->sign) {
|
if (!RBIGNUM(x)->sign) {
|
||||||
return -num;
|
return -num;
|
||||||
}
|
}
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
VALUE
|
||||||
rb_big2ulong(VALUE x)
|
rb_big2ulong(VALUE x)
|
||||||
{
|
{
|
||||||
unsigned long num = big2ulong(x, "unsigned long", Qtrue);
|
VALUE num = big2ulong(x, "unsigned long", Qtrue);
|
||||||
|
|
||||||
if (!RBIGNUM(x)->sign) {
|
if (!RBIGNUM(x)->sign) {
|
||||||
if ((long)num < 0) {
|
if ((SIGNED_VALUE)num < 0) {
|
||||||
rb_raise(rb_eRangeError, "bignum out of range of unsigned long");
|
rb_raise(rb_eRangeError, "bignum out of range of unsigned long");
|
||||||
}
|
}
|
||||||
return -num;
|
return -num;
|
||||||
@ -731,15 +731,16 @@ rb_big2ulong(VALUE x)
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
SIGNED_VALUE
|
||||||
rb_big2long(VALUE x)
|
rb_big2long(VALUE x)
|
||||||
{
|
{
|
||||||
unsigned long num = big2ulong(x, "long", Qtrue);
|
VALUE num = big2ulong(x, "long", Qtrue);
|
||||||
|
|
||||||
if ((long)num < 0 && (RBIGNUM(x)->sign || (long)num != LONG_MIN)) {
|
if ((SIGNED_VALUE)num < 0 &&
|
||||||
|
(RBIGNUM(x)->sign || (SIGNED_VALUE)num != LONG_MIN)) {
|
||||||
rb_raise(rb_eRangeError, "bignum too big to convert into `long'");
|
rb_raise(rb_eRangeError, "bignum too big to convert into `long'");
|
||||||
}
|
}
|
||||||
if (!RBIGNUM(x)->sign) return -(long)num;
|
if (!RBIGNUM(x)->sign) return -(SIGNED_VALUE)num;
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
eval.c
7
eval.c
@ -8555,10 +8555,13 @@ VALUE
|
|||||||
rb_proc_yield(int argc, VALUE *argv, VALUE proc)
|
rb_proc_yield(int argc, VALUE *argv, VALUE proc)
|
||||||
{
|
{
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
|
case 1:
|
||||||
|
if (!NIL_P(argv[0])) {
|
||||||
|
return proc_invoke(proc, argv[0], Qundef, 0, 0);
|
||||||
|
}
|
||||||
|
/* fall through */
|
||||||
case 0:
|
case 0:
|
||||||
return proc_invoke(proc, Qundef, Qundef, 0, 0);
|
return proc_invoke(proc, Qundef, Qundef, 0, 0);
|
||||||
case 1:
|
|
||||||
return proc_invoke(proc, argv[0], Qundef, 0, 0);
|
|
||||||
default:
|
default:
|
||||||
return proc_invoke(proc, rb_ary_new4(argc, argv), Qundef, 0, 0);
|
return proc_invoke(proc, rb_ary_new4(argc, argv), Qundef, 0, 0);
|
||||||
}
|
}
|
||||||
|
12
intern.h
12
intern.h
@ -72,18 +72,18 @@ VALUE rb_get_values_at(VALUE, long, int, VALUE*, VALUE(*)(VALUE,long));
|
|||||||
VALUE rb_big_clone(VALUE);
|
VALUE rb_big_clone(VALUE);
|
||||||
void rb_big_2comp(VALUE);
|
void rb_big_2comp(VALUE);
|
||||||
VALUE rb_big_norm(VALUE);
|
VALUE rb_big_norm(VALUE);
|
||||||
VALUE rb_uint2big(unsigned long);
|
VALUE rb_uint2big(VALUE);
|
||||||
VALUE rb_int2big(long);
|
VALUE rb_int2big(SIGNED_VALUE);
|
||||||
VALUE rb_uint2inum(unsigned long);
|
VALUE rb_uint2inum(VALUE);
|
||||||
VALUE rb_int2inum(long);
|
VALUE rb_int2inum(SIGNED_VALUE);
|
||||||
VALUE rb_cstr_to_inum(const char*, int, int);
|
VALUE rb_cstr_to_inum(const char*, int, int);
|
||||||
VALUE rb_str_to_inum(VALUE, int, int);
|
VALUE rb_str_to_inum(VALUE, int, int);
|
||||||
VALUE rb_cstr2inum(const char*, int);
|
VALUE rb_cstr2inum(const char*, int);
|
||||||
VALUE rb_str2inum(VALUE, int);
|
VALUE rb_str2inum(VALUE, int);
|
||||||
VALUE rb_big2str(VALUE, int);
|
VALUE rb_big2str(VALUE, int);
|
||||||
long rb_big2long(VALUE);
|
SIGNED_VALUE rb_big2long(VALUE);
|
||||||
#define rb_big2int(x) rb_big2long(x)
|
#define rb_big2int(x) rb_big2long(x)
|
||||||
unsigned long rb_big2ulong(VALUE);
|
VALUE rb_big2ulong(VALUE);
|
||||||
#define rb_big2uint(x) rb_big2ulong(x)
|
#define rb_big2uint(x) rb_big2ulong(x)
|
||||||
#if HAVE_LONG_LONG
|
#if HAVE_LONG_LONG
|
||||||
VALUE rb_ll2inum(LONG_LONG);
|
VALUE rb_ll2inum(LONG_LONG);
|
||||||
|
38
numeric.c
38
numeric.c
@ -1458,7 +1458,7 @@ num_step(int argc, VALUE *argv, VALUE from)
|
|||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
SIGNED_VALUE
|
||||||
rb_num2long(VALUE val)
|
rb_num2long(VALUE val)
|
||||||
{
|
{
|
||||||
if (NIL_P(val)) {
|
if (NIL_P(val)) {
|
||||||
@ -1471,7 +1471,7 @@ rb_num2long(VALUE val)
|
|||||||
case T_FLOAT:
|
case T_FLOAT:
|
||||||
if (RFLOAT(val)->value <= (double)LONG_MAX
|
if (RFLOAT(val)->value <= (double)LONG_MAX
|
||||||
&& RFLOAT(val)->value >= (double)LONG_MIN) {
|
&& RFLOAT(val)->value >= (double)LONG_MIN) {
|
||||||
return (long)(RFLOAT(val)->value);
|
return (SIGNED_VALUE)(RFLOAT(val)->value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char buf[24];
|
char buf[24];
|
||||||
@ -1491,19 +1491,18 @@ rb_num2long(VALUE val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
VALUE
|
||||||
rb_num2ulong(VALUE val)
|
rb_num2ulong(VALUE val)
|
||||||
{
|
{
|
||||||
if (TYPE(val) == T_BIGNUM) {
|
if (TYPE(val) == T_BIGNUM) {
|
||||||
return rb_big2ulong(val);
|
return rb_big2ulong(val);
|
||||||
}
|
}
|
||||||
return (unsigned long)rb_num2long(val);
|
return (VALUE)rb_num2long(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SIZEOF_INT < SIZEOF_LONG
|
#if SIZEOF_INT < SIZEOF_VALUE
|
||||||
static void
|
static void
|
||||||
check_int(num)
|
check_int(SIGNED_VALUE num)
|
||||||
long num;
|
|
||||||
{
|
{
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
@ -1516,21 +1515,27 @@ check_int(num)
|
|||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#if LONG_LONG_VALUE
|
||||||
|
rb_raise(rb_eRangeError, "integer %lld too %s to convert to `int'", num, s);
|
||||||
|
#else
|
||||||
rb_raise(rb_eRangeError, "integer %ld too %s to convert to `int'", num, s);
|
rb_raise(rb_eRangeError, "integer %ld too %s to convert to `int'", num, s);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_uint(num)
|
check_uint(VALUE num)
|
||||||
unsigned long num;
|
|
||||||
{
|
{
|
||||||
if (num > UINT_MAX) {
|
if (num > UINT_MAX) {
|
||||||
|
#if LONG_LONG_VALUE
|
||||||
|
rb_raise(rb_eRangeError, "integer %llu too big to convert to `unsigned int'", num);
|
||||||
|
#else
|
||||||
rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
|
rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
rb_num2int(val)
|
rb_num2int(VALUE val)
|
||||||
VALUE val;
|
|
||||||
{
|
{
|
||||||
long num = rb_num2long(val);
|
long num = rb_num2long(val);
|
||||||
|
|
||||||
@ -1539,8 +1544,7 @@ rb_num2int(val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
rb_fix2int(val)
|
rb_fix2int(VALUE val)
|
||||||
VALUE val;
|
|
||||||
{
|
{
|
||||||
long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2long(val);
|
long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2long(val);
|
||||||
|
|
||||||
@ -1549,8 +1553,7 @@ rb_fix2int(val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long
|
||||||
rb_num2uint(val)
|
rb_num2uint(VALUE val)
|
||||||
VALUE val;
|
|
||||||
{
|
{
|
||||||
unsigned long num = rb_num2ulong(val);
|
unsigned long num = rb_num2ulong(val);
|
||||||
|
|
||||||
@ -1561,8 +1564,7 @@ rb_num2uint(val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long
|
||||||
rb_fix2uint(val)
|
rb_fix2uint(VALUE val)
|
||||||
VALUE val;
|
|
||||||
{
|
{
|
||||||
unsigned long num;
|
unsigned long num;
|
||||||
|
|
||||||
@ -1837,7 +1839,7 @@ VALUE
|
|||||||
rb_fix2str(VALUE x, int base)
|
rb_fix2str(VALUE x, int base)
|
||||||
{
|
{
|
||||||
extern const char ruby_digitmap[];
|
extern const char ruby_digitmap[];
|
||||||
char buf[SIZEOF_LONG*CHAR_BIT + 2], *b = buf + sizeof buf;
|
char buf[SIZEOF_VALUE*CHAR_BIT + 2], *b = buf + sizeof buf;
|
||||||
long val = FIX2LONG(x);
|
long val = FIX2LONG(x);
|
||||||
int neg = 0;
|
int neg = 0;
|
||||||
|
|
||||||
|
9
ruby.h
9
ruby.h
@ -94,15 +94,18 @@ extern "C" {
|
|||||||
typedef unsigned long VALUE;
|
typedef unsigned long VALUE;
|
||||||
typedef unsigned long ID;
|
typedef unsigned long ID;
|
||||||
# define SIGNED_VALUE long
|
# define SIGNED_VALUE long
|
||||||
|
# define SIZEOF_VALUE SIZEOF_LONG
|
||||||
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
||||||
typedef unsigned LONG_LONG VALUE;
|
typedef unsigned LONG_LONG VALUE;
|
||||||
typedef unsigned LONG_LONG ID;
|
typedef unsigned LONG_LONG ID;
|
||||||
# define SIGNED_VALUE LONG_LONG
|
# define SIGNED_VALUE LONG_LONG
|
||||||
# define LONG_LONG_VALUE 1
|
# define LONG_LONG_VALUE 1
|
||||||
|
# define SIZEOF_VALUE SIZEOF_LONG_LONG
|
||||||
#else
|
#else
|
||||||
# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
|
# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __STDC__
|
#ifdef __STDC__
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
#else
|
#else
|
||||||
@ -273,8 +276,8 @@ RUBY_EXTERN int ruby_safe_level;
|
|||||||
void rb_set_safe_level(int);
|
void rb_set_safe_level(int);
|
||||||
void rb_secure_update(VALUE);
|
void rb_secure_update(VALUE);
|
||||||
|
|
||||||
long rb_num2long(VALUE);
|
SIGNED_VALUE rb_num2long(VALUE);
|
||||||
unsigned long rb_num2ulong(VALUE);
|
VALUE rb_num2ulong(VALUE);
|
||||||
#define NUM2LONG(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2long((VALUE)x))
|
#define NUM2LONG(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2long((VALUE)x))
|
||||||
#define NUM2ULONG(x) rb_num2ulong((VALUE)x)
|
#define NUM2ULONG(x) rb_num2ulong((VALUE)x)
|
||||||
#if SIZEOF_INT < SIZEOF_LONG
|
#if SIZEOF_INT < SIZEOF_LONG
|
||||||
@ -336,7 +339,7 @@ VALUE rb_newobj(void);
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
struct RBasic {
|
struct RBasic {
|
||||||
unsigned long flags;
|
VALUE flags;
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user