aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-02-12 22:54:40 +0000
committerTed Kremenek <kremenek@apple.com>2010-02-12 22:54:40 +0000
commita2a9d6e4e5b6001b86b7dfc5db1ea296ce29a3d3 (patch)
tree3ad4e855afd9356c2e8b5f395a7b6a376f8be45d
parent36ead2e992abb30aa3b4a40b4c8cb22cc9389fef (diff)
Make the following functions thread-safe but having them return an std::string that is reconstructed
every time they are called: getClangRevision() getClangFullRepositoryVersion() getClangFullVersion() git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96033 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang-c/Index.h2
-rw-r--r--include/clang/Basic/Version.h6
-rw-r--r--lib/Basic/Version.cpp47
-rw-r--r--tools/CIndex/CIndex.cpp4
4 files changed, 26 insertions, 33 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 90894e303e..a42ec0669e 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -1638,7 +1638,7 @@ void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
* \brief Return a version string, suitable for showing to a user, but not
* intended to be parsed (the format is not guaranteed to be stable).
*/
-CINDEX_LINKAGE const char *clang_getClangVersion();
+CINDEX_LINKAGE CXString clang_getClangVersion();
/**
* \brief Return a version string, suitable for showing to a user, but not
diff --git a/include/clang/Basic/Version.h b/include/clang/Basic/Version.h
index 4710b6b608..2728637ba4 100644
--- a/include/clang/Basic/Version.h
+++ b/include/clang/Basic/Version.h
@@ -56,16 +56,16 @@ namespace clang {
/// \brief Retrieves the repository revision number (or identifer) from which
/// this Clang was built.
- llvm::StringRef getClangRevision();
+ std::string getClangRevision();
/// \brief Retrieves the full repository version that is an amalgamation of
/// the information in getClangRepositoryPath() and getClangRevision().
- llvm::StringRef getClangFullRepositoryVersion();
+ std::string getClangFullRepositoryVersion();
/// \brief Retrieves a string representing the complete clang version,
/// which includes the clang version number, the repository version,
/// and the vendor tag.
- const char *getClangFullVersion();
+ std::string getClangFullVersion();
}
#endif // LLVM_CLANG_BASIC_VERSION_H
diff --git a/lib/Basic/Version.cpp b/lib/Basic/Version.cpp
index f9d62f9dc7..0c81fdd075 100644
--- a/lib/Basic/Version.cpp
+++ b/lib/Basic/Version.cpp
@@ -39,44 +39,37 @@ llvm::StringRef getClangRepositoryPath() {
return llvm::StringRef(URL, URLEnd - URL);
}
-
-llvm::StringRef getClangRevision() {
+std::string getClangRevision() {
#ifndef SVN_REVISION
// Subversion was not available at build time?
- return llvm::StringRef();
+ return "";
#else
- static std::string revision;
- if (revision.empty()) {
- llvm::raw_string_ostream OS(revision);
- OS << strtol(SVN_REVISION, 0, 10);
- }
+ std::string revision;
+ llvm::raw_string_ostream OS(revision);
+ OS << strtol(SVN_REVISION, 0, 10);
return revision;
#endif
}
-llvm::StringRef getClangFullRepositoryVersion() {
- static std::string buf;
- if (buf.empty()) {
- llvm::raw_string_ostream OS(buf);
- OS << getClangRepositoryPath();
- llvm::StringRef Revision = getClangRevision();
- if (!Revision.empty())
- OS << ' ' << Revision;
- }
+std::string getClangFullRepositoryVersion() {
+ std::string buf;
+ llvm::raw_string_ostream OS(buf);
+ OS << getClangRepositoryPath();
+ llvm::StringRef Revision = getClangRevision();
+ if (!Revision.empty())
+ OS << ' ' << Revision;
return buf;
}
-const char *getClangFullVersion() {
- static std::string buf;
- if (buf.empty()) {
- llvm::raw_string_ostream OS(buf);
+std::string getClangFullVersion() {
+ std::string buf;
+ llvm::raw_string_ostream OS(buf);
#ifdef CLANG_VENDOR
- OS << CLANG_VENDOR;
+ OS << CLANG_VENDOR;
#endif
- OS << "clang version " CLANG_VERSION_STRING " ("
- << getClangFullRepositoryVersion() << ')';
- }
- return buf.c_str();
+ OS << "clang version " CLANG_VERSION_STRING " ("
+ << getClangFullRepositoryVersion() << ')';
+ return buf;
}
-
+
} // end namespace clang
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index dc1608bbc8..8d887eb32e 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -2169,8 +2169,8 @@ void clang_disposeString(CXString string) {
extern "C" {
-const char *clang_getClangVersion() {
- return getClangFullVersion();
+CXString clang_getClangVersion() {
+ return CIndexer::createCXString(getClangFullVersion(), true);
}
} // end: extern "C"