]> granicus.if.org Git - clang/commitdiff
Revert 98439. There is a bad race condition in sys::Path::makeUnique on win32.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 13 Mar 2010 21:22:49 +0000 (21:22 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 13 Mar 2010 21:22:49 +0000 (21:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98452 91177308-0d34-0410-b5e6-96231b3b80d8

tools/CIndex/CIndex.cpp
tools/CIndex/CIndexCodeCompletion.cpp
tools/CIndex/CIndexer.cpp
tools/CIndex/CIndexer.h

index 594654fe6c6df5164f00023f6e434eb325f110aa..b52a32ed9b5183c84c555d19a3123170665e0a9e 100644 (file)
@@ -29,6 +29,9 @@
 #include "llvm/System/Program.h"
 #include "llvm/System/Signals.h"
 
+// Needed to define L_TMPNAM on some systems.
+#include <cstdio>
+
 using namespace clang;
 using namespace clang::cxcursor;
 using namespace clang::cxstring;
@@ -1052,8 +1055,8 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
 
   // Generate a temporary name for the AST file.
   argv.push_back("-o");
-  llvm::sys::Path astTmpFile(CIndexer::getTemporaryPath());
-  argv.push_back(astTmpFile.c_str());
+  char astTmpFile[L_tmpnam];
+  argv.push_back(tmpnam(astTmpFile));
 
   // Remap any unsaved files to temporary files.
   std::vector<llvm::sys::Path> TemporaryFiles;
@@ -1084,7 +1087,9 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
     }
 
   // Generate a temporary name for the diagnostics file.
-  llvm::sys::Path DiagnosticsFile(CIndexer::getTemporaryPath());
+  char tmpFileResults[L_tmpnam];
+  char *tmpResultsFileName = tmpnam(tmpFileResults);
+  llvm::sys::Path DiagnosticsFile(tmpResultsFileName);
   TemporaryFiles.push_back(DiagnosticsFile);
   argv.push_back("-fdiagnostics-binary");
 
@@ -1113,7 +1118,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
     Diags->Report(diag::err_fe_invoking) << AllArgs << ErrMsg;
   }
 
-  ASTUnit *ATU = ASTUnit::LoadFromPCHFile(astTmpFile.str(), *Diags,
+  ASTUnit *ATU = ASTUnit::LoadFromPCHFile(astTmpFile, *Diags,
                                           CXXIdx->getOnlyLocalDecls(),
                                           RemappedFiles.data(),
                                           RemappedFiles.size(),
index cd3787204cba35e24868d41d7fe7fc9256df306a..3b7674ec0d1d29b8f17a452e8b00e48f8fc1c055 100644 (file)
@@ -299,11 +299,15 @@ CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
   argv.push_back(NULL);
 
   // Generate a temporary name for the code-completion results file.
-  llvm::sys::Path ResultsFile(CIndexer::getTemporaryPath());
+  char tmpFile[L_tmpnam];
+  char *tmpFileName = tmpnam(tmpFile);
+  llvm::sys::Path ResultsFile(tmpFileName);
   TemporaryFiles.push_back(ResultsFile);
 
   // Generate a temporary name for the diagnostics file.
-  llvm::sys::Path DiagnosticsFile(CIndexer::getTemporaryPath());
+  char tmpFileResults[L_tmpnam];
+  char *tmpResultsFileName = tmpnam(tmpFileResults);
+  llvm::sys::Path DiagnosticsFile(tmpResultsFileName);
   TemporaryFiles.push_back(DiagnosticsFile);
 
   // Invoke 'clang'.
index 3cc1af8e1440c1d655a5b226c8bb08c183c1ede3..0774ae2f3722b255376aba811098f2abc5ee944d 100644 (file)
@@ -95,7 +95,7 @@ std::string CIndexer::getClangResourcesPath() {
   return P.str();
 }
 
-llvm::sys::Path CIndexer::getTemporaryPath() {
+static llvm::sys::Path GetTemporaryPath() {
   // FIXME: This is lame; sys::Path should provide this function (in particular,
   // it should know how to find the temporary files dir).
   std::string Error;
@@ -107,7 +107,7 @@ llvm::sys::Path CIndexer::getTemporaryPath() {
   if (!TmpDir)
     TmpDir = "/tmp";
   llvm::sys::Path P(TmpDir);
-  P.appendComponent("CIndex");
+  P.appendComponent("remap");
   if (P.makeUnique(false, &Error))
     return llvm::sys::Path("");
 
@@ -123,7 +123,7 @@ bool clang::RemapFiles(unsigned num_unsaved_files,
                        std::vector<llvm::sys::Path> &TemporaryFiles) {
   for (unsigned i = 0; i != num_unsaved_files; ++i) {
     // Write the contents of this unsaved file into the temporary file.
-    llvm::sys::Path SavedFile(CIndexer::getTemporaryPath());
+    llvm::sys::Path SavedFile(GetTemporaryPath());
     if (SavedFile.empty())
       return true;
 
index 80337a272d081527465f74742e0f796808e4bfe6..1fa3ca93876e30aafc59cb67361959069163063b 100644 (file)
@@ -64,9 +64,6 @@ public:
   
   /// \brief Get the path of the clang resource files.
   std::string getClangResourcesPath();
-
-  /// \brief Get an unique temporary filename.
-  static llvm::sys::Path getTemporaryPath();
 };
 
 namespace clang {