From 7559d2fd7accfd9eab2c8ab5864a5c61d6016d1d Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 19 Sep 2005 16:01:06 +0000 Subject: [PATCH] * io.c (io_close): call rb_io_close() directly if io is a T_FILE object. [ruby-dev:27156] * file.c (file_expand_path): allow pathnames to expand. [ruby-dev:27152] * numeric.c (Init_Numeric): should define Fixnum#div. [ruby-dev:27129] * file.c (rb_thread_flock): wrap flock(2) by TRAP_BEG and TRAP_END. [ruby-dev:27122] * file.c (rb_file_join): call FilePathValue() to all Pathnames to join. [ruby-dev:27127] * file.c (rb_get_path): call StringValueCStr() to ensure no nul bytes in path strings. * gc.c (garbage_collect): need value for return. [ruby-dev:27127] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 29 ++++++++++++++++++++++++++--- file.c | 15 +++++++++++++-- io.c | 4 ++++ lib/mathn.rb | 7 ++++++- lib/rational.rb | 6 ++++++ numeric.c | 2 +- 6 files changed, 56 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index c13417d516..043c3e3308 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,17 @@ +Tue Sep 20 00:34:07 2005 Yukihiro Matsumoto + + * io.c (io_close): call rb_io_close() directly if io is a T_FILE + object. [ruby-dev:27156] + Mon Sep 19 18:58:10 2005 Minero Aoki * file.c (rb_file_chown): should accept nil. [ruby-dev:27171] +Mon Sep 19 18:29:54 2005 Yukihiro Matsumoto + + * file.c (file_expand_path): allow pathnames to expand. + [ruby-dev:27152] + Mon Sep 19 15:12:15 2005 Minero Aoki * ext/ripper/depend: do not make ripper/core.rb. [ruby-dev:26462] @@ -63,6 +73,22 @@ Mon Sep 19 03:17:48 2005 Tanaka Akira TRAP_BEG/TRAP_END to run signal hander in syswrite method. [ruby-dev:27134] +Mon Sep 19 01:07:38 2005 Yukihiro Matsumoto + + * numeric.c (Init_Numeric): should define Fixnum#div. + [ruby-dev:27129] + + * file.c (rb_thread_flock): wrap flock(2) by TRAP_BEG and + TRAP_END. [ruby-dev:27122] + + * file.c (rb_file_join): call FilePathValue() to all Pathnames to + join. [ruby-dev:27127] + + * file.c (rb_get_path): call StringValueCStr() to ensure no nul + bytes in path strings. + + * gc.c (garbage_collect): need value for return. [ruby-dev:27127] + Sun Sep 18 02:10:47 2005 why the lucky stiff * lib/yaml/rubytypes.rb: remove comments that are bungling up @@ -81,9 +107,6 @@ Sun Sep 18 02:10:47 2005 why the lucky stiff Sun Sep 18 01:10:37 2005 Nobuyoshi Nakada - * file.c (rb_file_join): convert components by to_s instead of to_str. - fixed: [ruby-dev:27127] - * gc.c (garbage_collect): return false if no GC run. Sat Sep 17 23:25:04 2005 sheepman diff --git a/file.c b/file.c index 6302bb8935..d4a993be2a 100644 --- a/file.c +++ b/file.c @@ -88,7 +88,8 @@ rb_get_path(VALUE obj) if (rb_respond_to(obj, to_path)) { obj = rb_funcall(obj, to_path, 0, 0); } - tmp = rb_str_to_str(obj); + tmp = obj; + StringValueCStr(tmp); exit: if (obj != tmp) { rb_check_safe_obj(tmp); @@ -2271,6 +2272,7 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result) long buflen, dirlen; int tainted; + FilePathValue(fname); s = StringValuePtr(fname); BUFINIT(); tainted = OBJ_TAINTED(fname); @@ -2737,7 +2739,7 @@ rb_file_join(VALUE ary, VALUE sep) } break; default: - tmp = rb_obj_as_string(tmp); + FilePathValue(tmp); } name = StringValueCStr(result); if (i > 0 && !NIL_P(sep)) { @@ -2884,11 +2886,20 @@ static int rb_thread_flock(int fd, int op, OpenFile *fptr) { if (rb_thread_alone() || (op & LOCK_NB)) { +<<<<<<< file.c + int n; + + TRAP_BEG; + n = flock(fd, op); + TRAP_END; + return n; +======= int ret; TRAP_BEG; ret = flock(fd, op); TRAP_END; return ret; +>>>>>>> 1.208 } op |= LOCK_NB; while (flock(fd, op) < 0) { diff --git a/io.c b/io.c index 04e46e085d..f3badc966a 100644 --- a/io.c +++ b/io.c @@ -2064,6 +2064,10 @@ rb_io_close_m(VALUE io) static VALUE io_close(VALUE io) { + if (TYPE(io) == T_FILE) { + rb_io_close(io); + return Qnil; + } return rb_funcall(io, rb_intern("close"), 0, 0); } diff --git a/lib/mathn.rb b/lib/mathn.rb index 19325f2996..ddfca57681 100644 --- a/lib/mathn.rb +++ b/lib/mathn.rb @@ -116,17 +116,22 @@ class Prime end class Fixnum + remove_method :/ alias / quo + alias_method :/, :quo + p :fixdiv + p [[:fixdiv, 1.div(1)]] end class Bignum + remove_method :/ alias / quo end class Rational Unify = true - remove_method(:inspect) + remove_method :inspect def inspect format "%s/%s", numerator.inspect, denominator.inspect end diff --git a/lib/rational.rb b/lib/rational.rb index 2241004852..f4570bd306 100644 --- a/lib/rational.rb +++ b/lib/rational.rb @@ -37,6 +37,7 @@ # def Rational(a, b = 1) + p [:Rational, a, b] if a.kind_of?(Rational) && b == 1 a else @@ -54,9 +55,13 @@ class Rational < Numeric num = -num den = -den end + p [:reduce, num, den] gcd = num.gcd(den) + p [:div1, num, num.class, gcd] num = num.div(gcd) + p [:div2, den, gcd] den = den.div(gcd) + p [:gcd=, gcd] if den == 1 && defined?(Unify) num else @@ -333,6 +338,7 @@ end class Fixnum undef quo def quo(other) + p [:quo, self, other] Rational.new!(self,1) / other end alias rdiv quo diff --git a/numeric.c b/numeric.c index f30d959a89..8ab8cd6623 100644 --- a/numeric.c +++ b/numeric.c @@ -259,7 +259,6 @@ num_div(VALUE x, VALUE y) } - /* * call-seq: * num.divmod( aNumeric ) -> anArray @@ -2825,6 +2824,7 @@ Init_Numeric(void) rb_define_method(rb_cFixnum, "-", fix_minus, 1); rb_define_method(rb_cFixnum, "*", fix_mul, 1); rb_define_method(rb_cFixnum, "/", fix_div, 1); + rb_define_method(rb_cFixnum, "div", fix_div, 1); rb_define_method(rb_cFixnum, "%", fix_mod, 1); rb_define_method(rb_cFixnum, "modulo", fix_mod, 1); rb_define_method(rb_cFixnum, "divmod", fix_divmod, 1);