[llvm-commits] [llvm] r120913 - in /llvm/trunk/lib/Support: PathV2.cpp Unix/PathV2.inc Windows/PathV2.inc

Michael J. Spencer bigcheesegs at gmail.com
Sat Dec 4 10:45:32 PST 2010


Author: mspencer
Date: Sat Dec  4 12:45:32 2010
New Revision: 120913

URL: http://llvm.org/viewvc/llvm-project?rev=120913&view=rev
Log:
Support/PathV2: Remove redundant calls to make_error_code.

Modified:
    llvm/trunk/lib/Support/PathV2.cpp
    llvm/trunk/lib/Support/Unix/PathV2.inc
    llvm/trunk/lib/Support/Windows/PathV2.inc

Modified: llvm/trunk/lib/Support/PathV2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PathV2.cpp?rev=120913&r1=120912&r2=120913&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PathV2.cpp (original)
+++ llvm/trunk/lib/Support/PathV2.cpp Sat Dec  4 12:45:32 2010
@@ -293,28 +293,28 @@
       if ((++pos != e) && is_separator((*pos)[0])) {
         // {C:/,//net/}, so get the first two components.
         result = StringRef(path.begin(), b->size() + pos->size());
-        return make_error_code(errc::success);
+        return success;
       } else {
         // just {C:,//net}, return the first component.
         result = *b;
-        return make_error_code(errc::success);
+        return success;
       }
     }
 
     // POSIX style root directory.
     if (is_separator((*b)[0])) {
       result = *b;
-      return make_error_code(errc::success);
+      return success;
     }
 
     // No root_path.
     result = StringRef();
