On Mon, Sep 22, 2014 at 1:47 PM, Nicolas Cellier < nicolas.cellier.aka.nice@gmail.com> wrote:
2014-09-22 22:34 GMT+02:00 Bert Freudenberg bert@freudenbergs.de:
On 22.09.2014, at 22:21, Ron Teitelbaum ron@usmedrec.com wrote:
From: Bert Freudenberg Sent: Monday, September 22, 2014 4:00 PM
I just found out why PNG decoding was broken in SqueakJS [*]. Wouldn't have believed that any code actually relied on the following behavior:
| a | a := (1 to: 20) asArray. a replaceFrom: 11 to: 20 with: a startingAt: 8. ==> #(1 2 3 4 5 6 7 8 9 10 8 9 10 8 9 10 8 9 10 8)
That's funky! Hope it wasn't my code! Seems wrong to not copy the
array
before modifying it (Like your buggy VM did).
It's not a copy. It moved the numbers 8-17 to index 11. Which is what I erroneously had assumed to be the desired behavior.
- Bert -
It's a known problem. The primitive should use memmove rather than memcpy. So the solution is quite simple, it's just that it's waiting for a good soul to integrate it.
Um, no. It has ever been so and must therefore remain. This is the method (as in the Smalltalk-80 V2 sources) that the primitive optimizes:
replaceFrom: start to: stop with: replacement startingAt: repStart "This destructively replaces elements from start to stop in the receiver starting at index, repStart, in the collection, replacement. Answer the receiver. No range checks are performed - this may be primitively implemented."
| index repOff | repOff _ repStart - start. index _ start - 1. [(index _ index + 1) <= stop] whileTrue: [self at: index put: (replacement at: repOff + index)]
So the primitive is correct. This is memcpy behaviour. IIRC BitBlt is the same. There were some BitBlt ticks played with image fill that depended on this.
| oc | oc := OrderedCollection withAll: (1 to: 20). oc replaceFrom: 11 to: 20 with: oc startingAt: 8. oc => an OrderedCollection(1 2 3 4 5 6 7 8 9 10 8 9 10 8 9 10 8 9 10 8)
Ron
In my (buggy) VM it answered
==> #(1 2 3 4 5 6 7 8 9 10 8 9 10 11 12 13 14 15 16 17)
which apparently did not at all match what The Creators intended ;)
- Bert -
[*] specifically, #decompressBlock:with:
vm-dev@lists.squeakfoundation.org