[PATCH 1/2] streams: Fix the ConcatenatedStream>>#copyFrom:to: implementation

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

[PATCH 1/2] streams: Fix the ConcatenatedStream>>#copyFrom:to: implementation

Holger Freyther
From: Holger Hans Peter Freyther <[hidden email]>

$ gst-convert -F squeak -o out.st File1.st File2.st File3.st

failed with nil doesn't understand copyFrom: to:. This happens when
the stream is at the end and 'self stream' returns nil and the last
stream is not migrated to 'last'. Check for this condition in the
copyFrom:to:.

2012-10-06  Holger Freyther  <[hidden email]>

        * kernel/StreamOps.st: Modify ConcatenatedStream>>#copyFrom:to:
        when at the end of the last stream.
        * tests/stream.st: Add testcase for ConcatenatedStream>>#copyFrom:to:
        at the end of the last stream.
        * tests/stream.ok: Create the test result.
        * tests/testsuite.at: Add the stream.st to the regression tests.
---
 ChangeLog           |    9 +++++++++
 kernel/StreamOps.st |    2 +-
 tests/testsuite.at  |    1 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 91c384e..9ddd89e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-10-06  Holger Freyther  <[hidden email]>
+
+ * kernel/StreamOps.st: Modify ConcatenatedStream>>#copyFrom:to:
+ when at the end of the last stream.
+ * tests/stream.st: Add testcase for ConcatenatedStream>>#copyFrom:to:
+ at the end of the last stream.
+ * tests/stream.ok: Create the test result.
+ * tests/testsuite.at: Add the stream.st to the regression tests.
+
 2012-10-02  Holger Freyther  <[hidden email]>
 
  * tests/stcompiler.st: Add testcase for pragma parsing.
diff --git a/kernel/StreamOps.st b/kernel/StreamOps.st
index 9fd1769..0525e5f 100644
--- a/kernel/StreamOps.st
+++ b/kernel/StreamOps.st
@@ -158,7 +158,7 @@ Stream subclass: ConcatenatedStream [
 
  <category: 'all'>
  | adjust stream |
- stream := self stream.
+ stream := self stream ifNil: [streams first].
  end + 1 = start ifTrue: [^''].
  adjust := end <= startPos
     ifTrue: [stream := last. lastStart]
diff --git a/tests/testsuite.at b/tests/testsuite.at
index ffa3919..d64f061 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -52,6 +52,7 @@ AT_DIFF_TEST([getopt.st])
 AT_DIFF_TEST([quit.st])
 AT_DIFF_TEST([pools.st])
 AT_DIFF_TEST([shape.st])
+AT_DIFF_TEST([stream.st])
 
 AT_BANNER([Other simple tests.])
 AT_DIFF_TEST([ackermann.st])
--
1.7.10.4


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] stinst: Squeak does not like nil as category string use a string

Holger Freyther
From: Holger Hans Peter Freyther <[hidden email]>

2012-10-06  Holger Freyther  <[hidden email]>

        * SqueakExporter.st: Use 'as yet unclassified' as category string
        if it is nil.
---
 packages/stinst/parser/ChangeLog         |    5 +++++
 packages/stinst/parser/SqueakExporter.st |    7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog
index 58affee..9681f53 100644
--- a/packages/stinst/parser/ChangeLog
+++ b/packages/stinst/parser/ChangeLog
@@ -1,3 +1,8 @@
+2012-10-06  Holger Freyther  <[hidden email]>
+
+ * SqueakExporter.st: Use 'as yet unclassified' as category string
+ if it is nil.
+
 2012-10-02  Holger Freyther  <[hidden email]>
 
  * GSTParser.st: Change GSTFileInParser>>#parseClassTag to parse
diff --git a/packages/stinst/parser/SqueakExporter.st b/packages/stinst/parser/SqueakExporter.st
index ac314f8..cf37505 100644
--- a/packages/stinst/parser/SqueakExporter.st
+++ b/packages/stinst/parser/SqueakExporter.st
@@ -69,4 +69,11 @@ OldSyntaxExporter subclass: SqueakSyntaxExporter [
 
  super fileOutClassDeclaration: aBlock
     ]
+
+    fileOutCategory: aString methods: methods class: aClass [
+        | cat |
+        "Pharo does not like 'nil' as category name pick something else."
+        cat := aString ifNil: ['as yet unclassified'].
+        ^super fileOutCategory: cat methods: methods class: aClass.
+    ]
 ]
--
1.7.10.4


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] streams: Fix the ConcatenatedStream>>#copyFrom:to: implementation

Paolo Bonzini-2
In reply to this post by Holger Freyther
Il 06/10/2012 18:32, Holger Hans Peter Freyther ha scritto:

> From: Holger Hans Peter Freyther <[hidden email]>
>
> $ gst-convert -F squeak -o out.st File1.st File2.st File3.st
>
> failed with nil doesn't understand copyFrom: to:. This happens when
> the stream is at the end and 'self stream' returns nil and the last
> stream is not migrated to 'last'. Check for this condition in the
> copyFrom:to:.
>
> 2012-10-06  Holger Freyther  <[hidden email]>
>
> * kernel/StreamOps.st: Modify ConcatenatedStream>>#copyFrom:to:
> when at the end of the last stream.
> * tests/stream.st: Add testcase for ConcatenatedStream>>#copyFrom:to:
> at the end of the last stream.
> * tests/stream.ok: Create the test result.
> * tests/testsuite.at: Add the stream.st to the regression tests.
> ---
>  ChangeLog           |    9 +++++++++
>  kernel/StreamOps.st |    2 +-
>  tests/testsuite.at  |    1 +
>  3 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index 91c384e..9ddd89e 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,12 @@
> +2012-10-06  Holger Freyther  <[hidden email]>
> +
> + * kernel/StreamOps.st: Modify ConcatenatedStream>>#copyFrom:to:
> + when at the end of the last stream.
> + * tests/stream.st: Add testcase for ConcatenatedStream>>#copyFrom:to:
> + at the end of the last stream.
> + * tests/stream.ok: Create the test result.
> + * tests/testsuite.at: Add the stream.st to the regression tests.
> +
>  2012-10-02  Holger Freyther  <[hidden email]>
>  
>   * tests/stcompiler.st: Add testcase for pragma parsing.
> diff --git a/kernel/StreamOps.st b/kernel/StreamOps.st
> index 9fd1769..0525e5f 100644
> --- a/kernel/StreamOps.st
> +++ b/kernel/StreamOps.st
> @@ -158,7 +158,7 @@ Stream subclass: ConcatenatedStream [
>  
>   <category: 'all'>
>   | adjust stream |
> - stream := self stream.
> + stream := self stream ifNil: [streams first].
>   end + 1 = start ifTrue: [^''].
>   adjust := end <= startPos
>      ifTrue: [stream := last. lastStart]
> diff --git a/tests/testsuite.at b/tests/testsuite.at
> index ffa3919..d64f061 100644
> --- a/tests/testsuite.at
> +++ b/tests/testsuite.at
> @@ -52,6 +52,7 @@ AT_DIFF_TEST([getopt.st])
>  AT_DIFF_TEST([quit.st])
>  AT_DIFF_TEST([pools.st])
>  AT_DIFF_TEST([shape.st])
> +AT_DIFF_TEST([stream.st])
>  
>  AT_BANNER([Other simple tests.])
>  AT_DIFF_TEST([ackermann.st])
>

You didn't include stream.st and stream.ok. :)

Does this work instead?  As you mentioned the problem is that
last was not initialized.

diff --git a/kernel/StreamOps.st b/kernel/StreamOps.st
index 9fd1769..63bea8a 100644
--- a/kernel/StreamOps.st
+++ b/kernel/StreamOps.st
@@ -78,11 +78,13 @@ Stream subclass: ConcatenatedStream [
     stream [
  <category: 'all'>
  | s |
- [(s := streams first) atEnd] whileTrue:
- [streams size = 1 ifTrue: [^nil].
- lastStart := startPos.
+        "This is somewhat performance-sensitive, so avoid testing for an
+         empty collection."
+ [(s := streams at: 1) atEnd] whileTrue:
+ [lastStart := startPos.
  startPos := startPos + curPos.
  curPos := 0.
+                streams size = 1 ifTrue: [last := streams first. ^nil].
  last := streams removeFirst].
  ^s
     ]

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] stinst: Squeak does not like nil as category string use a string

Paolo Bonzini-2
In reply to this post by Holger Freyther
Il 06/10/2012 18:32, Holger Hans Peter Freyther ha scritto:

> From: Holger Hans Peter Freyther <[hidden email]>
>
> 2012-10-06  Holger Freyther  <[hidden email]>
>
> * SqueakExporter.st: Use 'as yet unclassified' as category string
> if it is nil.
> ---
>  packages/stinst/parser/ChangeLog         |    5 +++++
>  packages/stinst/parser/SqueakExporter.st |    7 +++++++
>  2 files changed, 12 insertions(+)
>
> diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog
> index 58affee..9681f53 100644
> --- a/packages/stinst/parser/ChangeLog
> +++ b/packages/stinst/parser/ChangeLog
> @@ -1,3 +1,8 @@
> +2012-10-06  Holger Freyther  <[hidden email]>
> +
> + * SqueakExporter.st: Use 'as yet unclassified' as category string
> + if it is nil.
> +
>  2012-10-02  Holger Freyther  <[hidden email]>
>  
>   * GSTParser.st: Change GSTFileInParser>>#parseClassTag to parse
> diff --git a/packages/stinst/parser/SqueakExporter.st b/packages/stinst/parser/SqueakExporter.st
> index ac314f8..cf37505 100644
> --- a/packages/stinst/parser/SqueakExporter.st
> +++ b/packages/stinst/parser/SqueakExporter.st
> @@ -69,4 +69,11 @@ OldSyntaxExporter subclass: SqueakSyntaxExporter [
>  
>   super fileOutClassDeclaration: aBlock
>      ]
> +
> +    fileOutCategory: aString methods: methods class: aClass [
> +        | cat |
> +        "Pharo does not like 'nil' as category name pick something else."
> +        cat := aString ifNil: ['as yet unclassified'].
> +        ^super fileOutCategory: cat methods: methods class: aClass.
> +    ]
>  ]
>

Applied, thanks!

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] streams: Fix the ConcatenatedStream>>#copyFrom:to: implementation

