[Pharo-project] I am missing userful functionality?
Hello, guys i want to do a simple thing, which can be expressed by following: oldClass replaceWith: newClass migrateInstances: [:inst | ... ] In my case, first, i installing a WeakFinalizationRegistry class, and then want to replace an old WeakRegistry class with it, silently and painlessly. I end up with following script: | old new oldClass newClass | old := OrderedCollection new. new := OrderedCollection new. "migrate instances" WeakRegistry allInstancesDo: [:registry | | newr | old add: registry. newr := WeakFinalizationRegistry basicNew initialize. registry migrateTo: newr. new add: newr ]. old asArray elementsForwardIdentityTo: new asArray. "replace the class" oldClass := WeakRegistry. newClass := WeakFinalizationRegistry. Smalltalk forgetClass: #WeakFinalizationRegistry logged: false. newClass superclass removeSubclass: newClass. newClass setName: #WeakRegistry. oldClass becomeForward: newClass. -- it looks a bit hackish, and i wonder how to do that in more 'standard' way. Initially replacing classes was: oldClass removeFromSystem. newClass rename: #WeakRegistry the problem with that, is that all compiled methods , which was referring to old class through association, still using it, and to get rid of them i have to recompile them. -- Best regards, Igor Stasenko AKA sig.
One more variant (not sure if its a bug-free) oldBinding := Smalltalk associationAt: #WeakRegistry. WeakRegistry removeFromSystem. WeakFinalizationRegistry rename: #WeakRegistry. oldBinding becomeForward: (Smalltalk associationAt: #WeakRegistry). On 23 September 2010 01:02, Igor Stasenko <siguctua@gmail.com> wrote:
Hello, guys
i want to do a simple thing, which can be expressed by following:
oldClass replaceWith: newClass migrateInstances: [:inst | Â ... ]
In my case, first, i installing a WeakFinalizationRegistry class, and then want to replace an old WeakRegistry class with it, silently and painlessly.
I end up with following script:
 | old new oldClass newClass |     old := OrderedCollection new.     new := OrderedCollection new.
"migrate instances" WeakRegistry allInstancesDo: [:registry | | newr | Â Â Â Â Â Â Â Â old add: registry. Â Â Â Â Â Â Â Â newr := WeakFinalizationRegistry basicNew initialize. Â Â Â Â Â Â Â Â registry migrateTo: newr. Â Â Â Â Â Â Â Â new add: newr ]. Â Â Â Â old asArray elementsForwardIdentityTo: new asArray.
"replace the class"
    oldClass := WeakRegistry.     newClass := WeakFinalizationRegistry.
    Smalltalk forgetClass: #WeakFinalizationRegistry logged: false.     newClass superclass removeSubclass: newClass.     newClass setName: #WeakRegistry.     oldClass becomeForward: newClass.
--
it looks a bit hackish, and i wonder how to do that in more 'standard' way.
Initially replacing classes was:
 oldClass removeFromSystem.  newClass rename: #WeakRegistry
the problem with that, is that all compiled methods , which was referring to old class through association, still using it, and to get rid of them i have to recompile them.
-- Best regards, Igor Stasenko AKA sig.
-- Best regards, Igor Stasenko AKA sig.
participants (1)
-
Igor Stasenko