[squeak-dev] Tracing proxies

Levente Uzonyi leves at elte.hu
Thu May 26 19:35:54 UTC 2011


On Thu, 26 May 2011, Chris Muller wrote:

>>> If so, that's very nicely elegant.  At first, I was hoping this
>>> approach would allow Magma a chance to handle the problem of passing a
>>> proxy to a primitive, rather than the user having to send a #yourself,
>>> but it doesn't look like it would help for that.
>>
>> If we add this package to the Trunk, then we will be able to identify these
>> kind of proxies in the arguments of primitive calls when they fail and retry
>> the primitive with the real objects. This should help in most cases.
>
> I'm not opposed to adding this package to trunk, but I guess we could
> do that even if we didn't add it trunk by sending #yourself couldn't
> we?  For example, for Object>>#perform:
>
> perform: aSymbol
> 	"Send the unary selector, aSymbol, to the receiver.
> 	Fail if the number of arguments expected by the selector is not zero.
> 	Primitive. Optional. See Object documentation whatIsAPrimitive."
>
> 	<primitive: 83>
> 	^ self perform: aSymbol yourself withArguments: (Array new: 0)

This wouldn't work, because either not all primitives work with proxies 
(not all of them send #yourself), or there will be infinite recursion if 
the primitive keeps failing (e.g. the argument is nil).

>
> Would would the solution look like (approximately) using
> stratified-proxys approach?  I thought this is nice because it doesn't
> necessarily assume the primitive failed because aSymbol was a proxy..

Let's say we have a MutatingProxy class (a subclass of 
MessageCatchingProxy) and all mutating proxies are subinstances of this 
class. This way all mutating proxies have something common we can check. 
Since the #class method won't be a real message send, therefore something 
like the following will work for all primitives:

perform: aSymbol

 	<primitive: 83>
 	(aSymbol class inheritsFrom: MutatingProxy) ifTrue: [
 		^self perform: aSymbol someMethodThatReturnsTheRealObject ].
 	self primitiveFail


Levente

>
> Whatever the solution, I am ready to do something soon; I have several
> #yourself sends sprinkled throughout my code to avoid the situation,
> which is annoying.
>


More information about the Squeak-dev mailing list