On Fri, 6 Jan 2012, Mariano Martinez Peck wrote:

Hi guys. Levente recommended us to integrate the new version of #pointsTo:,
and I did it. But not I think I found a bug. The method is:

pointsTo: anObject
"Answers true if I hold a reference to anObject, or false otherwise. Or
stated another way:

Answers true if the garbage collector would fail to collect anObject
because I hold a reference to it, or false otherwise"

   ^ (self instVarsInclude: anObject)
       or: [self class == anObject]


The problem is that if the receiver is an instance of a compact class, this
method answers true to:
'aaa' pointsTo: ByteString
and I think that's incorrect.  Moreoever, you can read the comment of the
method "Or stated another way: Answers true if the garbage collector would
fail to collect anObject because I hold a reference to it, or false
otherwise"
That's not true for compact classes.

With this change:

pointsTo: anObject
"Answers true if I hold a reference to anObject, or false otherwise. Or
stated another way:

Answers true if the garbage collector would fail to collect anObject
because I hold a reference to it, or false otherwise"

   ^ (self instVarsInclude: anObject)
       or: [(self class indexIfCompact = 0) and: [self class == anObject] ]

it works fine.

Do you agree with the change?

Of course, but I'd check for the class equality first, because it's faster (yeah, i know you turned off inlining of #class, but Cog doesn't care about that ;)). Another thing that you should add (besides tests of course) is SmallInteger >> #pointsTo: which should return false. Also make sure that pointer tracing tools use #pointsTo:. In Squeak I found that some of them "reinvented" this method...


Levente


cheers

--
Mariano
http://marianopeck.wordpress.com


Reply via email to