Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecated buffer_cast has been dropped in boost 1.87.0 #1305

Closed
heitbaum opened this issue Dec 16, 2024 · 5 comments
Closed

deprecated buffer_cast has been dropped in boost 1.87.0 #1305

heitbaum opened this issue Dec 16, 2024 · 5 comments

Comments

@heitbaum
Copy link
Contributor

heitbaum commented Dec 16, 2024

snapcast 0.29.0 does not compile with boost-1.87.0

auto* data = boost::asio::buffer_cast<char*>(buffer_.data());

FAILED: server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o
/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/toolchain/bin/x86_64-libreelec-linux-gnu-g++ -DBOOST_ASIO_NO_TS_EXECUTORS -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON -DHAS_EXPAT -DHAS_FLAC -DHAS_OGG -DHAS_OPUS -DHAS_PULSE -DHAS_SOXR -DHAS_VORBIS -DHAS_VORBIS_ENC -DVERSION=\"0.29.0\" -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/build/snapcast-0.29.0 -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/build/snapcast-0.29.0/include -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/build/snapcast-0.29.0/server -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/toolchain/x86_64-libreelec-linux-gnu/sysroot/usr/include/dbus-1.0 -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/toolchain/x86_64-libreelec-linux-gnu/sysroot/usr/lib/dbus-1.0/include -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/toolchain/x86_64-libreelec-linux-gnu/sysroot/usr/include/opus -march=x86-64-v3 -Wall -pipe  -O2 -fomit-frame-pointer -DNDEBUG -pthread
            -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/aixlog-1.5.0/usr/include                       -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/asio-1.31.0/usr/include                       -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/popl-1.3.0/usr/include -std=gnu++17 -Wall -Wextra -pedantic -Wno-unused-function -MD -MT server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o -MF server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o.d -o server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o -c /var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/build/snapcast-0.29.0/server/stream_session_ws.cpp
../server/stream_session_ws.cpp: In member function 'void StreamSessionWebsocket::on_read_ws(boost::beast::error_code, std::size_t)':
../server/stream_session_ws.cpp:117:31: error: 'buffer_cast' is not a member of 'boost::asio'; did you mean 'buffer_copy'?
  117 |     auto* data = boost::asio::buffer_cast<char*>(buffer_.data());
      |                               ^~~~~~~~~~~
      |                               buffer_copy
../server/stream_session_ws.cpp:117:43: error: expected primary-expression before 'char'
  117 |     auto* data = boost::asio::buffer_cast<char*>(buffer_.data());
      |                                           ^~~~

This will be the final fix (now that #1310 is queued) to remove all boost 1.87.0 deprecated code.

@heitbaum
Copy link
Contributor Author

In trying to fix this based on the boost documentation https://www.boost.org/doc/libs/1_85_0/doc/html/boost_asio/reference/mutable_buffer.html. The following compile error occurs. Previous version of the documentation https://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/reference/mutable_buffer.html.

--- a/server/stream_session_ws.cpp
+++ b/server/stream_session_ws.cpp
@@ -114,7 +114,7 @@ void StreamSessionWebsocket::on_read_ws(beast::error_code ec, std::size_t bytes_
���������return;
�����}

-    auto* data = boost::asio::buffer_cast<char*>(buffer_.data());
+    auto* data = static_cast<char*>(buffer_.data());
�����baseMessage_.deserialize(data);
�����LOG(DEBUG, LOG_TAG) << "getNextMessage: " << baseMessage_.type << ", size: " << baseMessage_.size << ", id: " << baseMessage_.id
�������������������������<< ", refers: " << baseMessage_.refersTo << "\n";

error

[54/56] Building CXX object server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o
FAILED: server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o 
/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/toolchain/bin/x86_64-libreelec-linux-gnu-g++ -DBOOST_ASIO_NO_TS_EXECUTORS -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON -DHAS_EXPAT -DHAS_FLAC -DHAS_OGG -DHAS_OPUS -DHAS_PULSE -DHAS_SOXR -DHAS_VORBIS -DHAS_VORBIS_ENC -DVERSION=\"0.29.0\" -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/build/snapcast-0.29.0 -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/build/snapcast-0.29.0/include -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/build/snapcast-0.29.0/server -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/toolchain/x86_64-libreelec-linux-gnu/sysroot/usr/include/dbus-1.0 -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/toolchain/x86_64-libreelec-linux-gnu/sysroot/usr/lib/dbus-1.0/include -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/toolchain/x86_64-libreelec-linux-gnu/sysroot/usr/include/opus -march=x86-64-v3 -Wall -pipe  -O2 -fomit-frame-pointer -DNDEBUG -pthread                       -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/aixlog-1.5.0/usr/include                       -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/asio-1.31.0/usr/include                       -I/var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/popl-1.3.0/usr/include -std=gnu++17 -Wall -Wextra -pedantic -Wno-unused-function -MD -MT server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o -MF server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o.d -o server/CMakeFiles/snapserver.dir/stream_session_ws.cpp.o -c /var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/build/snapcast-0.29.0/server/stream_session_ws.cpp
../server/stream_session_ws.cpp: In member function 'void StreamSessionWebsocket::on_read_ws(boost::beast::error_code, std::size_t)':
../server/stream_session_ws.cpp:117:18: error: invalid 'static_cast' from type 'boost::beast::basic_flat_buffer<std::allocator<char> >::mutable_buffers_type' {aka 'boost::asio::mutable_buffer'} to type 'char*'
  117 |     auto* data = static_cast<char*>(buffer_.data());
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@heitbaum
Copy link
Contributor Author

heitbaum commented Dec 19, 2024

I did some further testing and using auto* data = static_cast<char*>(buffer_.data().data()); allows for successful compile, and matches the previous function and its return. But not sure if this is the corr3ct use/intention of this current code.

Previous buffer_cast code is:

/// Cast a non-modifiable buffer to a specified pointer to POD type.
template <typename PointerToPodType>
inline PointerToPodType buffer_cast(const mutable_buffer& b) noexcept
{
  return static_cast<PointerToPodType>(b.data());
}

So if the previous code is correct, then the fix is:

--- a/server/stream_session_ws.cpp
+++ b/server/stream_session_ws.cpp
@@ -114,7 +114,7 @@ void StreamSessionWebsocket::on_read_ws(beast::error_code ec, std::size_t bytes_
         return;
     }
 
-    auto* data = boost::asio::buffer_cast<char*>(buffer_.data());
+    auto* data = static_cast<char*>(buffer_.data().data());
     baseMessage_.deserialize(data);
     LOG(DEBUG, LOG_TAG) << "getNextMessage: " << baseMessage_.type << ", size: " << baseMessage_.size << ", id: " << baseMessage_.id
                         << ", refers: " << baseMessage_.refersTo << "\n";

I’m happy to raise the PR if this is the case.
This will be the final fix (now that #1310 is queued) to remove all boost 1.87.0 deprecated code.

@badaix
Copy link
Owner

badaix commented Dec 19, 2024

Yes, this looks like the correct (original) solution to me:
auto* data = static_cast<char*>(buffer_.data().data());

@badaix
Copy link
Owner

badaix commented Dec 19, 2024

Thanks, I've added the change here 6190041

@heitbaum
Copy link
Contributor Author

Fixed

erikkundiman added a commit to megapahit/viewer that referenced this issue Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants