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

On Wed, Jul 19, 2017 at 6:10 AM, Bert Freudenberg <bert@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:

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

- Bert -​