Add Process.argv0.

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2013-08-07 14:12:08 +00:00
parent 34bb945c40
commit d5ecd17aee
5 changed files with 14 additions and 6 deletions

View File

@ -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> Wed Aug 7 23:05:55 2013 Akinori MUSHA <knu@iDaemons.org>
* ruby.c (Process.setproctitle): New method to change the title of * ruby.c (Process.setproctitle): New method to change the title of

3
NEWS
View File

@ -49,7 +49,8 @@ with all sufficient information, see the ChangeLog file.
* Mutex#owned? is no longer experimental. * Mutex#owned? is no longer experimental.
* Process * 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. * Process.setproctitle() sets the process title without affecting $0.
* String * String

8
ruby.c
View File

@ -1205,7 +1205,8 @@ opt_enc_index(VALUE enc_name)
return i; 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; VALUE rb_argv0;
static VALUE static VALUE
@ -1834,7 +1835,7 @@ void
ruby_script(const char *name) ruby_script(const char *name)
{ {
if (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); rb_vm_set_progname(rb_progname);
} }
} }
@ -1846,7 +1847,7 @@ ruby_script(const char *name)
void void
ruby_set_script_name(VALUE name) 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); 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("$0", &rb_progname, 0, set_arg0);
rb_define_hooked_variable("$PROGRAM_NAME", &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); rb_define_module_function(rb_mProcess, "setproctitle", proc_setproctitle, 1);
/* /*

View File

@ -462,7 +462,7 @@ class TestRubyOptions < Test::Unit::TestCase
skip "platform dependent feature" if /linux|freebsd|netbsd|openbsd|darwin/ !~ RUBY_PLATFORM skip "platform dependent feature" if /linux|freebsd|netbsd|openbsd|darwin/ !~ RUBY_PLATFORM
with_tmpchdir do 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") pid = spawn(EnvUtil.rubybin, "test-script")
ps = nil ps = nil

View File

@ -377,7 +377,7 @@ typedef struct rb_vm_struct {
int src_encoding_index; int src_encoding_index;
VALUE verbose, debug, progname; VALUE verbose, debug, orig_progname, progname;
VALUE coverages; VALUE coverages;
struct unlinked_method_entry_list_entry *unlinked_method_entry_list; struct unlinked_method_entry_list_entry *unlinked_method_entry_list;