Compare commits

..

2 Commits

Author SHA1 Message Date
Gennaro Prota 228f211423 Record the first-registered serializer's tracking flag on save
Since 1.85, a Derived object serialized through a Base pointer across
module boundaries loses its data on load: the base subobject reads back
empty. PR #287 changed save to decide whether to emit an object id from
`co.m_bos_ptr` (the first serializer instance registered for a type),
but left the tracking flag written into the class preamble taken from
`bos`, the instance the current call happens to use.

Those can differ. With `track_selectively`, two module-local serializer
singletons for one type report different `tracking()`: the one whose
pointer serializer has been registered has `serialized_as_pointer()`
true, the other false. The writer then records one flag but lays the
object out per the other, so the reader desyncs and the subobject is
misread.

Record `co.m_bos_ptr`'s flag, the same instance the id decision uses, so
save is self-consistent again, as it was before PR #287 when both sides
read `bos`. The output is byte-identical whenever `co.m_bos_ptr == &bos`
(every single-module archive); only the already-broken cross-module case
changes.

Fixes issue #329.
2026-07-21 11:21:52 +02:00
Gennaro Prota 22ae0cd043 Run CI on merge-queue candidates 2026-07-17 18:01:05 +02:00
5 changed files with 8 additions and 53 deletions
+3 -18
View File
@@ -7,6 +7,7 @@ on:
- master
- develop
- feature/**
merge_group:
env:
UBSAN_OPTIONS: print_stacktrace=1
@@ -243,15 +244,7 @@ jobs:
run: |
cd ../boost-root
export ADDRMD=${{matrix.address-model}}
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} ${ADDRMD:+address-model=$ADDRMD} variant=debug,release
- name: Run examples
run: |
cd ../boost-root
export ADDRMD=${{matrix.address-model}}
# The demos use fixed temp filenames, so run them serially (-j1)
# to avoid concurrent runs clobbering each other's archive files.
./b2 -j1 libs/$LIBRARY/example toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} ${ADDRMD:+address-model=$ADDRMD} variant=debug,release
./b2 -j3 libs/$LIBRARY/test libs/$LIBRARY/example toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} ${ADDRMD:+address-model=$ADDRMD} variant=debug,release
windows:
strategy:
@@ -306,15 +299,7 @@ jobs:
shell: cmd
run: |
cd ../boost-root
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker
- name: Run examples
shell: cmd
run: |
cd ../boost-root
rem The demos use fixed temp filenames, so run them serially (-j1)
rem to avoid concurrent runs clobbering each other's archive files.
b2 -j1 libs/%LIBRARY%/example toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker
b2 -j3 libs/%LIBRARY%/test libs/%LIBRARY%/example toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker
posix-cmake-subdir:
strategy:
-2
View File
@@ -11,8 +11,6 @@ project libs/serialization/example
: requirements <library>../build//boost_serialization
;
import testing ;
import ../util/test :
run-template
run-invoke
+1 -5
View File
@@ -18,12 +18,8 @@
#include <boost/config.hpp>
// GCC's <filesystem> before version 9 is the initial, incomplete
// implementation (shipped in a separate libstdc++fs and buggy at runtime),
// so the feature is disabled there.
#if defined(__has_include)
# if __has_include(<filesystem>) && (BOOST_CXX_VERSION >= 201703L) \
&& ! (defined(__GNUC__) && ! defined(__clang__) && __GNUC__ < 9)
# if __has_include(<filesystem>) && (BOOST_CXX_VERSION >= 201703L)
# define BOOST_SERIALIZATION_HAS_STD_FILESYSTEM
# endif
#endif
+2 -2
View File
@@ -255,7 +255,7 @@ basic_oarchive_impl::save_object(
if(bos.class_info()){
if( ! co.m_initialized){
ar.vsave(class_id_optional_type(co.m_class_id));
ar.vsave(tracking_type(bos.tracking(m_flags)));
ar.vsave(tracking_type(co.m_bos_ptr->tracking(m_flags)));
ar.vsave(version_type(bos.version()));
(const_cast<cobject_type &>(co)).m_initialized = true;
}
@@ -343,7 +343,7 @@ basic_oarchive_impl::save_pointer(
}
}
if(bos.class_info()){
ar.vsave(tracking_type(bos.tracking(m_flags)));
ar.vsave(tracking_type(co.m_bos_ptr->tracking(m_flags)));
ar.vsave(version_type(bos.version()));
}
(const_cast<cobject_type &>(co)).m_initialized = true;
+2 -26
View File
@@ -17,11 +17,8 @@
// `std::filesystem::path` is a C++17 feature; when it isn't available, this
// test has nothing to exercise and simply succeeds.
// Note the guard for GCC < 9, which matches the one in
// boost/serialization/filesystem.hpp: see the comment there for the why.
#if defined(__has_include)
# if __has_include(<filesystem>) && (BOOST_CXX_VERSION >= 201703L) \
&& ! (defined(__GNUC__) && ! defined(__clang__) && __GNUC__ < 9)
# if __has_include(<filesystem>) && (BOOST_CXX_VERSION >= 201703L)
# define BOOST_SERIALIZATION_TEST_STD_FILESYSTEM
# endif
#endif
@@ -32,11 +29,6 @@
#include <boost/serialization/filesystem.hpp>
#include <filesystem>
#include <type_traits>
#ifndef BOOST_NO_STD_WSTREAMBUF
#include <boost/archive/text_woarchive.hpp>
#endif
void check_roundtrip(const std::filesystem::path & original){
const char * testfile = boost::archive::tmpnam(NULL);
@@ -65,21 +57,6 @@ std::filesystem::path from_utf8(const std::string & utf8){
#endif
}
// The wide *text* archive is the one archive that cannot round-trip non-ASCII
// content: it transcodes the narrow UTF-8 std::string through the stream
// locale's codecvt (codecvt_null), which mangles bytes outside the ASCII
// range. Every other archive in the test list preserves them -- narrow text
// and XML store the bytes verbatim, binary stores them raw, and wide XML
// installs a UTF-8 codecvt. So the non-ASCII case is exercised everywhere
// except that single archive.
bool archive_round_trips_non_ascii(){
#ifndef BOOST_NO_STD_WSTREAMBUF
return ! std::is_same<test_oarchive, boost::archive::text_woarchive>::value;
#else
return true;
#endif
}
int test_main(int /* argc */, char * /* argv */ []){
check_roundtrip(std::filesystem::path()); // empty
check_roundtrip("foo/bar/baz.txt"); // relative
@@ -89,8 +66,7 @@ int test_main(int /* argc */, char * /* argv */ []){
// The escapes are the UTF-8 encoding of U+00E9, U+00EF and U+00FC
// (e-acute, i-diaeresis, u-diaeresis); written as `\x` so the source
// file stays pure ASCII and encoding-independent.
if(archive_round_trips_non_ascii())
check_roundtrip(from_utf8("caf\xC3\xA9/na\xC3\xAF" "ve/\xC3\xBC.txt"));
check_roundtrip(from_utf8("caf\xC3\xA9/na\xC3\xAF" "ve/\xC3\xBC.txt"));
return EXIT_SUCCESS;
}