[Vm-dev] Problem with Proxies, objects and MethoDict

Igor Stasenko siguctua at gmail.com
Wed Sep 29 20:23:47 UTC 2010


On 29 September 2010 16:12, Mariano Martinez Peck <marianopeck at gmail.com> wrote:
>
>
>
> On Tue, Sep 28, 2010 at 11:12 PM, Igor Stasenko <siguctua at gmail.com> wrote:
>>
>>
>> Here it is.
>> Just be aware, that its not intercepting all messages.
>> Some messages like #== or #class is early bound by compiler/VM,
>> so even if you redefine them, their behavior won't be changed.
>>
>
> Thanks Igor. I am trying to understand your code.
> Now...how I should use MessageCatchingProxy ?
>
> how can I adapt this code to use your proxy?
>
Just subclass it, and override #handleMessage: forProxy:
where you can send a message to other object or do something else.

Then you can wrap some object with it:

wrapped := MyProxy wrap: myclass.



> | o p |
> o := MyClass new.
> o foo: 123.
> p := ClassProxy3 new.
> p become: MyClass.
> MyClass flushCache.
> ClassProxy3 flushCache.
> o == nil.
> Transcript show: o class name; cr.
> o foo.
>
>
> thanks a lot
>
> mariano
>
>
>>
>> (I forgot where to get the list of these exceptional selectors).
>> Smalltalk specialSelectors seems like not the same thing.
>
>
>
>
>>
>> On 28 September 2010 23:48, Bert Freudenberg <bert at freudenbergs.de> wrote:
>> >
>> >
>> > On 28.09.2010, at 22:29, Mariano Martinez Peck wrote:
>> >
>> > Hi folks. I am trying to do something and I found a VM crash. Suppose I want to swap out a class, do a become with a proxy (that with the DNU will load the class back). In addition, I have instances of the swapped class.
>> >
>> > Example of code (will crash in the last line):
>> >
>> > o := MyObject new.
>> > o foo: 123.
>> > p := ClassProxy new.
>> > p become: MyObject.
>> > o == nil.
>> > o foo.
>> >
>> >
>> > My Object just extends Object, has an instVar 'foo',  and implements the accessors.
>> >
>> > ClassProxy implements:
>> >
>> > become: aClass
>> >     className := aClass name.
>> >     aClass fileOut.
>> >     super become: aClass
>> >
>> > and
>> >
>> > doesNotUnderstand: aMessage
>> >     | reloadedClass |
>> >     (FileStream fileNamed: className, '.st') fileIn.
>> >     reloadedClass := Smalltalk at: className.
>> >     self becomeForward: reloadedClass.
>> >     ^aMessage sendTo: reloadedClass
>> >
>> >
>> > So....does someone know why the crash?
>> >
>> > Looks like o's class pointer does not point to a class after the become. When the VM tries to lookup #foo in o's class it crashes.
>> >
>> > how can I solve it ?
>> >
>> > I'd say you cannot get rid of a class if there are still instances of it. You can stub out the class however. If the method dict is nil, the VM will send cannotInterpret: if you send a message to an instance. You should be able to use that instead of #doesNotUnderstand:.
>> > - Bert -
>> >
>> >
>> >
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.


More information about the Vm-dev mailing list