Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local_variables is broken #3710

Closed
i110 opened this issue Jun 18, 2017 · 3 comments
Closed

local_variables is broken #3710

i110 opened this issue Jun 18, 2017 · 3 comments

Comments

@i110
Copy link
Contributor

@i110 i110 commented Jun 18, 2017

def _generate
  var = 110
  proc {|hoge| p local_variables }
end
_generate.call

outputs [:hoge], but I expect [:hoge, :var] as CRuby does.

As I looked the code, struct REnv * assigned to the generated proc gets unshared when cipop called in OP_RETURN, and that makes the env not enumarated. Is this a mruby's spec or not?

Even if that's a spec, I believe that the following behavior is absolutely a bug.

def _generate
  eval("var = 110; proc {|hoge| p local_variables }")
end

def _call(invisible)
  invisible.call
end

_call(_generate)

says [:hoge, :invisible], but if I'm correct invisible shouldn't appear.
In this case, the env of the generated proc is not unshared due to another callinfo, but mrb_local_variables refers current callinfo stack, so variables not related to the proc appears. As a similar example,

def _generate
  eval("var = 110; proc {|hoge| p local_variables }")
end

def dummy(invisible)
end

Fiber.new {
  ret = _generate
  dummy(nil)
  ret
}.resume.call

outputs the same, [:hoge, :invisible]. In this case, another context's callinfo which gets overwrited by calling dummy function is referred.

@matz
Copy link
Member

@matz matz commented Jun 18, 2017

The first issue is mruby limitation. We will try to address it but it would take time.
The second issue is caused by a bug in eval (create_proc_from_string).

matz added a commit that referenced this issue Jun 19, 2017
This patch fixes the latter part of #3710. We need to change
`struct REnv` to fix the former part of the issue.
@i110
Copy link
Contributor Author

@i110 i110 commented Jun 19, 2017

Actually I found the first issue when debugging the second one, so I'm not stacked at that if I know that's a limitation. Thanks a lot!

@matz matz closed this in bf1cb87 Jun 20, 2017
@matz
Copy link
Member

@matz matz commented Jun 20, 2017

Oops, issue number was wrong.

@matz matz reopened this Jun 20, 2017
@matz matz mentioned this issue Jul 4, 2017
@matz matz closed this in 7b88c1a Aug 1, 2017
tsahara added a commit to iij/mruby that referenced this issue Jun 11, 2018
dearblue added a commit to dearblue/mruby that referenced this issue May 31, 2020
matz added a commit that referenced this issue Jun 1, 2020
Get local variable names from orphan block; ref #3710
matz added a commit that referenced this issue Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.