[Vm-dev] Bug in #instVarAt:put: for read-only objects
Eliot Miranda
eliot.miranda at gmail.com
Fri Jan 5 17:17:44 UTC 2018
Hi Norbert,
> On Jan 5, 2018, at 7:53 AM, Clément Bera <bera.clement at gmail.com> wrote:
>
>
>
>> On Fri, Jan 5, 2018 at 4:05 PM, Norbert Hartl <norbert at hartl.name> wrote:
>>
>> You mean
>>
>> <primitive: 174 error: ec>
>> self isReadOnlyObject
>> ifTrue: [(ModificationForbidden for: self atInstVar: index with: anObject) signal]
>> ifFalse: [ self primitiveFailed ]
>> ?
>>
>> Norbert
The index and bounds validation should also occur, probably first. So something like
Object>>instVarAt: index put: anObject
<primitive: 174 error: ec>
(index isInteger
and: [index between: 1 and: self class instSize + self basicSize]) ifFalse:
[self badIndexError: index].
self isReadOnlyObject ifTrue:
[^(NoModificationError for: self atInstVar: index with: anObject) signal].
self primitiveFailed
>
> yes something like that.
>
>
> Same thing for Object>>#at:put:, floatAt:put: and so on.
>
>>
>>> Am 05.01.2018 um 14:22 schrieb Clément Bera <bera.clement at gmail.com>:
>>>
>>> Hi,
>>>
>>> No this is not a bug.
>>>
>>> This needs to be handled in the primitive failure code in the image, the method should be something like that :
>>>
>>> Object>>instVarAt: index put: anObject
>>> <primitive: 174 error: ec>
>>> self isReadOnlyObject ifTrue: [(ModificationForbidden for: self atInstVar: index with: anObject) signal]
>>> self primitiveFailed
>>>
>>> All primitive fall-back code triggering object mutation should be rewritten this way, especially primitives such as #at:put:, #instVarAt:put:, etc.
>>>
>>> Cheers
>>>
>>>> On Fri, Jan 5, 2018 at 1:42 PM, Norbert Hartl <norbert at hartl.name> wrote:
>>>>
>>>> If I do
>>>>
>>>> (#foo -> #bar)
>>>> beReadOnlyObject;
>>>> value: #baz
>>>>
>>>> it throws
>>>>
>>>> ModificationForbidden: #foo->#bar is read-only, hence its field 2 cannot be modified with #baz
>>>>
>>>> which is as expected. But if I do
>>>>
>>>> (#foo -> #bar)
>>>> beReadOnlyObject;
>>>> instVarNamed: #value put: #baz
>>>>
>>>> I get
>>>>
>>>> PrimitiveFailed: primitive #instVarAt:put: in Association failed
>>>>
>>>> I think this a bug, no?
>>>>
>>>> Norbert
>>>>
>>>
>>>
>>>
>>> --
>>> Clément Béra
>>> Pharo consortium engineer
>>> https://clementbera.wordpress.com/
>>> Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq
>>
>>
>
>
>
> --
> Clément Béra
> Pharo consortium engineer
> https://clementbera.wordpress.com/
> Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20180105/08016a69/attachment-0001.html>
More information about the Vm-dev
mailing list