Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3747: Serialization code speculate in order of static initialization
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-03-30 07:44:38
#3747: Serialization code speculate in order of static initialization
--------------------------------------------------+-------------------------
Reporter: Runar Undheim <r.undheim@â¦> | Owner: ramey
Type: Bugs | Status: reopened
Milestone: Boost 1.43.0 | Component: serialization
Version: Boost 1.41.0 | Severity: Showstopper
Resolution: | Keywords: serialization static order
--------------------------------------------------+-------------------------
Comment(by Runar Undheim <r.undheim@â¦>):
''What is the problem?''[[BR]]
The BOOST_CLASS_EXPORT does not register classes correctly. I got an
exception from basic_oarchive.cpp line 351 (boost 1.42)
(archive_exception(archive_exception::unregistered_class)) during export.
This message only come when CLASS_EXPORT_IN_MAIN is 0. I got a pointer to
serialization::extended_type_info (variable eti), but the m_key is NULL.
''Why should static initialization be in some particular order?''[[BR]]
It should not, the order is decided by the compiler. But why does the code
work when the static initialization is in one particular order and not in
an other order? The serialization code should handle any order.
''I unzipped the files. and tried to compile and got ...'' [[BR]]
I am sorry, but I work with VisualC++ 2005 where abstract is a legal
keyword. But you could just remove the abstract behind "class Base". It
does not matter on how the code is working. I think it may be impossible
to reproduce this on other compilers, because it is the order of the
static initialization that cause the problem. I have only tested with
Visual C++ 2008 and Visual C++ 2010 RC, but I got the same problem there.
I set a break point in constructor to extended_type_info. When
CLASS_EXPORT_IN_MAIN is 0 the key is always NULL pointer. When
CLASS_EXPORT_IN_MAIN is 1 I got a valid key.
{{{
extended_type_info_typeid() :
typeid_system::extended_type_info_typeid_0(get_key())
{
type_register(typeid(T));
key_register();
}
const char * get_key() const {
return boost::serialization::guid<T>();
}
}}}
The extended_type_info_typeid::get_key function speculate in that the
boost::serialization::guid<T>() is registered.
So this static function:
{{{
boost::serialization::singleton<boost::archive::detail::oserializer<boost::archive::text_oarchive,Main>
>::instance''(void)
}}}
speculate that this function is called before:
{{{
boost::archive::detail::`anonymous namespace'::init_guid<Main>::g''(void)
}}}
This is not always the case. At least not with Visual Studio C++ 2005 and
newer. See order_of_static_registration_fail.txt for order of static
initialization when the code fail and see
order_of_static_registration_ok.txt for order when everything works nice.
Runar Undheim
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3747#comment:12> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC