summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog46
-rw-r--r--array.c9
-rw-r--r--bignum.c3
-rw-r--r--class.c7
-rw-r--r--configure.in2
-rw-r--r--eval.c8
-rw-r--r--file.c4
-rw-r--r--intern.h3
-rw-r--r--io.c2
-rw-r--r--marshal.c2
-rw-r--r--numeric.c43
-rw-r--r--object.c4
-rw-r--r--parse.y2
-rw-r--r--range.c17
-rw-r--r--re.c23
-rw-r--r--signal.c2
-rw-r--r--string.c16
-rw-r--r--variable.c12
18 files changed, 158 insertions, 47 deletions
diff --git a/ChangeLog b/ChangeLog
index 5ae2d094bb..da89f1e6a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,40 @@
+Thu Dec 19 01:00:09 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * numeric.c (num_step): use DBL_EPSILON.
+
+ * array.c (rb_check_array_type): new function: return an array
+ (convert if possible), or nil.
+
+ * string.c (rb_check_string_type): new function: return a string
+ (convert if possible), or nil.
+
+ * numeric.c (rb_dbl_cmp): returns nil if values are not
+ comparable.
+
+ * numeric.c (fix_cmp,flo_cmp): use rb_num_coerce_cmp()
+
+ * bignum.c (rb_big_cmp): ditto.
+
+ * numeric.c (rb_num_coerce_cmp): new coercing function for "<=>",
+ which does not raise TypeError.
+
+ * numeric.c (do_coerce): can be supress exception now.
+
+ * object.c (rb_mod_cmp): should return nil for non class/module
+ objects.
+
Thu Dec 19 04:21:10 2002 Akinori MUSHA <knu@iDaemons.org>
* lib/open-uri.rb: add a missing ||. (found by: ruby -wc)
+Wed Dec 18 17:53:05 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * re.c (rb_reg_eqq): return false if the argument is not a
+ string. now returns boolean value.
+
+ * class.c (rb_include_module): argument should be T_MODULE, not
+ T_class, nor T_ICLASS.
+
Wed Dec 18 03:52:55 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* string.c (rb_str_new4): handle tail shared string.
@@ -22,6 +55,14 @@ Tue Dec 17 21:08:29 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* re.c (rb_reg_nth_match): ditto.
+Tue Dec 17 16:52:38 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (is_defined): "defined?" should return "assignment" for
+ attribute assignment (e.g. a.foo=b) and indexed assignment
+ (e.g. a[2] = 44).
+
+ * parse.y (aryset): use NODE_ATTRASGN.
+
Tue Dec 17 04:03:45 2002 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb: new file.
@@ -78,6 +119,11 @@ Fri Dec 13 23:42:16 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/dbm/extconf.rb (db_check): check existence of the function
in the specified library before checking it in libc.
+Fri Dec 13 17:15:49 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * variable.c (generic_ivar_get): should always warn uninitialized
+ instance variables.
+
Fri Dec 13 12:33:22 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* parse.y (expr): rescue clause was ignored.
diff --git a/array.c b/array.c
index e6c605db14..927d4dcbde 100644
--- a/array.c
+++ b/array.c
@@ -204,6 +204,13 @@ to_ary(ary)
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
+VALUE
+rb_check_array_type(ary)
+ VALUE ary;
+{
+ return rb_check_convert_type(ary, T_ARRAY, "Array", "to_ary");
+}
+
static VALUE rb_ary_replace _((VALUE, VALUE));
static VALUE
@@ -225,7 +232,7 @@ rb_ary_initialize(argc, argv, ary)
}
if (argc == 1 && !FIXNUM_P(size)) {
- val = rb_check_convert_type(size, T_ARRAY, "Array", "to_ary");
+ val = rb_check_array_type(size);
if (!NIL_P(val)) {
rb_ary_replace(ary, val);
return ary;
diff --git a/bignum.c b/bignum.c
index f3ab04ab8e..03c2d7d198 100644
--- a/bignum.c
+++ b/bignum.c
@@ -853,7 +853,7 @@ rb_big_cmp(x, y)
return rb_dbl_cmp(rb_big2dbl(x), RFLOAT(y)->value);
default:
- return rb_num_coerce_bin(x, y);
+ return rb_num_coerce_cmp(x, y);
}
if (RBIGNUM(x)->sign > RBIGNUM(y)->sign) return INT2FIX(1);
@@ -1749,7 +1749,6 @@ Init_Bignum()
rb_define_method(rb_cBignum, "<=>", rb_big_cmp, 1);
rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
- rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
rb_define_method(rb_cBignum, "eql?", rb_big_eql, 1);
rb_define_method(rb_cBignum, "hash", rb_big_hash, 0);
rb_define_method(rb_cBignum, "to_f", rb_big_to_f, 0);
diff --git a/class.c b/class.c
index e680dc7a67..6aed94a992 100644
--- a/class.c
+++ b/class.c
@@ -365,12 +365,7 @@ rb_include_module(klass, module)
if (NIL_P(module)) return;
if (klass == module) return;
- switch (TYPE(module)) {
- case T_MODULE:
- case T_CLASS:
- case T_ICLASS:
- break;
- default:
+ if (TYPE(module) != T_MODULE) {
Check_Type(module, T_MODULE);
}
diff --git a/configure.in b/configure.in
index a00dc0d7cb..bc6b58ea38 100644
--- a/configure.in
+++ b/configure.in
@@ -354,7 +354,7 @@ AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
syscall.h pwd.h a.out.h utime.h memory.h direct.h sys/resource.h \
- sys/mkdev.h sys/utime.h)
+ sys/mkdev.h sys/utime.h float.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T
diff --git a/eval.c b/eval.c
index 86c22ab0d0..b7662c9428 100644
--- a/eval.c
+++ b/eval.c
@@ -1881,6 +1881,7 @@ is_defined(self, node, buf)
goto check_bound;
case NODE_CALL:
+ case NODE_ATTRASGN:
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
val = rb_eval(self, node->nd_recv);
@@ -1909,7 +1910,9 @@ is_defined(self, node, buf)
}
else if (!rb_method_boundp(val, node->nd_mid, call))
break;
- return arg_defined(self, node->nd_args, buf, "method");
+ return arg_defined(self, node->nd_args, buf,
+ nd_type(node) == NODE_ATTRASGN ?
+ "assignment" : "method");
}
break;
@@ -1936,7 +1939,6 @@ is_defined(self, node, buf)
return "false";
case NODE_ATTRSET:
- case NODE_ATTRASGN:
case NODE_OP_ASGN1:
case NODE_OP_ASGN2:
case NODE_MASGN:
@@ -5039,7 +5041,7 @@ compile(src, file, line)
NODE *node;
ruby_nerrs = 0;
- Check_Type(src, T_STRING);
+ StringValue(src);
node = rb_compile_string(file, src, line);
if (ruby_nerrs == 0) return node;
diff --git a/file.c b/file.c
index f8a0037e3c..4905de9f0b 100644
--- a/file.c
+++ b/file.c
@@ -1826,13 +1826,11 @@ test_check(n, argc, argv)
for (i=1; i<n; i++) {
switch (TYPE(argv[i])) {
case T_STRING:
+ default:
SafeStringValue(argv[i]);
break;
case T_FILE:
break;
- default:
- Check_Type(argv[i], T_STRING);
- break;
}
}
}
diff --git a/intern.h b/intern.h
index 07b5b5e2e8..eca1fd1fd3 100644
--- a/intern.h
+++ b/intern.h
@@ -52,6 +52,7 @@ VALUE rb_ary_includes _((VALUE, VALUE));
VALUE rb_ary_cmp _((VALUE, VALUE));
VALUE rb_protect_inspect _((VALUE(*)(ANYARGS),VALUE,VALUE));
VALUE rb_inspecting_p _((VALUE));
+VALUE rb_check_array_value _((VALUE));
/* bignum.c */
VALUE rb_big_clone _((VALUE));
void rb_big_2comp _((VALUE));
@@ -262,6 +263,7 @@ VALUE rb_marshal_load _((VALUE));
/* numeric.c */
void rb_num_zerodiv _((void));
VALUE rb_num_coerce_bin _((VALUE, VALUE));
+VALUE rb_num_coerce_cmp _((VALUE, VALUE));
VALUE rb_float_new _((double));
VALUE rb_num2fix _((VALUE));
VALUE rb_fix2str _((VALUE, int));
@@ -371,6 +373,7 @@ VALUE rb_str_buf_append _((VALUE, VALUE));
VALUE rb_str_buf_cat _((VALUE, const char*, long));
VALUE rb_str_buf_cat2 _((VALUE, const char*));
VALUE rb_obj_as_string _((VALUE));
+VALUE rb_check_string_type _((VALUE));
VALUE rb_str_dup _((VALUE));
VALUE rb_str_dup_frozen _((VALUE));
VALUE rb_str_plus _((VALUE, VALUE));
diff --git a/io.c b/io.c
index b9060773e1..6c8379802a 100644
--- a/io.c
+++ b/io.c
@@ -2581,7 +2581,7 @@ rb_io_puts(argc, argv, out)
line = rb_str_new2("nil");
}
else {
- line = rb_check_convert_type(argv[i], T_ARRAY, "Array", "to_ary");
+ line = rb_check_array_type(argv[i]);
if (!NIL_P(line)) {
rb_protect_inspect(io_puts_ary, line, out);
continue;
diff --git a/marshal.c b/marshal.c
index 5d34b9e4c8..25d08ac471 100644
--- a/marshal.c
+++ b/marshal.c
@@ -752,7 +752,7 @@ r_bytes0(len, arg)
VALUE n = LONG2NUM(len);
str = rb_funcall2(src, s_read, 1, &n);
if (NIL_P(str)) goto too_short;
- Check_Type(str, T_STRING);
+ StringValue(str);
if (RSTRING(str)->len != len) goto too_short;
if (OBJ_TAINTED(str)) arg->taint = Qtrue;
}
diff --git a/numeric.c b/numeric.c
index c1e064588b..0da0e64279 100644
--- a/numeric.c
+++ b/numeric.c
@@ -13,10 +13,19 @@
#include "ruby.h"
#include <math.h>
#include <stdio.h>
+
#if defined(__FreeBSD__) && __FreeBSD__ < 4
#include <floatingpoint.h>
#endif
+#ifdef HAVE_FLOAT_H
+#include <float.h>
+#endif
+
+#ifndef DBL_EPSILON
+#define 2.2204460492503131E-16
+#endif
+
static ID id_coerce, id_to_i, id_div;
VALUE rb_cNumeric;
@@ -61,32 +70,46 @@ coerce_rescue(x)
return Qnil; /* dummy */
}
-static void
-do_coerce(x, y)
+static int
+do_coerce(x, y, err)
VALUE *x, *y;
+ int err;
{
VALUE ary;
VALUE a[2];
a[0] = *x; a[1] = *y;
- ary = rb_rescue(coerce_body, (VALUE)a, coerce_rescue, (VALUE)a);
+ ary = rb_rescue(coerce_body, (VALUE)a, err?coerce_rescue:0, (VALUE)a);
if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) {
- rb_raise(rb_eTypeError, "coerce must return [x, y]");
+ if (err) {
+ rb_raise(rb_eTypeError, "coerce must return [x, y]");
+ }
+ return Qfalse;
}
*x = RARRAY(ary)->ptr[0];
*y = RARRAY(ary)->ptr[1];
+ return Qtrue;
}
VALUE
rb_num_coerce_bin(x, y)
VALUE x, y;
{
- do_coerce(&x, &y);
+ do_coerce(&x, &y, Qtrue);
return rb_funcall(x, rb_frame_last_func(), 1, y);
}
+VALUE
+rb_num_coerce_cmp(x, y)
+ VALUE x, y;
+{
+ if (do_coerce(&x, &y, Qfalse))
+ return rb_funcall(x, rb_frame_last_func(), 1, y);
+ return Qnil;
+}
+
static VALUE
num_copy_object(x, y)
VALUE x, y;
@@ -110,7 +133,7 @@ num_uminus(num)
VALUE zero;
zero = INT2FIX(0);
- do_coerce(&zero, &num);
+ do_coerce(&zero, &num, Qtrue);
return rb_funcall(zero, '-', 1, num);
}
@@ -494,7 +517,7 @@ rb_dbl_cmp(a, b)
if (a == b) return INT2FIX(0);
if (a > b) return INT2FIX(1);
if (a < b) return INT2FIX(-1);
- rb_raise(rb_eFloatDomainError, "comparing NaN");
+ return Qnil;
}
static VALUE
@@ -518,7 +541,7 @@ flo_cmp(x, y)
break;
default:
- return rb_num_coerce_bin(x, y);
+ return rb_num_coerce_cmp(x, y);
}
return rb_dbl_cmp(a, b);
}
@@ -824,7 +847,7 @@ num_step(argc, argv, from)
}
}
else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
- const double epsilon = 2.2204460492503131E-16;
+ const double epsilon = DBL_EPSILON;
double beg = NUM2DBL(from);
double end = NUM2DBL(to);
double unit = NUM2DBL(step);
@@ -1322,7 +1345,7 @@ fix_cmp(x, y)
return INT2FIX(-1);
}
else {
- return rb_num_coerce_bin(x, y);
+ return rb_num_coerce_cmp(x, y);
}
}
diff --git a/object.c b/object.c
index 7eed51b3d8..736348279d 100644
--- a/object.c
+++ b/object.c
@@ -651,9 +651,7 @@ rb_mod_cmp(mod, arg)
case T_CLASS:
break;
default:
- rb_raise(rb_eTypeError, "<=> requires Class or Module (%s given)",
- rb_class2name(CLASS_OF(arg)));
- break;
+ return Qnil;
}
if (rb_mod_le(mod, arg)) {
diff --git a/parse.y b/parse.y
index 74d4d09039..b1d2bfe8f8 100644
--- a/parse.y
+++ b/parse.y
@@ -4687,7 +4687,7 @@ aryset(recv, idx)
NODE *recv, *idx;
{
value_expr(recv);
- return NEW_CALL(recv, tASET, idx);
+ return NEW_ATTRASGN(recv, tASET, idx);
}
ID
diff --git a/range.c b/range.c
index a004f408ec..bb12bc38c2 100644
--- a/range.c
+++ b/range.c
@@ -123,6 +123,7 @@ r_lt(a, b)
{
VALUE r = rb_funcall(a, id_cmp, 1, b);
+ if (NIL_P(r)) return Qfalse;
if (rb_cmpint(r) < 0) return Qtrue;
return Qfalse;
}
@@ -133,16 +134,19 @@ r_le(a, b)
{
VALUE r = rb_funcall(a, id_cmp, 1, b);
+ if (NIL_P(r)) return Qfalse;
if (rb_cmpint(r) <= 0) return Qtrue;
return Qfalse;
}
+
static int
r_gt(a,b)
VALUE a, b;
{
VALUE r = rb_funcall(a, id_cmp, 1, b);
+ if (NIL_P(r)) return Qfalse;
if (rb_cmpint(r) > 0) return Qtrue;
return Qfalse;
}
@@ -474,12 +478,13 @@ range_include(range, val)
beg = rb_ivar_get(range, id_beg);
end = rb_ivar_get(range, id_end);
- if (r_gt(beg, val)) return Qfalse;
- if (EXCL(range)) {
- if (r_lt(val, end)) return Qtrue;
- }
- else {
- if (r_le(val, end)) return Qtrue;
+ if (r_le(beg, val)) {
+ if (EXCL(range)) {
+ if (r_lt(val, end)) return Qtrue;
+ }
+ else {
+ if (r_le(val, end)) return Qtrue;
+ }
}
return Qfalse;
}
diff --git a/re.c b/re.c
index 52fca7c2e4..0035f24624 100644
--- a/re.c
+++ b/re.c
@@ -1110,6 +1110,27 @@ rb_reg_match(re, str)
}
VALUE
+rb_reg_eqq(re, str)
+ VALUE re, str;
+{
+ long start;
+
+ if (TYPE(str) != T_STRING) {
+ str = rb_check_string_type(str);
+ if (NIL_P(str)) {
+ rb_backref_set(Qnil);
+ return Qfalse;
+ }
+ }
+ StringValue(str);
+ start = rb_reg_search(re, str, 0, 0);
+ if (start < 0) {
+ return Qfalse;
+ }
+ return Qtrue;
+}
+
+VALUE
rb_reg_match2(re)
VALUE re;
{
@@ -1583,7 +1604,7 @@ Init_Regexp()
rb_define_method(rb_cRegexp, "eql?", rb_reg_equal, 1);
rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
- rb_define_method(rb_cRegexp, "===", rb_reg_match, 1);
+ rb_define_method(rb_cRegexp, "===", rb_reg_eqq, 1);
rb_define_method(rb_cRegexp, "~", rb_reg_match2, 0);
rb_define_method(rb_cRegexp, "match", rb_reg_match_m, 1);
rb_define_method(rb_cRegexp, "to_s", rb_reg_to_s, 0);
diff --git a/signal.c b/signal.c
index 44ada105dc..0526fbfd75 100644
--- a/signal.c
+++ b/signal.c
@@ -234,7 +234,7 @@ rb_f_kill(argc, argv)
{
VALUE str;
- str = rb_check_convert_type(argv[0], T_STRING, "String", "to_str");
+ str = rb_check_string_type(argv[0]);
if (!NIL_P(str)) {
s = RSTRING(str)->ptr;
goto str_signal;
diff --git a/string.c b/string.c
index 26d1cbf2af..23a804a829 100644
--- a/string.c
+++ b/string.c
@@ -469,6 +469,13 @@ rb_string_value_ptr(ptr)
}
VALUE
+rb_check_string_type(str)
+ VALUE str;
+{
+ return rb_check_convert_type(str, T_STRING, "String", "to_str");
+}
+
+VALUE
rb_str_substr(str, beg, len)
VALUE str;
long beg, len;
@@ -763,7 +770,7 @@ rb_str_equal(str1, str2)
{
if (str1 == str2) return Qtrue;
if (TYPE(str2) != T_STRING) {
- str2 = rb_check_convert_type(str2, T_STRING, "String", "to_str");
+ str2 = rb_check_string_type(str2);
if (NIL_P(str2)) return Qfalse;
}
@@ -794,7 +801,10 @@ rb_str_cmp_m(str1, str2)
{
int result;
- StringValue(str2);
+ if (TYPE(str2) != T_STRING) {
+ str2 = rb_check_string_type(str2);
+ if (NIL_P(str2)) return Qnil;
+ }
result = rb_str_cmp(str1, str2);
return INT2FIX(result);
}
@@ -1428,7 +1438,7 @@ get_pat(pat, quote)
break;
default:
- val = rb_check_convert_type(pat, T_STRING, "String", "to_str");
+ val = rb_check_string_type(pat);
if (NIL_P(val)) {
Check_Type(pat, T_REGEXP);
}
diff --git a/variable.c b/variable.c
index 926cdb9160..aec1d92a64 100644
--- a/variable.c
+++ b/variable.c
@@ -816,11 +816,15 @@ generic_ivar_get(obj, id)
st_table *tbl;
VALUE val;
- if (!generic_iv_tbl) return Qnil;
- if (!st_lookup(generic_iv_tbl, obj, &tbl)) return Qnil;
- if (st_lookup(tbl, id, &val)) {
- return val;
+ if (generic_iv_tbl) {
+ if (st_lookup(generic_iv_tbl, obj, &tbl)) {
+ if (st_lookup(tbl, id, &val)) {
+ return val;
+ }
+ }
}
+
+ rb_warning("instance variable %s not initialized", rb_id2name(id));
return Qnil;
}