Ticket #9612: 0001-Changes-to-singleton-to-allow-extern-templates-on-si.patch

File 0001-Changes-to-singleton-to-allow-extern-templates-on-si.patch, 5.6 KB (added by Brandon Kohn, 9 years ago)

Patch to workaround issue

  • new file include/boost/serialization/extern.hpp

    From ae8bf9fa9c0c0baf275d68538804be6ac6f7922a Mon Sep 17 00:00:00 2001
    From: Brandon Kohn <blkohn@hotmail.com>
    Date: Sun, 2 Feb 2014 13:58:57 -0500
    Subject: [PATCH] Changes to singleton to allow extern templates on singletons.
    
    ---
     include/boost/serialization/extern.hpp    | 62 +++++++++++++++++++++++++++++++
     include/boost/serialization/singleton.hpp | 16 ++++----
     2 files changed, 70 insertions(+), 8 deletions(-)
     create mode 100644 include/boost/serialization/extern.hpp
    
    diff --git a/include/boost/serialization/extern.hpp b/include/boost/serialization/extern.hpp
    new file mode 100644
    index 0000000..8b2cc35
    - +  
     1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
     2// extern.hpp
     3
     4// (C) Copyright 2014 Brandon Kohn
     5// Use, modification and distribution is subject to the Boost Software
     6// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
     7// http://www.boost.org/LICENSE_1_0.txt)
     8
     9#ifndef BOOST_SERIALIZATION_EXTERN_HPP
     10#define BOOST_SERIALIZATION_EXTERN_HPP
     11
     12// MS compatible compilers support #pragma once
     13#if defined(_MSC_VER)
     14# pragma once
     15#endif
     16
     17#include <boost/config.hpp>
     18
     19#ifndef BOOST_NO_CXX11_EXTERN_TEMPLATE
     20    #define BOOST_SERIALIZATION_EXTERN_OSERIALIZER(Archive, T, Export) \
     21    namespace boost { namespace serialization {                        \
     22        extern template class Export singleton                         \
     23        <                                                              \
     24            ::boost::archive::detail::oserializer<Archive, T>          \
     25        >;                                                             \
     26    }}                                                                 \
     27    /***/
     28
     29    #define BOOST_SERIALIZATION_INSTANTIATE_OSERIALIZER(Archive, T, Export) \
     30    namespace boost { namespace serialization {                             \
     31        template class Export singleton                                     \
     32        <                                                                   \
     33            ::boost::archive::detail::oserializer<Archive, T>               \
     34        >;                                                                  \
     35    }}                                                                      \
     36    /***/
     37
     38    #define BOOST_SERIALIZATION_EXTERN_ISERIALIZER(Archive, T, Export) \
     39    namespace boost { namespace serialization {                        \
     40        extern template class Export singleton                         \
     41        <                                                              \
     42            ::boost::archive::detail::iserializer<Archive, T>          \
     43        >;                                                             \
     44    }}                                                                 \
     45    /***/
     46
     47    #define BOOST_SERIALIZATION_INSTANTIATE_ISERIALIZER(Archive, T, Export) \
     48    namespace boost { namespace serialization {                             \
     49        template class Export singleton                                     \
     50        <                                                                   \
     51            ::boost::archive::detail::iserializer<Archive, T>               \
     52        >;                                                                  \
     53    }}                                                                      \
     54    /***/
     55#else
     56    #define BOOST_SERIALIZATION_EXTERN_OSERIALIZER(Archive, T, Export)
     57    #define BOOST_SERIALIZATION_INSTANTIATE_OSERIALIZER(Archive, T, Export)
     58    #define BOOST_SERIALIZATION_EXTERN_ISERIALIZER(Archive, T, Export)
     59    #define BOOST_SERIALIZATION_INSTANTIATE_ISERIALIZER(Archive, T, Export)   
     60#endif
     61
     62#endif //! BOOST_SERIALIZATION_EXTERN_HPP
  • include/boost/serialization/singleton.hpp

    diff --git a/include/boost/serialization/singleton.hpp b/include/boost/serialization/singleton.hpp
    index 546118c..ab6e31c 100644
    a b namespace serialization {  
    7777// attempt to retieve a mutable instances while locked will
    7878// generate a assertion if compiled for debug.
    7979
    80 class singleton_module :
     80class BOOST_DLLEXPORT singleton_module :
    8181    public boost::noncopyable
    8282{
    8383private:
    bool detail::singleton_wrapper< T >::m_is_destroyed = false;  
    118118} // detail
    119119
    120120template <class T>
    121 class singleton : public singleton_module
     121class BOOST_DLLEXPORT singleton : public singleton_module
    122122{
    123123private:
    124     BOOST_DLLEXPORT static T & instance;
     124    static T & instance;
    125125    // include this to provoke instantiation at pre-execution time
    126126    static void use(T const &) {}
    127     BOOST_DLLEXPORT static T & get_instance() {
     127    static T & get_instance() {
    128128        static detail::singleton_wrapper< T > t;
    129129        // refer to instance, causing it to be instantiated (and
    130130        // initialized at startup on working compilers)
    private:  
    133133        return static_cast<T &>(t);
    134134    }
    135135public:
    136     BOOST_DLLEXPORT static T & get_mutable_instance(){
     136    static T & get_mutable_instance(){
    137137        BOOST_ASSERT(! is_locked());
    138138        return get_instance();
    139139    }
    140     BOOST_DLLEXPORT static const T & get_const_instance(){
     140    static const T & get_const_instance(){
    141141        return get_instance();
    142142    }
    143     BOOST_DLLEXPORT static bool is_destroyed(){
     143    static bool is_destroyed(){
    144144        return detail::singleton_wrapper< T >::m_is_destroyed;
    145145    }
    146146};
    147147
    148148template<class T>
    149 BOOST_DLLEXPORT T & singleton< T >::instance = singleton< T >::get_instance();
     149 T & singleton< T >::instance = singleton< T >::get_instance();
    150150
    151151} // namespace serialization
    152152} // namespace boost