diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ruby.c | 8 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 2 | ||||
-rw-r--r-- | vm_core.h | 2 |
5 files changed, 14 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Wed Aug 7 23:06:26 2013 Akinori MUSHA <knu@iDaemons.org> + + * 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@iDaemons.org> * ruby.c (Process.setproctitle): New method to change the title of @@ -49,7 +49,8 @@ with all sufficient information, see the ChangeLog file. * 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 @@ -1205,7 +1205,8 @@ opt_enc_index(VALUE enc_name) 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 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) 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) 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); /* diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 06c6b7337f..e2303d6a78 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -462,7 +462,7 @@ class TestRubyOptions < Test::Unit::TestCase 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 @@ -377,7 +377,7 @@ typedef struct rb_vm_struct { 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; |