[Bug #513] Tempfile yields [BUG] Stack consistency error

Bug #513: Tempfile yields [BUG] Stack consistency error
http://redmine.ruby-lang.org/issues/show/513

e$B5/I<<Te(B: Shyouhei U.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$BC4Ev<Te(B: Koichi Sasada, e$B%+%F%4%je(B: YARV

zsh % gdb --args ~/target/trunk/bin/ruby -rtempfile -ve
Tempfile.open(“”) do |f|
f.write “\n”;
f.rewind;
g = Tempfile.new “”;
f.each {break};
g.rewind;
end

GNU gdb 6.4.90-debian
Copyright (C) 2006 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-linux-gnu”…Using host libthread_db
library “/lib/libthread_db.so.1”.

(gdb) run
Starting program: /home/shyouhei/target/trunk/bin/ruby -rtempfile -ve
Tempfile.open("")\ do\ |f|
\ f.write\ "\n";
\ f.rewind;
\ g\ =\ Tempfile.new\ "";
\ f.each\ {break};
\ g.rewind;
end\

[Thread debugging using libthread_db enabled]
[New Thread 47466447361456 (LWP 21474)]
[New Thread 1073756512 (LWP 21477)]
ruby 1.9.0 (2008-08-28 revision 17576) [x86_64-linux]
-e:1: [BUG] Stack consistency error (sp: 16, bp: 15)
ruby 1.9.0 (2008-08-28 revision 17576) [x86_64-linux]

– control frame ----------
c:0005 p:0070 s:0016 b:0015 l:000148 d:0001d8 BLOCK -e:1
c:0004 p:0035 s:0011 b:0011 l:000010 d:000010 METHOD
/home/shyouhei/target/trunk/lib/ruby/1.9.0/tempfile.rb:186
c:0003 p:0017 s:0006 b:0006 l:000148 d:000148 TOP -e:1
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
:private_class_method
c:0001 p:0000 s:0002 b:0002 l:000001 d:000001 TOP

DBG> : “-e:1:in block in <main>'" DBG> : "/home/shyouhei/target/trunk/lib/ruby/1.9.0/tempfile.rb:186:in open’”
DBG> : “-e:1:in `'”
– backtrace of native function call (Use addr2line) –
0x4f5b51
0x51fa2f
0x51fb1f
0x4ee38f
0x4f2b2d
0x4f3337
0x41682f
0x4168de
0x415007
0x316ca1c4ca
0x414f1a

Program received signal SIGABRT, Aborted.
[Switching to Thread 47466447361456 (LWP 21474)]
0x000000316ca2f07b in raise () from /lib/libc.so.6
(gdb) bt
#0 0x000000316ca2f07b in raise () from /lib/libc.so.6
#1 0x000000316ca3084e in abort () from /lib/libc.so.6
#2 0x000000000051fb24 in rb_bug (fmt=0x564d80 “Stack consistency error
(sp: %ld, bp: %ld)”) at /home/shyouhei/ruby/trunk/error.c:226
#3 0x00000000004ee38f in vm_eval (th=0x6f0110, initial=0) at
/home/shyouhei/ruby/trunk/insns.def:1061
#4 0x00000000004f2b2d in vm_eval_body (th=0x6f0110) at
/home/shyouhei/ruby/trunk/vm.c:1062
#5 0x00000000004f3337 in rb_iseq_eval (iseqval=10262960) at
/home/shyouhei/ruby/trunk/vm.c:1267
#6 0x000000000041682f in ruby_exec_node (n=0x9c99b0, file=0x0) at
/home/shyouhei/ruby/trunk/eval.c:217
#7 0x00000000004168de in ruby_run_node (n=0x9c99b0) at
/home/shyouhei/ruby/trunk/eval.c:245
#8 0x0000000000415007 in main (argc=4, argv=0x7fff05ef52b8) at
/home/shyouhei/ruby/trunk/main.c:34
(gdb)

e$B1sF#$G$9!#e(B

2008/08/28 11:18 Shyouhei U. [email protected]:

zsh % gdb --args ~/target/trunk/bin/ruby -rtempfile -ve
Tempfile.open(“”) do |f|
f.write “\n”;
f.rewind;
g = Tempfile.new “”;
f.each {break};
g.rewind;
end

(snip)
-e:1: [BUG] Stack consistency error (sp: 16, bp: 15)
(snip)

e$B4JC1$K$G$-$^$7$?!#e(B

$ ./ruby -e ’
class Foo
define_method(:foo) do |&b|
b.call
end
end

Foo.new.foo do
break
end

-e:8: [BUG] Stack consistency error (sp: 7, bp: 6)
ruby 1.9.0 (2008-08-28 revision 18895) [i686-linux]

– control frame ----------
c:0003 p:0032 s:0007 b:0006 l:001084 d:001084 TOP -e:8
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
:private_class_method
c:0001 p:0000 s:0002 b:0002 l:000001 d:000001 TOP :17

DBG> : “-e:8:in `'”
– backtrace of native function call (Use addr2line) –
0x8112df4
0x813e18e
0x813e1d8
0x810bc5f
0x810c3a4
0x810c58c
0x805aa3f
0x805bd46
0x8058e70
0xb7e21ea8
0x8058d51

Aborted

BMETHOD e$BCf$Ge(B throw e$B$9$k2DG=@-$,$"$k$N$G!"e(BBMETHOD
e$B$r8F$S=P$9A0$Ke(B
e$B%9%?%C%/$r=L$a$k$Y$-$+$H;W$$$^$9!#e(B

Index: vm_insnhelper.c

— vm_insnhelper.c (revision 18895)
+++ vm_insnhelper.c (working copy)
@@ -519,8 +519,8 @@
}
case NODE_BMETHOD:{
VALUE *argv = cfp->sp - num;

  • cfp->sp += - num - 1;
    val = vm_call_bmethod(th, id, node->nd_cval, recv, klass, num,
    argv, blockptr);
  • cfp->sp += - num - 1;
    break;
    }
    case NODE_ZSUPER:{

e$B1sF#$G$9!#e(B

2008/08/28 21:40 Yukihiro M. [email protected]:

|— vm_insnhelper.c (revision 18895)
|+++ vm_insnhelper.c (working copy)

e$B%3%_%C%H$7$F$/$@$5$$!#e(B

e$B$9$$^$;$s!"$3$N%Q%C%A$@$He(B make test e$B$,DL$j$^$;$s$G$7$?!#e(B
e$B0J2<$N%Q%C%A$Ge(B make test && make test-all e$B$,DL$C$?$N$G!“e(B
e$B$H$j$”$($:%3%
%C%H$7$F$*$-$^$9!#e(B

Index: vm_insnhelper.c

— vm_insnhelper.c (revision 18897)
+++ vm_insnhelper.c (working copy)
@@ -519,8 +519,19 @@
}
case NODE_BMETHOD:{
VALUE *argv = cfp->sp - num;

  • val = vm_call_bmethod(th, id, node->nd_cval, recv, klass, num,
    argv, blockptr);
  • int state;
  • TH_PUSH_TAG(th);
  • if ((state = EXEC_TAG()) == 0) {
  •    val = vm_call_bmethod(th, id, node->nd_cval, recv, klass, num,
    

argv, blockptr);

  • }
  • TH_POP_TAG();
  • cfp->sp += - num - 1;
  • if (state) {
  •    JUMP_TAG(state);
    
  • }
    break;
    }
    case NODE_ZSUPER:{

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:36029] Re: [Bug #513] Tempfile yields [BUG]
Stack consistency error”
on Thu, 28 Aug 2008 20:52:05 +0900, “Yusuke ENDOH” [email protected]
writes:

|BMETHOD e$BCf$Ge(B throw e$B$9$k2DG=@-$,$"$k$N$G!"e(BBMETHOD e$B$r8F$S=P$9A0$Ke(B
|e$B%9%?%C%/$r=L$a$k$Y$-$+$H;W$$$^$9!#e(B
|
|Index: vm_insnhelper.c
|===================================================================
|— vm_insnhelper.c (revision 18895)
|+++ vm_insnhelper.c (working copy)

e$B%3%_%C%H$7$F$/$@$5$$!#e(B

e$B1sF#$G$9!#e(B

2008/08/28 23:09 Yusuke ENDOH [email protected]:

|
e$B$H$j$“$($:%3%%C%H$7$F$*$-$^$9!#e(B
e$B$H8@$C$?$P$+$j$G$9$,!"$5$5$@$5$s$,$b$&$A$g$C$H6l$7$
$?$$$H$Ne(B
e$B$3$H$J$N$G!”%F%9%H$@$1F~$l$k$3$H$K$7$^$9!#e(B

e$B%A%1%C%He(B #513 e$B$,99?7$5$l$^$7$?!#e(B (by Koichi Sasada)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

Applied in changeset r18918.

http://redmine.ruby-lang.org/issues/show/513