Author: wlux
Date: Sat Nov  1 19:26:39 2014
New Revision: 38146

URL: http://svn.gna.org/viewcvs/gnustep?rev=38146&view=rev
Log:
Fix bug where the cached context of a block could be reused prematurely.

Modified:
    libs/steptalk/trunk/Languages/Smalltalk/ChangeLog
    libs/steptalk/trunk/Languages/Smalltalk/STBlock.m

Modified: libs/steptalk/trunk/Languages/Smalltalk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/steptalk/trunk/Languages/Smalltalk/ChangeLog?rev=38146&r1=38145&r2=38146&view=diff
==============================================================================
--- libs/steptalk/trunk/Languages/Smalltalk/ChangeLog   (original)
+++ libs/steptalk/trunk/Languages/Smalltalk/ChangeLog   Sat Nov  1 19:26:39 2014
@@ -1,3 +1,19 @@
+2014-11-01  Wolfgang Lux  <[email protected]>
+
+    * STBlock.m (-valueWithArguments:): Fix bug where the cached context
+    of a block could be reused prematurely.
+    Note: This could happen only when a block is called recursively and
+    entered more than once in an inner invocation, as, e.g., in the
+    following code to compute the Fibonacci numbers:
+      fib := [:n |
+        (n <= 1)
+          ifTrue: [1]
+          ifFalse: [(fib value: (n - 1)) + (fib value: (n - 2))]].
+      fib value: 3.
+    Note that the code still does not produce the correct result because
+    blocks are not (yet) reentrant in the interpreter, but at least the
+    interpreter does not crash anymore.
+
 2014-11-01  Wolfgang Lux  <[email protected]>
 
     * STBlock.m (-dealloc): Release cachedContext attribute.

Modified: libs/steptalk/trunk/Languages/Smalltalk/STBlock.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/steptalk/trunk/Languages/Smalltalk/STBlock.m?rev=38146&r1=38145&r2=38146&view=diff
==============================================================================
--- libs/steptalk/trunk/Languages/Smalltalk/STBlock.m   (original)
+++ libs/steptalk/trunk/Languages/Smalltalk/STBlock.m   Sat Nov  1 19:26:39 2014
@@ -186,13 +186,25 @@
     parentContext = [interpreter context];
 
     [interpreter setContext:context];
-    retval = [interpreter interpret];
+    NS_DURING
+        retval = [interpreter interpret];
+    NS_HANDLER
+        if (context == cachedContext)
+            usingCachedContext = NO;
+        [localException raise];
+    NS_ENDHANDLER
     [interpreter setContext:parentContext];
 
     /* Release cached context */
-    if(usingCachedContext)
-    {
-        usingCachedContext = NO;
+    if (context == cachedContext)
+    {
+        if (usingCachedContext)
+            usingCachedContext = NO;
+        else
+            [NSException raise:STInternalInconsistencyException
+                        format:@"%@: using cached context %@",
+                               @" but usingCachedContext is not set",
+                               self, cachedContext];
     }
 
     return retval;


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to