Looking at the C++ implementation of the native method underlying that undocumented Object freeze
method, it sets the obj_permanent
flag (rather than the obj_immutable
one) on the object, i.e. PyrDeepFreezer::doDeepFreeze
calls BecomePermanent
.
So “freeze” seems to make the garbage collector ignore that object, but not actually make it immutable. I actually haven’t found a way to explicitly do the latter…
As an aside (or why I’m asking this), the logic of deepCopy
, which again has a C++ implementation (in PyrDeepCopier::constructObjectArray
) is to not copy any object that is both permanent and immutable.
if (!obj->IsMarked()) {
if (obj->obj_flags & (obj_immutable) && obj->obj_flags & (obj_permanent)) {
putSelf(obj);
// more "magic" cases that avoid copying Threads, Functions etc. (and I think thus their subclasses too)
} else {
putCopy(obj);
recurse(obj, obj->size);
}
}
I see there is a PyrGC::BecomeImmutable
too but it doesn’t seem to have any calls and thus any SC language mappings. (The obj_immutable
flag is set directly numerous times though in the C++ code.) So it looks like I can’t make an object immutable in a “clean” way, but it seems that I can do it by fakely subclassing Function for example, which has the same effect on deepCopy
.