зеркало из https://github.com/github/ruby.git
* compar.c (rb_cmperr): raise comparison failure.
* intern.h: prototype; rb_cmperr * numeric.c (flo_gt, flo_ge, flo_lt, flo_le, fix_gt, fix_ge, fix_lt, fix_le): should fail unless the argument is comparable. (ruby-bugs-ja:PR#456) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
908300d44f
Коммит
698a24674e
12
ChangeLog
12
ChangeLog
|
@ -1,4 +1,12 @@
|
||||||
Thu May 8 08:56:04 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Thu May 8 12:56:04 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* compar.c (rb_cmperr): raise comparison failure.
|
||||||
|
|
||||||
|
* intern.h: prototype; rb_cmperr
|
||||||
|
|
||||||
|
* numeric.c (flo_gt, flo_ge, flo_lt, flo_le, fix_gt, fix_ge,
|
||||||
|
fix_lt, fix_le): should fail unless the argument is comparable.
|
||||||
|
(ruby-bugs-ja:PR#456)
|
||||||
|
|
||||||
* numeric.c (int_upto, int_downto): should fail unless the
|
* numeric.c (int_upto, int_downto): should fail unless the
|
||||||
argument is comparable. (ruby-bugs-ja:PR#454)
|
argument is comparable. (ruby-bugs-ja:PR#454)
|
||||||
|
@ -43,7 +51,7 @@ Mon May 5 21:19:25 2003 Koji Arai <jca02266@nifty.ne.jp>
|
||||||
* ext/dbm/testdbm.rb: ditto.
|
* ext/dbm/testdbm.rb: ditto.
|
||||||
|
|
||||||
* ext/dbm/testdbm.rb (setup): DBM.open(path, 0400) cause EACCESS
|
* ext/dbm/testdbm.rb (setup): DBM.open(path, 0400) cause EACCESS
|
||||||
on Berkeley DB[234].
|
on Berkeley DB[234].
|
||||||
|
|
||||||
Mon May 5 22:57:07 2003 Tadayoshi Funaba <tadf@dotrb.org>
|
Mon May 5 22:57:07 2003 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
|
20
compar.c
20
compar.c
|
@ -30,13 +30,25 @@ rb_cmpint(val)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
void
|
||||||
cmperr()
|
rb_cmperr(x, y)
|
||||||
|
VALUE x, y;
|
||||||
{
|
{
|
||||||
rb_raise(rb_eArgError, "comparison failed");
|
const char *classname;
|
||||||
return Qnil; /* not reached */
|
|
||||||
|
if (SPECIAL_CONST_P(y)) {
|
||||||
|
y = rb_inspect(y);
|
||||||
|
classname = StringValuePtr(y);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
classname = rb_obj_classname(y);
|
||||||
|
}
|
||||||
|
rb_raise(rb_eArgError, "comparison of %s to %s failed",
|
||||||
|
rb_obj_classname(x), classname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define cmperr() (rb_cmperr(x, y), Qnil)
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
cmp_equal(x, y)
|
cmp_equal(x, y)
|
||||||
VALUE x, y;
|
VALUE x, y;
|
||||||
|
|
1
intern.h
1
intern.h
|
@ -122,6 +122,7 @@ void rb_define_singleton_method _((VALUE, const char*, VALUE(*)(ANYARGS), int));
|
||||||
VALUE rb_singleton_class _((VALUE));
|
VALUE rb_singleton_class _((VALUE));
|
||||||
/* compar.c */
|
/* compar.c */
|
||||||
int rb_cmpint _((VALUE));
|
int rb_cmpint _((VALUE));
|
||||||
|
NORETURN(void rb_cmperr _((VALUE, VALUE)));
|
||||||
/* enum.c */
|
/* enum.c */
|
||||||
/* error.c */
|
/* error.c */
|
||||||
RUBY_EXTERN int ruby_nerrs;
|
RUBY_EXTERN int ruby_nerrs;
|
||||||
|
|
62
numeric.c
62
numeric.c
|
@ -143,6 +143,20 @@ rb_num_coerce_cmp(x, y)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
num_coerce_relop(x, y)
|
||||||
|
VALUE x, y;
|
||||||
|
{
|
||||||
|
VALUE c, x0 = x, y0 = y;
|
||||||
|
|
||||||
|
if (!do_coerce(&x, &y, Qfalse) ||
|
||||||
|
NIL_P(c = rb_funcall(x, rb_frame_last_func(), 1, y))) {
|
||||||
|
rb_cmperr(x0, y0);
|
||||||
|
return Qnil; /* not reached */
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
num_copy_object(x, y)
|
num_copy_object(x, y)
|
||||||
VALUE x, y;
|
VALUE x, y;
|
||||||
|
@ -604,7 +618,7 @@ flo_gt(x, y)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return rb_num_coerce_cmp(x, y);
|
return num_coerce_relop(x, y);
|
||||||
}
|
}
|
||||||
if (isnan(a) || isnan(b)) return Qfalse;
|
if (isnan(a) || isnan(b)) return Qfalse;
|
||||||
return (a > b)?Qtrue:Qfalse;
|
return (a > b)?Qtrue:Qfalse;
|
||||||
|
@ -631,7 +645,7 @@ flo_ge(x, y)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return rb_num_coerce_cmp(x, y);
|
return num_coerce_relop(x, y);
|
||||||
}
|
}
|
||||||
if (isnan(a) || isnan(b)) return Qfalse;
|
if (isnan(a) || isnan(b)) return Qfalse;
|
||||||
return (a >= b)?Qtrue:Qfalse;
|
return (a >= b)?Qtrue:Qfalse;
|
||||||
|
@ -658,7 +672,7 @@ flo_lt(x, y)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return rb_num_coerce_cmp(x, y);
|
return num_coerce_relop(x, y);
|
||||||
}
|
}
|
||||||
if (isnan(a) || isnan(b)) return Qfalse;
|
if (isnan(a) || isnan(b)) return Qfalse;
|
||||||
return (a < b)?Qtrue:Qfalse;
|
return (a < b)?Qtrue:Qfalse;
|
||||||
|
@ -685,7 +699,7 @@ flo_le(x, y)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return rb_num_coerce_cmp(x, y);
|
return num_coerce_relop(x, y);
|
||||||
}
|
}
|
||||||
if (isnan(a) || isnan(b)) return Qfalse;
|
if (isnan(a) || isnan(b)) return Qfalse;
|
||||||
return (a <= b)?Qtrue:Qfalse;
|
return (a <= b)?Qtrue:Qfalse;
|
||||||
|
@ -1439,7 +1453,7 @@ fix_gt(x, y)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_num_coerce_cmp(x, y);
|
return num_coerce_relop(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1454,7 +1468,7 @@ fix_ge(x, y)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_num_coerce_cmp(x, y);
|
return num_coerce_relop(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1469,7 +1483,7 @@ fix_lt(x, y)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_num_coerce_cmp(x, y);
|
return num_coerce_relop(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1484,7 +1498,7 @@ fix_le(x, y)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_num_coerce_cmp(x, y);
|
return num_coerce_relop(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1653,28 +1667,6 @@ fix_size(fix)
|
||||||
return INT2FIX(sizeof(long));
|
return INT2FIX(sizeof(long));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
|
||||||
int_compare(i, to, id)
|
|
||||||
VALUE i, to;
|
|
||||||
ID id;
|
|
||||||
{
|
|
||||||
VALUE cmp = rb_funcall(i, id, 1, to);
|
|
||||||
if (NIL_P(cmp)) {
|
|
||||||
char *toclass;
|
|
||||||
|
|
||||||
if (SPECIAL_CONST_P(to)) {
|
|
||||||
to = rb_inspect(to);
|
|
||||||
toclass = StringValuePtr(to);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
toclass = rb_obj_classname(to);
|
|
||||||
}
|
|
||||||
rb_raise(rb_eArgError, "cannot compare %s with %s",
|
|
||||||
rb_obj_classname(i), toclass);
|
|
||||||
}
|
|
||||||
return cmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
int_upto(from, to)
|
int_upto(from, to)
|
||||||
VALUE from, to;
|
VALUE from, to;
|
||||||
|
@ -1688,12 +1680,13 @@ int_upto(from, to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE i = from;
|
VALUE i = from, c;
|
||||||
|
|
||||||
while (!int_compare(i, to, '>')) {
|
while (!(c = rb_funcall(i, '>', 1, to))) {
|
||||||
rb_yield(i);
|
rb_yield(i);
|
||||||
i = rb_funcall(i, '+', 1, INT2FIX(1));
|
i = rb_funcall(i, '+', 1, INT2FIX(1));
|
||||||
}
|
}
|
||||||
|
if (NIL_P(c)) rb_cmperr(i, to);
|
||||||
}
|
}
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
@ -1711,12 +1704,13 @@ int_downto(from, to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE i = from;
|
VALUE i = from, c;
|
||||||
|
|
||||||
while (!int_compare(i, to, '<')) {
|
while (!(c = rb_funcall(i, '<', 1, to))) {
|
||||||
rb_yield(i);
|
rb_yield(i);
|
||||||
i = rb_funcall(i, '-', 1, INT2FIX(1));
|
i = rb_funcall(i, '-', 1, INT2FIX(1));
|
||||||
}
|
}
|
||||||
|
if (NIL_P(c)) rb_cmperr(i, to);
|
||||||
}
|
}
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче