[PATCH] stinst: Avoid running into recursion in ProxyNamespace

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

[PATCH] stinst: Avoid running into recursion in ProxyNamespace

Holger Freyther
(STInST.STClassLoaderObjects.ProxyNamespace
        on: Smalltalk for: STInST.STClassLoader new) displayString

triggered a DNU for classNameString and after fixing that it ended
with an infinite recursion as the value is self. Avoid the recursion.

2013-03-31  Holger Hans Peter Freyther  <[hidden email]>

        * tests/stcompiler.ok: Update the test result.
        * tests/stcompiler.st: Add a testcase for ProxyNamespace>>#printOn:.

2013-03-31  Holger Hans Peter Freyther  <[hidden email]>

        * STLoaderObjs.st: Change ProxyNamespace>>#printOn to avoid
        recursion into self.
---
 ChangeLog                              |    5 +++++
 packages/stinst/parser/ChangeLog       |    5 +++++
 packages/stinst/parser/STLoaderObjs.st |   18 ++++++++++++------
 tests/stcompiler.ok                    |    5 +++++
 tests/stcompiler.st                    |    7 +++++++
 5 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6c2abb5..54683ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-03-31  Holger Hans Peter Freyther  <[hidden email]>
+
+ * tests/stcompiler.ok: Update the test result.
+ * tests/stcompiler.st: Add a testcase for ProxyNamespace>>#printOn:.
+
 2013-03-24  Holger Hans Peter Freyther  <[hidden email]>
 
  * libgst/files.c: Add DirPackage.st to the bootstrap.
diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog
index 24bf131..0bc8d23 100644
--- a/packages/stinst/parser/ChangeLog
+++ b/packages/stinst/parser/ChangeLog
@@ -1,3 +1,8 @@
+2013-03-31  Holger Hans Peter Freyther  <[hidden email]>
+
+ * STLoaderObjs.st: Change ProxyNamespace>>#printOn to avoid
+ recursion into self.
+
 2013-02-23  Holger Hans Peter Freyther  <[hidden email]>
 
  * RBParser.st: Fix RBParser>>#parsedNegatedNumber.
diff --git a/packages/stinst/parser/STLoaderObjs.st b/packages/stinst/parser/STLoaderObjs.st
index 195ceef..9bbb0ea 100644
--- a/packages/stinst/parser/STLoaderObjs.st
+++ b/packages/stinst/parser/STLoaderObjs.st
@@ -1507,13 +1507,19 @@ name
 
 printOn: aStream
     "Print a representation of the receiver on aStream"
-    aStream nextPutAll: self classNameString , '[', proxy name, '] (' ; nl.
+    aStream nextPutAll: self class storeString , '[', proxy name, '] (' ; nl.
     self myKeysAndValuesDo:
-     [ :key :value | aStream tab;
-   print: key;
-   nextPutAll: '->';
-   print: value;
-   nl ].
+        [ :key :value |
+            "The ProxyNamespace is linked to itself in
+             ProxyNamespace class>>#on:for: so we need to skip ourself
+             here or we will loop forever."
+            value == self ifFalse: [
+                aStream tab;
+                    print: key;
+                    nextPutAll: '->';
+                    print: value;
+                    nl ].
+        ].
     aStream nextPut: $)
 !
 
diff --git a/tests/stcompiler.ok b/tests/stcompiler.ok
index 4222e50..a0cebf4 100644
--- a/tests/stcompiler.ok
+++ b/tests/stcompiler.ok
@@ -52,6 +52,11 @@ Execution begins...
 returned value is 'an'
 
 Execution begins...
+STInST.STClassLoaderObjects.ProxyNamespace[Smalltalk] (
+)
+returned value is ProxyNamespace new: 32 "<0>"
+
+Execution begins...
 true
 true
 returned value is true
diff --git a/tests/stcompiler.st b/tests/stcompiler.st
index 36b48a7..5605a6e 100644
--- a/tests/stcompiler.st
+++ b/tests/stcompiler.st
@@ -118,6 +118,13 @@ Eval [
 ]
 
 Eval [
+    | proxy |
+    proxy := STInST.STClassLoaderObjects.ProxyNamespace
+                    on: Smalltalk for: STInST.STClassLoader new.
+    proxy printNl.
+]
+
+Eval [
     | classes bla |
     "Check class variable parsing.."
 
--
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] stinst: Avoid running into recursion in ProxyNamespace

Paolo Bonzini-2
Il 05/05/2013 11:24, Holger Hans Peter Freyther ha scritto:
> (STInST.STClassLoaderObjects.ProxyNamespace
> on: Smalltalk for: STInST.STClassLoader new) displayString
>
> triggered a DNU for classNameString and after fixing that it ended
> with an infinite recursion as the value is self. Avoid the recursion.

Ok.

Paolo

>
> 2013-03-31  Holger Hans Peter Freyther  <[hidden email]>
>
> * tests/stcompiler.ok: Update the test result.
> * tests/stcompiler.st: Add a testcase for ProxyNamespace>>#printOn:.
>
> 2013-03-31  Holger Hans Peter Freyther  <[hidden email]>
>
> * STLoaderObjs.st: Change ProxyNamespace>>#printOn to avoid
> recursion into self.
> ---
>  ChangeLog                              |    5 +++++
>  packages/stinst/parser/ChangeLog       |    5 +++++
>  packages/stinst/parser/STLoaderObjs.st |   18 ++++++++++++------
>  tests/stcompiler.ok                    |    5 +++++
>  tests/stcompiler.st                    |    7 +++++++
>  5 files changed, 34 insertions(+), 6 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index 6c2abb5..54683ff 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2013-03-31  Holger Hans Peter Freyther  <[hidden email]>
> +
> + * tests/stcompiler.ok: Update the test result.
> + * tests/stcompiler.st: Add a testcase for ProxyNamespace>>#printOn:.
> +
>  2013-03-24  Holger Hans Peter Freyther  <[hidden email]>
>  
>   * libgst/files.c: Add DirPackage.st to the bootstrap.
> diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog
> index 24bf131..0bc8d23 100644
> --- a/packages/stinst/parser/ChangeLog
> +++ b/packages/stinst/parser/ChangeLog
> @@ -1,3 +1,8 @@
> +2013-03-31  Holger Hans Peter Freyther  <[hidden email]>
> +
> + * STLoaderObjs.st: Change ProxyNamespace>>#printOn to avoid
> + recursion into self.
> +
>  2013-02-23  Holger Hans Peter Freyther  <[hidden email]>
>  
>   * RBParser.st: Fix RBParser>>#parsedNegatedNumber.
> diff --git a/packages/stinst/parser/STLoaderObjs.st b/packages/stinst/parser/STLoaderObjs.st
> index 195ceef..9bbb0ea 100644
> --- a/packages/stinst/parser/STLoaderObjs.st
> +++ b/packages/stinst/parser/STLoaderObjs.st
> @@ -1507,13 +1507,19 @@ name
>  
>  printOn: aStream
>      "Print a representation of the receiver on aStream"
> -    aStream nextPutAll: self classNameString , '[', proxy name, '] (' ; nl.
> +    aStream nextPutAll: self class storeString , '[', proxy name, '] (' ; nl.
>      self myKeysAndValuesDo:
> -     [ :key :value | aStream tab;
> -   print: key;
> -   nextPutAll: '->';
> -   print: value;
> -   nl ].
> +        [ :key :value |
> +            "The ProxyNamespace is linked to itself in
> +             ProxyNamespace class>>#on:for: so we need to skip ourself
> +             here or we will loop forever."
> +            value == self ifFalse: [
> +                aStream tab;
> +                    print: key;
> +                    nextPutAll: '->';
> +                    print: value;
> +                    nl ].
> +        ].
>      aStream nextPut: $)
>  !
>  
> diff --git a/tests/stcompiler.ok b/tests/stcompiler.ok
> index 4222e50..a0cebf4 100644
> --- a/tests/stcompiler.ok
> +++ b/tests/stcompiler.ok
> @@ -52,6 +52,11 @@ Execution begins...
>  returned value is 'an'
>  
>  Execution begins...
> +STInST.STClassLoaderObjects.ProxyNamespace[Smalltalk] (
> +)
> +returned value is ProxyNamespace new: 32 "<0>"
> +
> +Execution begins...
>  true
>  true
>  returned value is true
> diff --git a/tests/stcompiler.st b/tests/stcompiler.st
> index 36b48a7..5605a6e 100644
> --- a/tests/stcompiler.st
> +++ b/tests/stcompiler.st
> @@ -118,6 +118,13 @@ Eval [
>  ]
>  
>  Eval [
> +    | proxy |
> +    proxy := STInST.STClassLoaderObjects.ProxyNamespace
> +                    on: Smalltalk for: STInST.STClassLoader new.
> +    proxy printNl.
> +]
> +
> +Eval [
>      | classes bla |
>      "Check class variable parsing.."
>  
>


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