Kernel.eval("local_variables",binding) bug in Ruby 1.9

H

Howard Yeh

Hi,

My ruby runtime is "ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-
linux]"

Kernel eval works for these cases:

puts "2 times"
1.times do
a = 1
p Kernel.eval("local_variables",binding)
end

puts "while"
while true
a = 1
p Kernel.eval("local_variables",binding)
break
end

puts "lambda"
lambda {
a=1
p Kernel.eval("local_variables",binding)
}.call


But I get a segfault with

for i in 1..100
a = 1
p Kernel.eval("local_variables",binding)
break
end

But you can try,

for i in 1..100
a = 1
r = Kernel.eval("local_variables",binding)
p r.length # => 4, but should be 3
p r[1..-1] # => [:i,:a,:r]
p r.first.class # => Symbol
p r.first.object_id # => 4087
p r.first # segfault
break
end

And we see that there's an extraneous variable reported by evaluating
local_variables. The first element of the result seems an invalid
pointer?

for i in 1..100
p Kernel.eval("local_variables") # this works
break
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top