|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55738 - in trunk/libs/serialization: src test vc7ide
From: ramey_at_[hidden]
Date: 2009-08-23 15:27:11
Author: ramey
Date: 2009-08-23 15:27:10 EDT (Sun, 23 Aug 2009)
New Revision: 55738
URL: http://svn.boost.org/trac/boost/changeset/55738
Log:
Improved implemenation of boost_serializer_map
Improved support for serialization of types in DLLS
New exception for violations of ODR when using DLLS
Fix error in recent update of export.hpp
Added class names to exception messages
Text files modified:
trunk/libs/serialization/src/basic_serializer_map.cpp | 77 +++++++++++++++++++++++----------------
trunk/libs/serialization/src/extended_type_info.cpp | 3 +
trunk/libs/serialization/src/void_cast.cpp | 11 +++++
trunk/libs/serialization/test/test_exported.cpp | 5 ++
trunk/libs/serialization/test/test_simple_class_ptr.cpp | 2
trunk/libs/serialization/vc7ide/Library.vcproj | 12 +++---
6 files changed, 70 insertions(+), 40 deletions(-)
Modified: trunk/libs/serialization/src/basic_serializer_map.cpp
==============================================================================
--- trunk/libs/serialization/src/basic_serializer_map.cpp (original)
+++ trunk/libs/serialization/src/basic_serializer_map.cpp 2009-08-23 15:27:10 EDT (Sun, 23 Aug 2009)
@@ -12,6 +12,12 @@
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
+#include <set>
+#include <utility>
+
+#include <boost/archive/archive_exception.hpp>
+#include <boost/serialization/throw_exception.hpp>
+
#define BOOST_ARCHIVE_SOURCE
#include <boost/archive/detail/basic_serializer.hpp>
#include <boost/archive/detail/basic_serializer_map.hpp>
@@ -23,52 +29,59 @@
namespace archive {
namespace detail {
-// note: We can't implement this as an associative
-// container as such a container might be dependent
-// upon the extended_type_info::m_key which might not
-// be assigned until later. So we use a "slower" method.
-// This not a big deal however as the slower "find" operations
-// operations are only called occasionally:
-// a) At module unloading
-// b) Once per input archive - the value is cached in the archive
-// implemenation.
+bool
+basic_serializer_map::type_info_pointer_compare::operator()(
+ const basic_serializer * lhs, const basic_serializer * rhs
+) const {
+ return *lhs < *rhs;
+}
-BOOST_ARCHIVE_DECL(void)
+BOOST_ARCHIVE_DECL(bool)
basic_serializer_map::insert(const basic_serializer * bs){
- m_map.push_back(bs);
+ // attempt to insert serializer into it's map
+ const std::pair<map_type::iterator, bool> result =
+ m_map.insert(bs);
+ // if this fails, it's because it's been instantiated
+ // in multiple modules - DLLS - a recipe for problems.
+ // So trap this here
+ if(!result.second){
+ boost::serialization::throw_exception(
+ archive_exception(
+ archive_exception::multiple_code_instantiation,
+ bs->get_debug_info()
+ )
+ );
+ }
+ return true;
}
BOOST_ARCHIVE_DECL(void)
basic_serializer_map::erase(const basic_serializer * bs){
map_type::iterator it = m_map.begin();
map_type::iterator it_end = m_map.end();
- it = std::find(it, it_end, bs);
- if(it != it_end){
- m_map.erase(it);
- }
- else
- assert(false); // this should never occur
-}
-class equals {
- const boost::serialization::extended_type_info * m_eti;
-public:
- bool operator()(const basic_serializer * bs) const {
- return *m_eti == bs->get_eti();
+ while(it != it_end){
+ // note item 9 from Effective STL !!! it++
+ if(*it == bs)
+ m_map.erase(it++);
+ else
+ it++;
}
- equals(const boost::serialization::extended_type_info * eti) :
- m_eti(eti)
- {}
-};
-
-// find the "oldest" matching pointer serializer
+ // note: we can't do this since some of the eti records
+ // we're pointing to might be expired and the comparison
+ // won't work. Leave this as a reminder not to "optimize" this.
+ //it = m_map.find(bs);
+ //assert(it != m_map.end());
+ //if(*it == bs)
+ // m_map.erase(it);
+}
BOOST_ARCHIVE_DECL(const basic_serializer *)
basic_serializer_map::find(
const boost::serialization::extended_type_info & eti
) const {
- map_type::const_iterator it = m_map.begin();
- map_type::const_iterator it_end = m_map.end();
- it = std::find_if(it, it_end, equals(& eti));
+ const basic_serializer_arg bs(eti);
+ map_type::const_iterator it;
+ it = m_map.find(& bs);
assert(it != m_map.end());
return *it;
}
Modified: trunk/libs/serialization/src/extended_type_info.cpp
==============================================================================
--- trunk/libs/serialization/src/extended_type_info.cpp (original)
+++ trunk/libs/serialization/src/extended_type_info.cpp 2009-08-23 15:27:10 EDT (Sun, 23 Aug 2009)
@@ -75,6 +75,9 @@
assert(false);
return false;
};
+ virtual const char * get_debug_info() const {
+ return get_key();
+ }
public:
extended_type_info_arg(const char * key) :
extended_type_info(0, key)
Modified: trunk/libs/serialization/src/void_cast.cpp
==============================================================================
--- trunk/libs/serialization/src/void_cast.cpp (original)
+++ trunk/libs/serialization/src/void_cast.cpp 2009-08-23 15:27:10 EDT (Sun, 23 Aug 2009)
@@ -15,6 +15,9 @@
#include <cassert>
#include <cstddef> // NULL
+#ifdef BOOST_SERIALIZATION_LOG
+#include <iostream>
+#endif
// STL
#include <set>
@@ -190,6 +193,14 @@
void_cast_detail::set_type & s
= void_cast_detail::void_caster_registry::get_mutable_instance();
+ #ifdef BOOST_SERIALIZATION_LOG
+ std::clog << "recursive_register\n";
+ std::clog << m_derived->get_debug_info();
+ std::clog << "<-";
+ std::clog << m_base->get_debug_info();
+ std::clog << "\n";
+ #endif
+
s.insert(this);
// generate all implied void_casts.
Modified: trunk/libs/serialization/test/test_exported.cpp
==============================================================================
--- trunk/libs/serialization/test/test_exported.cpp (original)
+++ trunk/libs/serialization/test/test_exported.cpp 2009-08-23 15:27:10 EDT (Sun, 23 Aug 2009)
@@ -24,12 +24,15 @@
#include <boost/serialization/type_info_implementation.hpp>
#include <boost/serialization/extended_type_info_typeid.hpp>
+#include <boost/serialization/force_include.hpp>
+
#include <boost/archive/archive_exception.hpp>
#include "test_tools.hpp"
#include "polymorphic_base.hpp"
-class polymorphic_derived1 : public polymorphic_base
+class polymorphic_derived1 :
+ public polymorphic_base
{
friend class boost::serialization::access;
template<class Archive>
Modified: trunk/libs/serialization/test/test_simple_class_ptr.cpp
==============================================================================
--- trunk/libs/serialization/test/test_simple_class_ptr.cpp (original)
+++ trunk/libs/serialization/test/test_simple_class_ptr.cpp 2009-08-23 15:27:10 EDT (Sun, 23 Aug 2009)
@@ -30,7 +30,7 @@
BOOST_REQUIRE(NULL != testfile);
- A *ta = new A();
+ const A *ta = new A();
A *ta1 = NULL;
{
Modified: trunk/libs/serialization/vc7ide/Library.vcproj
==============================================================================
--- trunk/libs/serialization/vc7ide/Library.vcproj (original)
+++ trunk/libs/serialization/vc7ide/Library.vcproj 2009-08-23 15:27:10 EDT (Sun, 23 Aug 2009)
@@ -395,6 +395,9 @@
RelativePath="..\..\..\boost\serialization\access.hpp">
</File>
<File
+ RelativePath="..\..\..\boost\archive\archive_exception.hpp">
+ </File>
+ <File
RelativePath="..\..\..\boost\serialization\base_object.hpp">
</File>
<File
@@ -615,6 +618,9 @@
RelativePath="..\..\..\boost\archive\detail\basic_serializer_map.hpp">
</File>
<File
+ RelativePath="..\..\..\boost\archive\detail\check.hpp">
+ </File>
+ <File
RelativePath="..\..\..\boost\archive\detail\common_iarchive.hpp">
</File>
<File
@@ -679,9 +685,6 @@
RelativePath="..\..\..\boost\serialization\force_include.hpp">
</File>
<File
- RelativePath="..\..\..\boost\serialization\non_convertible.hpp">
- </File>
- <File
RelativePath="..\..\..\boost\serialization\pfto.hpp">
</File>
<File
@@ -771,9 +774,6 @@
Name="Archive Implementations"
Filter="">
<File
- RelativePath="..\..\..\boost\archive\archive_exception.hpp">
- </File>
- <File
RelativePath="..\..\..\boost\archive\binary_iarchive.hpp">
</File>
<File
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk