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 <[hidden email]> 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. |
Free forum by Nabble | Edit this page |