mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-24 03:00:16 +00:00
Corrently handle buffer flush
This commit is contained in:
parent
5a3576acc8
commit
a35389b3c2
@ -505,8 +505,8 @@ constexpr auto to_pointer(OutputIt, size_t) -> T* {
|
||||
template <typename T>
|
||||
FMT_CONSTEXPR20 auto to_pointer(basic_appender<T> it, size_t n) -> T* {
|
||||
buffer<T>& buf = get_container(it);
|
||||
buf.try_reserve(buf.size() + n);
|
||||
auto size = buf.size();
|
||||
buf.try_reserve(size + n);
|
||||
if (buf.capacity() < size + n) return nullptr;
|
||||
buf.try_resize(size + n);
|
||||
return buf.data() + size;
|
||||
|
@ -1821,7 +1821,9 @@ TEST(format_test, big_print) {
|
||||
}
|
||||
|
||||
// Windows CRT implements _IOLBF incorrectly (full buffering).
|
||||
#if FMT_USE_FCNTL && !defined(_WIN32)
|
||||
#if FMT_USE_FCNTL
|
||||
|
||||
# ifndef _WIN32
|
||||
TEST(format_test, line_buffering) {
|
||||
auto pipe = fmt::pipe();
|
||||
|
||||
@ -1845,7 +1847,26 @@ TEST(format_test, line_buffering) {
|
||||
|
||||
reader.join();
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
TEST(format_test, buffer_boundary) {
|
||||
auto pipe = fmt::pipe();
|
||||
|
||||
auto write_end = pipe.write_end.fdopen("w");
|
||||
setvbuf(write_end.get(), nullptr, _IOFBF, 4096);
|
||||
for (int i = 3; i < 4094; i++)
|
||||
write_end.print("{}", (i % 73) != 0 ? 'x' : '\n');
|
||||
write_end.print("{} {}", 1234, 567);
|
||||
write_end.close();
|
||||
|
||||
auto read_end = pipe.read_end.fdopen("r");
|
||||
char buf[4091] = {};
|
||||
size_t n = fread(buf, 1, sizeof(buf), read_end.get());
|
||||
EXPECT_EQ(n, sizeof(buf));
|
||||
EXPECT_STREQ(fgets(buf, sizeof(buf), read_end.get()), "1234 567");
|
||||
}
|
||||
|
||||
#endif // FMT_USE_FCNTL
|
||||
|
||||
struct deadlockable {
|
||||
int value = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user