[cfe-commits] r98439 - in /cfe/trunk/tools/CIndex: CIndex.cpp CIndexCodeCompletion.cpp CIndexer.cpp CIndexer.h

Benjamin Kramer benny.kra at googlemail.com
Sat Mar 13 05:05:20 PST 2010


Author: d0k
Date: Sat Mar 13 07:05:20 2010
New Revision: 98439

URL: http://llvm.org/viewvc/llvm-project?rev=98439&view=rev
Log:
Make getTemporaryPath a static member of CIndexer and use it to replace tmpnam calls.
This fixes linker warnings on linux.

Modified:
    cfe/trunk/tools/CIndex/CIndex.cpp
    cfe/trunk/tools/CIndex/CIndexCodeCompletion.cpp
    cfe/trunk/tools/CIndex/CIndexer.cpp
    cfe/trunk/tools/CIndex/CIndexer.h

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=98439&r1=98438&r2=98439&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Sat Mar 13 07:05:20 2010
@@ -29,9 +29,6 @@
 #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;
@@ -1055,8 +1052,8 @@
 
   // Generate a temporary name for the AST file.
   argv.push_back("-o");
-  char astTmpFile[L_tmpnam];
-  argv.push_back(tmpnam(astTmpFile));
+  llvm::sys::Path astTmpFile(CIndexer::getTemporaryPath());
+  argv.push_back(astTmpFile.c_str());
 
   // Remap any unsaved files to temporary files.
   std::vector<llvm::sys::Path> TemporaryFiles;
@@ -1087,9 +1084,7 @@
     }
 
   // Generate a temporary name for the diagnostics file.
-  char tmpFileResults[L_tmpnam];
-  char *tmpResultsFileName = tmpnam(tmpFileResults);
-  llvm::sys::Path DiagnosticsFile(tmpResultsFileName);
+  llvm::sys::Path DiagnosticsFile(CIndexer::getTemporaryPath());
   TemporaryFiles.push_back(DiagnosticsFile);
   argv.push_back("-fdiagnostics-binary");
 
@@ -1118,7 +1113,7 @@
     Diags->Report(diag::err_fe_invoking) << AllArgs << ErrMsg;
   }
 
-  ASTUnit *ATU = ASTUnit::LoadFromPCHFile(astTmpFile, *Diags,
+  ASTUnit *ATU = ASTUnit::LoadFromPCHFile(astTmpFile.str(), *Diags,
                                           CXXIdx->getOnlyLocalDecls(),
                                           RemappedFiles.data(),
                                           RemappedFiles.size(),

Modified: cfe/trunk/tools/CIndex/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexCodeCompletion.cpp?rev=98439&r1=98438&r2=98439&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndexCodeCompletion.cpp Sat Mar 13 07:05:20 2010
@@ -299,15 +299,11 @@
   argv.push_back(NULL);
 
   // Generate a temporary name for the code-completion results file.
-  char tmpFile[L_tmpnam];
-  char *tmpFileName = tmpnam(tmpFile);
-  llvm::sys::Path ResultsFile(tmpFileName);
+  llvm::sys::Path ResultsFile(CIndexer::getTemporaryPath());
   TemporaryFiles.push_back(ResultsFile);
 
   // Generate a temporary name for the diagnostics file.
-  char tmpFileResults[L_tmpnam];
-  char *tmpResultsFileName = tmpnam(tmpFileResults);
-  llvm::sys::Path DiagnosticsFile(tmpResultsFileName);
+  llvm::sys::Path DiagnosticsFile(CIndexer::getTemporaryPath());
   TemporaryFiles.push_back(DiagnosticsFile);
 
   // Invoke 'clang'.

Modified: cfe/trunk/tools/CIndex/CIndexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexer.cpp?rev=98439&r1=98438&r2=98439&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexer.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndexer.cpp Sat Mar 13 07:05:20 2010
@@ -95,7 +95,7 @@
   return P.str();
 }
 
-static llvm::sys::Path GetTemporaryPath() {
+llvm::sys::Path CIndexer::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 @@
   if (!TmpDir)
     TmpDir = "/tmp";
   llvm::sys::Path P(TmpDir);
-  P.appendComponent("remap");
+  P.appendComponent("CIndex");
   if (P.makeUnique(false, &Error))
     return llvm::sys::Path("");
 
@@ -123,7 +123,7 @@
                        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(GetTemporaryPath());
+    llvm::sys::Path SavedFile(CIndexer::getTemporaryPath());
     if (SavedFile.empty())
       return true;
 

Modified: cfe/trunk/tools/CIndex/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexer.h?rev=98439&r1=98438&r2=98439&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexer.h (original)
+++ cfe/trunk/tools/CIndex/CIndexer.h Sat Mar 13 07:05:20 2010
@@ -64,6 +64,9 @@
   
   /// \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 {





More information about the cfe-commits mailing list