WriteStream problem

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

WriteStream problem

Barry Carr-3
Hello All,

Could anyone give me a clue as to why a WriteStream would bail with:
"Attempt to update read-only object" when I am appending a string to the
stream. The Signal is being "thrown" when the stream is trying to resize
the string I've passed in.

Any clues appreciated.

Regards

Barry Carr

Ixian Software Components Ltd
Blairgowrie
Perthshire
Scotland
www.ixian-software.com


Reply | Threaded
Open this post in threaded view
|

Re: WriteStream problem

John Brant
"Barry Carr" <[hidden email]> wrote in message
news:Xns9284941357E4Cbarryarrakisclaranet@158.152.254.254...

> Could anyone give me a clue as to why a WriteStream would bail with:
> "Attempt to update read-only object" when I am appending a string to the
> stream. The Signal is being "thrown" when the stream is trying to resize
> the string I've passed in.

How did you create your stream? Did you use (WriteStream on: '')? If so, you
need to change it to be (WriteStream on: String new). Dolphin is preventing
you from modifying the literal string.

BTW Andy/Blair, why does ((WriteStream on: #()) nextPut: 1) work? Shouldn't
this also be an error? What about ('1' at: 1 put: $2) -- shouldn't that be
an error?


John Brant


Reply | Threaded
Open this post in threaded view
|

Re: WriteStream problem

Bill Schwab-2
In reply to this post by Barry Carr-3
Barry,

> Could anyone give me a clue as to why a WriteStream would bail with:
> "Attempt to update read-only object" when I am appending a string to the
> stream. The Signal is being "thrown" when the stream is trying to resize
> the string I've passed in.

Well, it sounds like you might be trying to update a read-only object :)
Dolphin puts some objects in read-only memory to prevent illegal updates.
Did you open the write stream on a literal string?  If so, try something
like

out := String writeStream.
out nextPutAll:'Some text'.
...

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: WriteStream problem

Blair McGlashan
In reply to this post by John Brant
John

You wrote in message news:QX1f9.258758$aA.44349@sccrnsc02...
> "Barry Carr" <[hidden email]> wrote in message
> news:Xns9284941357E4Cbarryarrakisclaranet@158.152.254.254...
>
> > Could anyone give me a clue as to why a WriteStream would bail with:
> > "Attempt to update read-only object" when I am appending a string to the
> > stream. The Signal is being "thrown" when the stream is trying to resize
> > the string I've passed in.
>
> How did you create your stream? Did you use (WriteStream on: '')? If so,
you
> need to change it to be (WriteStream on: String new). Dolphin is
preventing
> you from modifying the literal string.
>
> BTW Andy/Blair, why does ((WriteStream on: #()) nextPut: 1) work?
Shouldn't
> this also be an error? What about ('1' at: 1 put: $2) -- shouldn't that be
> an error?

Yes, it should, but at present the VM/compiler do not store method literals
in read-only memory. The empty string is stored in read-only memory because
the compiler uses a single instance of it, and if this is not protected
against modification then it is easy to get into a very sorry state. To
protect it the empty string constant is stored in an area of memory that is
physically protected against modification. I've always intended to do this
eventually for all literals, but it isn't a very high priority. A simple
approach to this (basically just setting a flag on the object, and then
testing this is all places that might modify the object) is possible, but
that implies some overhead and to my mind it would be a bodge. Storing the
literals in read-only memory, on the other hand, is the clean solution but
involves significantly more effort, so it has not yet been done.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: WriteStream problem

Barry Carr-3
In reply to this post by John Brant
"John Brant" <[hidden email]> wrote in
news:QX1f9.258758$aA.44349@sccrnsc02:

> "Barry Carr" <[hidden email]> wrote in message
> news:Xns9284941357E4Cbarryarrakisclaranet@158.152.254.254...
>
>> Could anyone give me a clue as to why a WriteStream would bail with:
>> "Attempt to update read-only object" when I am appending a string to
>> the stream. The Signal is being "thrown" when the stream is trying to
>> resize the string I've passed in.
>
> How did you create your stream? Did you use (WriteStream on: '')? If
> so, you need to change it to be (WriteStream on: String new). Dolphin
> is preventing you from modifying the literal string.
>
> BTW Andy/Blair, why does ((WriteStream on: #()) nextPut: 1) work?
> Shouldn't this also be an error? What about ('1' at: 1 put: $2) --
> shouldn't that be an error?
>
>
> John Brant
>
>

John,

Thanks very much. It was, as you said, a literal string that caused the
problem.

Cheers

Barry