summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog29
-rw-r--r--bignum.c3
-rw-r--r--eval.c5
-rw-r--r--hash.c63
-rw-r--r--io.c25
-rw-r--r--lib/cgi.rb2
-rw-r--r--lib/csv.rb8
-rw-r--r--lib/generator.rb4
-rw-r--r--lib/logger.rb1
-rw-r--r--lib/ostruct.rb2
-rw-r--r--lib/rational.rb4
-rw-r--r--lib/singleton.rb20
-rw-r--r--lib/tempfile.rb2
-rw-r--r--lib/test/unit/testcase.rb4
-rw-r--r--misc/ruby-mode.el2
-rw-r--r--numeric.c34
-rw-r--r--string.c12
17 files changed, 145 insertions, 75 deletions
diff --git a/ChangeLog b/ChangeLog
index d4a4d2a003..374993e6c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -62,6 +62,10 @@ Fri Apr 30 20:08:41 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* time.c (SIZEOF_TIME_T): support SIZEOF_TIME_T == SIZEOF_INT.
+Tue Apr 27 13:12:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (rb_eval): too many line trace call. (ruby-bugs PR#1320)
+
Tue Apr 27 08:41:28 2004 why the lucky stiff <why@ruby-lang.org>
* lib/yaml/rubytypes.rb: passing Range tests.
@@ -129,6 +133,14 @@ Thu Apr 22 04:15:36 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (aref_args): should pass expanded list. [ruby-core:02793]
+Thu Apr 22 01:12:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * numeric.c (flo_to_s): tweak output string based to preserve
+ decimal point and to remove trailing zeros. [ruby-talk:97891]
+
+ * string.c (rb_str_index_m): use unsigned comparison for T_FIXNUM
+ search. [ruby-talk:97342]
+
Wed Apr 21 22:57:27 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/rinda.rb, test/rinda/test_rinda.rb: check Hash tuple size.
@@ -138,6 +150,14 @@ Wed Apr 21 20:05:00 2004 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb (URI::HTTP#proxy_open): set Host: field explicitly.
[ruby-list:39542]
+Mon Apr 19 18:11:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * hash.c (rb_hash_equal): returns true if two hashes have same set
+ of key-value set. [ruby-talk:97559]
+
+ * hash.c (rb_hash_eql): returns true if two hashes are equal and
+ have same default values.
+
Mon Apr 19 08:19:58 2004 Doug Kearns <djkea2@mugca.its.monash.edu.au>
* dln.c, io.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb, lib/date.rb,
@@ -158,6 +178,11 @@ Fri Apr 16 22:33:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* ext/iconv/iconv.c: nearly finished RDoc comments.
+Fri Apr 16 17:04:07 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_equal): always returns true or false, never
+ returns nil. [ruby-dev:23404]
+
Fri Apr 16 08:27:02 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb: skip linking when libraries to be preloaded not
@@ -263,6 +288,10 @@ Wed Apr 7 00:19:50 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/rinda/test_rinda.rb
+Tue Apr 6 18:24:18 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * io.c (rb_io_reopen): should use rb_io_check_io().
+
Tue Apr 6 16:46:09 2004 Tanaka Akira <akr@m17n.org>
* configure.in: check the size of time_t.
diff --git a/bignum.c b/bignum.c
index f5ec1fe015..92384bf8e3 100644
--- a/bignum.c
+++ b/bignum.c
@@ -463,6 +463,9 @@ rb_cstr_to_inum(str, base, badcheck)
}
continue;
}
+ else if (!ISASCII(c)) {
+ break;
+ }
else if (isdigit(c)) {
c -= '0';
}
diff --git a/eval.c b/eval.c
index fb91c7ac2a..0c4f60a5eb 100644
--- a/eval.c
+++ b/eval.c
@@ -2697,11 +2697,6 @@ rb_eval(self, n)
if (!node) RETURN(Qnil);
ruby_current_node = node;
- if (trace_func && FL_TEST(node, NODE_NEWLINE)) {
- call_trace_func("line", node, self,
- ruby_frame->last_func,
- ruby_frame->last_class);
- }
switch (nd_type(node)) {
case NODE_BLOCK:
if (contnode) {
diff --git a/hash.c b/hash.c
index fc2897668c..9d1c5d04bc 100644
--- a/hash.c
+++ b/hash.c
@@ -1392,6 +1392,35 @@ equal_i(key, val1, data)
return ST_CONTINUE;
}
+static VALUE
+hash_equal(hash1, hash2, eql)
+ VALUE hash1, hash2;
+ int eql; /* compare default value if true */
+{
+ struct equal_data data;
+
+ if (hash1 == hash2) return Qtrue;
+ if (TYPE(hash2) != T_HASH) {
+ if (!rb_respond_to(hash2, rb_intern("to_hash"))) {
+ return Qfalse;
+ }
+ return rb_equal(hash2, hash1);
+ }
+ if (RHASH(hash1)->tbl->num_entries != RHASH(hash2)->tbl->num_entries)
+ return Qfalse;
+ if (eql) {
+ if (!(rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone) &&
+ FL_TEST(hash1, HASH_PROC_DEFAULT) == FL_TEST(hash2, HASH_PROC_DEFAULT)))
+ return Qfalse;
+ }
+
+ data.tbl = RHASH(hash2)->tbl;
+ data.result = Qtrue;
+ st_foreach(RHASH(hash1)->tbl, equal_i, (st_data_t)&data);
+
+ return data.result;
+}
+
/*
* call-seq:
* hsh == other_hash => true or false
@@ -1415,26 +1444,23 @@ static VALUE
rb_hash_equal(hash1, hash2)
VALUE hash1, hash2;
{
- struct equal_data data;
-
- if (hash1 == hash2) return Qtrue;
- if (TYPE(hash2) != T_HASH) {
- if (!rb_respond_to(hash2, rb_intern("to_hash"))) {
- return Qfalse;
- }
- return rb_equal(hash2, hash1);
- }
- if (RHASH(hash1)->tbl->num_entries != RHASH(hash2)->tbl->num_entries)
- return Qfalse;
- if (!(rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone) &&
- FL_TEST(hash1, HASH_PROC_DEFAULT) == FL_TEST(hash2, HASH_PROC_DEFAULT)))
- return Qfalse;
+ return hash_equal(hash1, hash2, Qfalse);
+}
- data.tbl = RHASH(hash2)->tbl;
- data.result = Qtrue;
- st_foreach(RHASH(hash1)->tbl, equal_i, (st_data_t)&data);
+/*
+ * call-seq:
+ * hsh.eql?(other_hash) => true or false
+ *
+ * Returns true if two hashes are equal, i.e they have same key-value set,
+ * and same default values.
+ *
+ */
- return data.result;
+static VALUE
+rb_hash_eql(hash1, hash2)
+ VALUE hash1, hash2;
+{
+ return hash_equal(hash1, hash2, Qtrue);
}
static int
@@ -2368,6 +2394,7 @@ Init_Hash()
rb_define_method(rb_cHash,"inspect", rb_hash_inspect, 0);
rb_define_method(rb_cHash,"==", rb_hash_equal, 1);
+ rb_define_method(rb_cHash,"eql?", rb_hash_eql, 1);
rb_define_method(rb_cHash,"[]", rb_hash_aref, 1);
rb_define_method(rb_cHash,"fetch", rb_hash_fetch, -1);
rb_define_method(rb_cHash,"[]=", rb_hash_aset, 2);
diff --git a/io.c b/io.c
index 4e74f6f859..0b094ca99e 100644
--- a/io.c
+++ b/io.c
@@ -2368,16 +2368,29 @@ rb_fdopen(fd, mode)
{
FILE *file;
+#if defined(sun)
+ errno = 0;
+#endif
file = fdopen(fd, mode);
if (!file) {
+#if defined(sun)
+ if (errno == 0 || errno == EMFILE || errno == ENFILE) {
+#else
if (errno == EMFILE || errno == ENFILE) {
+#endif
rb_gc();
+#if defined(sun)
+ errno = 0;
+#endif
file = fdopen(fd, mode);
}
if (!file) {
#ifdef _WIN32
if (errno == 0) errno = EINVAL;
#endif
+#if defined(sun)
+ if (errno == 0) errno = EMFILE;
+#endif
rb_sys_fail(0);
}
}
@@ -2993,6 +3006,13 @@ rb_io_get_io(io)
return rb_convert_type(io, T_FILE, "IO", "to_io");
}
+static VALUE
+rb_io_check_io(io)
+ VALUE io;
+{
+ return rb_check_convert_type(io, T_FILE, "IO", "to_io");
+}
+
static char*
rb_io_mode_string(fptr)
OpenFile *fptr;
@@ -3122,8 +3142,9 @@ rb_io_reopen(argc, argv, file)
rb_secure(4);
if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) {
- if (TYPE(fname) != T_STRING) { /* fname must be IO */
- return io_reopen(file, fname);
+ VALUE tmp = rb_io_check_io(fname);
+ if (!NIL_P(tmp)) {
+ return io_reopen(file, tmp);
}
}
diff --git a/lib/cgi.rb b/lib/cgi.rb
index 73e4915308..460a8b8868 100644
--- a/lib/cgi.rb
+++ b/lib/cgi.rb
@@ -30,7 +30,7 @@
# See http://www.w3.org/CGI/ for more information on the CGI
# protocol.
-raise "Please, use ruby1.5.4 or later." if RUBY_VERSION < "1.5.4"
+raise "Please, use ruby 1.5.4 or later." if RUBY_VERSION < "1.5.4"
require 'English'
diff --git a/lib/csv.rb b/lib/csv.rb
index 5500fb55bb..3eb13192fe 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -557,7 +557,7 @@ class CSV
private
def initialize(dev)
- raise RuntimeError.new('do not instanciate this class directly')
+ raise RuntimeError.new('do not instantiate this class directly')
end
def get_row(row)
@@ -709,7 +709,7 @@ class CSV
private
def initialize(dev)
- raise RuntimeError.new('do not instanciate this class directly')
+ raise RuntimeError.new('do not instantiate this class directly')
end
def terminate
@@ -801,7 +801,7 @@ class CSV
# end
# end
#
- class StreamBuf # pure virtual. (do not instanciate it directly)
+ class StreamBuf # pure virtual. (do not instantiate it directly)
# get a char or a partial string from the stream.
# idx: index of a string to specify a start point of a string to get.
@@ -893,7 +893,7 @@ class CSV
return idx_is_eos?(0)
end
- # WARN: Do not instanciate this class directly. Define your own class
+ # WARN: Do not instantiate this class directly. Define your own class
# which derives this class and define 'read' instance method.
def initialize
@buf_list = []
diff --git a/lib/generator.rb b/lib/generator.rb
index 805e7a2630..a010559b60 100644
--- a/lib/generator.rb
+++ b/lib/generator.rb
@@ -125,7 +125,7 @@ class Generator
# Returns the element at the current position and moves forward.
def next()
if end?
- raise EOFError, "no more element is supplied"
+ raise EOFError, "no more elements available"
end
if @cont_next = callcc { |c| c }
@@ -140,7 +140,7 @@ class Generator
# Returns the element at the current position.
def current()
if @queue.empty?
- raise EOFError, "no more element is supplied"
+ raise EOFError, "no more elements available"
end
@queue.first
diff --git a/lib/logger.rb b/lib/logger.rb
index d3ce495f17..6c1e492f4e 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -539,6 +539,7 @@ private
def create_logfile(filename)
logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
+ logdev.sync = true
add_log_header(logdev)
logdev
end
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 786bd4de20..d603c04759 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -57,7 +57,7 @@ class OpenStruct
len = args.length
if mname =~ /=$/
if len != 1
- raise ArgumentError, "wrong # of arguments (#{len} for 1)", caller(1)
+ raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
end
if self.frozen?
raise TypeError, "can't modify frozen #{self.class}", caller(1)
diff --git a/lib/rational.rb b/lib/rational.rb
index 38af7b8a81..2019363ac6 100644
--- a/lib/rational.rb
+++ b/lib/rational.rb
@@ -48,7 +48,7 @@ class Rational < Numeric
@RCS_ID='-$Id: rational.rb,v 1.7 1999/08/24 12:49:28 keiju Exp keiju $-'
def Rational.reduce(num, den = 1)
- raise ZeroDivisionError, "denominator is 0" if den == 0
+ raise ZeroDivisionError, "denominator is zero" if den == 0
if den < 0
num = -num
@@ -135,7 +135,7 @@ class Rational < Numeric
den = @denominator * a.numerator
Rational(num, den)
elsif a.kind_of?(Integer)
- raise ZeroDivisionError, "divided by 0" if a == 0
+ raise ZeroDivisionError, "division by zero" if a == 0
self / Rational.new!(a, 1)
elsif a.kind_of?(Float)
Float(self) / a
diff --git a/lib/singleton.rb b/lib/singleton.rb
index 2954bfa153..18fda0bc58 100644
--- a/lib/singleton.rb
+++ b/lib/singleton.rb
@@ -13,7 +13,7 @@
# a == b # => true
# a.new # NoMethodError - new is private ...
#
-# * ``The instance'' is created at instanciation time, in other
+# * ``The instance'' is created at instantiation time, in other
# words the first call of Klass.instance(), thus
#
# class OtherKlass
@@ -44,11 +44,11 @@
#
# * Klass._load(str) - calling Klass.instance()
#
-# * Klass._instanciate?() - returning ``the instance'' or
+# * Klass._instantiate?() - returning ``the instance'' or
# nil. This hook method puts a second (or nth) thread calling
# Klass.instance() on a waiting loop. The return value
# signifies the successful completion or premature termination
-# of the first, or more generally, current "instanciation thread".
+# of the first, or more generally, current "instantiation thread".
#
#
# The instance method of Singleton are
@@ -103,7 +103,7 @@ class << Singleton
@__instance__ = nil # failed instance creation
end
end
- elsif _instanciate?()
+ elsif _instantiate?()
Thread.critical = false
else
@__instance__ = false
@@ -144,7 +144,7 @@ class << Singleton
end
# waiting-loop hook
- def _instanciate?()
+ def _instantiate?()
while false.equal?(@__instance__)
Thread.critical = false
sleep(0.08) # timeout
@@ -209,7 +209,7 @@ end
-puts "\nThreaded example with exception and customized #_instanciate?() hook"; p
+puts "\nThreaded example with exception and customized #_instantiate?() hook"; p
Thread.abort_on_exception = false
class Ups < SomeSingletonClass
@@ -220,7 +220,7 @@ class Ups < SomeSingletonClass
end
class << Ups
- def _instanciate?
+ def _instantiate?
@enter.push Thread.current[:i]
while false.equal?(@__instance__)
Thread.critical = false
@@ -247,7 +247,7 @@ class << Ups
end
end
- def instanciate_all
+ def instantiate_all
@enter = []
@leave = []
1.upto(9) {|i|
@@ -270,7 +270,7 @@ class << Ups
end
-Ups.instanciate_all
+Ups.instantiate_all
# results in message like
# Before there were 0 Ups instance(s)
# boom - thread #6 failed to create instance
@@ -293,7 +293,7 @@ def Yup.new
end
end
end
-Yup.instanciate_all
+Yup.instantiate_all
puts "\n\n","Customized marshalling"
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index f5dc801b21..8105b30f50 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -9,7 +9,7 @@ require 'tmpdir'
# A class for managing temporary files. This library is written to be
# thread safe.
-class Tempfile < SimpleDelegator
+class Tempfile < DelegateClass(File)
MAX_TRY = 10
@@cleanlist = []
diff --git a/lib/test/unit/testcase.rb b/lib/test/unit/testcase.rb
index e765b91161..9c1c41d749 100644
--- a/lib/test/unit/testcase.rb
+++ b/lib/test/unit/testcase.rb
@@ -31,7 +31,9 @@ module Test
# Creates a new instance of the fixture for running the
# test represented by test_method_name.
def initialize(test_method_name)
- unless(respond_to?(test_method_name) && method(test_method_name).arity == 0)
+ unless(respond_to?(test_method_name) and
+ (method(test_method_name).arity == 0 ||
+ method(test_method_name).arity == -1))
throw :invalid_test
end
@method_name = test_method_name
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index 081218c408..a45b638f17 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -325,7 +325,7 @@ The variable ruby-indent-level controls the amount of indentation.
(looking-at ruby-block-op-re)
(looking-at ruby-block-mid-re))
(goto-char (match-end 0))
- (looking-at "\\>"))
+ (not (looking-at "\\s_")))
((eq option 'expr-qstr)
(looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]"))
((eq option 'expr-re)
diff --git a/numeric.c b/numeric.c
index 513b43b48c..ac5e125a8f 100644
--- a/numeric.c
+++ b/numeric.c
@@ -489,37 +489,29 @@ flo_to_s(flt)
VALUE flt;
{
char buf[32];
- char *fmt = "%.15g";
+ char *fmt = "%.15f";
double value = RFLOAT(flt)->value;
double avalue, d1, d2;
+ char *p, *e;
if (isinf(value))
return rb_str_new2(value < 0 ? "-Infinity" : "Infinity");
else if(isnan(value))
return rb_str_new2("NaN");
-
+
avalue = fabs(value);
- if (avalue == 0.0) {
- fmt = "%.1f";
- }
- else if (avalue < 1.0e-3) {
- d1 = avalue;
- while (d1 < 1.0) d1 *= 10.0;
- d1 = modf(d1, &d2);
- if (d1 == 0) fmt = "%.1e";
- }
- else if (avalue >= 1.0e15) {
- d1 = avalue;
- while (d1 > 10.0) d1 /= 10.0;
- d1 = modf(d1, &d2);
- if (d1 == 0) fmt = "%.1e";
- else fmt = "%.16e";
+ if (avalue < 1.0e-7 || avalue >= 1.0e15) {
+ fmt = "%.16e";
}
- else if ((d1 = modf(value, &d2)) == 0) {
- fmt = "%.1f";
- }
sprintf(buf, fmt, value);
-
+ if (!(e = strchr(buf, 'e'))) {
+ e = buf + strlen(buf);
+ }
+ p = e;
+ while (*--p=='0')
+ ;
+ if (*p == '.') *p++;
+ memmove(p+1, e, strlen(e)+1);
return rb_str_new2(buf);
}
diff --git a/string.c b/string.c
index 8b55d75212..4bd5de968e 100644
--- a/string.c
+++ b/string.c
@@ -889,7 +889,7 @@ rb_str_equal(str1, str2)
if (str1 == str2) return Qtrue;
if (TYPE(str2) != T_STRING) {
if (!rb_respond_to(str2, rb_intern("to_str"))) {
- return Qnil;
+ return Qfalse;
}
return rb_equal(str2, str1);
}
@@ -954,7 +954,7 @@ rb_str_cmp_m(str1, str2)
if (TYPE(str2) != T_STRING) {
if (!rb_respond_to(str2, rb_intern("to_str"))) {
- return Qnil;
+ return Qfalse;
}
else if (!rb_respond_to(str2, rb_intern("<=>"))) {
return Qnil;
@@ -1081,7 +1081,7 @@ rb_str_index_m(argc, argv, str)
{
int c = FIX2INT(sub);
long len = RSTRING(str)->len;
- char *p = RSTRING(str)->ptr;
+ unsigned char *p = RSTRING(str)->ptr;
for (;pos<len;pos++) {
if (p[pos] == c) return LONG2NUM(pos);
@@ -1203,15 +1203,15 @@ rb_str_rindex_m(argc, argv, str)
case T_FIXNUM:
{
int c = FIX2INT(sub);
- char *p = RSTRING(str)->ptr + pos;
- char *pbeg = RSTRING(str)->ptr;
+ unsigned char *p = RSTRING(str)->ptr + pos;
+ unsigned char *pbeg = RSTRING(str)->ptr;
if (pos == RSTRING(str)->len) {
if (pos == 0) return Qnil;
--p;
}
while (pbeg <= p) {
- if (*p == c) return LONG2NUM(p - RSTRING(str)->ptr);
+ if (*p == c) return LONG2NUM((char*)p - RSTRING(str)->ptr);
p--;
}
return Qnil;