[前][次][番号順一覧][スレッド一覧]

ruby-changes:1979

From: ko1@a...
Date: 20 Sep 2007 17:25:22 +0900
Subject: [ruby-changes:1979] nobu - Ruby:r13470 (ruby_1_8): * process.c (rb_detach_process): cast for the platforms where size of

nobu	2007-09-20 17:25:00 +0900 (Thu, 20 Sep 2007)

  New Revision: 13470

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/process.c
    branches/ruby_1_8/version.h

  Log:
    * process.c (rb_detach_process): cast for the platforms where size of
      pointer differs from size of int.
    
    * process.c (rb_f_exec, rb_f_system): should not exceptions after
      fork.  [ruby-core:08262]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=13470&r2=13469
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/process.c?r1=13470&r2=13469
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/version.h?r1=13470&r2=13469

Index: ruby_1_8/process.c
===================================================================
--- ruby_1_8/process.c	(revision 13469)
+++ ruby_1_8/process.c	(revision 13470)
@@ -851,19 +851,19 @@
 detach_process_watcher(arg)
     void *arg;
 {
-    int pid = (int)arg, status;
+    int pid = (int)(VALUE)arg, status;
 
     while (rb_waitpid(pid, &status, WNOHANG) == 0) {
 	rb_thread_sleep(1);
     }
-    return Qnil;
+    return rb_last_status;
 }
 
 VALUE
 rb_detach_process(pid)
     int pid;
 {
-    return rb_thread_create(detach_process_watcher, (void*)pid);
+    return rb_thread_create(detach_process_watcher, (void*)(VALUE)pid);
 }
 
 
@@ -1069,8 +1069,8 @@
     a = argv = ALLOCA_N(char*, (s-str)/2+2);
     ss = ALLOCA_N(char, s-str+1);
     strcpy(ss, str);
-    if (*a++ = strtok(ss, " \t")) {
-	while (t = strtok(NULL, " \t")) {
+    if ((*a++ = strtok(ss, " \t")) != 0) {
+	while ((t = strtok(NULL, " \t")) != 0) {
 	    *a++ = t;
 	}
 	*a = NULL;
@@ -1189,6 +1189,52 @@
 #endif
 #endif
 
+struct rb_exec_arg {
+    int argc;
+    VALUE *argv;
+    const char *prog;
+};
+
+static struct rb_exec_arg *
+proc_prepare_args(e, argc, argv, prog)
+    struct rb_exec_arg *e;
+    int argc;
+    VALUE *argv;
+    VALUE prog;
+{
+    MEMZERO(e, struct rb_exec_arg, 1);
+    if (prog) {
+	SafeStringValue(prog);
+	StringValueCStr(prog);
+    }
+    for (i = 0; i < argc; i++) {
+	SafeStringValue(argv[i]);
+	StringValueCStr(argv[i]);
+    }
+    security(RSTRING(prog ? prog : argv[0])->ptr);
+    e->prog = prog;
+    e->argc = argc;
+    e->argv = argv;
+    return e;
+}
+
+static VALUE
+proc_exec_args(earg)
+    VALUE earg;
+{
+    struct rb_exec_arg *e = (struct rb_exec_arg *)earg;
+    int argc = e->argc;
+    VALUE *argv = e->argv;
+    VALUE prog = e->prog;
+
+    if (argc == 1 && prog == 0) {
+	return (VALUE)rb_proc_exec(RSTRING(argv[0])->ptr);
+    }
+    else {
+	return (VALUE)proc_exec_n(argc, argv, prog);
+    }
+}
+
 /*
  *  call-seq:
  *     exec(command [, arg, ...])
@@ -1221,8 +1267,10 @@
 {
     VALUE prog = 0;
     VALUE tmp;
+    struct rb_exec_arg earg;
 
     if (argc == 0) {
+	rb_last_status = Qnil;
 	rb_raise(rb_eArgError, "wrong number of arguments");
     }
 
@@ -1235,15 +1283,7 @@
 	argv[0] = RARRAY(tmp)->ptr[1];
 	SafeStringValue(prog);
     }
-    if (argc == 1 && prog == 0) {
-	VALUE cmd = argv[0];
-
-	SafeStringValue(cmd);
-	rb_proc_exec(RSTRING(cmd)->ptr);
-    }
-    else {
-	proc_exec_n(argc, argv, prog);
-    }
+    proc_exec_args(proc_prepare_args(&earg, argc, argv, prog));
     rb_sys_fail(RSTRING(argv[0])->ptr);
     return Qnil;		/* dummy */
 }
@@ -1500,7 +1540,7 @@
 #else
     volatile VALUE prog = 0;
     int pid;
-    int i;
+    struct rb_exec_arg earg;
     RETSIGTYPE (*chfunc)(int);
 
     fflush(stdout);
@@ -1517,27 +1557,15 @@
 	prog = RARRAY(argv[0])->ptr[0];
 	argv[0] = RARRAY(argv[0])->ptr[1];
     }
+    proc_prepare_args(&earg, argc, argv, prog);
 
-    if (prog) {
-	SafeStringValue(prog);
-	StringValueCStr(prog);
-    }
-    for (i = 0; i < argc; i++) {
-	SafeStringValue(argv[i]);
-	StringValueCStr(argv[i]);
-    }
-    security(RSTRING(prog ? prog : argv[0])->ptr);
     chfunc = signal(SIGCHLD, SIG_DFL);
   retry:
     pid = fork();
     if (pid == 0) {
 	/* child process */
-	if (argc == 1 && prog == 0) {
-	    rb_proc_exec(RSTRING(argv[0])->ptr);
-	}
-	else {
-	    proc_exec_n(argc, argv, prog);
-	}
+	rb_thread_atfork();
+	rb_protect(proc_exec_args, (VALUE)&earg, NULL);
 	_exit(127);
     }
     if (pid < 0) {
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 13469)
+++ ruby_1_8/ChangeLog	(revision 13470)
@@ -1,3 +1,11 @@
+Thu Sep 20 17:24:59 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* process.c (rb_detach_process): cast for the platforms where size of
+	  pointer differs from size of int.
+
+	* process.c (rb_f_exec, rb_f_system): should not exceptions after
+	  fork.  [ruby-core:08262]
+
 Fri Sep 14 00:34:25 2007  Masatoshi SEKI  <m_seki@m...>
 
 	* lib/drb/extservm.rb (invoke_service): use Thread.exclusive instead of 
Index: ruby_1_8/version.h
===================================================================
--- ruby_1_8/version.h	(revision 13469)
+++ ruby_1_8/version.h	(revision 13470)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2007-09-12"
+#define RUBY_RELEASE_DATE "2007-09-20"
 #define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20070912
+#define RUBY_RELEASE_CODE 20070920
 #define RUBY_PATCHLEVEL 5000
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 6
 #define RUBY_RELEASE_YEAR 2007
 #define RUBY_RELEASE_MONTH 9
-#define RUBY_RELEASE_DAY 12
+#define RUBY_RELEASE_DAY 20
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]