From: nobu.nokada@... Date: 2005-05-18T10:50:28+09:00 Subject: Re: IRB, Mac OS X, command-line require via "-r" and Bus Errors Hi, At Wed, 18 May 2005 06:40:31 +0900, Jonathan Paisley wrote in [ruby-talk:142962]: > I'm not entirely sure what you mean here. The CFRuntime code removes -AppleLanguages > arguments from the command line, but the code that does it crashes if there are > NULLs present. We see the error if a ruby script calls set_arg0 before this happens. > set_arg0 sets argv[0], and sets argv[1 to argc-1] to NULL. The code "around line 720" you posted doesn't remove -AppleLanguages, but copies it to __CFAppleLanguages. So I guess it might be used later if it was given. > One of my suggestions was: in set_arg0 use empty strings ("") instead > of NULL values in set_arg0. This would prevent the crash. > > An alternative would be just to link ruby with the CoreFoundation framework. That way, > the CFRuntime initialisation code should get executed before ruby initialises, and > the problem goes away. Does the initialization run just once in the whole process? > > What about this? > > > > void > > ruby_sysinit(argc, argv) > > int *argc; > > char ***argv; > > { > > #if defined(__APPLE__) && (defined(__MACH__) || defined(__DARWIN__)) > > int i, n = *argc, len = 0; > > char **v1 = *argv, **v2 = ALLOC_N(char*, n + 1); > > MEMCPY(v2, v1, char*, n); > > v2[n] = 0; > > for (i = 0; i < n; ++i) { > > v1[i] = strdup(v1[i]); > > } > > *argv = v2; > > #elif defined(__MACOS__) && defined(__MWERKS__) > > *argc = ccommand(argv); > > #endif > > } > > The problem with this is that it causes set_arg0 to not have the desired effect. > > set_arg0 is designed to change the process name, as it appears in 'ps' output. > To do this, it's necessary to overwrite the existing argument strings. > Note: what I mean here is overwriting the character data in the existing > strings, and not changing string pointers in the argv array. 'ps' (or in > kernel process info, depending on OS) reads directly from the argument > strings, not going through any pointers in an argv array. > > The upshot is that changing argv for ruby in the proposed ruby_sysinit > means that a later set_arg0 will not change the necessary kernel-known > arguments. No, it duplicates the argument strings and remains them in the original argv (i.e., pointed from *_NSGetArgv()), but let the entire string area to be pointed by newly allocated argv, which is returned to the caller. -- Nobu Nakada