From f232bdfbe0d14a7dc5a838601b1a3b4d880d52d5 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 15 Nov 2004 16:45:03 +0000 Subject: * array.c (rb_ary_update): pedantic check to detect rb_ary_to_ary() to modify the receiver. [ruby-dev:24861] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@7273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ array.c | 2 +- lib/rational.rb | 24 +++++++++++++----------- lib/tempfile.rb | 2 +- string.c | 7 ++++--- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba9ab95c1..ad8407930 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Nov 16 01:41:31 2004 Yukihiro Matsumoto + + * array.c (rb_ary_update): pedantic check to detect + rb_ary_to_ary() to modify the receiver. [ruby-dev:24861] + Mon Nov 15 18:58:05 2004 Tanaka Akira * configure.in: check rlim_t more portably. [ruby-core:3735] @@ -473,6 +478,12 @@ Fri Oct 29 10:00:30 2004 Yukihiro Matsumoto * eval.c (ruby_cleanup): ruby_finalize_1 may cause exception, should be wrapped by PUSH_TAG/POP_TAG(). [ruby-dev:24627] +Thu Oct 28 08:42:02 2004 Tanaka Akira + + * io.c (argf_forward): use ANSI style. + (argf_read): call argf_forward with argv argument. + [ruby-dev:24624] + Wed Oct 27 09:17:30 2004 Nobuyoshi Nakada * string.c (str_gsub): use a string object for exception safeness. diff --git a/array.c b/array.c index 8b9c62063..3e55ca4e3 100644 --- a/array.c +++ b/array.c @@ -1090,7 +1090,6 @@ rb_ary_update(ary, beg, len, rpl) len = RARRAY(ary)->len - beg; } - rb_ary_modify(ary); if (rpl == Qundef) { rlen = 0; } @@ -1098,6 +1097,7 @@ rb_ary_update(ary, beg, len, rpl) rpl = rb_ary_to_ary(rpl); rlen = RARRAY(rpl)->len; } + rb_ary_modify(ary); if (beg >= RARRAY(ary)->len) { len = beg + rlen; diff --git a/lib/rational.rb b/lib/rational.rb index 2019363ac..224100485 100644 --- a/lib/rational.rb +++ b/lib/rational.rb @@ -312,20 +312,22 @@ class Integer return a end - def lcm(int) - a = self.abs - b = int.abs - gcd = a.gcd(b) - (a.div(gcd)) * b + def lcm(other) + if self.zero? or other.zero? + 0 + else + (self.div(self.gcd(other)) * other).abs + end end - def gcdlcm(int) - a = self.abs - b = int.abs - gcd = a.gcd(b) - return gcd, (a.div(gcd)) * b + def gcdlcm(other) + gcd = self.gcd(other) + if self.zero? or other.zero? + [gcd, 0] + else + [gcd, (self.div(gcd) * other).abs] + end end - end class Fixnum diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 828e1cf8f..65b4bc69a 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -144,7 +144,7 @@ class Tempfile < DelegateClass(File) class << self def callback(data) # :nodoc: pid = $$ - lambda{ + Proc.new { if pid == $$ path, tmpfile, cleanlist = *data diff --git a/string.c b/string.c index 6ebbf9289..bf95d610c 100644 --- a/string.c +++ b/string.c @@ -4491,9 +4491,10 @@ rb_str_justify(argc, argv, str, jflag) res = rb_str_new5(str, 0, width); if (argc == 2) { StringValue(pad); - if (RSTRING(pad)->len > 0) { - f = RSTRING(pad)->ptr; - flen = RSTRING(pad)->len; + f = RSTRING(pad)->ptr; + flen = RSTRING(pad)->len; + if (flen == 0) { + rb_raise(rb_eArgError, "zero width padding"); } } p = RSTRING(res)->ptr; -- cgit