Hi,

At Tue, 10 Mar 2009 04:26:51 +0900,
Wolfgang N=E1dasi-Donner wrote in [ruby-core:22785]:
> Afterwards I rebuilt Ruby, but the stack overflow for both examples I=20
> posted before are still there.
>=20
> Should I change additional things in the source?

trace_instruction option prevents the optimization.

$ cat ~/tmp/tailcall.rb
#! /usr/bin/ruby
src, file, line =3D <<SRC, __FILE__, __LINE__+1
def a(n)
  return if (n -=3D 1) <=3D 0
  a(n)
end
SRC
tailcallopt =3D ARGV[0] =3D=3D "true"
traceinst =3D ARGV[1] !=3D "false"
puts "tailcall_optimization: #{tailcallopt}, trace_instruction: #{traceinst=
}"
iseq =3D RubyVM::InstructionSequence.new(src, file, line,
                                       tailcall_optimization: tailcallopt,
                                       trace_instruction: traceinst)
iseq.eval
begin
  a(1000000)
  puts :ok
rescue SystemStackError =3D> e
  puts "#{e.class} #{e.backtrace.size}"
end

$ ./ruby ~/tmp/tailcall.rb=20
tailcall_optimization: false, trace_instruction: true
SystemStackError 8187

$ ./ruby ~/tmp/tailcall.rb true=20
tailcall_optimization: true, trace_instruction: true
SystemStackError 8187

$ ./ruby ~/tmp/tailcall.rb true false
tailcall_optimization: true, trace_instruction: false
ok

--=20
Nobu Nakada