Skip to content

Commit c77792e

Browse files
committed
Merge remote-tracking branch 'origin/main' into simplify-blend
2 parents 6b0f436 + be28365 commit c77792e

File tree

19 files changed

+353
-171
lines changed

19 files changed

+353
-171
lines changed

libcxx/docs/Status/Cxx2cIssues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"`LWG4124 <https://wg21.link/LWG4124>`__","Cannot format ``zoned_time`` with resolution coarser than ``seconds``","2024-11 (Wrocław)","","",""
9898
"`LWG4126 <https://wg21.link/LWG4126>`__","Some feature-test macros for fully freestanding features are not yet marked freestanding","2024-11 (Wrocław)","","",""
9999
"`LWG4134 <https://wg21.link/LWG4134>`__","Issue with Philox algorithm specification","2024-11 (Wrocław)","","",""
100-
"`LWG4135 <https://wg21.link/LWG4135>`__","The helper lambda of ``std::erase`` for list should specify return type as ``bool``","2024-11 (Wrocław)","","",""
100+
"`LWG4135 <https://wg21.link/LWG4135>`__","The helper lambda of ``std::erase`` for list should specify return type as ``bool``","2024-11 (Wrocław)","|Complete|","21",""
101101
"`LWG4140 <https://wg21.link/LWG4140>`__","Useless default constructors for bit reference types","2024-11 (Wrocław)","","",""
102102
"`LWG4141 <https://wg21.link/LWG4141>`__","Improve prohibitions on ""additional storage""","2024-11 (Wrocław)","","",""
103103
"`LWG4142 <https://wg21.link/LWG4142>`__","``format_parse_context::check_dynamic_spec`` should require at least one type","2024-11 (Wrocław)","","",""

libcxx/include/forward_list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred) {
15571557
template <class _Tp, class _Allocator, class _Up>
15581558
inline _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Allocator>::size_type
15591559
erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) {
1560-
return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
1560+
return std::erase_if(__c, [&](const auto& __elem) -> bool { return __elem == __v; });
15611561
}
15621562
# endif
15631563

