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

ruby-changes:30357

From: knu <ko1@a...>
Date: Wed, 7 Aug 2013 23:12:22 +0900 (JST)
Subject: [ruby-changes:30357] knu:r42426 (trunk): Add Process.argv0.

knu	2013-08-07 23:12:08 +0900 (Wed, 07 Aug 2013)

  New Revision: 42426

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42426

  Log:
    Add Process.argv0.
    
    * ruby.c (Process.argv0): New method to return the original value
      of $0. [Feature #8696]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/ruby.c
    trunk/test/ruby/test_rubyoptions.rb
    trunk/vm_core.h
_______________________________________________
ruby-cvs mailing list
ruby-cvs@r...
http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-cvs
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42425)
+++ ChangeLog	(revision 42426)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Aug  7 23:06:26 2013  Akinori MUSHA  <knu@i...>
+
+	* ruby.c (Process.argv0): New method to return the original value
+	  of $0. [Feature #8696]
+
 Wed Aug  7 23:05:55 2013  Akinori MUSHA  <knu@i...>
 
 	* ruby.c (Process.setproctitle): New method to change the title of
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 42425)
+++ vm_core.h	(revision 42426)
@@ -377,7 +377,7 @@ typedef struct rb_vm_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L377
 
     int src_encoding_index;
 
-    VALUE verbose, debug, progname;
+    VALUE verbose, debug, orig_progname, progname;
     VALUE coverages;
 
     struct unlinked_method_entry_list_entry *unlinked_method_entry_list;
Index: NEWS
===================================================================
--- NEWS	(revision 42425)
+++ NEWS	(revision 42426)
@@ -49,7 +49,8 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L49
     * Mutex#owned? is no longer experimental.
 
 * Process
-  * New methods:
+  * New alternative methods to $0/$0=:
+    * Process.argv0() returns the original value of $0.
     * Process.setproctitle() sets the process title without affecting $0.
 
 * String
Index: ruby.c
===================================================================
--- ruby.c	(revision 42425)
+++ ruby.c	(revision 42426)
@@ -1205,7 +1205,8 @@ opt_enc_index(VALUE enc_name) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1205
     return i;
 }
 
-#define rb_progname (GET_VM()->progname)
+#define rb_progname      (GET_VM()->progname)
+#define rb_orig_progname (GET_VM()->orig_progname)
 VALUE rb_argv0;
 
 static VALUE
@@ -1834,7 +1835,7 @@ void https://github.com/ruby/ruby/blob/trunk/ruby.c#L1835
 ruby_script(const char *name)
 {
     if (name) {
-	rb_progname = rb_external_str_new(name, strlen(name));
+	rb_orig_progname = rb_progname = rb_external_str_new(name, strlen(name));
 	rb_vm_set_progname(rb_progname);
     }
 }
@@ -1846,7 +1847,7 @@ ruby_script(const char *name) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1847
 void
 ruby_set_script_name(VALUE name)
 {
-    rb_progname = rb_str_dup(name);
+    rb_orig_progname = rb_progname = rb_str_dup(name);
     rb_vm_set_progname(rb_progname);
 }
 
@@ -1914,6 +1915,7 @@ ruby_prog_init(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1915
     rb_define_hooked_variable("$0", &rb_progname, 0, set_arg0);
     rb_define_hooked_variable("$PROGRAM_NAME", &rb_progname, 0, set_arg0);
 
+    rb_define_module_function(rb_mProcess, "argv0", proc_argv0, 0);
     rb_define_module_function(rb_mProcess, "setproctitle", proc_setproctitle, 1);
 
     /*
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 42425)
+++ test/ruby/test_rubyoptions.rb	(revision 42426)
@@ -462,7 +462,7 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L462
     skip "platform dependent feature" if /linux|freebsd|netbsd|openbsd|darwin/ !~ RUBY_PLATFORM
 
     with_tmpchdir do
-      write_file("test-script", "$0 = 'hello world'; sleep 60")
+      write_file("test-script", "$0 = 'hello world'; /test-script/ =~ Process.argv0 or $0 = 'Process.argv0 changed!'; sleep 60")
 
       pid = spawn(EnvUtil.rubybin, "test-script")
       ps = nil

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

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