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.
|
||||
(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>
|
||||
|
||||
|
|
13
bignum.c
13
bignum.c
|
@ -33,6 +33,8 @@ VALUE rb_cBignum;
|
|||
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
|
||||
#define BDIGMAX ((BDIGIT)-1)
|
||||
|
||||
#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || (RBIGNUM(x)->len == 1 && BDIGITS(x)[0] == 0))
|
||||
|
||||
static VALUE
|
||||
bignew_1(klass, len, sign)
|
||||
VALUE klass;
|
||||
|
@ -612,7 +614,7 @@ rb_big2str(x, base)
|
|||
return rb_fix2str(x, base);
|
||||
}
|
||||
i = RBIGNUM(x)->len;
|
||||
if (i == 0 || (i == 1 && BDIGITS(x)[0] == 0)) {
|
||||
if (BIGZEROP(x)) {
|
||||
return rb_str_new2("0");
|
||||
}
|
||||
if (base == 10) {
|
||||
|
@ -1123,8 +1125,8 @@ bigdivrem(x, y, divp, modp)
|
|||
BDIGIT_DBL_SIGNED num;
|
||||
BDIGIT dd, q;
|
||||
|
||||
if (BIGZEROP(y)) rb_num_zerodiv();
|
||||
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 (divp) *divp = rb_int2big(0);
|
||||
if (modp) *modp = x;
|
||||
|
@ -1248,8 +1250,7 @@ bigdivmod(x, y, divp, modp)
|
|||
VALUE mod;
|
||||
|
||||
bigdivrem(x, y, divp, &mod);
|
||||
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign &&
|
||||
!(RBIGNUM(mod)->len == 1 && BDIGITS(mod)[0] == 0)) {
|
||||
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign && !BIGZEROP(x)) {
|
||||
if (divp) *divp = bigadd(*divp, rb_int2big(1), 0);
|
||||
if (modp) *modp = bigadd(mod, y, 1);
|
||||
}
|
||||
|
@ -1728,8 +1729,8 @@ rb_big_rand(max, rand_buf)
|
|||
{
|
||||
VALUE v;
|
||||
long len = RBIGNUM(max)->len;
|
||||
|
||||
if (len == 0 && BDIGITS(max)[0] == 0) {
|
||||
|
||||
if (BIGZEROP(max)) {
|
||||
return rb_float_new(rand_buf[0]);
|
||||
}
|
||||
v = bignew(len,1);
|
||||
|
|
2
eval.c
2
eval.c
|
@ -5083,7 +5083,7 @@ backtrace(lev)
|
|||
{
|
||||
struct FRAME *frame = ruby_frame;
|
||||
char buf[BUFSIZ];
|
||||
VALUE ary;
|
||||
volatile VALUE ary;
|
||||
NODE *n;
|
||||
|
||||
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)
|
||||
#endif
|
||||
|
||||
#define GC_WARTER_MARK 512
|
||||
|
||||
#define CHECK_STACK(ret) do {\
|
||||
SET_STACK_END;\
|
||||
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX);\
|
||||
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX + GC_WARTER_MARK);\
|
||||
} while (0)
|
||||
|
||||
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
|
||||
gc_mark_rest()
|
||||
{
|
||||
|
@ -491,10 +474,32 @@ gc_mark_rest()
|
|||
init_mark_stack();
|
||||
while(p != tmp_arry){
|
||||
p--;
|
||||
FL_UNSET(*p, FL_MARK);
|
||||
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
|
||||
is_pointer_to_heap(ptr)
|
||||
void *ptr;
|
||||
|
@ -597,6 +602,11 @@ rb_gc_mark(ptr)
|
|||
|
||||
CHECK_STACK(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_ptr - mark_stack < MARK_STACK_MAX) {
|
||||
*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);
|
||||
/* fall through */
|
||||
case T_BIGNUM:
|
||||
vmax = rb_big_norm(vmax);
|
||||
if (FIXNUM_P(vmax)) {
|
||||
max = FIX2INT(vmax);
|
||||
break;
|
||||
}
|
||||
bignum:
|
||||
{
|
||||
long len = RBIGNUM(vmax)->len;
|
||||
|
|
Loading…
Reference in a new issue