[MacRuby] #412: Calling return in a block raises an exception
#412: Calling return in a block raises an exception -------------------------------+-------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------+-------------------------------------------- MacRuby 0.5 beta 1 doesn't allow calling return in a block, which works in 1.8 and 1.9. {{{ #!ruby def foo f = Proc.new { return "return from foo from inside Proc.new" } f.call # control leaves foo here return "return from foo" end def bar f = lambda { return "return from bar from inside lambda" } f.call # control does not leave bar here return "return from bar" end def baz f = proc { return "return from baz from inside proc" } f.call # control does not leave bar here in 1.8, but does in 1.9 return "return from baz" end puts foo puts bar puts baz }}} ---------------------------------------- {{{ #!sh $ ruby blocks.rb return from foo from inside Proc.new return from bar return from baz $ ruby19 blocks.rb return from foo from inside Proc.new return from bar return from baz from inside proc $ macruby blocks.rb uncaught Objective-C/C++ exception... terminate called after throwing an instance of 'RoxorReturnFromBlockException*' Abort trap }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/412> MacRuby <http://macruby.org/>
#412: Calling return from a Proc raises an exception -------------------------------+-------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------+-------------------------------------------- Comment(by lsansonetti@…): Looks like #call is dispatched outside the return-from-block handler. {{{ $ gdb --args ./miniruby -e "proc { return 42 }.call" GNU gdb 6.3.50-20050815 (Apple version gdb-1344) (Fri Jul 3 01:19:56 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ......... done (gdb) r Starting program: /Users/lrz/src/macruby-trunk/miniruby -e proc\ \{\ return\ 42\ \}.call Reading symbols for shared libraries .++++++++.................... done uncaught Objective-C/C++ exception... terminate called after throwing an instance of 'RoxorReturnFromBlockException*' Program received signal SIGABRT, Aborted. 0x00007fff80158096 in __kill () (gdb) p RoxorCompiler::module->dump() ; ModuleID = 'Roxor' target triple = "x86_64-apple-darwin" define i64 @__ruby_scope(i64 %self, i8* %sel) { MainBlock: %0 = tail call i8* (i8*, i32, i64, i64, i8**, i8*, i32, ...)* @rb_vm_prepare_block(i8* inttoptr (i64 4311691648 to i8*), i32 0, i64 %self, i64 0, i8** null, i8* null, i32 0, i32 0) ; <i8*> [#uses=1] %1 = invoke i64 (i8*, i64, i64, i8*, i8*, i8, i32, ...)* @rb_vm_dispatch(i8* inttoptr (i64 4311694496 to i8*), i64 %self, i64 %self, i8* inttoptr (i64 4311539472 to i8*), i8* %0, i8 2, i32 0) to label %normal unwind label %return-from-block ; <i64> [#uses=1] return-from-block: ; preds = %MainBlock %2 = tail call i8* @llvm.eh.exception() ; <i8*> [#uses=2] %3 = tail call i64 (i8*, i8*, ...)* @llvm.eh.selector.i64(i8* %2, i8* bitcast (i8* ()* @__gxx_personality_v0 to i8*), i8* null) ; <i64> [#uses=0] %4 = tail call i8* @__cxa_begin_catch(i8* %2) ; <i8*> [#uses=1] %5 = tail call i64 @rb_vm_check_return_from_block_exc(i8* %4, i32 0) ; <i64> [#uses=2] %6 = icmp eq i64 %5, 6 ; <i1> [#uses=1] br i1 %6, label %rethrow, label %ret normal: ; preds = %MainBlock %7 = tail call i64 (i8*, i64, i64, i8*, i8*, i8, i32, ...)* @rb_vm_dispatch(i8* inttoptr (i64 4311690384 to i8*), i64 %self, i64 %1, i8* inttoptr (i64 140735458816510 to i8*), i8* null, i8 0, i32 0) ; <i64> [#uses=1] ret i64 %7 ret: ; preds = %return-from- block tail call void @__cxa_end_catch() ret i64 %5 rethrow: ; preds = %return-from- block tail call void @__cxa_rethrow() unreachable } define i64 @__ruby_scope1(i64 %self, i8* %sel, i64** %dvars, i8* %running_block) { MainBlock: tail call void @rb_vm_return_from_block(i64 169, i32 0) ret i64 169 } declare void @rb_vm_return_from_block(i64, i32) declare i8* @rb_vm_prepare_block(i8*, i32, i64, i64, i8**, i8*, i32, ...) declare i64 @rb_vm_dispatch(i8*, i64, i64, i8*, i8*, i8, i32, ...) declare i8* @llvm.eh.exception() nounwind declare i64 @llvm.eh.selector.i64(i8*, i8*, ...) nounwind declare i8* @__gxx_personality_v0() declare i8* @__cxa_begin_catch(i8*) declare i64 @rb_vm_check_return_from_block_exc(i8*, i32) declare void @__cxa_end_catch() declare void @__cxa_rethrow() $1 = void }}} Note that this is a problem with Proc#call. Calling return from a non-Proc block should work. I altered the title. -- Ticket URL: <http://www.macruby.org/trac/ticket/412#comment:2> MacRuby <http://macruby.org/>
#412: Calling return from a Proc raises an exception -------------------------------+-------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------+-------------------------------------------- Comment(by mike@…): I get the exception when calling return from a lambda as well. {{{ $ macruby -e "lambda { return 'hi' }.call" uncaught Objective-C/C++ exception... terminate called after throwing an instance of 'RoxorReturnFromBlockException*' Abort trap }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/412#comment:3> MacRuby <http://macruby.org/>
#412: Calling return from a Proc raises an exception -------------------------------+-------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------+-------------------------------------------- Comment(by lsansonetti@…): Yes, a lambda is a Proc too. {{{ $ ./miniruby -e "def foo; 1.times { return 42 }; end; p foo" 42 }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/412#comment:4> MacRuby <http://macruby.org/>
#412: Calling return from a Proc raises an exception -------------------------------+-------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------+-------------------------------------------- Comment(by mike@…): Ah, I see what you mean. You are right of course. :) -- Ticket URL: <http://www.macruby.org/trac/ticket/412#comment:5> MacRuby <http://macruby.org/>
#412: Calling return from a Proc raises an exception -------------------------------+-------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.5 Component: MacRuby | Resolution: fixed Keywords: | -------------------------------+-------------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.5 Comment: Should be fixed as of r2935: {{{ $ ./miniruby t.rb return from foo from inside Proc.new return from bar return from baz from inside proc }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/412#comment:6> MacRuby <http://macruby.org/>
#412: Calling return from a Proc raises an exception -------------------------------+-------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.5 Component: MacRuby | Resolution: fixed Keywords: | -------------------------------+-------------------------------------------- Comment(by conradwt@…): In Ruby 1.9, lambda produces a different variant of the Proc object than Proc.new. Also, proc is no longer a synonym for lambda. However, one can use proc as a synonym for Proc.new. -- Ticket URL: <http://www.macruby.org/trac/ticket/412#comment:7> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby