From d80736743bd583e633d2c388f6f10a7808bc529b Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 28 Feb 2023 21:06:52 +0100 Subject: [PATCH] Use `pubsetbuf` only with `libstdc++` This usage of the function seems only to work as intended with that standard lib. With `libc++` and the MSVC standard lib the call has no effect. --- tagvalue.cpp | 4 ++++ vorbis/vorbiscommentfield.cpp | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tagvalue.cpp b/tagvalue.cpp index 59754dd..0a1e69f 100644 --- a/tagvalue.cpp +++ b/tagvalue.cpp @@ -717,7 +717,11 @@ Popularity TagValue::toPopularity() const auto reader = BinaryReader(&s); try { s.exceptions(std::ios_base::failbit | std::ios_base::badbit); +#if defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION) s.rdbuf()->pubsetbuf(m_ptr.get(), static_cast(m_size)); +#else + s.write(m_ptr.get(), static_cast(m_size)); +#endif popularity.user = reader.readLengthPrefixedString(); popularity.rating = reader.readFloat64LE(); popularity.playCounter = reader.readUInt64LE(); diff --git a/vorbis/vorbiscommentfield.cpp b/vorbis/vorbiscommentfield.cpp index c68dba8..9191f36 100644 --- a/vorbis/vorbiscommentfield.cpp +++ b/vorbis/vorbiscommentfield.cpp @@ -78,7 +78,11 @@ template void VorbisCommentField::internalParse(StreamType &s auto decoded = decodeBase64(data.get() + idSize + 1, size - idSize - 1); stringstream bufferStream(ios_base::in | ios_base::out | ios_base::binary); bufferStream.exceptions(ios_base::failbit | ios_base::badbit); +#if defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION) bufferStream.rdbuf()->pubsetbuf(reinterpret_cast(decoded.first.get()), decoded.second); +#else + bufferStream.write(reinterpret_cast(decoded.first.get()), decoded.second); +#endif FlacMetaDataBlockPicture pictureBlock(value()); pictureBlock.parse(bufferStream, decoded.second); setTypeInfo(pictureBlock.pictureType()); @@ -197,10 +201,15 @@ bool VorbisCommentField::make(BinaryWriter &writer, VorbisCommentFlags flags, Di auto buffer = make_unique(requiredSize); stringstream bufferStream(ios_base::in | ios_base::out | ios_base::binary); bufferStream.exceptions(ios_base::failbit | ios_base::badbit); +#if defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION) bufferStream.rdbuf()->pubsetbuf(buffer.get(), requiredSize); - +#endif pictureBlock.make(bufferStream); +#if defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION) + bufferStream.read(buffer.get(), static_cast(requiredSize)); +#endif valueString = encodeBase64(reinterpret_cast(buffer.get()), requiredSize); + } catch (const Failure &) { diag.emplace_back(DiagLevel::Critical, "Unable to make METADATA_BLOCK_PICTURE struct from the assigned value.", context); throw;