libcxx/include/list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) {
17031703
template <class _Tp, class _Allocator, class _Up>
17041704
inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
17051705
erase(list<_Tp, _Allocator>& __c, const _Up& __v) {
1706-
return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
1706+
return std::erase_if(__c, [&](const auto& __elem) -> bool { return __elem == __v; });
17071707
}
17081708

17091709
template <>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++20
10+
11+
// <forward_list>
12+
13+
// This test shows the effect of implementing `LWG4135`, before it this code
14+
// was ill-formed, as the predicate is not bool. `LWG4135` suggests that
15+
// std::erase explicitly specifying the lambda's return type as bool.
16+
17+
#include <forward_list>
18+
19+
struct Bool {
20+
Bool() = default;
21+
Bool(const Bool&) = delete;
22+
operator bool() const { return true; }
23+
};
24+
25+
struct Int {
26+
Bool& operator==(Int) const {
27+
static Bool b;
28+
return b;
29+
}
30+
};
31+
32+
int main(int, char**) {
33+
std::forward_list<Int> l;
34+
std::erase(l, Int{});
35+
36+
return 0;
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++20
10+
11+
// <list>
12+
13+
// This test shows the effect of implementing `LWG4135`, before it this code
14+
// was ill-formed, as the predicate is not bool. `LWG4135` suggests that
15+
// std::erase explicitly specifying the lambda's return type as bool.
16+
17+
#include <list>
18+
19+
struct Bool {
20+
Bool() = default;
21+
Bool(const Bool&) = delete;
22+
operator bool() const { return true; }
23+
};
24+
25+
struct Int {
26+
Bool& operator==(Int) const {
27+
static Bool b;
28+
return b;
29+
}
30+
};
31+
32+
int main(int, char**) {
33+
std::list<Int> l;
34+
std::erase(l, Int{});
35+
36+
return 0;
37+
}

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/API/SBListener.h"
1919
#include "lldb/API/SBProcess.h"
2020
#include "lldb/API/SBStream.h"
21+
#include "lldb/Utility/IOObject.h"
2122
#include "lldb/Utility/Status.h"
2223
#include "lldb/lldb-defines.h"
2324
#include "lldb/lldb-enumerations.h"
@@ -61,7 +62,7 @@ const char DEV_NULL[] = "/dev/null";
6162
namespace lldb_dap {
6263

6364
DAP::DAP(std::string name, llvm::StringRef path, std::ofstream *log,
64-
StreamDescriptor input, StreamDescriptor output, ReplMode repl_mode,
65+
lldb::IOObjectSP input, lldb::IOObjectSP output, ReplMode repl_mode,
6566
std::vector<std::string> pre_init_commands)
6667
: name(std::move(name)), debug_adaptor_path(path), log(log),
6768
input(std::move(input)), output(std::move(output)),

lldb/tools/lldb-dap/DAP.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "lldb/API/SBThread.h"
3131
#include "lldb/API/SBValue.h"
3232
#include "lldb/API/SBValueList.h"
33+
#include "lldb/lldb-forward.h"
3334
#include "lldb/lldb-types.h"
3435
#include "llvm/ADT/DenseMap.h"
3536
#include "llvm/ADT/DenseSet.h"
@@ -210,7 +211,7 @@ struct DAP {
210211
std::string last_nonempty_var_expression;
211212

212213
DAP(std::string name, llvm::StringRef path, std::ofstream *log,
213-
StreamDescriptor input, StreamDescriptor output, ReplMode repl_mode,
214+
lldb::IOObjectSP input, lldb::IOObjectSP output, ReplMode repl_mode,
214215
std::vector<std::string> pre_init_commands);
215216
~DAP();
216217
DAP(const DAP &rhs) = delete;

lldb/tools/lldb-dap/IOStream.cpp

Lines changed: 13 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -7,125 +7,34 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "IOStream.h"
10+
#include "lldb/Utility/IOObject.h"
11+
#include "lldb/Utility/Status.h"
1012
#include <fstream>
1113
#include <string>
1214

13-
#if defined(_WIN32)
14-
#include <io.h>
15-
#else
16-
#include <netinet/in.h>
17-
#include <sys/socket.h>
18-
#include <unistd.h>
19-
#endif
20-
2115
using namespace lldb_dap;
2216

23-
StreamDescriptor::StreamDescriptor() = default;
24-
25-
StreamDescriptor::StreamDescriptor(StreamDescriptor &&other) {
26-
*this = std::move(other);
27-
}
28-
29-
StreamDescriptor::~StreamDescriptor() {
30-
if (!m_close)
31-
return;
32-
33-
if (m_is_socket)
34-
#if defined(_WIN32)
35-
::closesocket(m_socket);
36-
#else
37-
::close(m_socket);
38-
#endif
39-
else
40-
::close(m_fd);
41-
}
42-
43-
StreamDescriptor &StreamDescriptor::operator=(StreamDescriptor &&other) {
44-
m_close = other.m_close;
45-
other.m_close = false;
46-
m_is_socket = other.m_is_socket;
47-
if (m_is_socket)
48-
m_socket = other.m_socket;
49-
else
50-
m_fd = other.m_fd;
51-
return *this;
52-
}
53-
54-
StreamDescriptor StreamDescriptor::from_socket(SOCKET s, bool close) {
55-
StreamDescriptor sd;
56-
sd.m_is_socket = true;
57-
sd.m_socket = s;
58-
sd.m_close = close;
59-
return sd;
60-
}
61-
62-
StreamDescriptor StreamDescriptor::from_file(int fd, bool close) {
63-
StreamDescriptor sd;
64-
sd.m_is_socket = false;
65-
sd.m_fd = fd;
66-
sd.m_close = close;
67-
return sd;
68-
}
69-
7017
bool OutputStream::write_full(llvm::StringRef str) {
71-
while (!str.empty()) {
72-
int bytes_written = 0;
73-
if (descriptor.m_is_socket)
74-
bytes_written = ::send(descriptor.m_socket, str.data(), str.size(), 0);
75-
else
76-
bytes_written = ::write(descriptor.m_fd, str.data(), str.size());
77-
78-
if (bytes_written < 0) {
79-
if (errno == EINTR || errno == EAGAIN)
80-
continue;
81-
return false;
82-
}
83-
str = str.drop_front(bytes_written);
84-
}
18+
if (!descriptor)
19+
return false;
8520

86-
return true;
21+
size_t num_bytes = str.size();
22+
auto status = descriptor->Write(str.data(), num_bytes);
23+
return status.Success();
8724
}
8825

8926
bool InputStream::read_full(std::ofstream *log, size_t length,
9027
std::string &text) {
28+
if (!descriptor)
29+
return false;
30+
9131
std::string data;
9232
data.resize(length);
9333

94-
char *ptr = &data[0];
95-
while (length != 0) {
96-
int bytes_read = 0;
97-
if (descriptor.m_is_socket)
98-
bytes_read = ::recv(descriptor.m_socket, ptr, length, 0);
99-
else
100-
bytes_read = ::read(descriptor.m_fd, ptr, length);
101-
102-
if (bytes_read == 0) {
103-
if (log)
104-
*log << "End of file (EOF) reading from input file.\n";
105-
return false;
106-
}
107-
if (bytes_read < 0) {
108-
int reason = 0;
109-
#if defined(_WIN32)
110-
if (descriptor.m_is_socket)
111-
reason = WSAGetLastError();
112-
else
113-
reason = errno;
114-
#else
115-
reason = errno;
116-
if (reason == EINTR || reason == EAGAIN)
117-
continue;
118-
#endif
119-
120-
if (log)
121-
*log << "Error " << reason << " reading from input file.\n";
122-
return false;
123-
}
34+
auto status = descriptor->Read(data.data(), length);
35+
if (status.Fail())
36+
return false;
12437

125-
assert(bytes_read >= 0 && (size_t)bytes_read <= length);
126-
ptr += bytes_read;
127-
length -= bytes_read;
128-
}
12938
text += data;
13039
return true;
13140
}

lldb/tools/lldb-dap/IOStream.h

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,17 @@
99
#ifndef LLDB_TOOLS_LLDB_DAP_IOSTREAM_H
1010
#define LLDB_TOOLS_LLDB_DAP_IOSTREAM_H
1111

12-
#if defined(_WIN32)
13-
#include "lldb/Host/windows/windows.h"
14-
#include <winsock2.h>
15-
#else
16-
typedef int SOCKET;
17-
#endif
18-
12+
#include "lldb/lldb-forward.h"
1913
#include "llvm/ADT/StringRef.h"
20-
2114
#include <fstream>
2215
#include <string>
2316

24-
// Windows requires different system calls for dealing with sockets and other
25-
// types of files, so we can't simply have one code path that just uses read
26-
// and write everywhere. So we need an abstraction in order to allow us to
27-
// treat them identically.
2817
namespace lldb_dap {
29-
struct StreamDescriptor {
30-
StreamDescriptor();
31-
~StreamDescriptor();
32-
StreamDescriptor(StreamDescriptor &&other);
33-
34-
StreamDescriptor &operator=(StreamDescriptor &&other);
35-
36-
static StreamDescriptor from_socket(SOCKET s, bool close);
37-
static StreamDescriptor from_file(int fd, bool close);
38-
39-
bool m_is_socket = false;
40-
bool m_close = false;
41-
union {
42-
int m_fd;
43-
SOCKET m_socket;
44-
};
45-
};
4618

4719
struct InputStream {
48-
StreamDescriptor descriptor;
20+
lldb::IOObjectSP descriptor;
4921

50-
explicit InputStream(StreamDescriptor descriptor)
22+
explicit InputStream(lldb::IOObjectSP descriptor)
5123
: descriptor(std::move(descriptor)) {}
5224

5325
bool read_full(std::ofstream *log, size_t length, std::string &text);
@@ -58,9 +30,9 @@ struct InputStream {
5830
};
5931

6032
struct OutputStream {
61-
StreamDescriptor descriptor;
33+
lldb::IOObjectSP descriptor;
6234

63-
explicit OutputStream(StreamDescriptor descriptor)
35+
explicit OutputStream(lldb::IOObjectSP descriptor)
6436
: descriptor(std::move(descriptor)) {}
6537

6638
bool write_full(llvm::StringRef str);

0 commit comments

Comments
 (0)