Skip to content

Commit

Permalink
War of the wallpaper! I think my fix to remove bogus extra dynscope p…
Browse files Browse the repository at this point in the history
…er simple eval

exposed that we somewhere pop off toplevel scope before the runtime shuts down.  To
counteract this I add back a bogus scope only for shutdown.  This is likely a bug
in that any capture lvars in at_exit blocks is likely lost (haven't tested), but
this makes mspec fast run without error for now.
  • Loading branch information
enebo committed Dec 18, 2014
1 parent a8e5323 commit 0f4adc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.jruby.compiler.Constantizable;
import org.jruby.compiler.NotCompilableException;
import org.jruby.ir.IRScriptBody;
import org.jruby.parser.StaticScope;
import org.objectweb.asm.util.TraceClassVisitor;

import jnr.constants.Constant;
Expand Down Expand Up @@ -3164,6 +3165,16 @@ public void tearDown(boolean systemExit) {
// clear out threadlocals so they don't leak
recursive = new ThreadLocal<Map<String, RubyHash>>();

ThreadContext context = getCurrentContext();

// FIXME: 73df3d230b9d92c7237d581c6366df1b92ad9b2b exposed no toplevel scope existing anymore (I think the
// bogus scope I removed was playing surrogate toplevel scope and wallpapering this bug). For now, add a
// bogus scope back for at_exit block run. This is buggy if at_exit is capturing vars.
if (!context.hasAnyScopes()) {
StaticScope topStaticScope = getStaticScopeFactory().newLocalScope(null);
context.pushScope(new ManyVarsDynamicScope(topStaticScope, null));
}

while (!atExitBlocks.empty()) {
RubyProc proc = atExitBlocks.pop();
try {
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ public static void popBacktrace(ThreadContext context) {
context.backtraceIndex--;
}

public boolean hasAnyScopes() {
return scopeIndex > -1;
}

/**
* Check if a static scope is present on the call stack.
* This is the IR equivalent of isJumpTargetAlive
Expand Down

0 comments on commit 0f4adc3

Please sign in to comment.