Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2007-08-23 11:36:21 +0000
committerMarkus Schorn2007-08-23 11:36:21 +0000
commit33b66fff45fc4cd3e82c329c767d1998aaae1104 (patch)
treeb293e88b92e3a725bdf52bddbed095fda6d42c8b /core
parent60f62aafa8bc391a405a0a04b3846349dc942450 (diff)
downloadorg.eclipse.cdt-33b66fff45fc4cd3e82c329c767d1998aaae1104.tar.gz
org.eclipse.cdt-33b66fff45fc4cd3e82c329c767d1998aaae1104.tar.xz
org.eclipse.cdt-33b66fff45fc4cd3e82c329c767d1998aaae1104.zip
Fix and Testcase for 199412, endless loop computing AST for self-including source-file.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java37
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java10
3 files changed, 48 insertions, 5 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
index 948c371ecaf..55aa0d2dd42 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
@@ -60,6 +60,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
@@ -1041,5 +1042,39 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.releaseReadLock();
}
}
-
+
+ // #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();
+ }
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
index 95f5a2e00c6..61adf23500d 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
@@ -19,6 +19,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -789,8 +790,11 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
IIndexFile context= null;
IIndexFile indexFile= index.getFile(IndexLocationFactory.getIFL(this));
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);
- while (indexFile != null) {
+ while (indexFile != null && visited.add(indexFile)) {
context= indexFile;
indexFile= getParsedInContext(indexFile);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
index e84a571b23a..551287fa8a4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
@@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Andrew Ferguson (Symbian)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
@@ -107,6 +107,10 @@ public class PDOMFile implements IIndexFragmentFile {
return false;
}
+ public final int hashCode() {
+ return System.identityHashCode(pdom) + 41*record;
+ }
+
/**
* Directly changes this record's internal location string. The format
* of this string is unspecified in general and is determined by the

Back to the top