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

cannot call `Fiber.yield` in `#initialize` #3066

Closed
kazuho opened this Issue Dec 30, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@kazuho
Contributor

kazuho commented Dec 30, 2015

As shown in the code snippet below, it is impossible to call Fiber.yield in case it is invoked (either directly or indirectly) via #initialize.

My understanding is that this is because #new method (which calls #initialize) is implemented in C.

Is there any chance that this restriction will be raised, for example by making changes so that #initialize will be called right after returning from the C function that implements #new?

class T1
  def foo
    Fiber.yield "hello from T1#foo"
  end
end

class T2
  def initialize
    Fiber.yield "hello from T2#initialize"
  end
end

f = Fiber.new do
  T1.new.foo
end
puts f.resume # says "hello"

f = Fiber.new do
  T2.new
end
puts f.resume # can't cross C function boundary error
@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Dec 31, 2015

Member

It's because #initialize is called via mrb_funcall(). We can solve this by implementing Class#new in Ruby, but when I tried before it slows down mruby significantly. If this issue is not critical, I'd like to declare this as a mruby limitation.

Member

matz commented Dec 31, 2015

It's because #initialize is called via mrb_funcall(). We can solve this by implementing Class#new in Ruby, but when I tried before it slows down mruby significantly. If this issue is not critical, I'd like to declare this as a mruby limitation.

@kazuho

This comment has been minimized.

Show comment
Hide comment
@kazuho

kazuho Dec 31, 2015

Contributor

Thank you for the answer. The issue is not critical to me, I can live without it.

PS. I hope you have a good year!

Contributor

kazuho commented Dec 31, 2015

Thank you for the answer. The issue is not critical to me, I can live without it.

PS. I hope you have a good year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment