I am testing the CryptoDESTest. I am getting some strange behavior. When I
run the following code in a Workspace, repeatably, I get the same results: code: | plain key d | plain := 'squeaker'. key := 'hacking!'. Transcript cr; show: 'plain: ', plain printString. d := DES key: key. d encryptBlock: plain. Transcript cr; show: 'plain: ', plain printString. self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. plain destroy. output: plain: 'squeaker' plain: '@ÞF ;Lº' plain: 'squeaker' plain: '@ÞF ;Lº' plain: 'squeaker' plain: '@ÞF ;Lº' However, when I run this as a test method: testDES3 | plain key d | plain := 'squeaker'. key := 'hacking!'. Transcript cr; show: 'plain: ', plain printString. d := DES key: key. d encryptBlock: plain. Transcript cr; show: 'plain: ', plain printString. self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. plain destroy. I get the following output and the test fails: plain: 'squeaker' plain: '@ÞF ;Lº' plain: ' ' plain: '£¼ïùmÞ$' plain: '£¼ïùmÞ$' plain: '§,}ºé¨öú' plain: '§,}ºé¨öú' plain: '3qX¦wRË|' plain: '3qX¦wRË|' plain: 'Ê0ê^ó{ì' plain: 'Ê0ê^ó{ì' plain: 'çî³,ίw' Why is test runner remembering the old value and not setting it with: plain := 'squeaker'.? TIA, Rob |
Of course, 'squeaker' is a literal stored in the CompiledMethod.
If you write over it, then you break the literal for next method execution. Each time you evaluate in a workspace, you create a new CompiledMethod and a new literal. When you compile in a class, that's different because you compiled only once and execute many. Nicolas 2010/7/25 Rob Withers <[hidden email]>: > I am testing the CryptoDESTest. I am getting some strange behavior. When I > run the following code in a Workspace, repeatably, I get the same results: > > code: > > | plain key d | > plain := 'squeaker'. > key := 'hacking!'. > Transcript cr; show: 'plain: ', plain printString. > d := DES key: key. > d encryptBlock: plain. > Transcript cr; show: 'plain: ', plain printString. > self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. > plain destroy. > > output: > > plain: 'squeaker' > plain: '@ÞF > ;‘Lº' > plain: 'squeaker' > plain: '@ÞF > ;‘Lº' > plain: 'squeaker' > plain: '@ÞF > ;‘Lº' > > However, when I run this as a test method: > > testDES3 > | plain key d | > plain := 'squeaker'. > key := 'hacking!'. > Transcript cr; show: 'plain: ', plain printString. > d := DES key: key. > d encryptBlock: plain. > Transcript cr; show: 'plain: ', plain printString. > self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. > plain destroy. > > I get the following output and the test fails: > > plain: 'squeaker' > plain: '@ÞF > ;‘Lº' > plain: ' ' > plain: '£ƒ¼ïùmÞ$' > plain: '£ƒ¼ïùmÞ$' > plain: '§,}ºé¨öú' > plain: '§,}ºé¨öú' > plain: '3qX¦wRË|' > plain: '3qX¦wRË|' > plain: 'Ê0ê^ó{ì ' > plain: 'Ê0ê^ó{ì ' > plain: 'çî³›,ίw' > > Why is test runner remembering the old value and not setting it with: plain > := 'squeaker'.? > > TIA, > Rob > > |
Thanks, that makes sense. Isn't that a bug since Strings are mutable?
-------------------------------------------------- From: "Nicolas Cellier" <[hidden email]> Sent: Sunday, July 25, 2010 3:51 AM To: "The general-purpose Squeak developers list" <[hidden email]> Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering old values of temp vars. > Of course, 'squeaker' is a literal stored in the CompiledMethod. > If you write over it, then you break the literal for next method > execution. > > Each time you evaluate in a workspace, you create a new CompiledMethod > and a new literal. > When you compile in a class, that's different because you compiled > only once and execute many. > > Nicolas > > 2010/7/25 Rob Withers <[hidden email]>: >> I am testing the CryptoDESTest. I am getting some strange behavior. >> When I >> run the following code in a Workspace, repeatably, I get the same >> results: >> >> code: >> >> | plain key d | >> plain := 'squeaker'. >> key := 'hacking!'. >> Transcript cr; show: 'plain: ', plain printString. >> d := DES key: key. >> d encryptBlock: plain. >> Transcript cr; show: 'plain: ', plain printString. >> self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. >> plain destroy. >> >> output: >> >> plain: 'squeaker' >> plain: '@ÞF >> ;‘Lº' >> plain: 'squeaker' >> plain: '@ÞF >> ;‘Lº' >> plain: 'squeaker' >> plain: '@ÞF >> ;‘Lº' >> >> However, when I run this as a test method: >> >> testDES3 >> | plain key d | >> plain := 'squeaker'. >> key := 'hacking!'. >> Transcript cr; show: 'plain: ', plain printString. >> d := DES key: key. >> d encryptBlock: plain. >> Transcript cr; show: 'plain: ', plain printString. >> self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. >> plain destroy. >> >> I get the following output and the test fails: >> >> plain: 'squeaker' >> plain: '@ÞF >> ;‘Lº' >> plain: ' ' >> plain: '£ƒ¼ïùmÞ$' >> plain: '£ƒ¼ïùmÞ$' >> plain: '§,}ºé¨öú' >> plain: '§,}ºé¨öú' >> plain: '3qX¦wRË|' >> plain: '3qX¦wRË|' >> plain: 'Ê0ê^ó{ì ' >> plain: 'Ê0ê^ó{ì ' >> plain: 'çî³›,ίw' >> >> Why is test runner remembering the old value and not setting it with: >> plain >> := 'squeaker'.? >> >> TIA, >> Rob >> >> > |
There is no immutable support in Squeak.
Smalltalk custom is to avoid overwriting literals like String Array... ...Same for instances of other classes like Point Rectangle which are likely to be shared by several objects. Most algorithms will rather modify and answer a copy. This default behaviour has a cost (creates lots of objects) but is fool proof (no danger to overwrite a shared information). For DES, I don't know, maybe it's just an optimization you must be aware of. In that case, you are responsible for creating the copy by yourself when required. Nicolas 2010/7/25 Rob Withers <[hidden email]>: > Thanks, that makes sense. Isn't that a bug since Strings are mutable? > > -------------------------------------------------- > From: "Nicolas Cellier" <[hidden email]> > Sent: Sunday, July 25, 2010 3:51 AM > To: "The general-purpose Squeak developers list" > <[hidden email]> > Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering old > values of temp vars. > >> Of course, 'squeaker' is a literal stored in the CompiledMethod. >> If you write over it, then you break the literal for next method >> execution. >> >> Each time you evaluate in a workspace, you create a new CompiledMethod >> and a new literal. >> When you compile in a class, that's different because you compiled >> only once and execute many. >> >> Nicolas >> >> 2010/7/25 Rob Withers <[hidden email]>: >>> >>> I am testing the CryptoDESTest. I am getting some strange behavior. When >>> I >>> run the following code in a Workspace, repeatably, I get the same >>> results: >>> >>> code: >>> >>> | plain key d | >>> plain := 'squeaker'. >>> key := 'hacking!'. >>> Transcript cr; show: 'plain: ', plain printString. >>> d := DES key: key. >>> d encryptBlock: plain. >>> Transcript cr; show: 'plain: ', plain printString. >>> self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. >>> plain destroy. >>> >>> output: >>> >>> plain: 'squeaker' >>> plain: '@ÞF >>> ;‘Lº' >>> plain: 'squeaker' >>> plain: '@ÞF >>> ;‘Lº' >>> plain: 'squeaker' >>> plain: '@ÞF >>> ;‘Lº' >>> >>> However, when I run this as a test method: >>> >>> testDES3 >>> | plain key d | >>> plain := 'squeaker'. >>> key := 'hacking!'. >>> Transcript cr; show: 'plain: ', plain printString. >>> d := DES key: key. >>> d encryptBlock: plain. >>> Transcript cr; show: 'plain: ', plain printString. >>> self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. >>> plain destroy. >>> >>> I get the following output and the test fails: >>> >>> plain: 'squeaker' >>> plain: '@ÞF >>> ;‘Lº' >>> plain: ' ' >>> plain: '£ƒ¼ïùmÞ$' >>> plain: '£ƒ¼ïùmÞ$' >>> plain: '§,}ºé¨öú' >>> plain: '§,}ºé¨öú' >>> plain: '3qX¦wRË|' >>> plain: '3qX¦wRË|' >>> plain: 'Ê0ê^ó{ì ' >>> plain: 'Ê0ê^ó{ì ' >>> plain: 'çî³›,ίw' >>> >>> Why is test runner remembering the old value and not setting it with: >>> plain >>> := 'squeaker'.? >>> >>> TIA, >>> Rob >>> >>> >> > > |
-------------------------------------------------- From: "Nicolas Cellier" <[hidden email]> Sent: Sunday, July 25, 2010 4:09 AM To: "The general-purpose Squeak developers list" <[hidden email]> Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering old values of temp vars. > There is no immutable support in Squeak. > Smalltalk custom is to avoid overwriting literals like String Array... > ...Same for instances of other classes like Point Rectangle which are > likely to be shared by several objects. > Most algorithms will rather modify and answer a copy. > This default behaviour has a cost (creates lots of objects) but is > fool proof (no danger to overwrite a shared information). > > For DES, I don't know, maybe it's just an optimization you must be aware > of. > In that case, you are responsible for creating the copy by yourself > when required. You mean before calling encryptBlock:/decryptBlock: with string data, we should copy the string data. That's unfortunate. It works fine with ByteArrays. Thanks for the info! Rob > > Nicolas > > 2010/7/25 Rob Withers <[hidden email]>: >> Thanks, that makes sense. Isn't that a bug since Strings are mutable? >> >> -------------------------------------------------- >> From: "Nicolas Cellier" <[hidden email]> >> Sent: Sunday, July 25, 2010 3:51 AM >> To: "The general-purpose Squeak developers list" >> <[hidden email]> >> Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering >> old >> values of temp vars. >> >>> Of course, 'squeaker' is a literal stored in the CompiledMethod. >>> If you write over it, then you break the literal for next method >>> execution. >>> >>> Each time you evaluate in a workspace, you create a new CompiledMethod >>> and a new literal. >>> When you compile in a class, that's different because you compiled >>> only once and execute many. >>> >>> Nicolas >>> >>> 2010/7/25 Rob Withers <[hidden email]>: >>>> >>>> I am testing the CryptoDESTest. I am getting some strange behavior. >>>> When >>>> I >>>> run the following code in a Workspace, repeatably, I get the same >>>> results: >>>> >>>> code: >>>> >>>> | plain key d | >>>> plain := 'squeaker'. >>>> key := 'hacking!'. >>>> Transcript cr; show: 'plain: ', plain printString. >>>> d := DES key: key. >>>> d encryptBlock: plain. >>>> Transcript cr; show: 'plain: ', plain printString. >>>> self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. >>>> plain destroy. >>>> >>>> output: >>>> >>>> plain: 'squeaker' >>>> plain: '@ÞF >>>> ;‘Lº' >>>> plain: 'squeaker' >>>> plain: '@ÞF >>>> ;‘Lº' >>>> plain: 'squeaker' >>>> plain: '@ÞF >>>> ;‘Lº' >>>> >>>> However, when I run this as a test method: >>>> >>>> testDES3 >>>> | plain key d | >>>> plain := 'squeaker'. >>>> key := 'hacking!'. >>>> Transcript cr; show: 'plain: ', plain printString. >>>> d := DES key: key. >>>> d encryptBlock: plain. >>>> Transcript cr; show: 'plain: ', plain printString. >>>> self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. >>>> plain destroy. >>>> >>>> I get the following output and the test fails: >>>> >>>> plain: 'squeaker' >>>> plain: '@ÞF >>>> ;‘Lº' >>>> plain: ' ' >>>> plain: '£ƒ¼ïùmÞ$' >>>> plain: '£ƒ¼ïùmÞ$' >>>> plain: '§,}ºé¨öú' >>>> plain: '§,}ºé¨öú' >>>> plain: '3qX¦wRË|' >>>> plain: '3qX¦wRË|' >>>> plain: 'Ê0ê^ó{ì ' >>>> plain: 'Ê0ê^ó{ì ' >>>> plain: 'çî³›,ίw' >>>> >>>> Why is test runner remembering the old value and not setting it with: >>>> plain >>>> := 'squeaker'.? >>>> >>>> TIA, >>>> Rob >>>> >>>> >>> >> >> > |
2010/7/25 Rob Withers <[hidden email]>:
> > > -------------------------------------------------- > From: "Nicolas Cellier" <[hidden email]> > Sent: Sunday, July 25, 2010 4:09 AM > To: "The general-purpose Squeak developers list" > <[hidden email]> > Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering old > values of temp vars. > >> There is no immutable support in Squeak. >> Smalltalk custom is to avoid overwriting literals like String Array... >> ...Same for instances of other classes like Point Rectangle which are >> likely to be shared by several objects. >> Most algorithms will rather modify and answer a copy. >> This default behaviour has a cost (creates lots of objects) but is >> fool proof (no danger to overwrite a shared information). >> >> For DES, I don't know, maybe it's just an optimization you must be aware >> of. >> In that case, you are responsible for creating the copy by yourself >> when required. > > > You mean before calling encryptBlock:/decryptBlock: with string data, we > should copy the string data. That's unfortunate. It works fine with > ByteArrays. > No, if you use a literal ByteArray with #[ ] notations, you'll get same symptoms as with a String literal. Nicolas > Thanks for the info! > Rob > >> >> Nicolas >> >> 2010/7/25 Rob Withers <[hidden email]>: >>> >>> Thanks, that makes sense. Isn't that a bug since Strings are mutable? >>> >>> -------------------------------------------------- >>> From: "Nicolas Cellier" <[hidden email]> >>> Sent: Sunday, July 25, 2010 3:51 AM >>> To: "The general-purpose Squeak developers list" >>> <[hidden email]> >>> Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering >>> old >>> values of temp vars. >>> >>>> Of course, 'squeaker' is a literal stored in the CompiledMethod. >>>> If you write over it, then you break the literal for next method >>>> execution. >>>> >>>> Each time you evaluate in a workspace, you create a new CompiledMethod >>>> and a new literal. >>>> When you compile in a class, that's different because you compiled >>>> only once and execute many. >>>> >>>> Nicolas >>>> >>>> 2010/7/25 Rob Withers <[hidden email]>: >>>>> >>>>> I am testing the CryptoDESTest. I am getting some strange behavior. >>>>> When >>>>> I >>>>> run the following code in a Workspace, repeatably, I get the same >>>>> results: >>>>> >>>>> code: >>>>> >>>>> | plain key d | >>>>> plain := 'squeaker'. >>>>> key := 'hacking!'. >>>>> Transcript cr; show: 'plain: ', plain printString. >>>>> d := DES key: key. >>>>> d encryptBlock: plain. >>>>> Transcript cr; show: 'plain: ', plain printString. >>>>> self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. >>>>> plain destroy. >>>>> >>>>> output: >>>>> >>>>> plain: 'squeaker' >>>>> plain: '@ÞF >>>>> ;‘Lº' >>>>> plain: 'squeaker' >>>>> plain: '@ÞF >>>>> ;‘Lº' >>>>> plain: 'squeaker' >>>>> plain: '@ÞF >>>>> ;‘Lº' >>>>> >>>>> However, when I run this as a test method: >>>>> >>>>> testDES3 >>>>> | plain key d | >>>>> plain := 'squeaker'. >>>>> key := 'hacking!'. >>>>> Transcript cr; show: 'plain: ', plain printString. >>>>> d := DES key: key. >>>>> d encryptBlock: plain. >>>>> Transcript cr; show: 'plain: ', plain printString. >>>>> self assert: plain asByteArray = #[64 222 70 13 59 145 76 186]. >>>>> plain destroy. >>>>> >>>>> I get the following output and the test fails: >>>>> >>>>> plain: 'squeaker' >>>>> plain: '@ÞF >>>>> ;‘Lº' >>>>> plain: ' ' >>>>> plain: '£ƒ¼ïùmÞ$' >>>>> plain: '£ƒ¼ïùmÞ$' >>>>> plain: '§,}ºé¨öú' >>>>> plain: '§,}ºé¨öú' >>>>> plain: '3qX¦wRË|' >>>>> plain: '3qX¦wRË|' >>>>> plain: 'Ê0ê^ó{ì ' >>>>> plain: 'Ê0ê^ó{ì ' >>>>> plain: 'çî³›,ίw' >>>>> >>>>> Why is test runner remembering the old value and not setting it with: >>>>> plain >>>>> := 'squeaker'.? >>>>> >>>>> TIA, >>>>> Rob >>>>> >>>>> >>>> >>> >>> >> > > |
-------------------------------------------------- From: "Nicolas Cellier" <[hidden email]> Sent: Sunday, July 25, 2010 4:19 AM To: "The general-purpose Squeak developers list" <[hidden email]> Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering old values of temp vars. > 2010/7/25 Rob Withers <[hidden email]>: >> >> >> -------------------------------------------------- >> From: "Nicolas Cellier" <[hidden email]> >> Sent: Sunday, July 25, 2010 4:09 AM >> To: "The general-purpose Squeak developers list" >> <[hidden email]> >> Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering >> old >> values of temp vars. >> >>> There is no immutable support in Squeak. >>> Smalltalk custom is to avoid overwriting literals like String Array... >>> ...Same for instances of other classes like Point Rectangle which are >>> likely to be shared by several objects. >>> Most algorithms will rather modify and answer a copy. >>> This default behaviour has a cost (creates lots of objects) but is >>> fool proof (no danger to overwrite a shared information). >>> >>> For DES, I don't know, maybe it's just an optimization you must be aware >>> of. >>> In that case, you are responsible for creating the copy by yourself >>> when required. >> >> >> You mean before calling encryptBlock:/decryptBlock: with string data, we >> should copy the string data. That's unfortunate. It works fine with >> ByteArrays. >> > > No, if you use a literal ByteArray with #[ ] notations, you'll get > same symptoms as with a String literal. > Thanks for pointing this out. I am not happy about this at all. It is very non-intuitive, all due to an optimization that limits my expressiveness. Rob |
On 25.07.2010, at 04:22, Rob Withers wrote: > Thanks for pointing this out. I am not happy about this at all. It is very non-intuitive, all due to an optimization that limits my expressiveness. If string literals were immutable you would have to copy them yourself, too. So in any case you need to write plain := 'squeaker' copy if you intend to modify that string in-place. - Bert - |
-------------------------------------------------- From: "Bert Freudenberg" <[hidden email]> Sent: Sunday, July 25, 2010 12:40 PM To: "The general-purpose Squeak developers list" <[hidden email]> Subject: Re: [squeak-dev] TestRunner not assigning strings/remembering oldvalues of temp vars. > > On 25.07.2010, at 04:22, Rob Withers wrote: > >> Thanks for pointing this out. I am not happy about this at all. It is >> very non-intuitive, all due to an optimization that limits my >> expressiveness. > > If string literals were immutable you would have to copy them yourself, > too. So in any case you need to write > > plain := 'squeaker' copy > > if you intend to modify that string in-place. > Sure, but I like mutable strings...just an array for pete's sake, holding Characters (bytes). I don't like that the literals can be mutated. There must be a way to mutate the string, detect that it is a literal and replace the literal with a copy of the original. ...or something :). Rob > - Bert - > > > |
Free forum by Nabble | Edit this page |