Bug #2745

iseq_set_sequence: adjust bug (next inside begin...rescue)

Added by murphy (Kornelius Kalnbach) over 2 years ago. Updated about 1 year ago.

[ruby-core:28172]
Status:Closed Start date:02/15/2010
Priority:Normal Due date:
Assignee:wanabe (_ wanabe) % Done:

100%

Category:core
Target version:1.9.2
ruby -v:ruby 1.9.2dev (2010-02-14 trunk 26664) [i386-darwin10.2.0]

Description

Input:
while true
  begin
    raise
    next
  rescue
  end
  break
end

Output:
-: [BUG] iseq_set_sequence: adjust bug
ruby 1.9.2dev (2010-02-14 trunk 26664) [i386-darwin10.2.0]

-- control frame ----------
c:0001 p:0000 s:0002 b:0002 l:000be4 d:000be4 TOP   
---------------------------

-- C level backtrace information -------------------------------------------
0   libruby19.1.9.1.dylib               0x00184ae5 rb_vm_bugreport + 229
1   libruby19.1.9.1.dylib               0x00040e3b report_bug + 379
2   libruby19.1.9.1.dylib               0x00040eec rb_bug + 44
3   libruby19.1.9.1.dylib               0x001578eb iseq_setup + 5179
4   libruby19.1.9.1.dylib               0x001635d7 rb_iseq_compile_node + 1607
5   libruby19.1.9.1.dylib               0x001698ff rb_iseq_new_with_bopt_and_opt + 159
6   libruby19.1.9.1.dylib               0x00169b6b rb_iseq_new_main + 107
7   libruby19.1.9.1.dylib               0x0010997e process_options + 2830
8   libruby19.1.9.1.dylib               0x00109c4b ruby_process_options + 155
9   libruby19.1.9.1.dylib               0x0004690f ruby_options + 127
10  ruby19                              0x00001f17 main + 87
11  ruby19                              0x00001e75 start + 53

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Abort trap

adjust_sp.patch (976 Bytes) wanabe (_ wanabe), 02/21/2010 04:28 pm

Associated revisions

Revision 27424
Added by mame (Yusuke Endoh) about 2 years ago

* compile.c (NODE_NEXT, NODE_REDO): add dummy putnil instruction to fix stack consistency error. [ruby-core:28172] * bootstraptest/test_jump.rb: add a test for above.

History

Updated by murphy (Kornelius Kalnbach) over 2 years ago

Note: It works without the "next".

Updated by murphy (Kornelius Kalnbach) over 2 years ago

I'm sorry, the ruby -v is:
ruby 1.9.2dev (2010-02-14 trunk 26664) [i386-darwin10.2.0]

Updated by wanabe (_ wanabe) over 2 years ago

  • Assignee set to ko1 (Koichi Sasada)
  • ruby -v changed from ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin9.8.0] to ruby 1.9.2dev (2010-02-14 trunk 26664) [i386-darwin10.2.0]

Updated by wanabe (_ wanabe) over 2 years ago

The bug doesn't occur with attached patch.

Updated by murphy (Kornelius Kalnbach) over 2 years ago

Yes, that solved it for me. Does this need to be backported to Ruby 1.9.1?

Updated by mame (Yusuke Endoh) about 2 years ago

  • Assignee changed from ko1 (Koichi Sasada) to wanabe (_ wanabe)
Hi, wanabe

Ko1 agreed with your patch.
I also agree, but it would be better to insert dummy putnil
immediately after ADJUST_RESTORE.


diff --git a/compile.c b/compile.c
index e96e34d..f1a04fe 100644
--- a/compile.c
+++ b/compile.c
@@ -3359,6 +3359,9 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
 	    ADD_ADJUST(ret, nd_line(node), iseq->compile_data->redo_label);
 	    ADD_INSNL(ret, nd_line(node), jump, iseq->compile_data->start_label);
 	    ADD_ADJUST_RESTORE(ret, splabel);
+	    if (!poped) {
+		ADD_INSN(ret, nd_line(node), putnil);
+	    }
 	}
 	else if (iseq->compile_data->end_label) {
 	    LABEL *splabel = NEW_LABEL(0);
@@ -3424,6 +3427,9 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
 	    add_ensure_iseq(ret, iseq, 0);
 	    ADD_INSNL(ret, nd_line(node), jump, iseq->compile_data->redo_label);
 	    ADD_ADJUST_RESTORE(ret, splabel);
+	    if (!poped) {
+		ADD_INSN(ret, nd_line(node), putnil);
+	    }
 	}
 	else if (iseq->type == ISEQ_TYPE_EVAL) {
 	  redo_in_eval:

-- 
Yusuke Endoh <mame@tsg.ne.jp>

Updated by wanabe (_ wanabe) about 2 years ago

> I also agree, but it would be better to insert dummy putnil
> immediately after ADJUST_RESTORE.

I fully agree. Please commit your patch.

Updated by mame (Yusuke Endoh) about 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r27424.
Kornelius, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF