On Tue, 25 Apr 2006, Ryan L. wrote:
[YAML, 42]
hello
Maybe to be safe I should always just add -rubygems (i.e with a dash prefix.)
ruby.c, in proc_options:
731 if (rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) {
732 while (ISSPACE(*s)) s++;
733 if (*s == 'T' || (*s == '-' && *(s+1) == 'T')) {
734 int numlen;
735 int v = 1;
736
737 if (*s != 'T') ++s;
738 if (*++s) {
739 v = scan_oct(s, 2, &numlen);
740 if (numlen == 0) v = 1;
741 }
742 rb_set_safe_level(v);
743 }
in the else block we eat the dash and any space, iff present. then we
look
for the opt char
744 else {
745 while (s && *s) {
746 if (*s == '-') {
747 s++;
748 if (ISSPACE(*s)) {
749 do {s++;} while (ISSPACE(*s));
750 continue;
751 }
752 }
753 if (!*s) break;
754 if (!strchr("IdvwrK", *s))
755 rb_raise(rb_eRuntimeError, "illegal switch
in RUBYOPT: -%c", *s);
now, given RUBYOPT=-rubygems, and *s==r, we call moreswitches
756 s = moreswitches(s);
757 }
758 }
759 }
so in this function
433 static char*
434 moreswitches(s)
435 char *s;
436 {
437 int argc; char *argv[3];
438 char *p = s;
439
440 argc = 2; argv[0] = argv[2] = 0;
441 while (*s && !ISSPACE(*s))
442 s++;
443 argv[1] = ALLOCA_N(char, s-p+2);
444 argv[1][0] = '-';
445 strncpy(argv[1]+1, p, s-p);
446 argv[1][s-p+1] = '\0';
447 proc_options(argc, argv);
448 while (*s && ISSPACE(*s))
449 s++;
450 return s;
451 }
we eat whitespace, setup argv=[0, “-rubygems”, 0] and argc == 2. then
recurse
into proc_options (the first method shown).
so, as far as i can tell (and i’ve had three beers), proc_options finds
the
‘r’, jumps into moreswitches which restores the ‘-’, and the were back
into
proc_options with ‘-rubygems’, which works because of the ‘ubygems’
hack. the
parsing of RUBYOPT looks as if it ignores ‘-’ or lack thereof be design,
but i
certainly can’t be knowing.
good luck!
-a