Backport #8436

__dir__ not working in eval with binding

Added by Dawid Janczak about 2 years ago. Updated about 2 years ago.

[ruby-core:55123]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

Hello,
I think I might have found a bug concerning the new dir method.

Given binding (e.g. current top level binding) I would expect dir to return the directory I'm in, similarly to how FILE with binding does. Instead it returns nil.

I think I have found the solution, but since this is my first modification of Ruby code it might be inaccurate and not work in some cases. I hope it points to the right location though.
Please see attached patch along with a testcase showing the problem.

I also had to modify another testcase to use realpath when checking dir functionality, please check if it's correct.

dir_eval.diff Magnifier (1.39 KB) Dawid Janczak, 05/23/2013 02:31 AM

Associated revisions

Revision 41306
Added by Nobuyoshi Nakada about 2 years ago

vm_eval.c: dir in eval

  • vm_eval.c (eval_string_with_cref): propagate absolute path from the binding if it is given explicitly. patch by Gat (Dawid Janczak) at . [Bug #8436]

Revision 41315
Added by Nobuyoshi Nakada about 2 years ago

vm_eval.c: suppress warning

  • vm_eval.c (eval_string_with_cref): move absolute_path inside non-exception block, since it is used only there. [Bug #8436]

Revision 41317
Added by Tomoyuki Chikanaga about 2 years ago

merge revision(s) 40759,40966,41305,41306: [Backport #8436]

vm_eval.c: suppress warning

* vm_eval.c (eval_string_with_cref): narrow a variable scope into the

EXEC_TAG block to suppress -Wclobberd warning.
* vm_eval.c (eval_string_with_cref): propagate absolute path from the
binding if it is given explicitly. patch by Gat (Dawid Janczak) at
. [Bug #8436]

Revision 41318
Added by Tomoyuki Chikanaga about 2 years ago

merge revision(s) 41315: [Backport #8436]

vm_eval.c: suppress warning

* vm_eval.c (eval_string_with_cref): move absolute_path inside

non-exception block, since it is used only there. [Bug #8436]

Revision 42103
Added by Nobuyoshi Nakada almost 2 years ago

vm_eval.c: use file argument

  • vm_eval.c (eval_string_with_cref): use the given file name unless eval even if scope is given. additional fix for [Bug #8436]. based on the patch by srawlins at [Bug #8662].

Revision 42116
Added by Tomoyuki Chikanaga almost 2 years ago

merge revision(s) 42103: [Backport #8662]

* vm_eval.c (eval_string_with_cref): use the given file name unless
  eval even if scope is given.  additional fix for [Bug #8436].
  based on the patch by srawlins at  [Bug #8662].

History

#1 Updated by Nobuyoshi Nakada about 2 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

This issue was solved with changeset r41306.
Dawid, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


vm_eval.c: dir in eval

  • vm_eval.c (eval_string_with_cref): propagate absolute path from the binding if it is given explicitly. patch by Gat (Dawid Janczak) at . [Bug #8436]

#2 Updated by Nobuyoshi Nakada about 2 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: REQUIRED

#3 Updated by Tomoyuki Chikanaga about 2 years ago

  • Assignee set to Tomoyuki Chikanaga
  • Status changed from Closed to Assigned
  • Tracker changed from Bug to Backport
  • Project changed from Ruby trunk to Backport200

r41305 and 41306.

#4 Updated by Tomoyuki Chikanaga about 2 years ago

r40759 and r40966 are also required.

#5 Updated by Tomoyuki Chikanaga about 2 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r41317.
Dawid, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 40759,40966,41305,41306: [Backport #8436]

vm_eval.c: suppress warning

* vm_eval.c (eval_string_with_cref): narrow a variable scope into the

EXEC_TAG block to suppress -Wclobberd warning.
* vm_eval.c (eval_string_with_cref): propagate absolute path from the
binding if it is given explicitly. patch by Gat (Dawid Janczak) at
. [Bug #8436]

#6 Updated by Tomoyuki Chikanaga about 2 years ago

  • Status changed from Closed to Assigned

add r41315.

#7 Updated by Tomoyuki Chikanaga about 2 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r41318.
Dawid, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 41315: [Backport #8436]

vm_eval.c: suppress warning

* vm_eval.c (eval_string_with_cref): move absolute_path inside

non-exception block, since it is used only there. [Bug #8436]

Also available in: Atom PDF