Skip to content

Commit

Permalink
Fix infinite loop from recur mismatch (671)
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
jarpiain authored and stuarthalloway committed May 27, 2011
1 parent 62c4320 commit 2950679
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/jvm/clojure/lang/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5728,9 +5728,13 @@ public Expr parse(C context, Object frm) {
ObjMethod method = (ObjMethod) METHOD.deref();
IPersistentMap backupMethodLocals = method.locals;
IPersistentMap backupMethodIndexLocals = method.indexlocals;
PersistentVector recurMismatches = null;
IPersistentVector recurMismatches = PersistentVector.EMPTY;
for (int i = 0; i < bindings.count()/2; i++)
{
recurMismatches = recurMismatches.cons(RT.F);
}

//we might repeat once if a loop with a recurMistmatch, return breaks
//may repeat once for each binding with a mismatch, return breaks
while(true){
IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.deref(),
NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.deref());
Expand All @@ -5757,7 +5761,7 @@ public Expr parse(C context, Object frm) {
Expr init = analyze(C.EXPRESSION, bindings.nth(i + 1), sym.name);
if(isLoop)
{
if(recurMismatches != null && ((LocalBinding)recurMismatches.nth(i/2)).recurMistmatch)
if(recurMismatches != null && RT.booleanCast(recurMismatches.nth(i/2)))
{
init = new StaticMethodExpr("", 0, null, RT.class, "box", RT.vector(init));
if(RT.booleanCast(RT.WARN_ON_REFLECTION.deref()))
Expand All @@ -5779,6 +5783,7 @@ else if(maybePrimitiveType(init) == float.class)
if(isLoop)
LOOP_LOCALS.set(loopLocals);
Expr bodyExpr;
boolean moreMismatches = false;
try {
if(isLoop)
{
Expand All @@ -5795,16 +5800,18 @@ CLEAR_ROOT, new PathNode(PATHTYPE.PATH,root),
if(isLoop)
{
Var.popThreadBindings();
recurMismatches = null;
for(int i = 0;i< loopLocals.count();i++)
{
LocalBinding lb = (LocalBinding) loopLocals.nth(i);
if(lb.recurMistmatch)
recurMismatches = loopLocals;
{
recurMismatches = (IPersistentVector)recurMismatches.assoc(i, RT.T);
moreMismatches = true;
}
}
}
}
if(recurMismatches == null)
if(!moreMismatches)
return new LetExpr(bindingInits, bodyExpr, isLoop);
}
finally
Expand Down

0 comments on commit 2950679

Please sign in to comment.