ByteArray>>at:put:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ByteArray>>at:put:

Bert Freudenberg
#[195 164] collect: [:c | c hex]
=> #[16 16]

I think this should have raised an error. Tim?

- Bert -


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ByteArray>>at:put:

Levente Uzonyi
On Wed, 19 Jul 2017, Bert Freudenberg wrote:

> #[195 164] collect: [:c | c hex]
> => #[16 16]
>
> I think this should have raised an error. Tim?

Indeed. It would raise an error if ByteArray >> #at:put: weren't
there.

Levente

>
> - Bert -
>
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ByteArray>>at:put:

Eliot Miranda-2
In reply to this post by Bert Freudenberg
Hi Bert,

On Wed, Jul 19, 2017 at 6:10 AM, Bert Freudenberg <[hidden email]> 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.

But there's possibly another error here too.  Why is '16rC3' asInteger 16 instead of 195?


_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ByteArray>>at:put:

Igor Stasenko


On 20 July 2017 at 00:16, Eliot Miranda <[hidden email]> wrote:
Hi Bert,

On Wed, Jul 19, 2017 at 6:10 AM, Bert Freudenberg <[hidden email]> 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.

But there's possibly another error here too.  Why is '16rC3' asInteger 16 instead of 195?

indeed. And that has nothing to do with bytearray method.
 

_,,,^..^,,,_
best, Eliot






--
Best regards,
Igor Stasenko.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ByteArray>>at:put:

Bert Freudenberg
In reply to this post by Eliot Miranda-2
On Wed, Jul 19, 2017 at 11:16 PM, Eliot Miranda <[hidden email]> wrote:
Hi Bert,

On Wed, Jul 19, 2017 at 6:10 AM, Bert Freudenberg <[hidden email]> 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 -​



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ByteArray>>at:put:

Bert Freudenberg
On Thu, Jul 20, 2017 at 12:46 PM, Bert Freudenberg <[hidden email]> wrote:
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:

I take no response as silent ​agreement, so I moved this to trunk.
 
Also, ByteArray may not be the only class suffering from this problem:
SystemNavigation default browseAllSelect: [:cm | cm primitive = 105]

​Do we think these other places might need fixes?​
- Bert -




Loading...