Bug #513

Tempfile yields [BUG] Stack consistency error

Added by Shyouhei Urabe over 6 years ago. Updated almost 4 years ago.

[ruby-dev:36028]
Status:Closed
Priority:Normal
Assignee:Koichi Sasada
ruby -v: Backport:

Description

=begin
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)
=end

History

#1 Updated by Yusuke Endoh over 6 years ago

=begin
遠藤です。

2008/08/28 11:18 Shyouhei Urabe redmine@ruby-lang.org:

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)

簡単にできました。

$ ./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 中で throw する可能性があるので、BMETHOD を呼び出す前に
スタックを縮めるべきかと思います。

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:{

--
Yusuke ENDOH mame@tsg.ne.jp

=end

#2 Updated by Yukihiro Matsumoto over 6 years ago

=begin
まつもと ゆきひろです

In message "Re: Re: [Bug #513] Tempfile yields [BUG] Stack consistency error"
on Thu, 28 Aug 2008 20:52:05 +0900, "Yusuke ENDOH" mame@tsg.ne.jp writes:

|BMETHOD 中で throw する可能性があるので、BMETHOD を呼び出す前に
|スタックを縮めるべきかと思います。
|
|Index: vm_insnhelper.c
|===================================================================
|--- vm_insnhelper.c (revision 18895)
|+++ vm_insnhelper.c (working copy)

コミットしてください。

=end

#3 Updated by Yusuke Endoh over 6 years ago

=begin
遠藤です。

2008/08/28 21:40 Yukihiro Matsumoto matz@ruby-lang.org:

まつもと ゆきひろです

In message "Re: Re: [Bug #513] Tempfile yields [BUG] Stack consistency error"
on Thu, 28 Aug 2008 20:52:05 +0900, "Yusuke ENDOH" mame@tsg.ne.jp writes:

|BMETHOD 中で throw する可能性があるので、BMETHOD を呼び出す前に
|スタックを縮めるべきかと思います。
|
|Index: vm_insnhelper.c
|===================================================================
|--- vm_insnhelper.c (revision 18895)
|+++ vm_insnhelper.c (working copy)

コミットしてください。

すみません、このパッチだと make test が通りませんでした。
以下のパッチで make test && make test-all が通ったので、
とりあえずコミットしておきます。

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:{

--
Yusuke ENDOH mame@tsg.ne.jp

=end

#4 Updated by Yusuke Endoh over 6 years ago

=begin
遠藤です。

2008/08/28 23:09 Yusuke ENDOH mame@tsg.ne.jp:

遠藤です。

2008/08/28 21:40 Yukihiro Matsumoto matz@ruby-lang.org:

まつもと ゆきひろです

In message "Re: Re: [Bug #513] Tempfile yields [BUG] Stack consistency error"
on Thu, 28 Aug 2008 20:52:05 +0900, "Yusuke ENDOH" mame@tsg.ne.jp writes:

|BMETHOD 中で throw する可能性があるので、BMETHOD を呼び出す前に
|スタックを縮めるべきかと思います。
|
|Index: vm_insnhelper.c
|===================================================================
|--- vm_insnhelper.c (revision 18895)
|+++ vm_insnhelper.c (working copy)

コミットしてください。

すみません、このパッチだと make test が通りませんでした。
以下のパッチで make test && make test-all が通ったので、
とりあえずコミットしておきます。

と言ったばかりですが、ささださんがもうちょっと苦しみたいとの
ことなので、テストだけ入れることにします。

--
Yusuke ENDOH mame@tsg.ne.jp

=end

#5 Updated by Koichi Sasada over 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r18918.
=end

Also available in: Atom PDF