mirror of
https://github.com/gnustep/libs-steptalk.git
synced 2025-02-21 02:31:01 +00:00
Fix bug where the cached context of a block could be reused prematurely.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@38146 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
54ff99c389
commit
5e87e76a79
2 changed files with 31 additions and 3 deletions
|
@ -1,3 +1,19 @@
|
|||
2014-11-01 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* 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 <wolfgang.lux@gmail.com>
|
||||
|
||||
* STBlock.m (-dealloc): Release cachedContext attribute.
|
||||
|
|
|
@ -186,13 +186,25 @@ Class STBlockContextClass = nil;
|
|||
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)
|
||||
if (context == cachedContext)
|
||||
{
|
||||
usingCachedContext = NO;
|
||||
if (usingCachedContext)
|
||||
usingCachedContext = NO;
|
||||
else
|
||||
[NSException raise:STInternalInconsistencyException
|
||||
format:@"%@: using cached context %@",
|
||||
@" but usingCachedContext is not set",
|
||||
self, cachedContext];
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
|
Loading…
Reference in a new issue