mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (BIGZEROP): macro to determine if x is a bignum zero.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bb4ade0ab6
commit
5cb4133e67
5 changed files with 40 additions and 34 deletions
|
@ -8,9 +8,9 @@ Wed Apr 9 14:05:00 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
* marshal.c (w_object): preserve extended module on struct.
|
* marshal.c (w_object): preserve extended module on struct.
|
||||||
(ruby-bugs-ja:PR#422)
|
(ruby-bugs-ja:PR#422)
|
||||||
|
|
||||||
Tue Apr 8 17:13:53 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Wed Apr 9 03:43:14 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* random.c (rb_f_rand): normalize bignum argument.
|
* bignum.c (BIGZEROP): macro to determine if x is a bignum zero.
|
||||||
|
|
||||||
Tue Apr 8 11:49:31 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Tue Apr 8 11:49:31 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
|
11
bignum.c
11
bignum.c
|
@ -33,6 +33,8 @@ VALUE rb_cBignum;
|
||||||
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
|
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
|
||||||
#define BDIGMAX ((BDIGIT)-1)
|
#define BDIGMAX ((BDIGIT)-1)
|
||||||
|
|
||||||
|
#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || (RBIGNUM(x)->len == 1 && BDIGITS(x)[0] == 0))
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
bignew_1(klass, len, sign)
|
bignew_1(klass, len, sign)
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
|
@ -612,7 +614,7 @@ rb_big2str(x, base)
|
||||||
return rb_fix2str(x, base);
|
return rb_fix2str(x, base);
|
||||||
}
|
}
|
||||||
i = RBIGNUM(x)->len;
|
i = RBIGNUM(x)->len;
|
||||||
if (i == 0 || (i == 1 && BDIGITS(x)[0] == 0)) {
|
if (BIGZEROP(x)) {
|
||||||
return rb_str_new2("0");
|
return rb_str_new2("0");
|
||||||
}
|
}
|
||||||
if (base == 10) {
|
if (base == 10) {
|
||||||
|
@ -1123,8 +1125,8 @@ bigdivrem(x, y, divp, modp)
|
||||||
BDIGIT_DBL_SIGNED num;
|
BDIGIT_DBL_SIGNED num;
|
||||||
BDIGIT dd, q;
|
BDIGIT dd, q;
|
||||||
|
|
||||||
|
if (BIGZEROP(y)) rb_num_zerodiv();
|
||||||
yds = BDIGITS(y);
|
yds = BDIGITS(y);
|
||||||
if (ny == 0 && yds[0] == 0) rb_num_zerodiv();
|
|
||||||
if (nx < ny || (nx == ny && BDIGITS(x)[nx - 1] < BDIGITS(y)[ny - 1])) {
|
if (nx < ny || (nx == ny && BDIGITS(x)[nx - 1] < BDIGITS(y)[ny - 1])) {
|
||||||
if (divp) *divp = rb_int2big(0);
|
if (divp) *divp = rb_int2big(0);
|
||||||
if (modp) *modp = x;
|
if (modp) *modp = x;
|
||||||
|
@ -1248,8 +1250,7 @@ bigdivmod(x, y, divp, modp)
|
||||||
VALUE mod;
|
VALUE mod;
|
||||||
|
|
||||||
bigdivrem(x, y, divp, &mod);
|
bigdivrem(x, y, divp, &mod);
|
||||||
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign &&
|
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign && !BIGZEROP(x)) {
|
||||||
!(RBIGNUM(mod)->len == 1 && BDIGITS(mod)[0] == 0)) {
|
|
||||||
if (divp) *divp = bigadd(*divp, rb_int2big(1), 0);
|
if (divp) *divp = bigadd(*divp, rb_int2big(1), 0);
|
||||||
if (modp) *modp = bigadd(mod, y, 1);
|
if (modp) *modp = bigadd(mod, y, 1);
|
||||||
}
|
}
|
||||||
|
@ -1729,7 +1730,7 @@ rb_big_rand(max, rand_buf)
|
||||||
VALUE v;
|
VALUE v;
|
||||||
long len = RBIGNUM(max)->len;
|
long len = RBIGNUM(max)->len;
|
||||||
|
|
||||||
if (len == 0 && BDIGITS(max)[0] == 0) {
|
if (BIGZEROP(max)) {
|
||||||
return rb_float_new(rand_buf[0]);
|
return rb_float_new(rand_buf[0]);
|
||||||
}
|
}
|
||||||
v = bignew(len,1);
|
v = bignew(len,1);
|
||||||
|
|
2
eval.c
2
eval.c
|
@ -5083,7 +5083,7 @@ backtrace(lev)
|
||||||
{
|
{
|
||||||
struct FRAME *frame = ruby_frame;
|
struct FRAME *frame = ruby_frame;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
VALUE ary;
|
volatile VALUE ary;
|
||||||
NODE *n;
|
NODE *n;
|
||||||
|
|
||||||
ary = rb_ary_new();
|
ary = rb_ary_new();
|
||||||
|
|
50
gc.c
50
gc.c
|
@ -381,9 +381,11 @@ static unsigned int STACK_LEVEL_MAX = 655300;
|
||||||
: STACK_END - rb_gc_stack_start)
|
: STACK_END - rb_gc_stack_start)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define GC_WARTER_MARK 512
|
||||||
|
|
||||||
#define CHECK_STACK(ret) do {\
|
#define CHECK_STACK(ret) do {\
|
||||||
SET_STACK_END;\
|
SET_STACK_END;\
|
||||||
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX);\
|
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX + GC_WARTER_MARK);\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -460,25 +462,6 @@ sweep_source_filename(key, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gc_mark_all()
|
|
||||||
{
|
|
||||||
RVALUE *p, *pend;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
init_mark_stack();
|
|
||||||
for (i = 0; i < heaps_used; i++) {
|
|
||||||
p = heaps[i]; pend = p + heaps_limits[i];
|
|
||||||
while (p < pend) {
|
|
||||||
if ((p->as.basic.flags & FL_MARK) &&
|
|
||||||
(p->as.basic.flags != FL_MARK)) {
|
|
||||||
rb_gc_mark((VALUE)p);
|
|
||||||
}
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gc_mark_rest()
|
gc_mark_rest()
|
||||||
{
|
{
|
||||||
|
@ -491,10 +474,32 @@ gc_mark_rest()
|
||||||
init_mark_stack();
|
init_mark_stack();
|
||||||
while(p != tmp_arry){
|
while(p != tmp_arry){
|
||||||
p--;
|
p--;
|
||||||
|
FL_UNSET(*p, FL_MARK);
|
||||||
rb_gc_mark(*p);
|
rb_gc_mark(*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gc_mark_all()
|
||||||
|
{
|
||||||
|
RVALUE *p, *pend;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
gc_mark_rest();
|
||||||
|
init_mark_stack();
|
||||||
|
for (i = 0; i < heaps_used; i++) {
|
||||||
|
p = heaps[i]; pend = p + heaps_limits[i];
|
||||||
|
while (p < pend) {
|
||||||
|
if ((p->as.basic.flags & FL_MARK) &&
|
||||||
|
(p->as.basic.flags != FL_MARK)) {
|
||||||
|
FL_UNSET(p, FL_MARK);
|
||||||
|
rb_gc_mark((VALUE)p);
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
is_pointer_to_heap(ptr)
|
is_pointer_to_heap(ptr)
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
@ -597,6 +602,11 @@ rb_gc_mark(ptr)
|
||||||
|
|
||||||
CHECK_STACK(ret);
|
CHECK_STACK(ret);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
obj = RANY(ptr);
|
||||||
|
if (rb_special_const_p(ptr)) return; /* special const not marked */
|
||||||
|
if (obj->as.basic.flags == 0) return; /* free cell */
|
||||||
|
if (obj->as.basic.flags & FL_MARK) return; /* already marked */
|
||||||
|
obj->as.basic.flags |= FL_MARK;
|
||||||
if (!mark_stack_overflow) {
|
if (!mark_stack_overflow) {
|
||||||
if (mark_stack_ptr - mark_stack < MARK_STACK_MAX) {
|
if (mark_stack_ptr - mark_stack < MARK_STACK_MAX) {
|
||||||
*mark_stack_ptr = ptr;
|
*mark_stack_ptr = ptr;
|
||||||
|
|
5
random.c
5
random.c
|
@ -215,11 +215,6 @@ rb_f_rand(argc, argv, obj)
|
||||||
vmax = rb_dbl2big(RFLOAT(vmax)->value);
|
vmax = rb_dbl2big(RFLOAT(vmax)->value);
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case T_BIGNUM:
|
case T_BIGNUM:
|
||||||
vmax = rb_big_norm(vmax);
|
|
||||||
if (FIXNUM_P(vmax)) {
|
|
||||||
max = FIX2INT(vmax);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
bignum:
|
bignum:
|
||||||
{
|
{
|
||||||
long len = RBIGNUM(vmax)->len;
|
long len = RBIGNUM(vmax)->len;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue