Skip to content

Commit

Permalink
* main.c (main): use platform-independent per-process initialization.
Browse files Browse the repository at this point in the history
  [ruby-dev:31900]

* 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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Sep 29, 2007
1 parent 43c4d80 commit 400202f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 25 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
@@ -1,3 +1,17 @@
Sat Sep 29 17:45:22 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>

* main.c (main): use platform-independent per-process initialization.
[ruby-dev:31900]

* 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.

Sat Sep 29 17:31:04 2007 Yukihiro Matsumoto <matz@ruby-lang.org>

* array.c (rb_ary_combination): new method to give all combination
Expand Down
9 changes: 9 additions & 0 deletions include/ruby/ruby.h
Expand Up @@ -958,6 +958,15 @@ rb_special_const_p(VALUE obj)
static char *dln_libs_to_be_linked[] = { EXTLIB, 0 };
#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
int is_ruby_native_thread(void);
Expand Down
2 changes: 1 addition & 1 deletion include/ruby/win32.h
Expand Up @@ -204,7 +204,7 @@ struct timezone {
#undef isascii
#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 *);
extern int flock(int fd, int oper);
Expand Down
20 changes: 2 additions & 18 deletions main.c
Expand Up @@ -13,18 +13,7 @@
#undef RUBY_EXPORT
#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 void
objcdummyfunction(void)
{
objc_msgSend();
}
#endif
RUBY_GLOBAL_SETUP

int
main(int argc, char **argv, char **envp)
Expand All @@ -33,13 +22,8 @@ main(int argc, char **argv, char **envp)
extern void ruby_set_debug_option(const char *);
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;
ruby_init();
Expand Down
42 changes: 37 additions & 5 deletions ruby.c
Expand Up @@ -47,6 +47,10 @@
# define MAXPATHLEN 1024
#endif

#if defined(__MACOS__) && defined(__MWERKS__)
#include <console.h>
#endif

#include "ruby/util.h"

/* for gdb */
Expand Down Expand Up @@ -1307,17 +1311,12 @@ ruby_process_options(int argc, char **argv)
struct cmdline_options opt;
NODE *tree;

origarg.argc = argc;
origarg.argv = argv;

MEMZERO(&opt, opt, 1);
ruby_script(argv[0]); /* for the time being */
rb_argv0 = rb_progname;
#if defined(USE_DLN_A_OUT)
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);

Expand All @@ -1327,3 +1326,36 @@ ruby_process_options(int argc, char **argv)

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
}
1 change: 1 addition & 0 deletions win32/mkexports.rb
Expand Up @@ -50,6 +50,7 @@ def initialize(objs)
end
end
end
syms["NtInitialize"] ||= "ruby_sysinit" if syms["ruby_sysinit"]
@syms = syms
end

Expand Down
2 changes: 1 addition & 1 deletion win32/win32.c
Expand Up @@ -419,7 +419,7 @@ exit_handler(void)
// Initialization stuff
//
void
NtInitialize(int *argc, char ***argv)
rb_w32_sysinit(int *argc, char ***argv)
{

WORD version;
Expand Down

0 comments on commit 400202f

Please sign in to comment.