ruby-changes:4701
From: ko1@a...
Date: Sat, 26 Apr 2008 00:51:16 +0900 (JST)
Subject: [ruby-changes:4701] akr - Ruby:r16195 (trunk): * process.c (rb_spawn_internal): new function to specify
akr 2008-04-26 00:50:24 +0900 (Sat, 26 Apr 2008)
New Revision: 16195
Modified files:
trunk/ChangeLog
trunk/process.c
trunk/test/ruby/test_process.rb
Log:
* process.c (rb_spawn_internal): new function to specify
default_close_others.
(rb_spawn): specify default_close_others true.
(rb_f_system): call rb_spawn_internal with default_close_others as
false.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_process.rb?r1=16195&r2=16194&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16195&r2=16194&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/process.c?r1=16195&r2=16194&diff_format=u
Index: ChangeLog
===================================================================
--- ChangeLog (revision 16194)
+++ ChangeLog (revision 16195)
@@ -1,3 +1,11 @@
+Sat Apr 26 00:47:43 2008 Tanaka Akira <akr@f...>
+
+ * process.c (rb_spawn_internal): new function to specify
+ default_close_others.
+ (rb_spawn): specify default_close_others true.
+ (rb_f_system): call rb_spawn_internal with default_close_others as
+ false.
+
Fri Apr 25 17:56:25 2008 Yukihiro Matsumoto <matz@r...>
* gc.c (free_unused_heaps): preserve last used heap segment to
Index: process.c
===================================================================
--- process.c (revision 16194)
+++ process.c (revision 16195)
@@ -2544,14 +2544,26 @@
}
}
-rb_pid_t
-rb_spawn(int argc, VALUE *argv)
+static rb_pid_t
+rb_spawn_internal(int argc, VALUE *argv, int default_close_others)
{
rb_pid_t status;
VALUE prog;
struct rb_exec_arg earg;
+ int argc2 = argc;
+ VALUE *argv2 = argv, env = Qnil, opthash = Qnil;
+ VALUE close_others = ID2SYM(rb_intern("close_others"));
- prog = rb_exec_initarg(argc, argv, Qtrue, &earg);
+ prog = rb_exec_getargs(&argc2, &argv2, Qtrue, &env, &opthash);
+ if (default_close_others) {
+ if (NIL_P(opthash)) {
+ opthash = rb_hash_new();
+ RBASIC(opthash)->klass = 0;
+ }
+ if (!st_lookup(RHASH_TBL(opthash), close_others, 0))
+ rb_hash_aset(opthash, close_others, Qtrue);
+ }
+ rb_exec_initarg2(prog, argc2, argv2, env, opthash, &earg);
#if defined HAVE_FORK
status = rb_fork(&status, rb_exec_atfork, &earg, earg.redirect_fds);
@@ -2581,6 +2593,12 @@
return status;
}
+rb_pid_t
+rb_spawn(int argc, VALUE *argv)
+{
+ return rb_spawn_internal(argc, argv, Qtrue);
+}
+
/*
* call-seq:
* system([env,] cmd [, arg, ...] [,options]) => true, false or nil
@@ -2618,7 +2636,7 @@
chfunc = signal(SIGCHLD, SIG_DFL);
#endif
- status = rb_spawn(argc, argv);
+ status = rb_spawn_internal(argc, argv, Qfalse);
#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
if (status > 0) {
rb_syswait(status);
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb (revision 16194)
+++ test/ruby/test_process.rb (revision 16195)
@@ -419,9 +419,9 @@
assert_equal("ba\n", r.read)
}
with_pipe {|r, w|
- Process.wait spawn("echo bi >&#{w.fileno}")
+ Process.wait spawn("exec 2>/dev/null; echo bi >&#{w.fileno}")
w.close
- assert_equal("bi\n", r.read)
+ assert_equal("", r.read)
}
with_pipe {|r, w|
Process.wait fork { exec("echo bu >&#{w.fileno}") }
@@ -465,6 +465,11 @@
File.unlink("err")
}
with_pipe {|r, w|
+ Process.wait spawn("echo bi >&#{w.fileno}", :close_others=>false)
+ w.close
+ assert_equal("bi\n", r.read)
+ }
+ with_pipe {|r, w|
Process.wait fork { exec("exec >/dev/null 2>err; echo mu >&#{w.fileno}", :close_others=>true) }
w.close
assert_equal("", r.read)
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/