[Cuis-dev] ReferenceStream cannot read Dictionary object written with Squeak (was Re: ReferenceStream restoreFromFile: aFileEntry goes into infinite loop)

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Sep 23 14:11:56 PDT 2025


Hi Juan,
I fail to see the bug in current Squeak trunk.
I tried this

    | int out file |
    int := SmallInteger maxVal.
    file *:=* FileStream fileNamed: 'Test-Int'.
    file binary.
    (DataStream on: file) nextPut: int.
    file close.

    file *:=* FileStream fileNamed: 'Test-Int'.
    file binary.
    out *:=* (DataStream on: file) next.
    file close.

    self assert: int = out

The large SmallInteger is restored correctly.
This is because we find this method timestamped from 2015:

*SmallInteger>>objectForDataStream:* refStrm
    *"In a 64-bit Spur VM, we may have to fake 32-bit SmallIntegers for
compatibility."*

    | large |
    self > 16r3FFFFFFF ifTrue: [
        large *:=* LargePositiveInteger new: self digitLength neg: false.
        1 to: self digitLength do: [:i | large digitAt: i put: (self
digitAt: i)].
        ^large].
    self < -16r40000000 ifTrue: [
        large *:=* LargeNegativeInteger new: self digitLength neg: true.
        1 to: self digitLength do: [:i | large digitAt: i put: (self
digitAt: i)].
        ^large].
    ^ self

Did I overlook something?
I hope that Cuis and Squeak DataStream will remain consistent after your
latest changes

Nicolas

Le lun. 22 sept. 2025 à 15:45, Juan Vuletich via Cuis-dev <
cuis-dev at lists.cuis.st> a écrit :

> Hi,
> On 22/09/2025 10:10 AM, H. Hirzel via Cuis-dev wrote:
>
> I could identify the change set which causes the problem, it is from last
> Wednesday
>
> CoreUpdates\
> 7580-ReferenceStream-61BitSmallIntegers-fix-JuanVuletich-2025Sep17-08h16m-jmv.001.cs.st
>
> It introduces a new version of #readInteger and writeInteger: in the class
> DataStream.
> If I undo the change of this change set it works.
>
> --Hannes
>
>
> As you saw in that changeset (file name, comments in code, commit
> message), and as exemplified in the test added to BaseImageTests shortly
> after, what that code does is not to cause a problem, but to fix a serious
> bug that has been around for a long time and that is still present in
> Squeak. Just try to serialize an object with a largish SmallInteger and see
> what you get back.
>
> Anyway. I just pushed a better implementation that uses a different format
> for 32bit SmallIntegers than from larger ones. This brings back
> compatibility with the badly broken Squeak format, although it obviously
> can't bring back the bits that Squeak discarded when saving the file, and
> results will be wrong unless you're lucky enough to only use small
> SmallIntegers.
>
>
>
>
>
>
>
>
> On Mon, Sep 22, 2025 at 2:36 PM H. Hirzel <hannes.hirzel at gmail.com> wrote:
>
>> I am currently identifying which change set causes the problem.
>> So far Cuis update 7523 still works.
>>
>> This means if I produce a file ' aDictWithByteArraysFromSq.obj' in Squeak
>> I can read it in Cuis 7523
>>
>> So the problem has been introduced in one of the last 60 updates.
>>
>>
>> "Squeak"
>>> dict := Dictionary new.
>>> dict at: 1 put: #[1 2 3 4].
>>> dict at: 2 put: #[5 6 7 8].
>>> dict at: 3 put: #[10 20 30 40].
>>>
>>> fileStream := ReferenceStream fileNamed: 'aDictWithByteArraysFromSq.obj'.
>>> objectToSave := dict.
>>> fileStream nextPut: objectToSave.
>>> fileStream close
>>>
>>>
>>
>>> "-----------------------------------------------"
>>> "Restore in Cuis"
>>> ReferenceStream restoreFromFile: ('aDictWithByteArraysFromSq.obj'
>>> asFileEntry).
>>>
>>> "Result
>>> OK in Cuis 7523
>>> NOT OK in Cuis 7584"
>>>
>>>
> --
> Juan Vuletichwww.cuis.stgithub.com/jvuletichresearchgate.net/profile/Juan-Vuletichindependent.academia.edu/JuanVuletichpatents.justia.com/inventor/juan-manuel-vuletich
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250923/87afa7eb/attachment.htm>


More information about the Cuis-dev mailing list