Smalltalk object trampling
Carl E Gundel
carlg at world.std.com
Fri Mar 6 19:02:51 UTC 1998
Thanks. I was able to blow up Smalltalk using become: as you describe,
but we aren't using become: in our code.
Any other ideas?
Thanks,
Carl
On Fri, 6 Mar 1998, Hans-Martin Mosner wrote:
> Carl E Gundel wrote:
<snip>
> > I am trying to construct an reproducible example where an object is
> > corrupted (via some context switching or recursion perhaps), usually
> > causing a protection violation (often revealed at garbage collection). I
> > have seen this in Smalltalk applications in the past, and suspect I am
> > seeing the same kind of problem now in our Smalltalk work.
> >
> > I need some example code to construct a note to our developers
> > illustrating how the problem happens, what to look for, and how to avoid
<snip>
> >
> One very easy way is to (ab)use the #become: operation.
> When you do a "self become: anotherObject" and access an inst var later
> which does not have a corresponding slot in the other object, you're
> likely
> getting into trouble. I've got bitten by this once in a database
> framework
> where objects were replaced by proxies after being committed to the
> database.
> Here's some code that has worked for me :-)
> Try to inspect the result of (3 at 4) gack for some fun.
> It does not always work on the first try, but should work sooner or
> later.
> The example is done with VisualWorks, but Squeak should show
> similar symptoms (probably when you access x instead of y).
>
> Hans-Martin
>
> !Point methodsFor: 'private'!
>
> gack
> "Try to produce an object memory corruption via #become:"
> "(3 at 4) gack"
> self gargle.
> ^y!
>
> gargle
> | t1 t2 |
> t1 := Object new.
> t2 := String new: 4.
> self become: t1.
> ^t2! !
>
> --
> +--- Hans-Martin Mosner ---- Senior Smalltalk Guru :-) ---+
> | These opinions are entirely ficticious. Any similarity |
> | to real opinions is purely coincidental and unintended. |
> +--- <hmm at heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+
>
------------------------------------------------------------------
Carl Gundel carlg at world.std.com Shoptalk Systems 508-872-5315
author of Liberty BASIC, a 1996 PC Magazine Awards Finalist!
http://world.std.com/~carlg/basic.html
------------------------------------------------------------------
More information about the Squeak-dev
mailing list
|