Platform-independent per-process initialization

e$B$J$+$@$G$9!#e(B

e$B8=:_e(Bmain.ce$B$G%W%i%C%H%U%)!<%`$4$H$K9T$C$F$$$k=i4|2=$r!"%W%m%;%9C1e(B
e$B0L$N=i4|2=$H$7$FJ,N%$7$?$$$H;W$C$F$$$^$9!#e(BMetrowerkse$BMQ$NItJ,$,$9$Ce(B
e$B$-$j$7$^$;$s$,!"$3$l$O5le(BMacintoshe$B@lMQ$J$N$G$3$N:]:o$C$F$7$^$C$?e(B
e$B$[$&$,$$$$$+$b!#e(B

  • main.c (main): use platform-independent per-process initialization.

  • ruby.c (ruby_sysinit): new function for per-process initialization.

  • include/ruby/ruby.h (RUBY_GLOBAL_SETUP): toplevel setup declaration.

  • include/ruby/win32.h, win32/mkexports.rb: alias NtInitialize
    ruby_sysinit.

  • win32/win32.c (rb_w32_sysinit): renamed from NtInitialize.

Index: main.c

— main.c (revision 13560)
+++ main.c (working copy)
@@ -14,16 +14,5 @@
#include “ruby/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)
-static voidplatform independent
-objcdummyfunction(void)
-{

  • objc_msgSend();
    -}
    -#endif
    +RUBY_GLOBAL_SETUP

int
@@ -34,11 +23,6 @@ main(int argc, char **argv, char **envp)
ruby_set_debug_option(getenv(“RUBY_DEBUG”));
#endif
-#ifdef _WIN32

  • NtInitialize(&argc, &argv);
    -#endif
    -#if defined(MACOS) && defined(MWERKS)
  • argc = ccommand(&argv);
    -#endif
  • ruby_sysinit(&argc, &argv);
    {
    RUBY_INIT_STACK;
    Index: ruby.c
    ===================================================================
    — ruby.c (revision 13560)
    +++ ruby.c (working copy)
    @@ -48,4 +48,8 @@
    #endif

+#if defined(MACOS) && defined(MWERKS)
+#include <console.h>
+#endif
+
#include “ruby/util.h”

@@ -1308,6 +1312,10 @@ ruby_process_options(int argc, char **ar
NODE *tree;

  • origarg.argc = argc;
  • origarg.argv = argv;
    +#if defined(MACOS) && defined(MWERKS)
  • if (origarg.argv == 0) {

  • origarg.argc = argc;

  • origarg.argv = argv;

  • }
    +#endif

    MEMZERO(&opt, opt, 1);
    @@ -1317,7 +1325,4 @@ ruby_process_options(int argc, char **ar
    dln_argv0 = argv[0];
    #endif
    -#if !defined(PSTAT_SETCMD) && !defined(HAVE_SETPROCTITLE)

  • origarg.len = get_arglen(origarg.argc, origarg.argv);
    -#endif
    tree = process_options(argc, argv, &opt);

@@ -1328,2 +1333,35 @@ ruby_process_options(int argc, char **ar
return tree;
}
+
+void
+ruby_sysinit(int *argc, char ***argv)
+{
+#if defined(APPLE) && (defined(MACH) || defined(DARWIN))

  • int i, n = *argc, len = 0;
  • char **v1 = *argv, **v2, *p;
  • for (i = 0; i < n; ++i) {
  • len += strlen(v1[i]) + 1;
  • }
  • v2 = malloc((n + 1)* sizeof(char*) + len);
  • p = (char *)&v2[n + 1];
  • for (i = 0; i < n; ++i) {
  • int l = strlen(v1[i]);
  • memcpy(p, v1[i], l + 1);
  • v2[i] = p;
  • p += l + 1;
  • }
  • v2[n] = 0;
  • *argv = v2;
    +#elif defined(MACOS) && defined(MWERKS)
  • *argc = ccommand(argv);
    +#elif defined(_WIN32)
  • void rb_w32_sysinit(int *argc, char ***argv);
  • rb_w32_sysinit(argc, argv);
    +#endif
  • origarg.argc = *argc;
  • origarg.argv = *argv;
    +#if !defined(PSTAT_SETCMD) && !defined(HAVE_SETPROCTITLE)
  • origarg.len = get_arglen(origarg.argc, origarg.argv);
    +#endif
    +}
    Index: include/ruby/ruby.h
    ===================================================================
    — include/ruby/ruby.h (revision 13560)
    +++ include/ruby/ruby.h (working copy)
    @@ -959,4 +959,13 @@ static char *dln_libs_to_be_linked[] = {
    #endif

+#if (defined(APPLE) || defined(NeXT)) && defined(MACH)
+/* to link startup code with ObjC support */
+#define RUBY_GLOBAL_SETUP static void objcdummyfunction(void)
{objc_msgSend();}
+#else
+#define RUBY_GLOBAL_SETUP
+#endif
+
+void ruby_sysinit(int *, char **);
+
#define RUBY_VM 1 /
YARV */
#define HAVE_NATIVETHREAD
Index: include/ruby/win32.h

— include/ruby/win32.h (revision 13560)
+++ include/ruby/win32.h (working copy)
@@ -205,5 +205,5 @@ struct timezone {
#define isascii __isascii
#endif
-extern void NtInitialize(int *, char ***);
+#define NtInitialize ruby_sysinit
extern int rb_w32_cmdvector(const char *, char ***);
extern rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int
*);
Index: win32/mkexports.rb

— win32/mkexports.rb (revision 13560)
+++ win32/mkexports.rb (working copy)
@@ -51,4 +51,5 @@ class Exports
end
end

  • syms[“NtInitialize”] ||= “ruby_sysinit” if syms[“ruby_sysinit”]
    @syms = syms
    end
    Index: win32/win32.c
    ===================================================================
    — win32/win32.c (revision 13560)
    +++ win32/win32.c (working copy)
    @@ -420,5 +420,5 @@ exit_handler(void)
    //
    void
    -NtInitialize(int *argc, char ***argv)
    +rb_w32_sysinit(int *argc, char ***argv)
    {

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31900] platform-independent per-process
initialization”
on Sat, 29 Sep 2007 09:34:57 +0900, Nobuyoshi N.
[email protected] writes:

|e$B8=:_e(Bmain.ce$B$G%W%i%C%H%U%)!<%`$4$H$K9T$C$F$$$k=i4|2=$r!“%W%m%;%9C1e(B
|e$B0L$N=i4|2=$H$7$FJ,N%$7$?$$$H;W$C$F$$$^$9!#e(BMetrowerkse$BMQ$NItJ,$,$9$Ce(B
|e$B$-$j$7$^$;$s$,!”$3$l$O5le(BMacintoshe$B@lMQ$J$N$G$3$N:]:o$C$F$7$^$C$?e(B
|e$B$[$&$,$$$$$+$b!#e(B

e$B5le(BMace$B$O$b$&%3%s%Q%$%k$G$-$J$$$O$:$G$9$+$i:o$C$F$b$h$$$G$7$ge(B
e$B$&!#%Q%C%A$r8+$F$b$h$/$o$+$i$J$$$H$3$m$,$“$j$^$7$?$,!”%3%_%Ce(B
e$B%H$7$F$/$@$5$C$F$b$h$$$G$7$g$&!#e(B