diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-11-15 11:43:27 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-11-15 11:43:27 +0000 |
commit | b5c27d1cabde475d6fe6306e927707f10442af0e (patch) | |
tree | 2fdf5a0a2a6b2b19cfcedcd6b9f9349bd57ab659 | |
parent | b3c17635c2ad52b7afa76af39868613e2edf47c2 (diff) |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@29792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | hash.c | 10 | ||||
-rw-r--r-- | test/ruby/test_env.rb | 14 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 34 insertions, 4 deletions
@@ -1,3 +1,15 @@ +Tue Nov 2 21:33:43 2010 Yuki Sonoda (Yugui) <yugui@yugui.jp> + + * 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@ruby-lang.org> + + * 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@ruby-lang.org> * include/ruby/intern.h (rb_set_kcode, rb_get_kcode): removed @@ -2135,6 +2135,7 @@ ruby_setenv(const char *name, const char *value) #if defined(_WIN32) int len; char *buf; + int failed = 0; if (strchr(name, '=')) { errno = EINVAL; rb_sys_fail("ruby_setenv"); @@ -2143,18 +2144,21 @@ ruby_setenv(const char *name, const char *value) 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 diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index 785b6bb067..fb7f1cd694 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -374,4 +374,18 @@ class TestEnv < Test::Unit::TestCase 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 @@ -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 |