ruby-changes:17781
From: yugui <ko1@a...>
Date: Mon, 15 Nov 2010 20:43:42 +0900 (JST)
Subject: [ruby-changes:17781] Ruby:r29792 (ruby_1_9_2): merged r29225 but just warning instead of raising an exception. c.f. .
yugui 2010-11-15 20:43:27 +0900 (Mon, 15 Nov 2010) New Revision: 29792 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29792 Log: merged r29225 but just warning instead of raising an exception. c.f. [ruby-core:32250]. -- * hash.c (ruby_setenv): raise if putenv and SetEnvironmentVariable failed, because of the restriction of the size on Windows. based on a patch from Peter Weldon at [ruby-core:32304]. fix: Bug#3812, [ruby-core:32250] Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/hash.c branches/ruby_1_9_2/test/ruby/test_env.rb branches/ruby_1_9_2/version.h Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 29791) +++ ruby_1_9_2/ChangeLog (revision 29792) @@ -1,3 +1,15 @@ +Tue Nov 2 21:33:43 2010 Yuki Sonoda (Yugui) <yugui@y...> + + * hash.c (ruby_setenv): merged r29225 but just warning + instead of raising an exception. c.f. [ruby-core:32250]. + +Sep 11 16:47:41 2010 Nobuyoshi Nakada <nobu@r...> + + * hash.c (ruby_setenv): raise if putenv and SetEnvironmentVariable + failed, because of the restriction of the size on Windows. + based on a patch from Peter Weldon at [ruby-core:32304]. fix: + Bug#3812, [ruby-core:32250] + Sat Sep 11 12:32:05 2010 Nobuyoshi Nakada <nobu@r...> * include/ruby/intern.h (rb_set_kcode, rb_get_kcode): removed Index: ruby_1_9_2/hash.c =================================================================== --- ruby_1_9_2/hash.c (revision 29791) +++ ruby_1_9_2/hash.c (revision 29792) @@ -2135,6 +2135,7 @@ #if defined(_WIN32) int len; char *buf; + int failed = 0; if (strchr(name, '=')) { errno = EINVAL; rb_sys_fail("ruby_setenv"); @@ -2143,19 +2144,22 @@ len = strlen(name) + 1 + strlen(value) + 1; buf = ALLOCA_N(char, len); snprintf(buf, len, "%s=%s", name, value); - putenv(buf); + failed = putenv(buf); /* putenv() doesn't handle empty value */ if (!*value) - SetEnvironmentVariable(name,value); + failed = !SetEnvironmentVariable(name,value); } else { len = strlen(name) + 1 + 1; buf = ALLOCA_N(char, len); snprintf(buf, len, "%s=", name); putenv(buf); - SetEnvironmentVariable(name, 0); + failed = !SetEnvironmentVariable(name, 0); } + if (failed) { + rb_warn("failed to set environment variable. Ruby 1.9.3 will raise SystemCallError in this case."); + } #elif defined(HAVE_SETENV) && defined(HAVE_UNSETENV) #undef setenv #undef unsetenv Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 29791) +++ ruby_1_9_2/version.h (revision 29792) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 36 +#define RUBY_PATCHLEVEL 37 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_2/test/ruby/test_env.rb =================================================================== --- ruby_1_9_2/test/ruby/test_env.rb (revision 29791) +++ ruby_1_9_2/test/ruby/test_env.rb (revision 29792) @@ -374,4 +374,18 @@ ENV.update({"baz"=>"quux","a"=>"b"}) {|k, v1, v2| v1 ? k + "_" + v1 + "_" + v2 : v2 } check(ENV.to_hash.to_a, [%w(foo bar), %w(baz baz_qux_quux), %w(a b)]) end + + def test_huge_value + huge_value = "bar" * 40960 + ENV["foo"] = "bar" + if /mswin|mingw/ =~ RUBY_PLATFORM + warning = verbose_warning { ENV["foo"] = huge_value } + assert_match(/failed to set environment variable/, warning) + assert_match(/Ruby 1\.9\.3/, warning) + assert_equal("bar", ENV["foo"]) + else + assert_nothing_raised { ENV["foo"] = huge_value } + assert_equal(huge_value, ENV["foo"]) + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/