Newbie trying to make Module.freeze prevent singleton methods being added

13 views
Skip to first unread message

Aviv Ben-Yosef

unread,
Jun 17, 2011, 3:43:32 AM6/17/11
to rubinius-dev
Hey,

I'm fascinated by the project and so decided to try and to some small
stuff. After getting a trivial fix committed, I tried to find
something a bit more challenging, but I may have taken a bite a bit
too big.
Would love some direction about whether my steps are in the right path
and if this is indeed feasible without knowing too much of rubinius's
guts.

I saw that this spec fails: "Module#freeze prevents further
modifications to self"
It basically checks that after freezing a module, trying to define
singleton method on it raises a TypeError.

After some digging and comparing to the MRI I understood that while
MRI freezes the singleton class after freezing an object, rubinius
doesn't.
"Aha!", I thought. After digging, I ended up adding a simple change to
Object#singleton_class, something along the lines of:
if (this->frozen_p(state) == Qtrue) cl->freeze(state);

This seems to achieve the right result of freezing the singleton
classes just like MRI, but then I found out it doesn't seem like
there's any guard to stop you from adding methods to frozen classes.

What would be the right way to continue from this point? I've tried
adding a trivial guard in Rubinius#add_method that raises the proper
error in case it was called on a frozen object, but then found out
add_method is currently called for lots of frozen objects, which
breaks everything pretty much.

Any directions/suggestions would be really appreciated. Especially if
I'm just making a big mess :)

Cheers,
Aviv Ben-Yosef
@avivby http://codelord.net
Reply all
Reply to author
Forward
0 new messages