I am missing userful functionality?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

I am missing userful functionality?

Igor Stasenko
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.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: I am missing userful functionality?

Igor Stasenko
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.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: I am missing userful functionality?

Stéphane Ducasse
In reply to this post by Igor Stasenko
Hi igor

I cannot help but indeed we need a real brand new classbuilder
with a nice MOP for instance migrating too. We will start to work on that probably december/january.

Stef
On Sep 23, 2010, at 12:03 AM, Igor Stasenko 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.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project