зеркало из https://github.com/github/ruby.git
* string.c (rb_str_sum): wrong cast caused wrong result.
[ruby-dev:24385] * enum.c (enum_sort_by): hide temporary array from ObjectSpace.each_object. [ruby-dev:24386] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
9d923be604
Коммит
779f3d6d11
|
@ -1,5 +1,11 @@
|
||||||
Sat Oct 2 00:42:20 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Sat Oct 2 00:42:20 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_sum): wrong cast caused wrong result.
|
||||||
|
[ruby-dev:24385]
|
||||||
|
|
||||||
|
* enum.c (enum_sort_by): hide temporary array from
|
||||||
|
ObjectSpace.each_object. [ruby-dev:24386]
|
||||||
|
|
||||||
* string.c (rb_str_sum): check was done with false pointer.
|
* string.c (rb_str_sum): check was done with false pointer.
|
||||||
[ruby-dev:24383]
|
[ruby-dev:24383]
|
||||||
|
|
||||||
|
|
2
enum.c
2
enum.c
|
@ -493,6 +493,7 @@ enum_sort_by(obj)
|
||||||
else {
|
else {
|
||||||
ary = rb_ary_new();
|
ary = rb_ary_new();
|
||||||
}
|
}
|
||||||
|
RBASIC(ary)->klass = 0;
|
||||||
rb_iterate(rb_each, obj, sort_by_i, ary);
|
rb_iterate(rb_each, obj, sort_by_i, ary);
|
||||||
if (RARRAY(ary)->len > 1) {
|
if (RARRAY(ary)->len > 1) {
|
||||||
rb_iterate(rb_ary_sort_bang, ary, sort_by_cmp, ary);
|
rb_iterate(rb_ary_sort_bang, ary, sort_by_cmp, ary);
|
||||||
|
@ -500,6 +501,7 @@ enum_sort_by(obj)
|
||||||
for (i=0; i<RARRAY(ary)->len; i++) {
|
for (i=0; i<RARRAY(ary)->len; i++) {
|
||||||
RARRAY(ary)->ptr[i] = RNODE(RARRAY(ary)->ptr[i])->u2.value;
|
RARRAY(ary)->ptr[i] = RNODE(RARRAY(ary)->ptr[i])->u2.value;
|
||||||
}
|
}
|
||||||
|
RBASIC(ary)->klass = rb_cArray;
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
32
string.c
32
string.c
|
@ -4417,34 +4417,34 @@ rb_str_sum(argc, argv, str)
|
||||||
len = RSTRING(str)->len;
|
len = RSTRING(str)->len;
|
||||||
pend = p + len;
|
pend = p + len;
|
||||||
if (bits > sizeof(long)*CHAR_BIT) {
|
if (bits > sizeof(long)*CHAR_BIT) {
|
||||||
VALUE res = INT2FIX(0);
|
VALUE sum = INT2FIX(0);
|
||||||
VALUE mod;
|
|
||||||
|
|
||||||
mod = rb_funcall(INT2FIX(1), rb_intern("<<"), 1, INT2FIX(bits));
|
|
||||||
mod = rb_funcall(mod, '-', 1, INT2FIX(1));
|
|
||||||
|
|
||||||
while (p < pend) {
|
while (p < pend) {
|
||||||
str_mod_check(str, ptr, len);
|
str_mod_check(str, ptr, len);
|
||||||
res = rb_funcall(res, '+', 1, INT2FIX((unsigned int)*p));
|
sum = rb_funcall(sum, '+', 1, INT2FIX((unsigned char)*p));
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
res = rb_funcall(res, '&', 1, mod);
|
if (bits != 0) {
|
||||||
return res;
|
VALUE mod;
|
||||||
|
|
||||||
|
mod = rb_funcall(INT2FIX(1), rb_intern("<<"), 1, INT2FIX(bits));
|
||||||
|
mod = rb_funcall(mod, '-', 1, INT2FIX(1));
|
||||||
|
sum = rb_funcall(sum, '&', 1, mod);
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
unsigned int res = 0;
|
unsigned int sum = 0;
|
||||||
unsigned int mod = (1<<bits)-1;
|
|
||||||
|
|
||||||
if (mod == 0) {
|
|
||||||
mod = -1;
|
|
||||||
}
|
|
||||||
while (p < pend) {
|
while (p < pend) {
|
||||||
str_mod_check(str, ptr, len);
|
str_mod_check(str, ptr, len);
|
||||||
res += (unsigned int)*p;
|
sum += (unsigned char)*p;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
res &= mod;
|
if (bits != 0) {
|
||||||
return rb_int2inum(res);
|
sum &= (1<<bits)-1;
|
||||||
|
}
|
||||||
|
return rb_int2inum(sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче