summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-31 07:58:34 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-31 07:58:34 +0000
commit2982c5289210c02120172bf631270858681d031d (patch)
treebb4fe162eff05dd51a36fe7ca8ccd13d7a35e981
parented2c204a2f60cae73de2071b5648b60d83efb353 (diff)
* win32/win32.c (exit_handler): new function; release winsock and
environment work area. * win32/win32.c (NTInitialize): setup exit_handler. * win32/win32.c (StartSockets): use exit_handler. exit handler. * win32/win32.c (rb_w32_getenv): use GetEnvironmentStrings() instead of GetEnvironmentVariable(), because the latter cannot distinguish wheather a null environment variable exists or not. fixed: [ruby-talk:205123] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog15
-rw-r--r--win32/win32.c49
2 files changed, 45 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 779665edeb..df43aef4ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Mon Jul 31 16:51:40 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/win32.c (exit_handler): new function; release winsock and
+ environment work area.
+
+ * win32/win32.c (NTInitialize): setup exit_handler.
+
+ * win32/win32.c (StartSockets): use exit_handler.
+ exit handler.
+
+ * win32/win32.c (rb_w32_getenv): use GetEnvironmentStrings() instead
+ of GetEnvironmentVariable(), because the latter cannot distinguish
+ wheather a null environment variable exists or not.
+ fixed: [ruby-talk:205123]
+
Mon Jul 31 16:15:13 2006 Tanaka Akira <akr@fsij.org>
* test/ruby/test_process.rb (TestProcess#test_rlimit_nofile):
diff --git a/win32/win32.c b/win32/win32.c
index 01378ffe2a..348b8bb06e 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -423,6 +423,21 @@ static void invalid_parameter(const wchar_t *expr, const wchar_t *func, const wc
}
#endif
+static BOOL fWinsock;
+static char *envarea;
+static void
+exit_handler(void)
+{
+ if (fWinsock) {
+ WSACleanup();
+ fWinsock = FALSE;
+ }
+ if (envarea) {
+ FreeEnvironmentStrings(envarea);
+ envarea = NULL;
+ }
+}
+
//
// Initialization stuff
//
@@ -452,6 +467,8 @@ NtInitialize(int *argc, char ***argv)
init_stdhandle();
+ atexit(exit_handler);
+
// Initialize Winsock
StartSockets();
@@ -2207,7 +2224,7 @@ StartSockets(void)
if (LOBYTE(retdata.wVersion) != 2)
rb_fatal("could not find version 2 of winsock dll\n");
- atexit((void (*)(void)) WSACleanup);
+ fWinsock = TRUE;
main_thread.handle = GetCurrentThreadHandle();
main_thread.id = GetCurrentThreadId();
@@ -3116,28 +3133,22 @@ wait(int *status)
char *
rb_w32_getenv(const char *name)
{
- static char *curitem = NULL;
- static DWORD curlen = 0;
- DWORD needlen;
+ int len = strlen(name);
+ char *env;
- if (curitem == NULL || curlen == 0) {
- curlen = 512;
- curitem = ALLOC_N(char, curlen);
- }
-
- needlen = GetEnvironmentVariable(name, curitem, curlen);
- if (needlen != 0) {
- while (needlen > curlen) {
- REALLOC_N(curitem, char, needlen);
- curlen = needlen;
- needlen = GetEnvironmentVariable(name, curitem, curlen);
- }
- }
- else {
+ if (envarea)
+ FreeEnvironmentStrings(envarea);
+ envarea = GetEnvironmentStrings();
+ if (!envarea) {
+ map_errno(GetLastError());
return NULL;
}
- return curitem;
+ for (env = envarea; *env; env += strlen(env) + 1)
+ if (strncasecmp(env, name, len) == 0 && *(env + len) == '=')
+ return env + len + 1;
+
+ return NULL;
}
int