mirror of
https://github.com/fmtlib/fmt.git
synced 2025-12-01 23:00:15 +01:00
fmt::ostream - aggregate buffer instead of inheriting it (#3139)
Some MSVC-specific behavior: When class fmt::ostream inherits detail::buffer - the last gets implicitly exported when fmt is built as a shared library. Unless os.h is included, the compiler assumes detail::buffer is not externally exported and instantiates a local copy of it, which causes ODR violation. With aggregation - there is no extra exporting of detail::buffer symbols.
This commit is contained in:
26
src/os.cc
26
src/os.cc
@@ -366,8 +366,32 @@ long getpagesize() {
|
||||
# endif
|
||||
}
|
||||
|
||||
FMT_API void ostream::grow(size_t) {
|
||||
FMT_BEGIN_DETAIL_NAMESPACE
|
||||
|
||||
void file_buffer::grow(size_t) {
|
||||
if (this->size() == this->capacity()) flush();
|
||||
}
|
||||
|
||||
file_buffer::file_buffer(cstring_view path,
|
||||
const detail::ostream_params& params)
|
||||
: file_(path, params.oflag) {
|
||||
set(new char[params.buffer_size], params.buffer_size);
|
||||
}
|
||||
|
||||
file_buffer::file_buffer(file_buffer&& other)
|
||||
: detail::buffer<char>(other.data(), other.size(), other.capacity()),
|
||||
file_(std::move(other.file_)) {
|
||||
other.clear();
|
||||
other.set(nullptr, 0);
|
||||
}
|
||||
|
||||
file_buffer::~file_buffer() {
|
||||
flush();
|
||||
delete[] data();
|
||||
}
|
||||
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
|
||||
ostream::~ostream() = default;
|
||||
#endif // FMT_USE_FCNTL
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user