[Vm-dev] intAt from sqMemoryAccess.h does not extend sign

David T. Lewis lewis at mail.msen.com
Tue Nov 8 13:23:04 UTC 2016

On Tue, Nov 08, 2016 at 03:29:05AM +0100, Nicolas Cellier wrote:
> In this code:
>   static inline sqInt intAtPointer(char *ptr)   { return
> (sqInt)(*((unsigned int *)ptr)); }
>   static inline sqInt intAtPointerput(char *ptr, int val)  { return
> (sqInt)(*((unsigned int *)ptr)= val); }
> the usage of unsigned int is questionable...
> It means that intAt and long32At won't perform sign extension in 64bits
> Spur VM.
> Since it returns a signed result (sqInt), that's troubling.
> The sole real sender of intAt seems to be primitiveIntegerAt: which fails
> for this reason on 64bits spur when fed with negative integers.

Can you give an example of the failure? I tried on 64-bit Spur and also
on image format 68002 (64-bit V3) on Linux, and the accesses to elements
of an IntegerArray work correctly in both cases.

For example:

{ -1 . -2 . -3 . -4 . 7 . -9 } asIntegerArray ==> an IntegerArray(-1 -2 -3 -4 7 -9)

Accessing the elements of this IntegerArray works as expected, and I can see
in an inspector that the first element is stored internally as 16rFFFFFFFF.

Is there something else that is failing?


> For long32At, it's difficult to analyze: many senders!
> IMO, if we don't want a signed quantity, we should better write
> unsignedLong32At (or use lowcode uint32AtPointer which answers a 32 bits
> result)

More information about the Vm-dev mailing list