-    return make_error_code(errc::success);
+    return success;
   }
 
   // No path :(.
   result = StringRef();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code root_name(const StringRef &path, StringRef &result) {
@@ -332,13 +332,13 @@
     if (has_net || has_drive) {
       // just {C:,//net}, return the first component.
       result = *b;
-      return make_error_code(errc::success);
+      return success;
     }
   }
 
   // No path or no name.
   result = StringRef();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code root_directory(const StringRef &path, StringRef &result) {
@@ -358,26 +358,26 @@
         // {C:,//net}, skip to the next component.
         (++pos != e) && is_separator((*pos)[0])) {
       result = *pos;
-      return make_error_code(errc::success);
+      return success;
     }
 
     // POSIX style root directory.
     if (!has_net && is_separator((*b)[0])) {
       result = *b;
-      return make_error_code(errc::success);
+      return success;
     }
   }
 
   // No path or no root.
   result = StringRef();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code relative_path(const StringRef &path, StringRef &result) {
   StringRef root;
   if (error_code ec = root_path(path, root)) return ec;
   result = StringRef(path.begin() + root.size(), path.size() - root.size());
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code append(SmallVectorImpl<char> &path, const Twine &a,
@@ -421,7 +421,7 @@
     path.append(i->begin(), i->end());
   }
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code make_absolute(SmallVectorImpl<char> &path) {
@@ -433,7 +433,7 @@
 
   // Already absolute.
   if (rootName && rootDirectory)
-    return make_error_code(errc::success);
+    return success;
 
   // All of the following conditions will need the current directory.
   SmallString<128> current_dir;
@@ -445,7 +445,7 @@
     if (error_code ec = append(current_dir, p)) return ec;
     // Set path to the result.
     path.swap(current_dir);
-    return make_error_code(errc::success);
+    return success;
   }
 
   if (!rootName && rootDirectory) {
@@ -455,7 +455,7 @@
     if (error_code ec = append(curDirRootName, p)) return ec;
     // Set path to the result.
     path.swap(curDirRootName);
-    return make_error_code(errc::success);
+    return success;
   }
 
   if (rootName && !rootDirectory) {
@@ -472,7 +472,7 @@
     if (error_code ec = append(res, pRootName, bRootDirectory,
                                     bRelativePath, pRelativePath)) return ec;
     path.swap(res);
-    return make_error_code(errc::success);
+    return success;
   }
 
   llvm_unreachable("All rootName and rootDirectory combinations should have "
@@ -485,15 +485,15 @@
     result = StringRef();
   else
     result = StringRef(path.data(), end_pos);
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code remove_filename(SmallVectorImpl<char> &path) {
   size_t end_pos = parent_path_end(StringRef(path.begin(), path.size()));
   if (end_pos == StringRef::npos)
-    return make_error_code(errc::success);
+    return success;
   path.set_size(end_pos);
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code replace_extension(SmallVectorImpl<char> &path,
@@ -513,7 +513,7 @@
 
   // Append extension.
   path.append(ext.begin(), ext.end());
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code native(const Twine &path, SmallVectorImpl<char> &result) {
@@ -535,12 +535,12 @@
 #else
   path.toVector(result);
 #endif
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code filename(const StringRef &path, StringRef &result) {
   result = *(--end(path));
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code stem(const StringRef &path, StringRef &result) {
@@ -556,7 +556,7 @@
     else
       result = StringRef(fname.begin(), pos);
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code extension(const StringRef &path, StringRef &result) {
@@ -572,7 +572,7 @@
     else
       result = StringRef(fname.begin() + pos, fname.size() - pos);
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code has_root_name(const Twine &path, bool &result) {
@@ -582,7 +582,7 @@
   if (error_code ec = root_name(p, p)) return ec;
 
   result = !p.empty();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code has_root_directory(const Twine &path, bool &result) {
@@ -592,7 +592,7 @@
   if (error_code ec = root_directory(p, p)) return ec;
 
   result = !p.empty();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code has_root_path(const Twine &path, bool &result) {
@@ -602,7 +602,7 @@
   if (error_code ec = root_path(p, p)) return ec;
 
   result = !p.empty();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code has_filename(const Twine &path, bool &result) {
@@ -612,7 +612,7 @@
   if (error_code ec = filename(p, p)) return ec;
 
   result = !p.empty();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code has_parent_path(const Twine &path, bool &result) {
@@ -622,7 +622,7 @@
   if (error_code ec = parent_path(p, p)) return ec;
 
   result = !p.empty();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code has_stem(const Twine &path, bool &result) {
@@ -632,7 +632,7 @@
   if (error_code ec = stem(p, p)) return ec;
 
   result = !p.empty();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code has_extension(const Twine &path, bool &result) {
@@ -642,7 +642,7 @@
   if (error_code ec = extension(p, p)) return ec;
 
   result = !p.empty();
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code is_absolute(const Twine &path, bool &result) {
@@ -659,7 +659,7 @@
 #endif
 
   result = rootDir && rootName;
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code is_relative(const Twine &path, bool &result) {

Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=120913&r1=120912&r2=120913&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Sat Dec  4 12:45:32 2010
@@ -63,7 +63,7 @@
     result.set_size(0);
     StringRef d(dir);
     result.append(d.begin(), d.end());
-    return make_error_code(errc::success);
+    return success;
   }
 }
 
@@ -80,7 +80,7 @@
     return error_code(errno, system_category());
 
   result.set_size(strlen(result.data()));
-  return make_error_code(errc::success);
+  return success;
 }
 
 } // end namespace path
@@ -143,7 +143,7 @@
   if (sz_read < 0)
     return error_code(errno, system_category());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code create_directory(const Twine &path, bool &existed) {
@@ -151,13 +151,13 @@
   StringRef p = path.toNullTerminatedStringRef(path_storage);
 
   if (::mkdir(p.begin(), 0700) == -1) {
-    if (errno != EEXIST)
+    if (errno != errc::file_exists)
       return error_code(errno, system_category());
     existed = true;
   } else
     existed = false;
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code create_hard_link(const Twine &to, const Twine &from) {
@@ -170,7 +170,7 @@
   if (::link(t.begin(), f.begin()) == -1)
     return error_code(errno, system_category());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code create_symlink(const Twine &to, const Twine &from) {
@@ -183,7 +183,7 @@
   if (::symlink(t.begin(), f.begin()) == -1)
     return error_code(errno, system_category());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code remove(const Twine &path, bool &existed) {
@@ -191,13 +191,13 @@
   StringRef p = path.toNullTerminatedStringRef(path_storage);
 
   if (::remove(p.begin()) == -1) {
-    if (errno != ENOENT)
+    if (errno != errc::no_such_file_or_directory)
       return error_code(errno, system_category());
     existed = false;
   } else
     existed = true;
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code rename(const Twine &from, const Twine &to) {
@@ -210,7 +210,7 @@
   if (::rename(f.begin(), t.begin()) == -1)
     return error_code(errno, system_category());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code resize_file(const Twine &path, uint64_t size) {
@@ -220,7 +220,7 @@
   if (::truncate(p.begin(), size) == -1)
     return error_code(errno, system_category());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code exists(const Twine &path, bool &result) {
@@ -229,13 +229,13 @@
 
   struct stat status;
   if (::stat(p.begin(), &status) == -1) {
-    if (errno != ENOENT)
+    if (errno != errc::no_such_file_or_directory)
       return error_code(errno, system_category());
     result = false;
   } else
     result = true;
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code equivalent(const Twine &A, const Twine &B, bool &result) {
@@ -260,7 +260,7 @@
       stat_a.st_ino == stat_b.st_ino;
   }
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code file_size(const Twine &path, uint64_t &result) {
@@ -271,10 +271,10 @@
   if (::stat(p.begin(), &status) == -1)
     return error_code(errno, system_category());
   if (!S_ISREG(status.st_mode))
-    return error_code(EPERM, system_category());
+    return make_error_code(errc::operation_not_permitted);
 
   result = status.st_size;
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code status(const Twine &path, file_status &result) {
@@ -359,10 +359,10 @@
   int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
   if (RandomFD == -1) {
     // If the file existed, try again, otherwise, error.
-    if (errno == EEXIST)
+    if (errno == errc::file_exists)
       goto retry_random_path;
     // The path prefix doesn't exist.
-    if (errno == ENOENT) {
+    if (errno == errc::no_such_file_or_directory) {
       StringRef p(RandomPath.begin(), RandomPath.size());
       SmallString<64> dir_to_create;
       for (path::const_iterator i = path::begin(p),
@@ -375,7 +375,7 @@
           if (i->size() > 2 && (*i)[0] == '/' &&
                                (*i)[1] == '/' &&
                                (*i)[2] != '/')
-            return error_code(ENOENT, system_category());
+            return make_error_code(errc::no_such_file_or_directory);
           if (::mkdir(dir_to_create.c_str(), 0700) == -1)
             return error_code(errno, system_category());
         }
@@ -385,7 +385,7 @@
     return error_code(errno, system_category());
   }
 
-    // Make the path absolute.
+   // Make the path absolute.
   char real_path_buff[PATH_MAX + 1];
   if (realpath(RandomPath.c_str(), real_path_buff) == NULL) {
     ::close(RandomFD);
@@ -398,7 +398,7 @@
   result_path.append(d.begin(), d.end());
 
   result_fd = RandomFD;
-  return make_error_code(errc::success);
+  return success;
 }
 
 } // end namespace fs

Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=120913&r1=120912&r2=120913&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Sat Dec  4 12:45:32 2010
@@ -48,7 +48,7 @@
                                     utf16.begin(), 0);
 
     if (len == 0)
-      return make_error_code(windows_error(::GetLastError()));
+      return windows_error(::GetLastError());
 
     utf16.reserve(len + 1);
     utf16.set_size(len);
@@ -58,13 +58,13 @@
                                     utf16.begin(), utf16.size());
 
     if (len == 0)
-      return make_error_code(windows_error(::GetLastError()));
+      return windows_error(::GetLastError());
 
     // Make utf16 null terminated.
     utf16.push_back(0);
     utf16.pop_back();
 
-    return make_error_code(errc::success);
+    return success;
   }
 
   error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len,
@@ -76,7 +76,7 @@
                                     NULL, NULL);
 
     if (len == 0)
-      return make_error_code(windows_error(::GetLastError()));
+      return windows_error(::GetLastError());
 
     utf8.reserve(len);
     utf8.set_size(len);
@@ -88,13 +88,13 @@
                                 NULL, NULL);
 
     if (len == 0)
-      return make_error_code(windows_error(::GetLastError()));
+      return windows_error(::GetLastError());
 
     // Make utf8 null terminated.
     utf8.push_back(0);
     utf8.pop_back();
 
-    return make_error_code(errc::success);
+    return success;
   }
 
   error_code TempDir(SmallVectorImpl<wchar_t> &result) {
@@ -102,7 +102,7 @@
     DWORD len = ::GetTempPathW(result.capacity(), result.begin());
 
     if (len == 0)
-      return make_error_code(windows_error(::GetLastError()));
+      return windows_error(::GetLastError());
 
     if (len > result.capacity()) {
       result.reserve(len);
@@ -110,7 +110,7 @@
     }
 
     result.set_size(len);
-    return make_error_code(errc::success);
+    return success;
   }
 
   struct AutoCryptoProvider {
@@ -136,7 +136,7 @@
 
   // A zero return value indicates a failure other than insufficient space.
   if (len == 0)
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
   // If there's insufficient space, the len returned is larger than the len
   // given.
@@ -167,9 +167,9 @@
                               result.data(), result.size(),
                               NULL, NULL);
   if (len == 0)
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 } // end namespace path
@@ -194,9 +194,9 @@
                          copt != copy_option::overwrite_if_exists);
 
   if (res == 0)
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code create_directory(const Twine &path, bool &existed) {
@@ -208,15 +208,15 @@
     return ec;
 
   if (!::CreateDirectoryW(path_utf16.begin(), NULL)) {
-    error_code ec = make_error_code(windows_error(::GetLastError()));
-    if (ec == make_error_code(windows_error::already_exists))
+    error_code ec = windows_error(::GetLastError());
+    if (ec == windows_error::already_exists)
       existed = true;
     else
       return ec;
   } else
     existed = false;
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code create_hard_link(const Twine &to, const Twine &from) {
@@ -233,9 +233,9 @@
   if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec;
 
   if (!::CreateHardLinkW(wide_from.begin(), wide_to.begin(), NULL))
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code create_symlink(const Twine &to, const Twine &from) {
@@ -256,9 +256,9 @@
   if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec;
 
   if (!create_symbolic_link_api(wide_from.begin(), wide_to.begin(), 0))
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code remove(const Twine &path, bool &existed) {
@@ -270,14 +270,14 @@
     return ec;
 
   if (!::DeleteFileW(path_utf16.begin())) {
-    error_code ec = make_error_code(windows_error(::GetLastError()));
-    if (ec != make_error_code(windows_error::file_not_found))
+    error_code ec = windows_error(::GetLastError());
+    if (ec != windows_error::file_not_found)
       return ec;
     existed = false;
   } else
     existed = true;
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code rename(const Twine &from, const Twine &to) {
@@ -294,9 +294,9 @@
   if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec;
 
   if (!::MoveFileW(wide_from.begin(), wide_to.begin()))
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code resize_file(const Twine &path, uint64_t size) {
@@ -332,13 +332,13 @@
   if (attributes == INVALID_FILE_ATTRIBUTES) {
     // See if the file didn't actually exist.
     error_code ec = make_error_code(windows_error(::GetLastError()));
-    if (ec != error_code(windows_error::file_not_found) &&
-        ec != error_code(windows_error::path_not_found))
+    if (ec != windows_error::file_not_found &&
+        ec != windows_error::path_not_found)
       return ec;
     result = false;
   } else
     result = true;
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code equivalent(const Twine &A, const Twine &B, bool &result) {
@@ -375,21 +375,21 @@
   // If both handles are invalid, it's an error.
   if (HandleA == INVALID_HANDLE_VALUE &&
       HandleB == INVALID_HANDLE_VALUE)
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
   // If only one is invalid, it's false.
   if (HandleA == INVALID_HANDLE_VALUE &&
       HandleB == INVALID_HANDLE_VALUE) {
     result = false;
-    return make_error_code(errc::success);
+    return success;
   }
 
   // Get file information.
   BY_HANDLE_FILE_INFORMATION InfoA, InfoB;
   if (!::GetFileInformationByHandle(HandleA, &InfoA))
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
   if (!::GetFileInformationByHandle(HandleB, &InfoB))
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
   // See if it's all the same.
   result =
@@ -403,7 +403,7 @@
     InfoA.ftLastWriteTime.dwHighDateTime ==
       InfoB.ftLastWriteTime.dwHighDateTime;
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code file_size(const Twine &path, uint64_t &result) {
@@ -418,13 +418,13 @@
   if (!::GetFileAttributesExW(path_utf16.begin(),
                               ::GetFileExInfoStandard,
                               &FileData))
-    return make_error_code(windows_error(::GetLastError()));
+    return windows_error(::GetLastError());
 
   result =
     (uint64_t(FileData.nFileSizeHigh) << (sizeof(FileData.nFileSizeLow) * 8))
     + FileData.nFileSizeLow;
 
-  return make_error_code(errc::success);
+  return success;
 }
 
 error_code status(const Twine &path, file_status &result) {
@@ -504,13 +504,12 @@
 
   // Get a Crypto Provider for CryptGenRandom.
   AutoCryptoProvider CryptoProvider;
-  BOOL success = ::CryptAcquireContextW(&CryptoProvider.CryptoProvider,
-                                        NULL,
-                                        NULL,
-                                        PROV_RSA_FULL,
-                                        0);
-  if (!success)
-    return make_error_code(windows_error(::GetLastError()));
+  if (!::CryptAcquireContextW(&CryptoProvider.CryptoProvider,
+                              NULL,
+                              NULL,
+                              PROV_RSA_FULL,
+                              0))
+    return windows_error(::GetLastError());
 
 retry_random_path:
   random_path_utf16.set_size(0);
@@ -520,7 +519,7 @@
     if (*i == L'%') {
       BYTE val = 0;
       if (!::CryptGenRandom(CryptoProvider, 1, &val))
-          return make_error_code(windows_error(::GetLastError()));
+          return windows_error(::GetLastError());
       random_path_utf16.push_back("0123456789abcdef"[val & 15]);
     }
     else
@@ -543,11 +542,11 @@
                                         NULL);
   if (TempFileHandle == INVALID_HANDLE_VALUE) {
     // If the file existed, try again, otherwise, error.
-    error_code ec = make_error_code(windows_error(::GetLastError()));
-    if (ec == error_code(windows_error::file_exists))
+    error_code ec = windows_error(::GetLastError());
+    if (ec == windows_error::file_exists)
       goto retry_random_path;
     // Check for non-existing parent directories.
-    if (ec == error_code(windows_error::path_not_found)) {
+    if (ec == windows_error::path_not_found) {
       // Create the directories using result_path as temp storage.
       if (error_code ec = UTF16ToUTF8(random_path_utf16.begin(),
                                       random_path_utf16.size(), result_path))
@@ -570,7 +569,7 @@
 
           // Create the directory.
           if (!::CreateDirectoryW(dir_to_create_utf16.begin(), NULL))
-            return make_error_code(windows_error(::GetLastError()));
+            return windows_error(::GetLastError());
         }
       }
       goto retry_create_file;
@@ -593,11 +592,11 @@
     ::DeleteFileW(random_path_utf16.begin());
     // MSDN doesn't say anything about _open_osfhandle setting errno or
     // GetLastError(), so just return invalid_handle.
-    return make_error_code(windows_error::invalid_handle);
+    return windows_error::invalid_handle;
   }
 
   result_fd = fd;
-  return make_error_code(errc::success);
+  return success;
 }
 } // end namespace fs
 } // end namespace sys





More information about the llvm-commits mailing list