[squeak-dev] ByteArray>>at:put:

Bert Freudenberg bert at freudenbergs.de
Thu Jul 20 10:46:36 UTC 2017


On Wed, Jul 19, 2017 at 11:16 PM, Eliot Miranda <eliot.miranda at gmail.com>
wrote:

> Hi Bert,
>
> On Wed, Jul 19, 2017 at 6:10 AM, Bert Freudenberg <bert at freudenbergs.de>
> wrote:
>
>> #[195 164] collect: [:c | c hex]
>> => #[16 16]
>>
>
> +1
>
> at: index put: value
> <primitive: 61> "try primitiveAtPut, convert value to integer if that
> fails and try again"
> ^ self byteAt: index put: value asInteger
>
> is wrong.
>
>
>>
>> I think this should have raised an error. Tim?
>>
>
> Why don't we simply remove the method? Tim may be using this in his
> benchmarks but I'm sure there's a better way.
>

​Spoke to Tim. The problem is actually primitive 105, which allows this:

(ByteArray new: 10) replaceFrom: 1 to: 5 with: 'Hello'
=> #[72 101 108 108 111 0 0 0 0 0]

If you comment out the primitive call in
ByteArray>>replaceFrom:to:with:startingAt: and also remove Tim's at:put:,
it will fail. So if a VM does not implement the (optional) primitive 105,
the fallback code is wrong.

Using #asInteger in ByteArray>>at:put: is a simple fix for that. Or we have
to fix the fallback code in ByteArray>>replaceFrom:to:with:startingAt:.

I just committed the latter to the inbox but I'm not sure I like the
implementation:
http://source.squeak.org/inbox/Collections-bf.761.diff

Also, ByteArray may not be the only class suffering from this problem:
SystemNavigation default browseAllSelect: [:cm | cm primitive = 105]

- Bert -​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20170720/99809ffc/attachment.html>


More information about the Squeak-dev mailing list