Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-llvm: Commit

external/llvm


Commit MetaInfo

Revision69078b594c8586d40dc367b3e20237a9f3f7a1a4 (tree)
Time2018-06-11 05:53:30
AuthorMauro Rossi <issor.oruam@gmai...>
CommiterMauro Rossi

Log Message

Rollback "[Support] Add RetryAfterSignal helper function"

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")

Change Summary

Incremental Difference

--- a/include/llvm/Support/Errno.h
+++ b/include/llvm/Support/Errno.h
@@ -16,7 +16,6 @@
1616
1717 #include <cerrno>
1818 #include <string>
19-#include <type_traits>
2019
2120 namespace llvm {
2221 namespace sys {
@@ -30,16 +29,6 @@ std::string StrError();
3029 /// Like the no-argument version above, but uses \p errnum instead of errno.
3130 std::string StrError(int errnum);
3231
33-template <typename FailT, typename Fun, typename... Args>
34-inline auto RetryAfterSignal(const FailT &Fail, const Fun &F,
35- const Args &... As) -> decltype(F(As...)) {
36- decltype(F(As...)) Res;
37- do
38- Res = F(As...);
39- while (Res == Fail && errno == EINTR);
40- return Res;
41-}
42-
4332 } // namespace sys
4433 } // namespace llvm
4534
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -216,9 +216,11 @@ getMemoryBufferForStream(int FD, const Twine &BufferName) {
216216 // Read into Buffer until we hit EOF.
217217 do {
218218 Buffer.reserve(Buffer.size() + ChunkSize);
219- ReadBytes = sys::RetryAfterSignal(-1, read, FD, Buffer.end(), ChunkSize);
220- if (ReadBytes == -1)
219+ ReadBytes = read(FD, Buffer.end(), ChunkSize);
220+ if (ReadBytes == -1) {
221+ if (errno == EINTR) continue;
221222 return std::error_code(errno, std::generic_category());
223+ }
222224 Buffer.set_size(Buffer.size() + ReadBytes);
223225 } while (ReadBytes != 0);
224226
@@ -470,12 +472,13 @@ getOpenFileImpl(int FD, const Twine &Filename, uint64_t FileSize,
470472
471473 while (BytesLeft) {
472474 #ifdef HAVE_PREAD
473- ssize_t NumRead = sys::RetryAfterSignal(-1, ::pread, FD, BufPtr, BytesLeft,
474- MapSize - BytesLeft + Offset);
475+ ssize_t NumRead = ::pread(FD, BufPtr, BytesLeft, MapSize-BytesLeft+Offset);
475476 #else
476- ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, BufPtr, BytesLeft);
477+ ssize_t NumRead = ::read(FD, BufPtr, BytesLeft);
477478 #endif
478479 if (NumRead == -1) {
480+ if (errno == EINTR)
481+ continue;
479482 // Error while reading.
480483 return std::error_code(errno, std::generic_category());
481484 }
--- a/lib/Support/Unix/Path.inc
+++ b/lib/Support/Unix/Path.inc
@@ -767,9 +767,10 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
767767
768768 SmallString<128> Storage;
769769 StringRef P = Name.toNullTerminatedStringRef(Storage);
770- if ((ResultFD = sys::RetryAfterSignal(-1, open, P.begin(), OpenFlags, Mode)) <
771- 0)
772- return std::error_code(errno, std::generic_category());
770+ while ((ResultFD = open(P.begin(), OpenFlags, Mode)) < 0) {
771+ if (errno != EINTR)
772+ return std::error_code(errno, std::generic_category());
773+ }
773774 #ifndef O_CLOEXEC
774775 if (!(Flags & OF_ChildInherit)) {
775776 int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
--- a/lib/Support/Unix/Process.inc
+++ b/lib/Support/Unix/Process.inc
@@ -199,10 +199,13 @@ std::error_code Process::FixupStandardFileDescriptors() {
199199 for (int StandardFD : StandardFDs) {
200200 struct stat st;
201201 errno = 0;
202- if (RetryAfterSignal(-1, fstat, StandardFD, &st) < 0) {
202+ while (fstat(StandardFD, &st) < 0) {
203203 assert(errno && "expected errno to be set if fstat failed!");
204204 // fstat should return EBADF if the file descriptor is closed.
205- if (errno != EBADF)
205+ if (errno == EBADF)
206+ break;
207+ // retry fstat if we got EINTR, otherwise bubble up the failure.
208+ if (errno != EINTR)
206209 return std::error_code(errno, std::generic_category());
207210 }
208211 // if fstat succeeds, move on to the next FD.
@@ -211,8 +214,11 @@ std::error_code Process::FixupStandardFileDescriptors() {
211214 assert(errno == EBADF && "expected errno to have EBADF at this point!");
212215
213216 if (NullFD < 0) {
214- if ((NullFD = RetryAfterSignal(-1, open, "/dev/null", O_RDWR)) < 0)
217+ while ((NullFD = open("/dev/null", O_RDWR)) < 0) {
218+ if (errno == EINTR)
219+ continue;
215220 return std::error_code(errno, std::generic_category());
221+ }
216222 }
217223
218224 if (NullFD == StandardFD)
--- a/unittests/Support/CMakeLists.txt
+++ b/unittests/Support/CMakeLists.txt
@@ -23,7 +23,6 @@ add_llvm_unittest(SupportTests
2323 DJBTest.cpp
2424 EndianStreamTest.cpp
2525 EndianTest.cpp
26- ErrnoTest.cpp
2726 ErrorOrTest.cpp
2827 ErrorTest.cpp
2928 FileOutputBufferTest.cpp
--- a/unittests/Support/ErrnoTest.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
1-//===- ErrnoTest.cpp - Error handling unit tests --------------------------===//
2-//
3-// The LLVM Compiler Infrastructure
4-//
5-// This file is distributed under the University of Illinois Open Source
6-// License. See LICENSE.TXT for details.
7-//
8-//===----------------------------------------------------------------------===//
9-
10-#include "llvm/Support/Errno.h"
11-#include "gtest/gtest.h"
12-
13-using namespace llvm::sys;
14-
15-TEST(ErrnoTest, RetryAfterSignal) {
16- EXPECT_EQ(1, RetryAfterSignal(-1, [] { return 1; }));
17-
18- EXPECT_EQ(-1, RetryAfterSignal(-1, [] {
19- errno = EAGAIN;
20- return -1;
21- }));
22- EXPECT_EQ(EAGAIN, errno);
23-
24- unsigned calls = 0;
25- EXPECT_EQ(1, RetryAfterSignal(-1, [&calls] {
26- errno = EINTR;
27- ++calls;
28- return calls == 1 ? -1 : 1;
29- }));
30- EXPECT_EQ(2u, calls);
31-
32- EXPECT_EQ(1, RetryAfterSignal(-1, [](int x) { return x; }, 1));
33-
34- std::unique_ptr<int> P(RetryAfterSignal(nullptr, [] { return new int(47); }));
35- EXPECT_EQ(47, *P);
36-}
Show on old repository browser