Hi,

At Tue, 17 May 2005 20:45:31 +0900,
Luc Heinrich wrote in [ruby-talk:142884]:
> Now, if we look at CFRuntime.c and find the strcmp closest to line 720
> we fine this block of code:
> 
> {
>   CFIndex idx, cnt;
>   char **args = *_NSGetArgv();
>   cnt = *_NSGetArgc();
>   for (idx = 1; idx < cnt - 1; idx++) {
>     if (0 == strcmp(args[idx], "-AppleLanguages")) {
>       CFIndex length = strlen(args[idx + 1]);
>       __CFAppleLanguages = malloc(length + 1);
>       memmove(__CFAppleLanguages, args[idx + 1], length + 1);
>       break;
>     }
>   }
> }

Is this function called at each time when .so is loaded, and
the area pointed by _NSGetArgv() shouldn't be changed?

I suspect that system dependent initialization of arguments
should be integrated.


Index: main.c =================================================================== RCS file: /cvs/ruby/src/ruby/main.c,v retrieving revision 1.13 diff -U2 -p -r1.13 main.c --- main.c 23 Jun 2004 12:59:01 -0000 1.13 +++ main.c 17 May 2005 17:36:48 -0000 @@ -13,8 +13,4 @@ #include "ruby.h" -#if defined(__MACOS__) && defined(__MWERKS__) -#include <console.h> -#endif - /* to link startup code with ObjC support */ #if (defined(__APPLE__) || defined(__NeXT__)) && defined(__MACH__) @@ -27,11 +23,5 @@ main(argc, argv, envp) char **argv, **envp; { -#ifdef _WIN32 - NtInitialize(&argc, &argv); -#endif -#if defined(__MACOS__) && defined(__MWERKS__) - argc = ccommand(&argv); -#endif - + ruby_sysinit(&argc, &argv); ruby_init(); ruby_options(argc, argv); Index: ruby.c =================================================================== RCS file: /cvs/ruby/src/ruby/ruby.c,v retrieving revision 1.101 diff -U2 -p -r1.101 ruby.c --- ruby.c 14 May 2005 02:48:07 -0000 1.101 +++ ruby.c 17 May 2005 17:24:44 -0000 @@ -1253,2 +1253,28 @@ ruby_process_options(argc, argv) } } + +#if defined(__MACOS__) && defined(__MWERKS__) +#include <console.h> +#endif + +#if defined(_WIN32) +void +ruby_sysinit(argc, argv) + int *argc; + char ***argv; +{ +#if defined(__APPLE__) && (defined(__MACH__) || defined(__DARWIN__)) && !defined(__MacOS_X__) + if (*argv == *_NSGetArgv()) { + int i, n = *argc, len = 0; + char **v1 = *argv, **v2 = ALLOC_N(char*, n + 1);; + for (i = 0; i < n; ++i) { + *v2[i] = strdup(*v1[i]); + } + v2[i] = 0; + *_NSGetArgv() = v2; + } +#elif defined(__MACOS__) && defined(__MWERKS__) + *argc = ccommand(argv); +#endif +} +#endif Index: ruby.h =================================================================== RCS file: /cvs/ruby/src/ruby/ruby.h,v retrieving revision 1.113 diff -U2 -p -r1.113 ruby.h --- ruby.h 15 May 2005 09:56:49 -0000 1.113 +++ ruby.h 17 May 2005 17:13:11 -0000 @@ -561,4 +561,5 @@ NORETURN(void rb_throw _((const char*,VA VALUE rb_require _((const char*)); +void ruby_sysinit _((int*, char***)); void ruby_init _((void)); void ruby_options _((int, char**)); Index: win32/win32.c =================================================================== RCS file: /cvs/ruby/src/ruby/win32/win32.c,v retrieving revision 1.151 diff -U2 -p -r1.151 win32.c --- win32/win32.c 17 May 2005 02:50:42 -0000 1.151 +++ win32/win32.c 17 May 2005 17:26:00 -0000 @@ -418,5 +518,10 @@ void NtInitialize(int *argc, char ***argv) { + ruby_sysinit(argc, argv); +} +void +ruby_sysinit(int *argc, char ***argv) +{ WORD version; int ret;
-- Nobu Nakada