mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixes a potential CCE in the PDOMManager.
This commit is contained in:
parent
7cbba4df75
commit
c0244a5073
4 changed files with 39 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -17,6 +17,9 @@ import org.eclipse.core.runtime.CoreException;
|
|||
|
||||
public interface IWritableIndexManager extends IIndexManager {
|
||||
|
||||
/**
|
||||
* Returns a writable index or <code>null</code> if the project does not exist or is not yet
|
||||
* registered with the pdom manager.
|
||||
*/
|
||||
IWritableIndex getWritableIndex(ICProject project) throws CoreException;
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
|||
import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
||||
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
@ -58,13 +59,19 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
|||
monitor.subTask(NLS.bind(Messages.PDOMIndexerTask_collectingFilesTask,
|
||||
fIndexer.getProject().getElementName()));
|
||||
|
||||
ICProject project= fIndexer.getProject();
|
||||
if (project.getProject().isOpen()) {
|
||||
ICProject cproject= fIndexer.getProject();
|
||||
IProject project= cproject.getProject();
|
||||
if (project.isOpen() && project.exists()) {
|
||||
try {
|
||||
clearIndex(project);
|
||||
if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) {
|
||||
createDelegate(project, monitor);
|
||||
IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(cproject);
|
||||
if (index != null) {
|
||||
clearIndex(cproject, index);
|
||||
if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) {
|
||||
createDelegate(cproject, monitor);
|
||||
}
|
||||
}
|
||||
// remove task-tags.
|
||||
TodoTaskUpdater.removeTasksFor(project);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -76,8 +83,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
|||
}
|
||||
}
|
||||
|
||||
private void clearIndex(ICProject project) throws CoreException, InterruptedException {
|
||||
IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(project);
|
||||
private void clearIndex(ICProject project, IWritableIndex index) throws CoreException, InterruptedException {
|
||||
// First clear the pdom
|
||||
index.acquireWriteLock(0);
|
||||
try {
|
||||
|
@ -90,8 +96,6 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
|||
finally {
|
||||
index.releaseWriteLock(0);
|
||||
}
|
||||
// remove task-tags.
|
||||
TodoTaskUpdater.removeTasksFor(project.getProject());
|
||||
}
|
||||
|
||||
private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException {
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||
|
@ -79,7 +79,9 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
|||
}
|
||||
}
|
||||
|
||||
setupIndexAndReaderFactory();
|
||||
if (!setupIndexAndReaderFactory()) {
|
||||
return;
|
||||
}
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
registerTUsInReaderFactory(sources);
|
||||
|
@ -114,12 +116,16 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
|||
traceEnd(start, fIndex);
|
||||
}
|
||||
|
||||
private void setupIndexAndReaderFactory() throws CoreException {
|
||||
private boolean setupIndexAndReaderFactory() throws CoreException {
|
||||
fIndex= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
||||
if (fIndex == null) {
|
||||
return false;
|
||||
}
|
||||
fIndex.resetCacheCounters();
|
||||
fIflCache = new HashMap/*<String,IIndexFileLocation>*/();
|
||||
fCodeReaderFactory = new IndexBasedCodeReaderFactory(getCProject(), fIndex, fIflCache);
|
||||
fCodeReaderFactory.setCallbackHandler(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void registerTUsInReaderFactory(Collection tus) throws CoreException {
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
||||
|
@ -86,10 +86,12 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
|||
}
|
||||
}
|
||||
|
||||
setupIndex();
|
||||
if (!setupIndex()) {
|
||||
return;
|
||||
}
|
||||
registerTUsInReaderFactory(sources);
|
||||
registerTUsInReaderFactory(headers);
|
||||
|
||||
|
||||
Iterator i= fRemoved.iterator();
|
||||
while (i.hasNext()) {
|
||||
if (monitor.isCanceled())
|
||||
|
@ -118,12 +120,16 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
|||
traceEnd(start, fIndex);
|
||||
}
|
||||
|
||||
private void setupIndex() throws CoreException {
|
||||
private boolean setupIndex() throws CoreException {
|
||||
// there is no mechanism to clear dirty files from the cache, so flush it.
|
||||
SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush();
|
||||
|
||||
fIndex = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
||||
if (fIndex == null) {
|
||||
return false;
|
||||
}
|
||||
fIndex.resetCacheCounters();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void registerTUsInReaderFactory(Collection/*<ITranslationUnit>*/ sources)
|
||||
|
|
Loading…
Add table
Reference in a new issue