mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix and Testcase for 199412, endless loop computing AST for self-including source-file.
This commit is contained in:
parent
60f62aafa8
commit
33b66fff45
3 changed files with 48 additions and 5 deletions
|
@ -60,6 +60,7 @@ import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IProjectDescription;
|
import org.eclipse.core.resources.IProjectDescription;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
|
@ -1042,4 +1043,38 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #ifndef GUARD
|
||||||
|
// #include "source.cpp"
|
||||||
|
// #endif
|
||||||
|
public void testIncludeSource_Bug199412() throws Exception {
|
||||||
|
StringBuffer[] contents= getContentsForTest(1);
|
||||||
|
final IIndexManager indexManager = CCorePlugin.getIndexManager();
|
||||||
|
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[0].toString());
|
||||||
|
waitForIndexer();
|
||||||
|
|
||||||
|
final ITranslationUnit tu= (ITranslationUnit) fCProject.findElement(new Path("source.cpp"));
|
||||||
|
Thread th= new Thread() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
tu.getAST(fIndex, ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
th.start();
|
||||||
|
th.join(5000);
|
||||||
|
assertFalse(th.isAlive());
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
th.stop();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -789,8 +790,11 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
IIndexFile context= null;
|
IIndexFile context= null;
|
||||||
IIndexFile indexFile= index.getFile(IndexLocationFactory.getIFL(this));
|
IIndexFile indexFile= index.getFile(IndexLocationFactory.getIFL(this));
|
||||||
if (indexFile != null) {
|
if (indexFile != null) {
|
||||||
|
// bug 199412, when a source-file includes itself the context may recurse.
|
||||||
|
HashSet visited= new HashSet();
|
||||||
|
visited.add(indexFile);
|
||||||
indexFile = getParsedInContext(indexFile);
|
indexFile = getParsedInContext(indexFile);
|
||||||
while (indexFile != null) {
|
while (indexFile != null && visited.add(indexFile)) {
|
||||||
context= indexFile;
|
context= indexFile;
|
||||||
indexFile= getParsedInContext(indexFile);
|
indexFile= getParsedInContext(indexFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,10 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int hashCode() {
|
||||||
|
return System.identityHashCode(pdom) + 41*record;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directly changes this record's internal location string. The format
|
* Directly changes this record's internal location string. The format
|
||||||
* of this string is unspecified in general and is determined by the
|
* of this string is unspecified in general and is determined by the
|
||||||
|
|
Loading…
Add table
Reference in a new issue