[squeak-dev] primitiveClass infected after primitiveIdentityHash on wrong receiver

christoph.thiede at student.hpi.uni-potsdam.de christoph.thiede at student.hpi.uni-potsdam.de
Tue Dec 28 17:01:23 UTC 2021

Hi Eliot, Hi all,

the following snippet returns an unexpected result to me cross-platform (tested with 202112201228 on Win 21H1 and WSL/Ubuntu 18.04):

	ProtoObject tryPrimitive: 75 withArgs: #().
	thisContext objectClass: ProtoObject basicNew. "nil"

The example needs to be run in a fresh image. If primitiveBehaviorHash was sent to ProtoObject before, the bug does not occur:

	ProtoObject tryPrimitive: 175 withArgs: #().
	ProtoObject tryPrimitive: 75 withArgs: #().
	thisContext objectClass: ProtoObject basicNew. "ProtoObject"

I'm not sure whether this should be classified as a bug. On the one hand, the name and the implementors of primitiveIdentityHash make pretty clear that one should not invoke it with a behavior. On the other hand, incidents like this make the usage of primitives extremely hard.
I was writing a mirror primitive method that used primitiveIdentityHash in the first run and only falled back to primitiveBehaviorHash if the former failed [1]. Imagine how many hours it took me to trace a larger segfaulting test suite back to this unexpected behavior of primitiveClass. :-)
In my expectation, primitiveIdentityHash should consequently fail for unappropriate receivers. However, I have fixed my mirror implementation now and only wanted to let you know about this observation.


[1] Pointer if you want to read up to bloody details by yourself: https://github.com/LinqLover/SimulationStudio/pull/34/commits/0a55a8a23b6e842548049c07cbd96120a30cd06e

Sent from Squeak Inbox Talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211228/1a5f2489/attachment.html>

More information about the Squeak-dev mailing list