зеркало из https://github.com/github/ruby.git
* ruby.c (ruby_script): sets also VM toplevel program name.
* ruby.c (process_options): no longer needs additional frame. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
52b3bf363a
Коммит
589ec2beb5
|
@ -1,4 +1,8 @@
|
|||
Sun May 17 13:15:32 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Sun May 17 14:02:56 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ruby.c (ruby_script): sets also VM toplevel program name.
|
||||
|
||||
* ruby.c (process_options): no longer needs additional frame.
|
||||
|
||||
* vm.c (rb_vm_get_sourceline): should not access out of bound.
|
||||
|
||||
|
|
|
@ -207,6 +207,7 @@ VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val);
|
|||
NODE *rb_vm_cref(void);
|
||||
VALUE rb_obj_is_proc(VALUE);
|
||||
VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename);
|
||||
void rb_vm_set_progname(VALUE filename);
|
||||
void rb_thread_terminate_all(void);
|
||||
VALUE rb_vm_top_self();
|
||||
VALUE rb_vm_cbase(void);
|
||||
|
|
21
ruby.c
21
ruby.c
|
@ -112,12 +112,6 @@ cmdline_options_init(struct cmdline_options *opt)
|
|||
return opt;
|
||||
}
|
||||
|
||||
struct cmdline_arguments {
|
||||
int argc;
|
||||
char **argv;
|
||||
struct cmdline_options *opt;
|
||||
};
|
||||
|
||||
static NODE *load_file(VALUE, const char *, int, struct cmdline_options *);
|
||||
static void forbid_setid(const char *, struct cmdline_options *);
|
||||
#define forbid_setid(s) forbid_setid(s, opt)
|
||||
|
@ -1222,12 +1216,8 @@ rb_f_chomp(argc, argv)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
process_options(VALUE arg)
|
||||
process_options(int argc, char **argv, struct cmdline_options *opt)
|
||||
{
|
||||
struct cmdline_arguments *argp = (struct cmdline_arguments *)arg;
|
||||
struct cmdline_options *opt = argp->opt;
|
||||
int argc = argp->argc;
|
||||
char **argv = argp->argv;
|
||||
NODE *tree = 0;
|
||||
VALUE parser;
|
||||
VALUE iseq;
|
||||
|
@ -1754,6 +1744,7 @@ ruby_script(const char *name)
|
|||
{
|
||||
if (name) {
|
||||
rb_progname = rb_obj_freeze(rb_external_str_new(name, strlen(name)));
|
||||
rb_vm_set_progname(rb_progname);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1846,19 +1837,13 @@ ruby_set_argv(int argc, char **argv)
|
|||
void *
|
||||
ruby_process_options(int argc, char **argv)
|
||||
{
|
||||
struct cmdline_arguments args;
|
||||
struct cmdline_options opt;
|
||||
VALUE iseq;
|
||||
|
||||
ruby_script(argv[0]); /* for the time being */
|
||||
rb_argv0 = rb_str_new4(rb_progname);
|
||||
rb_gc_register_mark_object(rb_argv0);
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
args.opt = cmdline_options_init(&opt);
|
||||
iseq = rb_vm_call_cfunc(rb_vm_top_self(),
|
||||
process_options, (VALUE)&args,
|
||||
0, rb_progname);
|
||||
iseq = process_options(argc, argv, cmdline_options_init(&opt));
|
||||
return (void*)(struct RData*)iseq;
|
||||
}
|
||||
|
||||
|
|
15
vm.c
15
vm.c
|
@ -671,13 +671,13 @@ rb_vm_get_sourceline(const rb_control_frame_t *cfp)
|
|||
int line_no = 0;
|
||||
const rb_iseq_t *iseq = cfp->iseq;
|
||||
|
||||
if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
|
||||
if (RUBY_VM_NORMAL_ISEQ_P(iseq) && iseq->insn_info_size > 0) {
|
||||
rb_num_t i;
|
||||
size_t pos = cfp->pc - cfp->iseq->iseq_encoded;
|
||||
|
||||
for (i = 0; i < iseq->insn_info_size; i++) {
|
||||
if (iseq->insn_info_table[0].position == pos) goto found;
|
||||
for (i = 1; i < iseq->insn_info_size; i++) {
|
||||
if (iseq->insn_info_table[i].position == pos) {
|
||||
if (i == 0) goto found;
|
||||
line_no = iseq->insn_info_table[i - 1].line_no;
|
||||
goto found;
|
||||
}
|
||||
|
@ -1939,6 +1939,15 @@ Init_VM(void)
|
|||
vm_init_redefined_flag();
|
||||
}
|
||||
|
||||
void
|
||||
rb_vm_set_progname(VALUE filename)
|
||||
{
|
||||
rb_thread_t *th = GET_VM()->main_thread;
|
||||
rb_control_frame_t *cfp = (void *)(th->stack + th->stack_size);
|
||||
--cfp;
|
||||
cfp->iseq->filename = filename;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
||||
struct rb_objspace *rb_objspace_alloc(void);
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче