[Cuis-dev] ReferenceStreams with SmallIntegers in Cuis 7.5_7601 and Squeak 6.1a_23331 not yet compatible
Juan Vuletich
juan at cuis.st
Wed Sep 24 09:18:14 PDT 2025
Hi Hannes,
Please try adding this to LargePositiveInteger
comeFullyUpOnReload: smartRefStream
^self normalize
I think this should fix the result, converting back to SmallInteger.
Thanks,
On 24/09/2025 10:52 AM, H. Hirzel via Cuis-dev wrote:
> Hi
>
> The new change set
> 7600-ReferenceStream-Compatibility-JuanVuletich-2025Sep22-09h46m-jmv.003.cs.st
> <http://7600-ReferenceStream-Compatibility-JuanVuletich-2025Sep22-09h46m-jmv.003.cs.st>
> does not yet re-establish the compatibily for ReferenceStreams as far
> as SmallIntegers are concerned.
>
> Individually Cuis
> [3]
> ````
> ReferenceStreamTest new testSmallIntegers.
> ````
>
> and Squeak [4] pass with the test values given in the Cuis
> BaseImageTest package for ReferenceStreams.
>
> What the Cuis change set
> 7600-ReferenceStream-Compatibility-JuanVuletich-2025Sep22-09h46m-jmv.003.cs.st
> <http://7600-ReferenceStream-Compatibility-JuanVuletich-2025Sep22-09h46m-jmv.003.cs.st>
> does not provide yet is that the object file written in Squeak may be
> read in Cuis 7.5_7601 [5].
> Integers in the test array positions 6 to 11 are restored as
> LargePositiveInteger or LargeNegativeInteger values.
> In Squeak 6.1.a these values are restored as SmallInteger values, the
> way they were written.
>
> --Hannes
>
> Attachements: anArrayOfSmallIntegersFromSqueak.obj and
> Cuis test
> which provides the log in [5]
>
> ## [3] ReferenceStreamTest new testSmallIntegers
> (from Cuis package BaseImageTests)
> ````
> testSmallIntegers
> "
> ReferenceStreamTest new testSmallIntegers
> "
> | newInstance oldInstance |
> oldInstance := {-1. 0 . 1. 123456. -123456. 1234567890. -1234567890.
> 123456789012345678. -123456789012345678. (2 raisedTo: 60)-1. (2
> raisedTo: 60) negated }.
> newInstance := ReferenceStream unStream: (ReferenceStream
> streamedRepresentationOf: oldInstance).
> self assert: newInstance = oldInstance.
> ````
>
>
> ## [4] Test Serializing integer values with ReferenceStream in Squeak 6.1a
>
> ````
> "Squeak6.1alpha latest update: #23331"
> "Test also passes in Squeak5.3 latest update: #19459"
> objectToSave := {-1. 0 . 1. 123456. -123456. 1234567890. -1234567890.
> 123456789012345678. -123456789012345678. (2 raisedTo: 60)-1. (2
> raisedTo: 60) negated }.
>
> fileStream := ReferenceStream fileNamed:
> 'anArrayOfSmallIntegersFromSqueak.obj'.
> fileStream nextPut: objectToSave.
> fileStream close.
>
> rr := ReferenceStream fileNamed: 'anArrayOfSmallIntegersFromSqueak.obj'.
> restoredObject := rr next.
> rr close.
>
>
>
> objectToSave = restoredObject
> true
>
>
> "Note:
> SmallInteger maxVal 1152921504606846975"
> ````
>
> ## [5] Restore in Cuis
> ````
> "Cuis 7.5_6001"
>
> testSmallIntegersFromSqueak
> "
> ReferenceStreamTest new testSmallIntegersFromSqueak
> "
> | newInstanceCuis oldInstance newInstanceSqueak i |
> oldInstance := {-1. 0 . 1. 123456. -123456. 1234567890. -1234567890.
> 123456789012345678. -123456789012345678. (2 raisedTo: 60)-1. (2
> raisedTo: 60) negated }.
> newInstanceCuis := ReferenceStream unStream: (ReferenceStream
> streamedRepresentationOf: oldInstance).
> self assert: newInstanceCuis = oldInstance.
>
> newInstanceSqueak := ReferenceStream restoreFromFile:
> ('anArrayOfSmallIntegersFromSqueak.obj' asFileEntry).
>
> i := 1.
> newInstanceCuis do: [:item | |itemSq|
> itemSq := (newInstanceSqueak at: i). Transcript show: i printString, '
> '; show: item printString, ' '; show: (item = itemSq); show: ' Cuis
> class=', item class printString; show: ' Squeak class=', itemSq class
> printString;cr. i := i + 1].
>
> self assert: newInstanceSqueak = oldInstance.
>
> ````
>
> Log in Transcript
> ````
> 1 -1 true Cuis class=SmallInteger; Restored from Squeak class=SmallInteger
> 2 0 true Cuis class=SmallInteger; Restored from Squeak class=SmallInteger
> 3 1 true Cuis class=SmallInteger; Restored from Squeak class=SmallInteger
> 4 123456 true Cuis class=SmallInteger; Restored from Squeak
> class=SmallInteger
> 5 -123456 true Cuis class=SmallInteger; Restored from Squeak
> class=SmallInteger
> 6 1234567890 false Cuis class=SmallInteger; Restored from Squeak
> class=LargePositiveInteger
> 7 -1234567890 false Cuis class=SmallInteger; Restored from Squeak
> class=LargeNegativeInteger
> 8 123456789012345678 false Cuis class=SmallInteger; Restored from
> Squeak class=LargePositiveInteger
> 9 -123456789012345678 false Cuis class=SmallInteger; Restored from
> Squeak class=LargeNegativeInteger
> 10 1152921504606846975 false Cuis class=SmallInteger; Restored from
> Squeak class=LargePositiveInteger
> 11 -1152921504606846976 false Cuis class=SmallInteger; Restored from
> Squeak class=LargeNegativeInteger
>
> ReferenceStreamTest>>#testSmallIntegersFromSqueak -- Assertion (2)
> failed. TestFailure: Assertion (2) failed.
>
> ````
>
>
>
> On Wed, Sep 24, 2025 at 3:31 AM Juan Vuletich via Cuis-dev
> <cuis-dev at lists.cuis.st> wrote:
>
> Hi Nicolas,
>
> Oh gosh! #objectForDataStream: I didn't see that coming! I only
> saw #readInteger and #writeInteger: in Squeak and assumed Squeak
> was broken. And didn't try it before opening my mouth. Apologies
> for my ill informed and rude comment.
>
> It was only Cuis that was broken until last week WRT this.
>
> WRT compatibility between Squeak and Cuis wrt DataStream, a lot of
> content is compatible. Larger SmallIntegers written in Squeak (as
> LargeIntegers) will be read correctly in Cuis. But those written
> in Cuis will use a new TypeMap entry with code 25 that uses two 32
> bit words. I prefer this approach, because I want to be able to
> load DataStreams that don't have any LargeIntegers into small
> bootstrapped images that don't include LargeIntegers at all. The
> 'minimal kernel' images I'm building haven't seen need for
> LargeIntegers yet, and so I prefer not to include them, and keep
> them in a separate pre-compiled "dynamic cuis library". The "25"
> format is easy to add to Squeak, at least for reading, though.
>
> But I'm pretty sure there are incompatibilities in Character,
> UnicodeString and UnicodeSymbol. Floats and Byte-Strings seem to
> be OK.
>
> If you want to collaborate with me on keeping DataStream as
> compatible as possible (Morphs are out of the question, I guess!),
> and are willing to make minor tweaks for Squeak, I'm willing to
> make them for Cuis as needed.
>
> Thanks!
>
> On 23/09/2025 6:11 PM, Nicolas Cellier via Cuis-dev wrote:
>> Hi Juan,
>> I fail to see the bug in current Squeak trunk.
>> I tried this
>>
>> | int out file |
>> int := SmallInteger maxVal.
>> file*:=*FileStreamfileNamed:'Test-Int'.
>> filebinary.
>> (DataStreamon:file)nextPut:int.
>> fileclose.
>>
>> file*:=*FileStreamfileNamed:'Test-Int'.
>> filebinary.
>> out*:=*(DataStreamon:file)next.
>> fileclose.
>>
>> 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>16r3FFFFFFFifTrue:[
>> large*:=*LargePositiveIntegernew:selfdigitLengthneg:false.
>> 1to:selfdigitLengthdo:[:i|largedigitAt:iput:(selfdigitAt:i)].
>> ^large].
>> self<-16r40000000ifTrue:[
>> large*:=*LargeNegativeIntegernew:selfdigitLengthneg:true.
>> 1to:selfdigitLengthdo:[:i|largedigitAt:iput:(selfdigitAt: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
>>> <http://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 Vuletich
>> www.cuis.st <http://www.cuis.st>
>> github.com/jvuletich <http://github.com/jvuletich>
>> researchgate.net/profile/Juan-Vuletich <http://researchgate.net/profile/Juan-Vuletich>
>> independent.academia.edu/JuanVuletich <http://independent.academia.edu/JuanVuletich>
>> patents.justia.com/inventor/juan-manuel-vuletich <http://patents.justia.com/inventor/juan-manuel-vuletich>
>>
>> --
>> Cuis-dev mailing list
>> Cuis-dev at lists.cuis.st
>> https://lists.cuis.st/mailman/listinfo/cuis-dev
>>
>>
> --
> Juan Vuletich
> www.cuis.st <http://www.cuis.st>
> github.com/jvuletich <http://github.com/jvuletich>
> researchgate.net/profile/Juan-Vuletich <http://researchgate.net/profile/Juan-Vuletich>
> independent.academia.edu/JuanVuletich <http://independent.academia.edu/JuanVuletich>
> patents.justia.com/inventor/juan-manuel-vuletich <http://patents.justia.com/inventor/juan-manuel-vuletich>
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
>
--
Juan Vuletich
www.cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250924/9c0e44dc/attachment-0001.htm>
More information about the Cuis-dev
mailing list