summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--hash.c10
-rw-r--r--test/ruby/test_env.rb14
-rw-r--r--version.h2
4 files changed, 34 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index e22a1137df..b1604a11ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/hash.c b/hash.c
index 84d9eb3aec..7774aacc53 100644
--- a/hash.c
+++ b/hash.c
@@ -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
diff --git a/version.h b/version.h
index 655c323f29..7574c1251c 100644
--- a/version.h
+++ b/version.h
@@ -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