From de3bff164c3b8405f40d2e89cf726f7e865102d1 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 29 Dec 2005 12:05:16 +0000 Subject: * eval.c (rb_mod_define_method): should save safe_level in the proc object. [ruby-dev:28146] * test/drb/drbtest.rb (DRbService::self.ext_service): increase timeout limit. a patch from Kazuhiro NISHIYAMA . [ruby-dev:28132] * eval.c (ev_const_get): fixed a bug in constant reference during instance_eval. [yarv-dev:707] * eval.c (ev_const_defined): ditto. * lib/yaml.rb (YAML::add_domain_type): typo fixed. a patch from Joel VanderWerf . [ruby-talk:165285] [ruby-core:6995] * ext/digest/sha2/sha2.c (ULL): support AIX C. a patch from Kailden . [ruby-core:06984] * ext/syck/rubyext.c (rb_syck_compile): avoid potential memory leak. * ext/syck/rubyext.c (syck_set_ivars): avoid potential memory leak by explicit symbol allocation. * lib/delegate.rb (Delegator::method_missing): should delegate block as well. * lib/cgi.rb (CGI::QueryExtension::MorphingBody): fix criteria to use Tempfile. A fix from Zev Blut . [ruby-core:06076] * string.c: remove global functions work on $_. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 48 +++++++++++ enum.c | 112 ++++++++++++++++++++++-- eval.c | 35 ++++---- ext/digest/sha2/sha2.c | 2 +- ext/syck/rubyext.c | 13 +-- lib/cgi.rb | 71 +++++++++++---- lib/delegate.rb | 171 +++++++++++++++++++------------------ lib/sync.rb | 2 +- lib/thread.rb | 2 +- lib/yaml.rb | 2 +- sample/test.rb | 16 ++-- string.c | 228 ------------------------------------------------- test/drb/drbtest.rb | 2 +- 13 files changed, 338 insertions(+), 366 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc9fc3ce75..e10e8438ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,11 @@ Thu Dec 29 17:02:07 2005 Tanaka Akira * test/ruby/envutil.rb (EnvUtil.rubybin): search "ruby" instead of "miniruby". [ruby-dev:28140] +Thu Dec 29 14:35:10 2005 Yukihiro Matsumoto + + * eval.c (rb_mod_define_method): should save safe_level in the + proc object. [ruby-dev:28146] + Thu Dec 29 11:22:34 2005 Hirokazu Yamamoto * lib/generator.rb: reimplemented Generator class with Thread instead of @@ -23,6 +28,12 @@ Tue Dec 27 23:59:53 2005 Nobuyoshi Nakada * lib/optparse.rb (CompletingHash#match): fix for 1.9. +Tue Dec 27 16:59:52 2005 Yukihiro Matsumoto + + * test/drb/drbtest.rb (DRbService::self.ext_service): increase + timeout limit. a patch from Kazuhiro NISHIYAMA + . [ruby-dev:28132] + Tue Dec 27 14:17:55 2005 Tanaka Akira * configure.in: define IA64 for portability. (HP aC++/ANSI C doesn't @@ -74,6 +85,22 @@ Tue Dec 27 08:22:15 2005 GOTOU Yuuzou * ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLSocket#post_connection_chech): treat wildcard character in commonName. [ruby-dev:28121] +Mon Dec 26 08:50:36 2005 Yukihiro Matsumoto + + * eval.c (ev_const_get): fixed a bug in constant reference during + instance_eval. [yarv-dev:707] + + * eval.c (ev_const_defined): ditto. + + * lib/yaml.rb (YAML::add_domain_type): typo fixed. a patch from + Joel VanderWerf . + [ruby-talk:165285] [ruby-core:6995] + +Fri Dec 23 10:30:23 2005 Yukihiro Matsumoto + + * ext/digest/sha2/sha2.c (ULL): support AIX C. a patch from + Kailden . [ruby-core:06984] + Wed Dec 21 16:47:35 2005 Hirokazu Yamamoto * file.c (w32_io_info): should return handle because FileIndex is @@ -179,6 +206,14 @@ Sat Dec 17 21:50:41 2005 Hirokazu Yamamoto * ext/syck/rubyext.c (syck_mark_parser): should mark anchor nodes because they hold ruby objects. (ie: rb_syck_bad_anchor_handler) +Sat Dec 17 11:00:17 2005 Yukihiro Matsumoto + + * ext/syck/rubyext.c (rb_syck_compile): avoid potential memory + leak. + + * ext/syck/rubyext.c (syck_set_ivars): avoid potential memory + leak by explicit symbol allocation. + Sat Dec 17 03:57:01 2005 Tanaka Akira * bignum.c (rb_big_rshift): fix a GC problem on @@ -206,6 +241,19 @@ Fri Dec 16 11:44:43 2005 Hirokazu Yamamoto ... these fixes won't fix [ruby-dev:27839]. more work is needed. +Fri Dec 16 04:38:55 2005 Yukihiro Matsumoto + + * lib/delegate.rb (Delegator::method_missing): should delegate + block as well. + +Thu Dec 15 19:57:12 2005 Yukihiro Matsumoto + + * lib/cgi.rb (CGI::QueryExtension::MorphingBody): fix criteria to + use Tempfile. A fix from Zev Blut . + [ruby-core:06076] + + * string.c: remove global functions work on $_. + Thu Dec 15 12:35:14 2005 Yukihiro Matsumoto * lib/tmpdir.rb: merged RDoc patch from Eric Hodel all? will return true only if none of the * collection members are false or nil.) * - * %w{ ant bear cat}.all? {|word| word.length >= 3} #=> true - * %w{ ant bear cat}.all? {|word| word.length >= 4} #=> false - * [ nil, true, 99 ].all? #=> false + * %w{ant bear cat}.all? {|word| word.length >= 3} #=> true + * %w{ant bear cat}.all? {|word| word.length >= 4} #=> false + * [ nil, true, 99 ].all? #=> false * */ @@ -617,9 +617,9 @@ any_i(VALUE i, VALUE *memo) * of the collection members is not false or * nil. * - * %w{ ant bear cat}.any? {|word| word.length >= 3} #=> true - * %w{ ant bear cat}.any? {|word| word.length >= 4} #=> true - * [ nil, true, 99 ].any? #=> true + * %w{ant bear cat}.any? {|word| word.length >= 3} #=> true + * %w{ant bear cat}.any? {|word| word.length >= 4} #=> true + * [ nil, true, 99 ].any? #=> true * */ @@ -632,6 +632,104 @@ enum_any(VALUE obj) return result; } +static VALUE +one_iter_i(VALUE i, VALUE *memo) +{ + if (RTEST(rb_yield(i))) { + if (*memo == Qundef) { + *memo = Qtrue; + } + else if (*memo == Qtrue) { + *memo = Qfalse; + } + } + return Qnil; +} + +static VALUE +one_i(VALUE i, VALUE *memo) +{ + if (RTEST(i)) { + if (*memo == Qundef) { + *memo = Qtrue; + } + else if (*memo == Qtrue) { + *memo = Qfalse; + } + } + return Qnil; +} + +/* + * call-seq: + * enum.one? [{|obj| block }] => true or false + * + * Passes each element of the collection to the given block. The method + * returns true if the block returns true + * exactly once. If the block is not given, one? will return + * true only if exactly one of the collection members are + * true. + * + * %w{ant bear cat}.one? {|word| word.length == 4} #=> true + * %w{ant bear cat}.one? {|word| word.length >= 4} #=> false + * [ nil, true, 99 ].one? #=> true + * + */ + +static VALUE +enum_one(VALUE obj) +{ + VALUE result = Qundef; + + rb_iterate(rb_each, obj, rb_block_given_p() ? one_iter_i : one_i, (VALUE)&result); + if (result == Qundef) return Qfalse; + return result; +} + +static VALUE +none_iter_i(VALUE i, VALUE *memo) +{ + if (RTEST(rb_yield(i))) { + *memo = Qfalse; + rb_iter_break(); + } + return Qnil; +} + +static VALUE +none_i(VALUE i, VALUE *memo) +{ + if (RTEST(i)) { + *memo = Qfalse; + rb_iter_break(); + } + return Qnil; +} + +/* + * call-seq: + * enum.none? [{|obj| block }] => true or false + * + * Passes each element of the collection to the given block. The method + * returns true if the block never returns true + * for all elements. If the block is not given, one? will return + * true only if any of the collection members is true. + * + * %w{ant bear cat}.one? {|word| word.length == 4} #=> true + * %w{ant bear cat}.one? {|word| word.length >= 4} #=> false + * [ nil, true, 99 ].one? #=> true + * + */ + +static VALUE +enum_none(VALUE obj) +{ + VALUE result = Qtrue; + + rb_iterate(rb_each, obj, rb_block_given_p() ? none_iter_i : none_i, (VALUE)&result); + return result; +} + static VALUE min_i(VALUE i, VALUE *memo) { @@ -998,6 +1096,8 @@ Init_Enumerable(void) rb_define_method(rb_mEnumerable,"partition", enum_partition, 0); rb_define_method(rb_mEnumerable,"all?", enum_all, 0); rb_define_method(rb_mEnumerable,"any?", enum_any, 0); + rb_define_method(rb_mEnumerable,"one?", enum_one, 0); + rb_define_method(rb_mEnumerable,"none?", enum_none, 0); rb_define_method(rb_mEnumerable,"min", enum_min, 0); rb_define_method(rb_mEnumerable,"max", enum_max, 0); rb_define_method(rb_mEnumerable,"min_by", enum_min_by, 0); diff --git a/eval.c b/eval.c index ce3ace616c..21842c91b0 100644 --- a/eval.c +++ b/eval.c @@ -373,7 +373,6 @@ static ID init, eqq, each, aref, aset, match, missing; static ID added, singleton_added; static ID __id__, __send__, respond_to; -#define NOEX_TAINTED 8 #define NOEX_SAFE(n) ((n) >> 4) #define NOEX_WITH(n, v) ((n) | (v) << 4) #define NOEX_WITH_SAFE(n) NOEX_WITH(n, ruby_safe_level) @@ -1766,12 +1765,13 @@ ev_const_defined(NODE *cref, ID id, VALUE self) while (cbase && cbase->nd_next) { struct RClass *klass = RCLASS(cbase->nd_clss); - if (NIL_P(klass)) return rb_const_defined(CLASS_OF(self), id); - if (klass->iv_tbl && st_lookup(klass->iv_tbl, id, &result)) { - if (result == Qundef && NIL_P(rb_autoload_p((VALUE)klass, id))) { - return Qfalse; + if (!NIL_P(klass)) { + if (klass->iv_tbl && st_lookup(klass->iv_tbl, id, &result)) { + if (result == Qundef && NIL_P(rb_autoload_p((VALUE)klass, id))) { + return Qfalse; + } + return Qtrue; } - return Qtrue; } cbase = cbase->nd_next; } @@ -1787,13 +1787,15 @@ ev_const_get(NODE *cref, ID id, VALUE self) while (cbase && cbase->nd_next) { VALUE klass = cbase->nd_clss; - if (NIL_P(klass)) return rb_const_get(CLASS_OF(self), id); - while (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, &result)) { - if (result == Qundef) { - if (!RTEST(rb_autoload_load(klass, id))) break; - continue; + if (!NIL_P(klass)) { + while (RCLASS(klass)->iv_tbl && + st_lookup(RCLASS(klass)->iv_tbl, id, &result)) { + if (result == Qundef) { + if (!RTEST(rb_autoload_load(klass, id))) break; + continue; + } + return result; } - return result; } cbase = cbase->nd_next; } @@ -8038,11 +8040,11 @@ bind_eval(int argc, VALUE *argv, VALUE bind) #define PROC_TSHIFT (FL_USHIFT+1) #define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3) #define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT) -#define PROC_NOSAFE FL_USER4 +#define PROC_SAFE_SAVED FL_USER4 #define SAFE_LEVEL_MAX PROC_TMASK -#define proc_safe_level_p(data) (!(RBASIC(data)->flags & PROC_NOSAFE)) +#define proc_safe_level_p(data) (RBASIC(data)->flags & PROC_SAFE_SAVED) static void proc_save_safe_level(VALUE data) @@ -8050,6 +8052,7 @@ proc_save_safe_level(VALUE data) int safe = ruby_safe_level; if (safe > PROC_TMAX) safe = PROC_TMAX; FL_SET(data, (safe << PROC_TSHIFT) & PROC_TMASK); + FL_SET(data, PROC_SAFE_SAVED); } static int @@ -8887,7 +8890,7 @@ rb_method_call(int argc, VALUE *argv, VALUE method) rb_raise(rb_eTypeError, "can't call unbound method; bind first"); } if (OBJ_TAINTED(method)) { - safe = NOEX_WITH(data->safe_level, 4)|NOEX_TAINTED; + safe = NOEX_WITH(data->safe_level, 4); } else { safe = data->safe_level; @@ -9328,7 +9331,7 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod) struct BLOCK *block; body = proc_clone(body); - RBASIC(body)->flags |= PROC_NOSAFE; + proc_save_safe_level(body); Data_Get_Struct(body, struct BLOCK, block); block->frame.callee = id; block->frame.this_func = id; diff --git a/ext/digest/sha2/sha2.c b/ext/digest/sha2/sha2.c index 24a57ded0d..41ed2df106 100644 --- a/ext/digest/sha2/sha2.c +++ b/ext/digest/sha2/sha2.c @@ -67,7 +67,7 @@ typedef uint8_t sha2_byte; /* Exactly 1 byte */ typedef uint32_t sha2_word32; /* Exactly 4 bytes */ typedef uint64_t sha2_word64; /* Exactly 8 bytes */ -#if defined(__GNUC__) || defined(_HPUX_SOURCE) +#if defined(__GNUC__) || defined(_HPUX_SOURCE) || defined(__IBMC__) #define ULL(number) number##ULL #else #define ULL(number) (uint64_t)(number) diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c index 272cfd2571..f75e3ca561 100644 --- a/ext/syck/rubyext.c +++ b/ext/syck/rubyext.c @@ -115,14 +115,15 @@ rb_syck_compile(self, port) oid = syck_parse( parser ); syck_lookup_sym( parser, oid, (char **)&sav ); - ret = S_ALLOC_N( char, strlen( sav->buffer ) + 3 ); + bc = rb_str_new(0, strlen( sav->buffer ) + 3); + ret = RSTRING(bc)->ptr; ret[0] = '\0'; strcat( ret, "D\n" ); strcat( ret, sav->buffer ); syck_free_parser( parser ); - bc = rb_str_new2( ret ); S_FREE( ret ); + rb_str_resize( bc, strlen(ret) ); if ( taint ) OBJ_TAINT( bc ); return bc; } @@ -1042,13 +1043,13 @@ syck_set_ivars( vars, obj ) { VALUE ivname = rb_ary_entry( vars, 0 ); char *ivn; + ID ivns; StringValue( ivname ); ivn = S_ALLOC_N( char, RSTRING(ivname)->len + 2 ); - ivn[0] = '@'; - ivn[1] = '\0'; - strncat( ivn, RSTRING(ivname)->ptr, RSTRING(ivname)->len ); - rb_iv_set( obj, ivn, rb_ary_entry( vars, 1 ) ); + snprintf(ivn, RSTRING(ivname)->len + 1, "@%s", RSTRING(ivname)->ptr); + ivns = rb_intern(ivn); S_FREE( ivn ); + rb_ivar_set( obj, ivns, rb_ary_entry( vars, 1 ) ); return Qnil; } diff --git a/lib/cgi.rb b/lib/cgi.rb index 43122212d5..c1627cb521 100644 --- a/lib/cgi.rb +++ b/lib/cgi.rb @@ -993,22 +993,9 @@ class CGI loop do head = nil - if 10240 < content_length - require "tempfile" - body = Tempfile.new("CGI") - else - begin - require "stringio" - body = StringIO.new - rescue LoadError - require "tempfile" - body = Tempfile.new("CGI") - end - end - body.binmode if defined? body.binmode + body = MorphingBody.new until head and /#{boundary}(?:#{EOL}|--)/n.match(buf) - if (not head) and /#{EOL}#{EOL}/n.match(buf) buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do head = $1.dup @@ -1042,6 +1029,7 @@ class CGI "" end + p body body.rewind /Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head) @@ -1062,7 +1050,7 @@ class CGI end /Content-Disposition:.* name="?([^\";]*)"?/ni.match(head) - name = $1.dup + name = ($1 || "").dup if params.has_key?(name) params[name].push(body) @@ -1102,6 +1090,59 @@ class CGI end private :read_from_cmdline + # A wrapper class to use a StringIO object as the body and switch + # to a TempFile when the passed threshold is passed. + class MorphingBody + begin + require "stringio" + @@small_buffer = lambda{StringIO.new} + rescue LoadError + require "tempfile" + @@small_buffer = lambda{ + n = Tempfile.new("CGI") + n.binmode + n + } + end + + def initialize(morph_threshold = 10240) + @threshold = morph_threshold + @body = @@small_buffer.call + @cur_size = 0 + @morph_check = true + end + + def print(data) + if @morph_check && (@cur_size + data.size > @threshold) + convert_body + end + @body.print data + end + def rewind + @body.rewind + end + def path + @body.path + end + + # returns the true body object. + def extract + @body + end + + private + def convert_body + new_body = TempFile.new("CGI") + new_body.binmode if defined? @body.binmode + new_body.binmode if defined? new_body.binmode + + @body.rewind + new_body.print @body.read + @body = new_body + @morph_check = false + end + end + # Initialize the data from the query. # # Handles multipart forms (in particular, forms that involve file uploads). diff --git a/lib/delegate.rb b/lib/delegate.rb index b54b57d7b7..3be335580b 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -121,61 +121,93 @@ class Delegator undef_method m end - # - # Pass in the _obj_ to delegate method calls to. All methods supported by - # _obj_ will be delegated to. - # - def initialize(obj) - __setobj__(obj) - end + module MethodDelegation + # + # Pass in the _obj_ to delegate method calls to. All methods supported by + # _obj_ will be delegated to. + # + def initialize(obj) + __setobj__(obj) + end - # Handles the magic of delegation through \_\_getobj\_\_. - def method_missing(m, *args) - begin - target = self.__getobj__ - unless target.respond_to?(m) - super(m, *args) + # Handles the magic of delegation through \_\_getobj\_\_. + def method_missing(m, *args, &block) + begin + target = self.__getobj__ + unless target.respond_to?(m) + super(m, *args, &block) + else + target.__send__(m, *args, &block) + end + rescue Exception + $@.delete_if{|s| /^#{__FILE__}:\d+:in `method_missing'$/ =~ s} #` + ::Kernel::raise end - target.__send__(m, *args) - rescue Exception - $@.delete_if{|s| /^#{__FILE__}:\d+:in `method_missing'$/ =~ s} #` - ::Kernel::raise end - end - # - # Checks for a method provided by this the delegate object by fowarding the - # call through \_\_getobj\_\_. - # - def respond_to?(m) - return true if super - return self.__getobj__.respond_to?(m) - end + # + # Checks for a method provided by this the delegate object by fowarding the + # call through \_\_getobj\_\_. + # + def respond_to?(m) + return true if super + return self.__getobj__.respond_to?(m) + end - # - # This method must be overridden by subclasses and should return the object - # method calls are being delegated to. - # - def __getobj__ - raise NotImplementedError, "need to define `__getobj__'" - end + # + # Returns true if two objects are considered same. + # + def ==(obj) + return true if obj.equal?(self) + self.__getobj__ == obj + end - # - # This method must be overridden by subclasses and change the object delegate - # to _obj_. - # - def __setobj__(obj) - raise NotImplementedError, "need to define `__setobj__'" - end + # + # Returns true only if two objects are identical. + # + def equal?(obj) + self.object_id == obj.object_id + end - # Serialization support for the object returned by \_\_getobj\_\_. - def marshal_dump - __getobj__ - end - # Reinitializes delegation from a serialized object. - def marshal_load(obj) - __setobj__(obj) + # + # This method must be overridden by subclasses and should return the object + # method calls are being delegated to. + # + def __getobj__ + raise NotImplementedError, "need to define `__getobj__'" + end + + # + # This method must be overridden by subclasses and change the object delegate + # to _obj_. + # + def __setobj__(obj) + raise NotImplementedError, "need to define `__setobj__'" + end + + # Serialization support for the object returned by \_\_getobj\_\_. + def marshal_dump + __getobj__ + end + # Reinitializes delegation from a serialized object. + def marshal_load(obj) + __setobj__(obj) + end + + # Clone support for the object returned by \_\_getobj\_\_. + def clone + new = super + new.__setobj__(__getobj__.clone) + new + end + # Duplication support for the object returned by \_\_getobj\_\_. + def dup + new = super + new.__setobj__(__getobj__.dup) + new + end end + include MethodDelegation end # @@ -208,19 +240,6 @@ class SimpleDelegator true + p foo2.iter{[55,true]} # => true foo2.error # raise error! end diff --git a/lib/sync.rb b/lib/sync.rb index 79522ed885..566cfbfb2d 100644 --- a/lib/sync.rb +++ b/lib/sync.rb @@ -40,7 +40,7 @@ # unless defined? Thread - fail "Thread not available for this ruby interpreter" + raise "Thread not available for this ruby interpreter" end module Sync_m diff --git a/lib/thread.rb b/lib/thread.rb index 42611b7fce..5d4fedc73c 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -9,7 +9,7 @@ # unless defined? Thread - fail "Thread not available for this ruby interpreter" + raise "Thread not available for this ruby interpreter" end unless defined? ThreadError diff --git a/lib/yaml.rb b/lib/yaml.rb index 3130ad115d..fe8335c8f0 100644 --- a/lib/yaml.rb +++ b/lib/yaml.rb @@ -310,7 +310,7 @@ module YAML # # Add a transfer method for a builtin type # - def YAML.add_ruby_type( type, &transfer_proc ) + def YAML.add_ruby_type( type_tag, &transfer_proc ) resolver.add_type( "tag:ruby.yaml.org,2002:#{ type_tag }", transfer_proc ) end diff --git a/sample/test.rb b/sample/test.rb index d2d7a15b59..8003e8743f 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -520,15 +520,15 @@ tmp.close # test redo $bad = false tmp = open("while_tmp", "r") -while tmp.gets() - line = $_ - gsub(/vt100/, 'VT100') - if $_ != line - $_.gsub!('VT100', 'Vt100') +while line = tmp.gets() + lastline = line + line = line.gsub(/vt100/, 'VT100') + if lastline != line + line.gsub!('VT100', 'Vt100') redo end - $bad = 1 if /vt100/ =~ $_ - $bad = 1 if /VT100/ =~ $_ + $bad = 1 if /vt100/ =~ line + $bad = 1 if /VT100/ =~ line end test_ok(tmp.eof? && !$bad) tmp.close @@ -1837,7 +1837,7 @@ for i in 1..5 end tmp.close -`./miniruby -i.bak -pe 'sub(/^[0-9]+$/){$&.to_i * 5}' script_tmp` +`./miniruby -i.bak -pe '$_.sub!(/^[0-9]+$/){$&.to_i * 5}' script_tmp` done = true tmp = open("script_tmp", "r") while tmp.gets diff --git a/string.c b/string.c index 61baa930cf..f303dc58b0 100644 --- a/string.c +++ b/string.c @@ -2168,84 +2168,6 @@ uscore_get(void) return line; } -/* - * call-seq: - * sub!(pattern, replacement) => $_ or nil - * sub!(pattern) {|...| block } => $_ or nil - * - * Equivalent to $_.sub!(args). - */ - -static VALUE -rb_f_sub_bang(int argc, VALUE *argv) -{ - return rb_str_sub_bang(argc, argv, uscore_get()); -} - -/* - * call-seq: - * sub(pattern, replacement) => $_ - * sub(pattern) { block } => $_ - * - * Equivalent to $_.sub(args), except that - * $_ will be updated if substitution occurs. - */ - -static VALUE -rb_f_sub(int argc, VALUE *argv) -{ - VALUE str = rb_str_dup(uscore_get()); - - if (NIL_P(rb_str_sub_bang(argc, argv, str))) - return str; - rb_lastline_set(str); - return str; -} - -/* - * call-seq: - * gsub!(pattern, replacement) => string or nil - * gsub!(pattern) {|...| block } => string or nil - * - * Equivalent to Kernel::gsub, except nil is - * returned if $_ is not modified. - * - * $_ = "quick brown fox" - * gsub! /cat/, '*' #=> nil - * $_ #=> "quick brown fox" - */ - -static VALUE -rb_f_gsub_bang(int argc, VALUE *argv) -{ - return rb_str_gsub_bang(argc, argv, uscore_get()); -} - -/* - * call-seq: - * gsub(pattern, replacement) => string - * gsub(pattern) {|...| block } => string - * - * Equivalent to $_.gsub..., except that $_ - * receives the modified result. - * - * $_ = "quick brown fox" - * gsub /[aeiou]/, '*' #=> "q**ck br*wn f*x" - * $_ #=> "q**ck br*wn f*x" - */ - -static VALUE -rb_f_gsub(int argc, VALUE *argv) -{ - VALUE str = rb_str_dup(uscore_get()); - - if (NIL_P(rb_str_gsub_bang(argc, argv, str))) - return str; - rb_lastline_set(str); - return str; -} - - /* * call-seq: * str.reverse! => str @@ -3437,20 +3359,6 @@ rb_str_split(VALUE str, const char *sep0) return rb_str_split_m(1, &sep, str); } -/* - * call-seq: - * split([pattern [, limit]]) => array - * - * Equivalent to $_.split(pattern, limit). - * See String#split. - */ - -static VALUE -rb_f_split(int argc, VALUE *argv) -{ - return rb_str_split_m(argc, argv, uscore_get()); -} - /* * call-seq: * str.each(separator=$/) {|substr| block } => str @@ -3620,61 +3528,6 @@ rb_str_chop(VALUE str) } -/* - * call-seq: - * chop! => $_ or nil - * - * Equivalent to $_.chop!. - * - * a = "now\r\n" - * $_ = a - * chop! #=> "now" - * chop! #=> "no" - * chop! #=> "n" - * chop! #=> "" - * chop! #=> nil - * $_ #=> "" - * a #=> "" - */ - -static VALUE -rb_f_chop_bang(VALUE str) -{ - return rb_str_chop_bang(uscore_get()); -} - -/* - * call-seq: - * chop => string - * - * Equivalent to ($_.dup).chop!, except nil - * is never returned. See String#chop!. - * - * a = "now\r\n" - * $_ = a - * chop #=> "now" - * $_ #=> "now" - * chop #=> "no" - * chop #=> "n" - * chop #=> "" - * chop #=> "" - * a #=> "now\r\n" - */ - -static VALUE -rb_f_chop(void) -{ - VALUE str = uscore_get(); - - if (RSTRING(str)->len > 0) { - str = rb_str_dup(str); - rb_str_chop_bang(str); - rb_lastline_set(str); - } - return str; -} - - /* * call-seq: * str.chomp!(separator=$/) => str or nil @@ -3780,57 +3633,6 @@ rb_str_chomp(int argc, VALUE *argv, VALUE str) return str; } -/* - * call-seq: - * chomp! => $_ or nil - * chomp!(string) => $_ or nil - * - * Equivalent to $_.chomp!(string). See - * String#chomp! - * - * $_ = "now\n" - * chomp! #=> "now" - * $_ #=> "now" - * chomp! "x" #=> nil - * $_ #=> "now" - */ - -static VALUE -rb_f_chomp_bang(int argc, VALUE *argv) -{ - return rb_str_chomp_bang(argc, argv, uscore_get()); -} - -/* - * call-seq: - * chomp => $_ - * chomp(string) => $_ - * - * Equivalent to $_ = $_.chomp(string). See - * String#chomp. - * - * $_ = "now\n" - * chomp #=> "now" - * $_ #=> "now" - * chomp "ow" #=> "n" - * $_ #=> "n" - * chomp "xxx" #=> "n" - * $_ #=> "n" - */ - -static VALUE -rb_f_chomp(int argc, VALUE *argv) -{ - VALUE str = uscore_get(); - VALUE dup = rb_str_dup(str); - - if (NIL_P(rb_str_chomp_bang(argc, argv, dup))) - return str; - rb_lastline_set(dup); - return dup; -} - - /* * call-seq: * str.lstrip! => self or nil @@ -4075,21 +3877,6 @@ rb_str_scan(VALUE str, VALUE pat) return str; } -/* - * call-seq: - * scan(pattern) => array - * scan(pattern) {|///| block } => $_ - * - * Equivalent to calling $_.scan. See - * String#scan. - */ - -static VALUE -rb_f_scan(VALUE self, VALUE pat) -{ - return rb_str_scan(uscore_get(), pat); -} - /* * call-seq: @@ -4510,21 +4297,6 @@ Init_String(void) rb_define_method(rb_cString, "sum", rb_str_sum, -1); - rb_define_global_function("sub", rb_f_sub, -1); - rb_define_global_function("gsub", rb_f_gsub, -1); - - rb_define_global_function("sub!", rb_f_sub_bang, -1); - rb_define_global_function("gsub!", rb_f_gsub_bang, -1); - - rb_define_global_function("chop", rb_f_chop, 0); - rb_define_global_function("chop!", rb_f_chop_bang, 0); - - rb_define_global_function("chomp", rb_f_chomp, -1); - rb_define_global_function("chomp!", rb_f_chomp_bang, -1); - - rb_define_global_function("split", rb_f_split, -1); - rb_define_global_function("scan", rb_f_scan, 1); - rb_define_method(rb_cString, "slice", rb_str_aref_m, -1); rb_define_method(rb_cString, "slice!", rb_str_slice_bang, -1); diff --git a/test/drb/drbtest.rb b/test/drb/drbtest.rb index 410a33c7e1..30aafb5788 100644 --- a/test/drb/drbtest.rb +++ b/test/drb/drbtest.rb @@ -31,7 +31,7 @@ class DRbService @server || @@server end def self.ext_service(name) - timeout(10, RuntimeError) do + timeout(100, RuntimeError) do manager.service(name) end end -- cgit v1.2.3