summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--eval_intern.h1
-rw-r--r--ruby.c21
-rw-r--r--vm.c15
4 files changed, 21 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 055e64a..b7c7d1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/eval_intern.h b/eval_intern.h
index 03660a6..09ecf44 100644
--- a/eval_intern.h
+++ b/eval_intern.h
@@ -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);
diff --git a/ruby.c b/ruby.c
index 125455c..059f3c2 100644
--- a/ruby.c
+++ b/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;
}
diff --git a/vm.c b/vm.c
index b38bcdf..74321f4 100644
--- a/vm.c
+++ b/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