Project

General

Profile

Bug #7729 ยป __dir__to_relative.rb

authorNari (Narihiro Nakamura), 01/23/2013 01:54 PM

 
diff --git a/ChangeLog b/ChangeLog
index f87cbbb..5d76ee2 100644
diff --git a/eval.c b/eval.c
index 1b746f2..2041459 100644
--- a/eval.c
+++ b/eval.c
@@ -1512,7 +1512,7 @@ rb_f_callee_name(void)
static VALUE
f_current_dirname(void)
{
- VALUE base = rb_current_realfilepath();
+ VALUE base = rb_current_relative_realfilepath();
if (NIL_P(base)) {
return Qnil;
}
diff --git a/internal.h b/internal.h
index c8317a5..8ac577e 100644
--- a/internal.h
+++ b/internal.h
@@ -313,6 +313,7 @@ void rb_vm_bugreport(void);
/* vm_eval.c */
void Init_vm_eval(void);
VALUE rb_current_realfilepath(void);
+VALUE rb_current_relative_realfilepath(void);
VALUE rb_check_block_call(VALUE, ID, int, VALUE *, VALUE (*)(ANYARGS), VALUE);
typedef void rb_check_funcall_hook(int, VALUE, ID, int, VALUE *, VALUE);
VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, VALUE *argv,
diff --git a/vm_eval.c b/vm_eval.c
index 2f4bbcb..04ec017 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1905,6 +1905,16 @@ rb_current_realfilepath(void)
return Qnil;
}
+VALUE
+rb_current_relative_realfilepath(void)
+{
+ rb_thread_t *th = GET_THREAD();
+ rb_control_frame_t *cfp = th->cfp;
+ cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
+ if (cfp != 0) return cfp->iseq->location.path;
+ return Qnil;
+}
+
void
Init_vm_eval(void)
{
    (1-1/1)