String>>at:put: fails with JSON

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

String>>at:put: fails with JSON

Max Leske
Hi

I'm loading objects with JSON and getting a really weird exception. This is JSON>>readString

| s c |
s := WriteStream on: ''.
[
c := stream next.
c == $\
ifTrue: [s nextPut: self interpretStringEscape.]
ifFalse:[c == $" ifTrue: [^ s contents.].
s nextPut: c]
] repeat.

When reading my objects the ifFalse block is evaluated for the first character and "s nextPut: c" is executed. WriteStream>>nextPut: delegates to #_nextPut: where the following is evaluated:

itsCollection at: position put: anObject.

"itsCollection" is the empty string initialized before, "position" is 1 and anObject is "$a" ($a being the first character after the initial double quote). When stepping into this and over the following primitive everything works as expected but when I let it run through I get: 

"InterpreterError 2018: An attempt was made to evaluate the block or method <aComplexVCBlock> with <1> arguments when <0> were expected."

I really can't find any other explanation for this than that something's wrong with the VM.

Can somebody help? I copied the stack trace below this message.

Thanks,
Max




trace.txt (101K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: String>>at:put: fails with JSON

James Foster-8
Max,

One thing I see right off is that you have initialized the stream contents to an invariant object (a string literal). The VM will be unable to add characters to your stream. I suggest your first line be:

s := WriteStream on: String new.

Alternatively, you can make a copy of the string literal.

In my environment, I get an error, but it is a different error, so this might not be the only problem.

James

On Mar 4, 2011, at 5:45 AM, Max Leske wrote:

Hi

I'm loading objects with JSON and getting a really weird exception. This is JSON>>readString

| s c |
s := WriteStream on: ''.
[
c := stream next.
c == $\
ifTrue: [s nextPut: self interpretStringEscape.]
ifFalse:[c == $" ifTrue: [^ s contents.].
s nextPut: c]
] repeat.

When reading my objects the ifFalse block is evaluated for the first character and "s nextPut: c" is executed. WriteStream>>nextPut: delegates to #_nextPut: where the following is evaluated:

itsCollection at: position put: anObject.

"itsCollection" is the empty string initialized before, "position" is 1 and anObject is "$a" ($a being the first character after the initial double quote). When stepping into this and over the following primitive everything works as expected but when I let it run through I get: 

"InterpreterError 2018: An attempt was made to evaluate the block or method <aComplexVCBlock> with <1> arguments when <0> were expected."

I really can't find any other explanation for this than that something's wrong with the VM.

Can somebody help? I copied the stack trace below this message.

Thanks,
Max


<trace.txt>

Reply | Threaded
Open this post in threaded view
|

Re: String>>at:put: fails with JSON

Max Leske
Perfect!
That did the trick, thanks.

As I explained, this is code in a JSON package which runs fine in Pharo (SqueakVM). Is this a GemStone VM thing?

Cheers,
Max


On 04.03.2011, at 14:56, James Foster wrote:

Max,

One thing I see right off is that you have initialized the stream contents to an invariant object (a string literal). The VM will be unable to add characters to your stream. I suggest your first line be:

s := WriteStream on: String new.

Alternatively, you can make a copy of the string literal.

In my environment, I get an error, but it is a different error, so this might not be the only problem.

James

On Mar 4, 2011, at 5:45 AM, Max Leske wrote:

Hi

I'm loading objects with JSON and getting a really weird exception. This is JSON>>readString

| s c |
s := WriteStream on: ''.
[
c := stream next.
c == $\
ifTrue: [s nextPut: self interpretStringEscape.]
ifFalse:[c == $" ifTrue: [^ s contents.].
s nextPut: c]
] repeat.

When reading my objects the ifFalse block is evaluated for the first character and "s nextPut: c" is executed. WriteStream>>nextPut: delegates to #_nextPut: where the following is evaluated:

itsCollection at: position put: anObject.

"itsCollection" is the empty string initialized before, "position" is 1 and anObject is "$a" ($a being the first character after the initial double quote). When stepping into this and over the following primitive everything works as expected but when I let it run through I get: 

"InterpreterError 2018: An attempt was made to evaluate the block or method <aComplexVCBlock> with <1> arguments when <0> were expected."

I really can't find any other explanation for this than that something's wrong with the VM.

Can somebody help? I copied the stack trace below this message.

Thanks,
Max


<trace.txt>


Reply | Threaded
Open this post in threaded view
|

Re: String>>at:put: fails with JSON

James Foster-8
I'm glad that fixed it. And, yes, this is a GemStone VM "thing." Whether the ability to modify literals is a bug or a feature has been debated. In Pharo you may do so, in GemStone you may not do so. There are arguments either way, but I like the immutability of literals, so I'm happy with GemStone (for that and many other reasons!).

James

On Mar 4, 2011, at 6:04 AM, Max Leske wrote:

Perfect!
That did the trick, thanks.

As I explained, this is code in a JSON package which runs fine in Pharo (SqueakVM). Is this a GemStone VM thing?

Cheers,
Max


On 04.03.2011, at 14:56, James Foster wrote:

Max,

One thing I see right off is that you have initialized the stream contents to an invariant object (a string literal). The VM will be unable to add characters to your stream. I suggest your first line be:

s := WriteStream on: String new.

Alternatively, you can make a copy of the string literal.

In my environment, I get an error, but it is a different error, so this might not be the only problem.

James

On Mar 4, 2011, at 5:45 AM, Max Leske wrote:

Hi

I'm loading objects with JSON and getting a really weird exception. This is JSON>>readString

| s c |
s := WriteStream on: ''.
[
c := stream next.
c == $\
ifTrue: [s nextPut: self interpretStringEscape.]
ifFalse:[c == $" ifTrue: [^ s contents.].
s nextPut: c]
] repeat.

When reading my objects the ifFalse block is evaluated for the first character and "s nextPut: c" is executed. WriteStream>>nextPut: delegates to #_nextPut: where the following is evaluated:

itsCollection at: position put: anObject.

"itsCollection" is the empty string initialized before, "position" is 1 and anObject is "$a" ($a being the first character after the initial double quote). When stepping into this and over the following primitive everything works as expected but when I let it run through I get: 

"InterpreterError 2018: An attempt was made to evaluate the block or method <aComplexVCBlock> with <1> arguments when <0> were expected."

I really can't find any other explanation for this than that something's wrong with the VM.

Can somebody help? I copied the stack trace below this message.

Thanks,
Max


<trace.txt>



Reply | Threaded
Open this post in threaded view
|

Re: String>>at:put: fails with JSON

Max Leske
Good to know. Thanks.

Max

On 04.03.2011, at 15:08, James Foster wrote:

I'm glad that fixed it. And, yes, this is a GemStone VM "thing." Whether the ability to modify literals is a bug or a feature has been debated. In Pharo you may do so, in GemStone you may not do so. There are arguments either way, but I like the immutability of literals, so I'm happy with GemStone (for that and many other reasons!).

James

On Mar 4, 2011, at 6:04 AM, Max Leske wrote:

Perfect!
That did the trick, thanks.

As I explained, this is code in a JSON package which runs fine in Pharo (SqueakVM). Is this a GemStone VM thing?

Cheers,
Max


On 04.03.2011, at 14:56, James Foster wrote:

Max,

One thing I see right off is that you have initialized the stream contents to an invariant object (a string literal). The VM will be unable to add characters to your stream. I suggest your first line be:

s := WriteStream on: String new.

Alternatively, you can make a copy of the string literal.

In my environment, I get an error, but it is a different error, so this might not be the only problem.

James

On Mar 4, 2011, at 5:45 AM, Max Leske wrote:

Hi

I'm loading objects with JSON and getting a really weird exception. This is JSON>>readString

| s c |
s := WriteStream on: ''.
[
c := stream next.
c == $\
ifTrue: [s nextPut: self interpretStringEscape.]
ifFalse:[c == $" ifTrue: [^ s contents.].
s nextPut: c]
] repeat.

When reading my objects the ifFalse block is evaluated for the first character and "s nextPut: c" is executed. WriteStream>>nextPut: delegates to #_nextPut: where the following is evaluated:

itsCollection at: position put: anObject.

"itsCollection" is the empty string initialized before, "position" is 1 and anObject is "$a" ($a being the first character after the initial double quote). When stepping into this and over the following primitive everything works as expected but when I let it run through I get: 

"InterpreterError 2018: An attempt was made to evaluate the block or method <aComplexVCBlock> with <1> arguments when <0> were expected."

I really can't find any other explanation for this than that something's wrong with the VM.

Can somebody help? I copied the stack trace below this message.

Thanks,
Max


<trace.txt>