Re: [asio-users] boost/asio/buffer.hpp silent runtime breaking change 1.79->1.80
Brought to you by:
chris_kohlhoff
From: Marian K. <mkl...@gm...> - 2023-03-25 11:00:33
|
Yes, your suggestion would work but that would require changes at hundreds places in my application. Code should behave the same with no changes to the application. The next two exceptions for const_buffers_1 and mutable_buffers_1 should have been added in 1.80 boost in buffers.hpp I test const_buffers_1 case and it works for me. Please , can you add to 1.82 ? namespace boost { namespace asio { BOOST_ASIO_NODISCARD inline BOOST_ASIO_CONST_BUFFER buffer( const const_buffers_1& b, std::size_t max_size_in_bytes) BOOST_ASIO_NOEXCEPT { return buffer(static_cast<const const_buffer&>(b),max_size_in_bytes); } BOOST_ASIO_NODISCARD inline BOOST_ASIO_MUTABLE_BUFFER buffer( const mutable_buffers_1& b, std::size_t max_size_in_bytes) BOOST_ASIO_NOEXCEPT { return buffer(static_cast<const mutable_buffer&>(b),max_size_in_bytes); } } } On Sat, 25 Mar 2023 at 08:13, Allen <all...@gm...> wrote: > > Would your code work correctly on all versions of boost >= 1.66 (which added buffer.size) if you did this: > > size_t chunk_size=min(16, buf.size()); > auto buf2= boost::asio::buffer(buf.data(),chunk_size); > > Definitely frustrating to work around a breaking change, but better solution is to get your code working on all versions, IMO. > > (FYI, I am not affiliated with boost or asio projects.) > > On Sat, Mar 25, 2023, 12:06 AM Marian Klein <mkl...@gm...> wrote: >> >> Hey guys. >> >> This is my first message on this forum. >> I believed the project follows the principle: >> If the code compiles over the change it has to have the same or >> equivalent meaning at the runtime under any use (or none) of the >> pre-existing preprocessor definitions. >> It is better to break something at compile time over the change rather >> than wasting time debugging applications. Wasting 3 days to cluelessly >> debug an application is no fun. >> >> https://www.boost.org/doc/libs/1_80_0/doc/html/boost_asio/history.html >> >> Asio 1.24.0 / Boost 1.80 >> "Added buffer() overloads for contiguous containers, such as std::span". >> >> Example: >> BOOST_ASIO_NO_DEPRECATED is undefined, I use (Visual Studio 2019, x86 >> build C++17 standard enabled) >> >> void broken(const boost::asio::const_buffer& data) >> { >> auto buf=boost::asio::buffer(data);//works in 1.79 and in 1.80.1.81, >> in all versions invokes/uses correctly boost/asio/buffer.hpp:942 >> //buf is const_buffers_1 type >> >> size_t chunk_size=16; >> auto buf2= boost::asio::buffer(buf,chunk_size); >> //for me it works in version 1.79 (intended behaviour getting left >> part of buffer of chunk_size), >> // the code compiles ,but it does not work the same in 1.80/1.81 >> //invokes boost/asio/buffer.hpp:954 in 1.79 correctly, but >> silently invokes/calls new code in boost/asio/buffer.hpp:1705 in >> 1.80/1.81 >> //with buf2 pointing to buff class , rather than its underlying data. >> >> //buf2 is const_buffers_1 type >> } >> >> You should have maintained original binding (as if const_buffer type) >> if the type is both (sequence of const_buffer of size 1) >> const_buffers_1 and (base class) const_buffer. >> And new changing behaviour must be requested explicitly with a new define >> BOOST_ASIO_BUFFERS_1_IS_BUFFER_SEQUENCE >> Can you rectify in 1.82 , please? >> Thank you. >> Best Regards >> >> boost/asio/buffer.hpp:954 : >> >> /// Create a new non-modifiable buffer from an existing buffer. >> /** >> * @returns A const_buffer value equivalent to: >> * @code const_buffer( >> * b.data(), >> * min(b.size(), max_size_in_bytes)); @endcode >> */ >> BOOST_ASIO_NODISCARD inline BOOST_ASIO_CONST_BUFFER buffer( >> const const_buffer& b, >> std::size_t max_size_in_bytes) BOOST_ASIO_NOEXCEPT >> { >> return BOOST_ASIO_CONST_BUFFER(b.data(), >> b.size() < max_size_in_bytes >> ? b.size() : max_size_in_bytes >> #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) >> , b.get_debug_check() >> #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING >> ); >> } >> >> >> >> boost/asio/buffer.hpp:1705: >> >> /// Create a new non-modifiable buffer from a contiguous container. >> /** >> * @returns A const_buffer value equivalent to: >> * @code const_buffer( >> * data.size() ? &data[0] : 0, >> * min( >> * data.size() * sizeof(typename T::value_type), >> * max_size_in_bytes)); @endcode >> */ >> template <typename T> >> BOOST_ASIO_NODISCARD inline BOOST_ASIO_CONST_BUFFER buffer( >> const T& data, std::size_t max_size_in_bytes, >> typename constraint< >> is_contiguous_iterator<typename T::const_iterator>::value, >> defaulted_constraint >> >::type = defaulted_constraint()) BOOST_ASIO_NOEXCEPT >> { >> return BOOST_ASIO_CONST_BUFFER( >> data.size() ? detail::to_address(data.begin()) : 0, >> data.size() * sizeof(typename T::value_type) < max_size_in_bytes >> ? data.size() * sizeof(typename T::value_type) : max_size_in_bytes); >> } >> >> >> _______________________________________________ >> asio-users mailing list >> asi...@li... >> https://lists.sourceforge.net/lists/listinfo/asio-users >> _______________________________________________ >> Using Asio? List your project at >> http://think-async.com/Asio/WhoIsUsingAsio > > _______________________________________________ > asio-users mailing list > asi...@li... > https://lists.sourceforge.net/lists/listinfo/asio-users > _______________________________________________ > Using Asio? List your project at > http://think-async.com/Asio/WhoIsUsingAsio |