version.c: remove ruby_engine_name

* ruby.c (load_file_internal, ruby_process_options): share
  ruby_engine instead of literal strings.

* version.c (Init_version): remove internal `ruby_engine_name`,
  but set the VM program name in addition to the global constant.

* vm_backtrace.c (location_to_str, oldbt_init): use th eVM program
  name always.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-11-29 02:25:12 +00:00
parent d6beaf3215
commit fc0c2d1cc2
4 changed files with 8 additions and 7 deletions

View File

@ -1187,7 +1187,7 @@ VALUE rb_attr_delete(VALUE, ID);
VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef);
/* version.c */
extern VALUE ruby_engine_name;
extern const char ruby_engine[];
/* vm_insnhelper.h */
rb_serial_t rb_next_class_serial(void);

6
ruby.c
View File

@ -1678,7 +1678,7 @@ load_file_internal(VALUE argp_v)
if (RSTRING_LEN(line) > 2
&& RSTRING_PTR(line)[0] == '#'
&& RSTRING_PTR(line)[1] == '!') {
if ((p = strstr(RSTRING_PTR(line), "ruby")) != 0) {
if ((p = strstr(RSTRING_PTR(line), ruby_engine)) != 0) {
goto start_read;
}
}
@ -1694,7 +1694,7 @@ load_file_internal(VALUE argp_v)
if (NIL_P(line))
return 0;
if ((p = strstr(RSTRING_PTR(line), "ruby")) == 0) {
if ((p = strstr(RSTRING_PTR(line), ruby_engine)) == 0) {
/* not ruby script, assume -x flag */
goto search_shebang;
}
@ -2083,7 +2083,7 @@ ruby_process_options(int argc, char **argv)
{
struct cmdline_options opt;
VALUE iseq;
const char *script_name = (argc > 0 && argv[0]) ? argv[0] : "ruby";
const char *script_name = (argc > 0 && argv[0]) ? argv[0] : ruby_engine;
ruby_script(script_name); /* for the time being */
rb_argv0 = rb_str_new4(rb_progname);

View File

@ -33,7 +33,6 @@ const int ruby_patchlevel = RUBY_PATCHLEVEL;
const char ruby_description[] = RUBY_DESCRIPTION;
const char ruby_copyright[] = RUBY_COPYRIGHT;
const char ruby_engine[] = "ruby";
VALUE ruby_engine_name = Qnil;
/*! Defines platform-depended Ruby-level constants */
void
@ -42,6 +41,7 @@ Init_version(void)
enum {ruby_patchlevel = RUBY_PATCHLEVEL};
enum {ruby_revision = RUBY_REVISION};
VALUE version;
VALUE ruby_engine_name;
/*
* The running version of ruby
*/
@ -75,6 +75,7 @@ Init_version(void)
* The engine or interpreter this ruby uses.
*/
rb_define_global_const("RUBY_ENGINE", ruby_engine_name = MKSTR(engine));
ruby_set_script_name(ruby_engine_name);
/*
* The version of the engine or interpreter this ruby uses.
*/

View File

@ -333,7 +333,7 @@ location_to_str(rb_backtrace_location_t *loc)
}
else {
rb_thread_t *th = GET_THREAD();
file = th->vm->progname ? th->vm->progname : ruby_engine_name;
file = th->vm->progname;
lineno = INT2FIX(0);
}
name = rb_id2str(loc->body.cfunc.mid);
@ -683,7 +683,7 @@ oldbt_init(void *ptr, size_t dmy)
struct oldbt_arg *arg = (struct oldbt_arg *)ptr;
rb_thread_t *th = GET_THREAD();
arg->filename = th->vm->progname ? th->vm->progname : ruby_engine_name;;
arg->filename = th->vm->progname;
arg->lineno = 0;
}