ruby-changes:43900
From: nobu <ko1@a...>
Date: Sat, 20 Aug 2016 11:20:41 +0900 (JST)
Subject: [ruby-changes:43900] nobu:r55973 (trunk): rubystub
nobu 2016-08-20 11:20:34 +0900 (Sat, 20 Aug 2016) New Revision: 55973 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55973 Log: rubystub * rubystub.c: generalize win32/stub.c. Added files: trunk/rubystub.c Removed files: trunk/win32/stub.c Modified files: trunk/ChangeLog trunk/cygwin/GNUmakefile.in trunk/defs/gmake.mk trunk/missing/setproctitle.c trunk/win32/Makefile.sub Index: ChangeLog =================================================================== --- ChangeLog (revision 55972) +++ ChangeLog (revision 55973) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Aug 20 11:20:32 2016 Nobuyoshi Nakada <nobu@r...> + + * rubystub.c: generalize win32/stub.c. + Fri Aug 19 11:39:06 2016 Nobuyoshi Nakada <nobu@r...> * parse.y (primary): allow parenthesised statement as a method Index: win32/stub.c =================================================================== --- win32/stub.c (revision 55972) +++ win32/stub.c (revision 55973) @@ -1,48 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/win32/stub.c#L0 -#include <ruby.h> -static void stub_sysinit(int *argc, char ***argv); -#define ruby_sysinit stub_sysinit -#include <main.c> -#undef ruby_sysinit - -void -stub_sysinit(int *argc, char ***argv) -{ - WCHAR exename[4096]; - size_t wlenexe, len0, lenall; - int lenexe; - int i, ac; - char **av, *p; - - wlenexe = (size_t)GetModuleFileNameW(NULL, exename, sizeof(exename) / sizeof(*exename)); - lenexe = WideCharToMultiByte(CP_UTF8, 0, exename, wlenexe, NULL, 0, NULL, NULL); - ruby_sysinit(argc, argv); - ac = *argc; - av = *argv; - len0 = strlen(av[0]) + 1; - lenall = 0; - for (i = 1; i < ac; ++i) { - lenall += strlen(av[i]) + 1; - } - av = realloc(av, lenall + len0 + (lenexe + 1) + sizeof(char *) * (i + 2)); - if (!av) { - perror("realloc command line"); - exit(-1); - } - *argv = av; - *argc = ++ac; - p = (char *)(av + i + 2); - memmove(p + len0 + lenexe + 1, (char *)(av + ac) + len0, lenall); - memmove(p, (char *)(av + ac), len0); - *av++ = p; - p += len0; - WideCharToMultiByte(CP_UTF8, 0, exename, wlenexe, p, lenexe, NULL, NULL); - p[lenexe] = '\0'; - *av++ = p; - p += lenexe + 1; - while (--i) { - *av++ = p; - p += strlen(p) + 1; - } - *av = NULL; -} - Index: win32/Makefile.sub =================================================================== --- win32/Makefile.sub (revision 55972) +++ win32/Makefile.sub (revision 55973) @@ -418,6 +418,7 @@ prog: config https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L418 ruby: $(PROGRAM) rubyw: $(WPROGRAM) stub: $(STUBPROGRAM) +rubystub: $(STUBPROGRAM) !if !exist(enc/trans/newline.c) && exist($(srcdir)/enc/trans/newline.c) NEWLINE_C = $(srcdir)/enc/trans/newline.c @@ -1005,9 +1006,9 @@ $(WPROGRAM): $(MAINOBJ) $(WINMAINOBJ) $( https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L1006 !endif !if "$(STUBPROGRAM)" != "" -$(STUBPROGRAM): win32/stub.$(OBJEXT) $(LIBRUBY) $(LIBRUBY_SO) $(RUBY_INSTALL_NAME).res +$(STUBPROGRAM): rubystub.$(OBJEXT) $(LIBRUBY) $(LIBRUBY_SO) $(RUBY_INSTALL_NAME).res $(ECHO) linking $(@:\=/) - $(Q) $(PURIFY) $(CC) win32/stub.$(OBJEXT) $(RUBY_INSTALL_NAME).res \ + $(Q) $(PURIFY) $(CC) rubystub.$(OBJEXT) $(RUBY_INSTALL_NAME).res \ $(OUTFLAG)$@ $(LIBRUBYARG) -link $(LDFLAGS) $(XLDFLAGS) $(Q) $(LDSHARED_0) $(Q) $(LDSHARED_1) Index: missing/setproctitle.c =================================================================== --- missing/setproctitle.c (revision 55972) +++ missing/setproctitle.c (revision 55973) @@ -35,6 +35,7 @@ https://github.com/ruby/ruby/blob/trunk/missing/setproctitle.c#L35 #include "ruby.h" #include "ruby/util.h" #define compat_init_setproctitle ruby_init_setproctitle +RUBY_FUNC_EXPORTED void ruby_init_setproctitle(int argc, char *argv[]); #ifndef HAVE_SETPROCTITLE Index: cygwin/GNUmakefile.in =================================================================== --- cygwin/GNUmakefile.in (revision 55972) +++ cygwin/GNUmakefile.in (revision 55973) @@ -13,9 +13,6 @@ else https://github.com/ruby/ruby/blob/trunk/cygwin/GNUmakefile.in#L13 DLL_BASE_NAME := $(RUBY_SO_NAME) DLLWRAP += -mno-cygwin VPATH := $(VPATH):$(srcdir)/win32 - STUBPROGRAM = rubystub$(EXEEXT) - IGNOREDPATTERNS = %~ .% %.orig %.rej \#%\# - SCRIPTPROGRAMS = $(addsuffix $(EXEEXT),$(filter-out $(IGNOREDPATTERNS),$(notdir $(wildcard $(srcdir)/bin/*)))) endif ifneq ($(ENABLE_SHARED),yes) @@ -44,13 +41,6 @@ RUBYDEF = $(DLL_BASE_NAME).def https://github.com/ruby/ruby/blob/trunk/cygwin/GNUmakefile.in#L41 ruby: $(PROGRAM) rubyw: $(WPROGRAM) -stub: $(STUBPROGRAM) -scriptbin: $(SCRIPTPROGRAMS) - -%$(EXEEXT): bin/% $(STUBPROGRAM) - $(ECHO) generating $@ - $(Q) { cat $(STUBPROGRAM); echo; sed -e '1{' -e '/^#!.*ruby/!i\' -e '#!/bin/ruby' -e '}' $<; } > $@ - $(Q) chmod +x $@ $(LIBRUBY): $(RUBY_EXP) $(LIBRUBY_SO) $(RUBY_EXP) $(LIBRUBY_SO): $(DLL_BASE_NAME).res.@OBJEXT@ @@ -72,12 +62,7 @@ $(WPROGRAM): $(RUBYW_INSTALL_NAME).res.@ https://github.com/ruby/ruby/blob/trunk/cygwin/GNUmakefile.in#L62 $(ECHO) linking $@ $(Q) $(PURIFY) $(CC) -mwindows -e $(SYMBOL_PREFIX)mainCRTStartup $(LDFLAGS) $(XLDFLAGS) \ $(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ -$(STUBPROGRAM): $(RUBY_INSTALL_NAME).res.@OBJEXT@ win32/stub.@OBJEXT@ - @rm -f $@ - $(ECHO) linking $@ - $(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) \ - win32/stub.@OBJEXT@ $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ - $(if $(STRIP),$(Q) $(STRIP) $@) +$(STUBPROGRAM): $(RUBY_INSTALL_NAME).res.@OBJEXT@ $(RUBY_EXP): $(LIBRUBY_A) $(ECHO) creating $@ Index: defs/gmake.mk =================================================================== --- defs/gmake.mk (revision 55972) +++ defs/gmake.mk (revision 55973) @@ -92,3 +92,36 @@ else https://github.com/ruby/ruby/blob/trunk/defs/gmake.mk#L92 $(Q) mv $@.new $@ $(Q) $(RMALL) make_des_table* endif + +STUBPROGRAM = rubystub$(EXEEXT) +IGNOREDPATTERNS = %~ .% %.orig %.rej \#%\# +SCRIPTBINDIR := $(if $(EXEEXT),,exec/) +SCRIPTPROGRAMS = $(addprefix $(SCRIPTBINDIR),$(addsuffix $(EXEEXT),$(filter-out $(IGNOREDPATTERNS),$(notdir $(wildcard $(srcdir)/bin/*))))) + +stub: $(STUBPROGRAM) +scriptbin: $(SCRIPTPROGRAMS) +ifneq ($(STUBPROGRAM),rubystub) +rubystub: $(STUBPROGRAM) +endif + +$(SCRIPTPROGRAMS): $(STUBPROGRAM) + +$(STUBPROGRAM): rubystub.$(OBJEXT) $(LIBRUBY) $(MAINOBJ) $(OBJS) $(EXTOBJS) $(SETUP) $(PREP) + +rubystub$(EXEEXT): + @rm -f $@ + $(ECHO) linking $@ + $(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) rubystub.$(OBJEXT) $(EXTOBJS) $(LIBRUBYARG) $(MAINLIBS) $(LIBS) $(EXTLIBS) $(OUTFLAG)$@ + $(Q) $(POSTLINK) + $(if $(STRIP),$(Q) $(STRIP) $@) + +$(SCRIPTBINDIR)%$(EXEEXT): bin/% $(STUBPROGRAM) \ + $(if $(SCRIPTBINDIR),$(TIMESTAMPDIR)/.exec.time) + $(ECHO) generating $@ + $(Q) { cat $(STUBPROGRAM); echo; sed -e '1{' -e '/^#!.*ruby/!i\' -e '#!/bin/ruby' -e '}' $<; } > $@ + $(Q) chmod +x $@ + $(Q) $(POSTLINK) + +$(TIMESTAMPDIR)/.exec.time: + $(Q) mkdir exec + $(Q) exit > $@ Index: rubystub.c =================================================================== --- rubystub.c (revision 0) +++ rubystub.c (revision 55973) @@ -0,0 +1,57 @@ https://github.com/ruby/ruby/blob/trunk/rubystub.c#L1 +#include "internal.h" +#if defined HAVE_DLADDR +#include <dlfcn.h> +#endif +static void* stub_options(int argc, char **argv); +#define ruby_options stub_options +#include <main.c> +#undef ruby_options + +void * +stub_options(int argc, char **argv) +{ + char xflag[] = "-x"; + char *xargv[4] = {NULL, xflag}; + char *cmd = argv[0]; + void *ret; + +#if defined __CYGWIN__ || defined _WIN32 + /* GetCommandLineW should contain the accessible path, + * use argv[0] as is */ +#elif defined __linux__ + { + char selfexe[MAXPATHLEN]; + ssize_t len = readlink("/proc/self/exe", selfexe, sizeof(selfexe)); + if (len < 0) { + perror("readlink(\"/proc/self/exe\")"); + return NULL; + } + selfexe[len] = '\0'; + cmd = selfexe; + } +#elif defined HAVE_DLADDR + { + Dl_info dli; + if (!dladdr(stub_options, &dli)) { + perror("dladdr"); + return NULL; + } + cmd = (char *)dli.dli_fname; + } +#endif + +#ifndef HAVE_SETPROCTITLE + /* argc and argv must be the original */ + ruby_init_setproctitle(argc, argv); +#endif + + /* set script with -x option */ + /* xargv[0] is NULL not to re-initialize setproctitle again */ + xargv[2] = cmd; + ret = ruby_options(3, xargv); + + /* set all arguments to ARGV */ + ruby_set_argv(argc - 1, argv + 1); + + return ret; +} Property changes on: rubystub.c ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/