[8.5.2] Stack overflow printing self-referential collection

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

[8.5.2] Stack overflow printing self-referential collection

Richard Sargent
Administrator
Collection implements a printing protocol to avoid stack overflows, but it is inadequate.
The following example is paraphrased from something I just encountered. (I didn't make the example up, just for the sake of reporting an error! <s>)

| a |
a := Array new: 1.
a at: 1 put: 'second' -> a.
a printString

The recursion set logic doesn't really help if the self-reference occurs inside one of the elements.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [8.5.2] Stack overflow printing self-referential collection

Richard Sargent
Administrator
Hacked in Association to mimic the functionality used for #storeOn:... It's still far from a complete solution.

printOn: aStream recursionSet: objectsAlreadyCopied

    "Append to the argument aStream, a sequence of characters that
     describes the receiver.  Answer self.

     Fail if aStream is not a kind of Stream."

    "This method avoids the use of printString or storeString messages"


    (self recursiveAccessCheck: objectsAlreadyCopied) ifTrue: [
        ExCLDTRecursiveStoreOnError signal].

     self key printOn: aStream recursionSet: objectsAlreadyCopied.
     aStream nextPutAll: ' -> '.  "$NON-NLS$"
     value printOn: aStream recursionSet: objectsAlreadyCopied.

    self recursiveAccessClear: objectsAlreadyCopied.


On Thursday, March 13, 2014 2:18:39 PM UTC-7, Richard Sargent wrote:
Collection implements a printing protocol to avoid stack overflows, but it is inadequate.
The following example is paraphrased from something I just encountered. (I didn't make the example up, just for the sake of reporting an error! <s>)

| a |
a := Array new: 1.
a at: 1 put: 'second' -> a.
a printString

The recursion set logic doesn't really help if the self-reference occurs inside one of the elements.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.