OSDN Git Service

Rollback "[Support] Add RetryAfterSignal helper function" nougat-x86 android-x86-7.1-r4 android-x86-7.1-r5
authorMauro Rossi <issor.oruam@gmail.com>
Sat, 9 Jun 2018 23:49:36 +0000 (01:49 +0200)
committerMauro Rossi <issor.oruam@gmail.com>
Sun, 10 Jun 2018 20:53:30 +0000 (22:53 +0200)
This rollback is necessary to avoid the following building error:

In file included from external/llvm70/lib/Support/Path.cpp:1082:
external/llvm70/lib/Support/Unix/Path.inc:770:19: error: no matching function for call to 'RetryAfterSignal'
  if ((ResultFD = sys::RetryAfterSignal(-1, open, P.begin(), OpenFlags, Mode)) <
                  ^~~~~~~~~~~~~~~~~~~~~
external/llvm/lib/Support/../../include/llvm/Support/Errno.h:34:13:
note: candidate template ignored: couldn't infer template argument 'Fun'
inline auto RetryAfterSignal(const FailT &Fail, const Fun &F,
            ^
1 error generated.

Fixes: d04333d38b (Recommit "[Support] Add RetryAfterSignal helper function")

include/llvm/Support/Errno.h
lib/Support/MemoryBuffer.cpp
lib/Support/Unix/Path.inc
lib/Support/Unix/Process.inc
unittests/Support/CMakeLists.txt
unittests/Support/ErrnoTest.cpp [deleted file]

index 35dc1ea..4ce65e7 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <cerrno>
 #include <string>
-#include <type_traits>
 
 namespace llvm {
 namespace sys {
@@ -30,16 +29,6 @@ std::string StrError();
 /// Like the no-argument version above, but uses \p errnum instead of errno.
 std::string StrError(int errnum);
 
-template <typename FailT, typename Fun, typename... Args>
-inline auto RetryAfterSignal(const FailT &Fail, const Fun &F,
-                             const Args &... As) -> decltype(F(As...)) {
-  decltype(F(As...)) Res;
-  do
-    Res = F(As...);
-  while (Res == Fail && errno == EINTR);
-  return Res;
-}
-
 }  // namespace sys
 }  // namespace llvm
 
index d8cc853..2fd3159 100644 (file)
@@ -216,9 +216,11 @@ getMemoryBufferForStream(int FD, const Twine &BufferName) {
   // Read into Buffer until we hit EOF.
   do {
     Buffer.reserve(Buffer.size() + ChunkSize);
-    ReadBytes = sys::RetryAfterSignal(-1, read, FD, Buffer.end(), ChunkSize);
-    if (ReadBytes == -1)
+    ReadBytes = read(FD, Buffer.end(), ChunkSize);
+    if (ReadBytes == -1) {
+      if (errno == EINTR) continue;
       return std::error_code(errno, std::generic_category());
+    }
     Buffer.set_size(Buffer.size() + ReadBytes);
   } while (ReadBytes != 0);
 
@@ -470,12 +472,13 @@ getOpenFileImpl(int FD, const Twine &Filename, uint64_t FileSize,
 
   while (BytesLeft) {
 #ifdef HAVE_PREAD
-    ssize_t NumRead = sys::RetryAfterSignal(-1, ::pread, FD, BufPtr, BytesLeft,
-                                            MapSize - BytesLeft + Offset);
+    ssize_t NumRead = ::pread(FD, BufPtr, BytesLeft, MapSize-BytesLeft+Offset);
 #else
-    ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, BufPtr, BytesLeft);
+    ssize_t NumRead = ::read(FD, BufPtr, BytesLeft);
 #endif
     if (NumRead == -1) {
+      if (errno == EINTR)
+        continue;
       // Error while reading.
       return std::error_code(errno, std::generic_category());
     }
index f3f529e..bf4cb15 100644 (file)
@@ -767,9 +767,10 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
 
   SmallString<128> Storage;
   StringRef P = Name.toNullTerminatedStringRef(Storage);
-  if ((ResultFD = sys::RetryAfterSignal(-1, open, P.begin(), OpenFlags, Mode)) <
-      0)
-    return std::error_code(errno, std::generic_category());
+  while ((ResultFD = open(P.begin(), OpenFlags, Mode)) < 0) {
+    if (errno != EINTR)
+      return std::error_code(errno, std::generic_category());
+  }
 #ifndef O_CLOEXEC
   if (!(Flags & OF_ChildInherit)) {
     int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
index 68baab8..2d22025 100644 (file)
@@ -199,10 +199,13 @@ std::error_code Process::FixupStandardFileDescriptors() {
   for (int StandardFD : StandardFDs) {
     struct stat st;
     errno = 0;
-    if (RetryAfterSignal(-1, fstat, StandardFD, &st) < 0) {
+    while (fstat(StandardFD, &st) < 0) {
       assert(errno && "expected errno to be set if fstat failed!");
       // fstat should return EBADF if the file descriptor is closed.
-      if (errno != EBADF)
+      if (errno == EBADF)
+        break;
+      // retry fstat if we got EINTR, otherwise bubble up the failure.
+      if (errno != EINTR)
         return std::error_code(errno, std::generic_category());
     }
     // if fstat succeeds, move on to the next FD.
@@ -211,8 +214,11 @@ std::error_code Process::FixupStandardFileDescriptors() {
     assert(errno == EBADF && "expected errno to have EBADF at this point!");
 
     if (NullFD < 0) {
-      if ((NullFD = RetryAfterSignal(-1, open, "/dev/null", O_RDWR)) < 0)
+      while ((NullFD = open("/dev/null", O_RDWR)) < 0) {
+        if (errno == EINTR)
+          continue;
         return std::error_code(errno, std::generic_category());
+      }
     }
 
     if (NullFD == StandardFD)
index 89e16ef..33016fc 100644 (file)
@@ -23,7 +23,6 @@ add_llvm_unittest(SupportTests
   DJBTest.cpp
   EndianStreamTest.cpp
   EndianTest.cpp
-  ErrnoTest.cpp
   ErrorOrTest.cpp
   ErrorTest.cpp
   FileOutputBufferTest.cpp
diff --git a/unittests/Support/ErrnoTest.cpp b/unittests/Support/ErrnoTest.cpp
deleted file mode 100644 (file)
index 67f834a..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-//===- ErrnoTest.cpp - Error handling unit tests --------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/Errno.h"
-#include "gtest/gtest.h"
-
-using namespace llvm::sys;
-
-TEST(ErrnoTest, RetryAfterSignal) {
-  EXPECT_EQ(1, RetryAfterSignal(-1, [] { return 1; }));
-
-  EXPECT_EQ(-1, RetryAfterSignal(-1, [] {
-    errno = EAGAIN;
-    return -1;
-  }));
-  EXPECT_EQ(EAGAIN, errno);
-
-  unsigned calls = 0;
-  EXPECT_EQ(1, RetryAfterSignal(-1, [&calls] {
-              errno = EINTR;
-              ++calls;
-              return calls == 1 ? -1 : 1;
-            }));
-  EXPECT_EQ(2u, calls);
-
-  EXPECT_EQ(1, RetryAfterSignal(-1, [](int x) { return x; }, 1));
-
-  std::unique_ptr<int> P(RetryAfterSignal(nullptr, [] { return new int(47); }));
-  EXPECT_EQ(47, *P);
-}