[cfe-commits] r84413 - /cfe/trunk/tools/CIndex/CIndex.cpp
Benjamin Kramer
benny.kra at googlemail.com
Sun Oct 18 04:10:57 PDT 2009
Author: d0k
Date: Sun Oct 18 06:10:55 2009
New Revision: 84413
URL: http://llvm.org/viewvc/llvm-project?rev=84413&view=rev
Log:
CIndex: avoid a dangling pointer issue.
Modified:
cfe/trunk/tools/CIndex/CIndex.cpp
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=84413&r1=84412&r2=84413&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Sun Oct 18 06:10:55 2009
@@ -268,7 +268,8 @@
class CIndexer : public Indexer {
public:
- explicit CIndexer(Program *prog) : Indexer(*prog), OnlyLocalDecls(false) {}
+ explicit CIndexer(Program *prog, std::string &path)
+ : Indexer(*prog), OnlyLocalDecls(false), ClangPath(path) {}
virtual ~CIndexer() { delete &getProgram(); }
@@ -277,17 +278,17 @@
/// declarations.
bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
-
+
+ const std::string& getClangPath() { return ClangPath; }
private:
bool OnlyLocalDecls;
+ std::string ClangPath;
};
}
extern "C" {
-static const char *clangPath;
-
CXIndex clang_createIndex()
{
// FIXME: This is a hack to unbreak the MSVC build.
@@ -308,9 +309,7 @@
// We now have the CIndex directory, locate clang relative to it.
std::string ClangPath = CIndexDir + "/../bin/clang";
- clangPath = ClangPath.c_str();
-
- return new CIndexer(new Program());
+ return new CIndexer(new Program(), ClangPath);
}
void clang_disposeIndex(CXIndex CIdx)
@@ -345,7 +344,7 @@
#else
// Build up the arguments for involing clang.
std::vector<const char *> argv;
- argv.push_back(clangPath);
+ argv.push_back(static_cast<CIndexer *>(CIdx)->getClangPath().c_str());
argv.push_back("-emit-ast");
argv.push_back(source_filename);
argv.push_back("-o");
More information about the cfe-commits
mailing list