OpenStruct, OpenObject both seg fault, this does not, anything wrong?

A

aktxyz

Ok, I am using 1.8.6 p110 with rails 1.2.5 and I use alot of
OpenStructs.
Well, it seg faults pretty regularly:
0.upto(100) {|n| member.driver_process_member}
/usr/lib/ruby/1.8/ostruct.rb:75: [BUG] Segmentation fault
ruby 1.8.6 (2007-09-23) [i686-linux]


So I tried ruby 1.8.5, same thing.
So I tried OpenObject in the facets lib, seg faults in a different
place now:
/usr/lib/ruby/gems/1.8/gems/facets-2.1.1/lib/more/facets/openobject.rb:
183: [BUG] Segmentation fault
ruby 1.8.5 (2006-08-25) [i686-linux]

class HashDot < Hash
def method_missing(sym, arg=nil)
type = sym.to_s[-1,1]
key = sym.to_s.sub(/[=?!]$/,'').to_sym
if type == "="
self[key] = arg
return self[key]
else
return self[key]
end
end
end

So I created this minimalist class that extends hash, and it does not
segfault.
The questions are:
- how to figure out what's wrong with OpenStruct (I am not a gdb guy
but could follow instructions)
- why is the source for OpenStruct and OpenObject so complicated
(compared to HashDot)?
 
T

Trans

Ok, I am using 1.8.6 p110 with rails 1.2.5 and I use alot of
OpenStructs.
Well, it seg faults pretty regularly:
0.upto(100) {|n| member.driver_process_member}
/usr/lib/ruby/1.8/ostruct.rb:75: [BUG] Segmentation fault
ruby 1.8.6 (2007-09-23) [i686-linux]

So I tried ruby 1.8.5, same thing.
So I tried OpenObject in the facets lib, seg faults in a different
place now:

/usr/lib/ruby/gems/1.8/gems/facets-2.1.1/lib/more/facets/openobject.rb:
183: [BUG] Segmentation fault
ruby 1.8.5 (2006-08-25) [i686-linux]

class HashDot < Hash
def method_missing(sym, arg=nil)
type = sym.to_s[-1,1]
key = sym.to_s.sub(/[=?!]$/,'').to_sym
if type == "="
self[key] = arg
return self[key]
else
return self[key]
end
end
end

So I created this minimalist class that extends hash, and it does not
segfault.
The questions are:
- how to figure out what's wrong with OpenStruct (I am not a gdb guy
but could follow instructions)
- why is the source for OpenStruct and OpenObject so complicated
(compared to HashDot)?

They both remove as many Kernel methods as they possibly can in order
to make the objects as "open" as possible. So my guess is, this must
be arising from a method that Ruby is expecting to exist (as public)
but that both classes are clobbering. The question then is which one.
To help out this is what OpenObject does.

PUBLIC_METHODS = /(^__|^instance_|^object_|^\W|^as$|^send$|^class$|\?
$)/

protected *public_instance_methods.select{ |m| m !~ PUBLIC_METHODS }

T.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top