summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-11 07:48:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-11 07:48:14 +0000
commit2f9adccc9bcbbcb4d8c38074efde9c9741c76211 (patch)
tree7ac04d26e80f0b904b8bf7905d47b8d3a66dbc6f
parentf477963e6e4b942628300ee151f071b11aca64e9 (diff)
* ruby.c (DllMain, ruby_init_loadpath): use DLL instance handle given
to DllMain instead of VirtualQuery so that loadpath becomes relative from the DLL on WinCE too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ruby.c35
2 files changed, 28 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 47c483443e..fe66483173 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-Sun Apr 11 16:37:12 2010 Nobuyoshi Nakada <[email protected]>
+Sun Apr 11 16:48:13 2010 Nobuyoshi Nakada <[email protected]>
+
+ * ruby.c (DllMain, ruby_init_loadpath): use DLL instance handle given
+ to DllMain instead of VirtualQuery so that loadpath becomes relative
+ from the DLL on WinCE too.
* ruby.c (ruby_init_loadpath): do not mangle relative path.
diff --git a/ruby.c b/ruby.c
index b88c0f5955..cd821aa988 100644
--- a/ruby.c
+++ b/ruby.c
@@ -242,6 +242,24 @@ ruby_incpush(path)
#define LOAD_RELATIVE 1
#endif
+#if defined _WIN32 || defined __CYGWIN__
+static HMODULE libruby;
+
+BOOL WINAPI
+DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved)
+{
+ if (reason == DLL_PROCESS_ATTACH)
+ libruby = dll;
+ return TRUE;
+}
+
+HANDLE
+rb_libruby_handle(void)
+{
+ return libruby;
+}
+#endif
+
void
ruby_init_loadpath()
{
@@ -251,27 +269,20 @@ ruby_init_loadpath()
char libpath[FILENAME_MAX+1];
size_t baselen;
char *p;
-#if defined _WIN32 || defined __CYGWIN__
- HMODULE libruby = NULL;
- MEMORY_BASIC_INFORMATION m;
-#ifndef _WIN32_WCE
- memset(&m, 0, sizeof(m));
- if (VirtualQuery(ruby_init_loadpath, &m, sizeof(m)) && m.State == MEM_COMMIT)
- libruby = (HMODULE)m.AllocationBase;
-#endif
+#if defined _WIN32 || defined __CYGWIN__
GetModuleFileName(libruby, libpath, sizeof libpath);
#elif defined(DJGPP)
extern char *__dos_argv0;
- strncpy(libpath, __dos_argv0, FILENAME_MAX);
+ strncpy(libpath, __dos_argve0, sizeof(libpath) - 1);
#elif defined(__human68k__)
extern char **_argv;
- strncpy(libpath, _argv[0], FILENAME_MAX);
+ strncpy(libpath, _argv[0], sizeof(libpath) - 1);
#elif defined(__EMX__)
- _execname(libpath, FILENAME_MAX);
+ _execname(libpath, sizeof(libpath) - 1);
#endif
- libpath[FILENAME_MAX] = '\0';
+ libpath[sizeof(libpath) - 1] = '\0';
#if defined DOSISH
translate_char(libpath, '\\', '/');
#elif defined __CYGWIN__