Holger Freyther
In reply to this post by Paolo Bonzini-2
On Mon, Oct 08, 2012 at 06:07:13PM +0200, Paolo Bonzini wrote:
> You didn't include stream.st and stream.ok. :)

Yeah, had to stop in the middle of turbulances.. and then forgot that
I didn't finish it. The test and test result is attached and your patch
is failing with my testcase.

> - [(s := streams first) atEnd] whileTrue:
> - [streams size = 1 ifTrue: [^nil].
> - lastStart := startPos.
> +        "This is somewhat performance-sensitive, so avoid testing for an
> +         empty collection."
> + [(s := streams at: 1) atEnd] whileTrue:
> + [lastStart := startPos.
>   startPos := startPos + curPos.
>   curPos := 0.
> +                streams size = 1 ifTrue: [last := streams first. ^nil].
I don't see why it is failing but maybe the test helps.

holger

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk

stream.st (1K) Download Attachment
stream.ok (102 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] streams: Fix the ConcatenatedStream>>#copyFrom:to: implementation

Paolo Bonzini-2
Il 09/10/2012 16:43, Holger Hans Peter Freyther ha scritto:

>> > - [(s := streams first) atEnd] whileTrue:
>> > - [streams size = 1 ifTrue: [^nil].
>> > - lastStart := startPos.
>> > +        "This is somewhat performance-sensitive, so avoid testing for an
>> > +         empty collection."
>> > + [(s := streams at: 1) atEnd] whileTrue:
>> > + [lastStart := startPos.
>> >   startPos := startPos + curPos.
>> >   curPos := 0.
>> > +                streams size = 1 ifTrue: [last := streams first. ^nil].
> I don't see why it is failing but maybe the test helps.

Yes, this fixes it:

diff --git a/kernel/StreamOps.st b/kernel/StreamOps.st
index 63bea8a..54f82af 100644
--- a/kernel/StreamOps.st
+++ b/kernel/StreamOps.st
@@ -81,9 +81,10 @@ Stream subclass: ConcatenatedStream [
         "This is somewhat performance-sensitive, so avoid testing for an
          empty collection."
  [(s := streams at: 1) atEnd] whileTrue:
- [lastStart := startPos.
- startPos := startPos + curPos.
- curPos := 0.
+ [curPos > 0 ifTrue: [
+                    lastStart := startPos.
+    startPos := startPos + curPos.
+    curPos := 0].
                 streams size = 1 ifTrue: [last := streams first. ^nil].
  last := streams removeFirst].
  ^s

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk