Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f1337c6

Browse filesBrowse files
committed
Ported library to Boost.TypeIndex. This solves symbol visibility problems with Clang on Linux when the library is built with -fvisibility=hidden.
1 parent 2e7eb45 commit f1337c6
Copy full SHA for f1337c6
Expand file treeCollapse file tree

15 files changed

+89
-76
lines changed
Open diff view settings
Collapse file

‎doc/changelog.qbk‎

Copy file name to clipboardExpand all lines: doc/changelog.qbk
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
[section:changelog Changelog]
1111

12+
[heading 2.6, Boost 1.59]
13+
14+
[*General changes:]
15+
16+
* On systems with [@https://gcc.gnu.org/wiki/Visibility symbol visibility] support (e.g. Linux) the library is now built with all internal symbols hidden. API symbols still have default visibility, so this shouldn't affect linking with the library.
17+
* *Breaking change:* The library has been ported to __boost_type_index__ for its underlying type info management tool. This affected the following public interfaces:
18+
* `invalid_type` exceptions thrown by the library now have `typeindex::type_index` attached as the description of the offending type. The type was previously identified by `type_info_wrapper`.
19+
* __boost_exception__ `type_info_info` error information now contains `typeindex::type_index` instead of `type_info_wrapper`. This is the error info that can be used to obtain the type info from `invalid_type` exceptions.
20+
* `attribute_value::get_type()` now returns `typeindex::type_index` instead of `type_info_wrapper`. If the `attribute_value` object is empty, the returned `type_index` is default-constructed (i.e. refers to the `void` type). User-defined attribute value implementations should be similatly changed (the `attribute_value::impl::get_type()` virtual method now also returns `typeindex::type_index`).
21+
1222
[heading 2.5, Boost 1.58]
1323

1424
[*Bug fixes:]
Collapse file

‎doc/log.qbk‎

Copy file name to clipboardExpand all lines: doc/log.qbk
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
[def __boost_asio__ [@http://www.boost.org/doc/libs/release/doc/html/boost_asio.html Boost.ASIO]]
4747
[def __boost_move__ [@http://www.boost.org/doc/libs/release/doc/html/move.html Boost.Move]]
4848
[def __boost_locale__ [@http://www.boost.org/doc/libs/release/libs/locale/doc/html/index.html Boost.Locale]]
49+
[def __boost_type_index__ [@http://www.boost.org/doc/libs/release/doc/html/boost_typeindex.html Boost.TypeIndex]]
4950
[def __boost_utility__ [@http://www.boost.org/doc/libs/release/libs/utility/utility.htm Boost.Utility]]
5051
[def __boost_quickbook__ [@http://www.boost.org/doc/libs/release/doc/html/quickbook.html Boost.Quickbook]]
5152

Collapse file

‎include/boost/log/attributes/attribute_value.hpp‎

Copy file name to clipboardExpand all lines: include/boost/log/attributes/attribute_value.hpp
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
#ifndef BOOST_LOG_ATTRIBUTE_VALUE_HPP_INCLUDED_
1616
#define BOOST_LOG_ATTRIBUTE_VALUE_HPP_INCLUDED_
1717

18+
#include <boost/type_index.hpp>
1819
#include <boost/move/core.hpp>
1920
#include <boost/smart_ptr/intrusive_ptr.hpp>
2021
#include <boost/log/detail/config.hpp>
2122
#include <boost/utility/explicit_operator_bool.hpp>
22-
#include <boost/log/utility/type_info_wrapper.hpp>
2323
#include <boost/log/utility/type_dispatch/type_dispatcher.hpp>
2424
#include <boost/log/attributes/attribute.hpp>
2525
#include <boost/log/attributes/value_extraction_fwd.hpp>
@@ -103,7 +103,7 @@ class attribute_value
103103
/*!
104104
* \return The attribute value type
105105
*/
106-
virtual type_info_wrapper get_type() const { return type_info_wrapper(); }
106+
virtual typeindex::type_index get_type() const { return typeindex::type_index(); }
107107
};
108108

109109
private:
@@ -166,12 +166,12 @@ class attribute_value
166166
* the information cannot be provided. If the returned value is not empty, the type
167167
* can be used for value extraction.
168168
*/
169-
type_info_wrapper get_type() const
169+
typeindex::type_index get_type() const
170170
{
171171
if (m_pImpl.get())
172172
return m_pImpl->get_type();
173173
else
174-
return type_info_wrapper();
174+
return typeindex::type_index();
175175
}
176176

177177
/*!
Collapse file

‎include/boost/log/attributes/attribute_value_impl.hpp‎

Copy file name to clipboardExpand all lines: include/boost/log/attributes/attribute_value_impl.hpp
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_
1616
#define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_
1717

18+
#include <boost/type_index.hpp>
1819
#include <boost/move/core.hpp>
1920
#include <boost/move/utility.hpp>
2021
#include <boost/type_traits/remove_cv.hpp>
@@ -87,7 +88,7 @@ class attribute_value_impl :
8788
/*!
8889
* \return The attribute value type
8990
*/
90-
type_info_wrapper get_type() const { return type_info_wrapper(typeid(value_type)); }
91+
typeindex::type_index get_type() const { return typeindex::type_id< value_type >(); }
9192

9293
/*!
9394
* \return Reference to the contained value.
Collapse file

‎include/boost/log/attributes/current_thread_id.hpp‎

Copy file name to clipboardExpand all lines: include/boost/log/attributes/current_thread_id.hpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class current_thread_id :
7979
return new detached_value(boost::log::aux::this_thread::get_id());
8080
}
8181

82-
type_info_wrapper get_type() const { return type_info_wrapper(typeid(value_type)); }
82+
typeindex::type_index get_type() const { return typeindex::type_id< value_type >(); }
8383
};
8484

8585
public:
Collapse file

‎include/boost/log/attributes/fallback_policy.hpp‎

Copy file name to clipboardExpand all lines: include/boost/log/attributes/fallback_policy.hpp
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
#ifndef BOOST_LOG_ATTRIBUTES_FALLBACK_POLICY_HPP_INCLUDED_
1616
#define BOOST_LOG_ATTRIBUTES_FALLBACK_POLICY_HPP_INCLUDED_
1717

18+
#include <boost/type_index.hpp>
1819
#include <boost/type_traits/remove_cv.hpp>
1920
#include <boost/type_traits/remove_reference.hpp>
2021
#include <boost/log/detail/config.hpp>
2122
#include <boost/log/exceptions.hpp>
22-
#include <boost/log/utility/type_info_wrapper.hpp>
2323
#include <boost/log/attributes/fallback_policy_fwd.hpp>
2424
#include <boost/log/detail/header.hpp>
2525

@@ -59,7 +59,7 @@ struct fallback_to_none
5959
/*!
6060
* The method is called when value extraction failed because the attribute value has different type than requested.
6161
*/
62-
static void on_invalid_type(type_info_wrapper const&)
62+
static void on_invalid_type(typeindex::type_index const&)
6363
{
6464
}
6565

@@ -99,7 +99,7 @@ struct fallback_to_throw
9999
/*!
100100
* The method is called when value extraction failed because the attribute value has different type than requested.
101101
*/
102-
static void on_invalid_type(type_info_wrapper const& t)
102+
static void on_invalid_type(typeindex::type_index const& t)
103103
{
104104
BOOST_LOG_THROW_DESCR_PARAMS(invalid_type, "Attribute value has incompatible type", (t));
105105
}
@@ -161,7 +161,7 @@ struct fallback_to_default
161161
/*!
162162
* The method is called when value extraction failed because the attribute value has different type than requested.
163163
*/
164-
static void on_invalid_type(type_info_wrapper const&)
164+
static void on_invalid_type(typeindex::type_index const&)
165165
{
166166
}
167167

Collapse file

‎include/boost/log/exceptions.hpp‎

Copy file name to clipboardExpand all lines: include/boost/log/exceptions.hpp
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#include <cstddef>
1919
#include <string>
2020
#include <stdexcept>
21+
#include <boost/type_index.hpp>
2122
#include <boost/preprocessor/seq/enum.hpp>
2223
#include <boost/log/detail/config.hpp>
2324
#include <boost/log/attributes/attribute_name.hpp>
24-
#include <boost/log/utility/type_info_wrapper.hpp>
2525
#include <boost/log/detail/header.hpp>
2626

2727
#ifdef BOOST_HAS_PRAGMA_ONCE
@@ -130,8 +130,8 @@ class BOOST_LOG_API invalid_type :
130130
static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line);
131131
static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr);
132132
static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name);
133-
static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, type_info_wrapper const& type);
134-
static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name, type_info_wrapper const& type);
133+
static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, typeindex::type_index const& type);
134+
static BOOST_LOG_NORETURN void throw_(const char* file, std::size_t line, std::string const& descr, attribute_name const& name, typeindex::type_index const& type);
135135
#endif
136136
};
137137

Collapse file

‎include/boost/log/sources/global_logger_storage.hpp‎

Copy file name to clipboardExpand all lines: include/boost/log/sources/global_logger_storage.hpp
+24-18Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
#ifndef BOOST_LOG_SOURCES_GLOBAL_LOGGER_STORAGE_HPP_INCLUDED_
1616
#define BOOST_LOG_SOURCES_GLOBAL_LOGGER_STORAGE_HPP_INCLUDED_
1717

18-
#include <typeinfo>
1918
#include <stdexcept>
19+
#include <boost/type_index.hpp>
2020
#include <boost/smart_ptr/shared_ptr.hpp>
2121
#include <boost/smart_ptr/make_shared_object.hpp>
2222
#include <boost/preprocessor/seq/enum.hpp>
2323
#include <boost/log/detail/config.hpp>
2424
#include <boost/log/detail/singleton.hpp>
25-
#include <boost/log/detail/visible_type.hpp>
2625
#include <boost/log/detail/header.hpp>
2726

2827
#ifdef BOOST_HAS_PRAGMA_ONCE
@@ -41,17 +40,19 @@ namespace aux {
4140
struct BOOST_LOG_NO_VTABLE BOOST_SYMBOL_VISIBLE logger_holder_base
4241
{
4342
//! The source file name where the logger was registered
44-
const char* m_RegistrationFile;
43+
const char* const m_RegistrationFile;
4544
//! The line number where the logger was registered
46-
unsigned int m_RegistrationLine;
45+
const unsigned int m_RegistrationLine;
46+
//! Stored logger type
47+
const typeindex::type_index m_LoggerType;
4748

48-
logger_holder_base(const char* file, unsigned int line) :
49+
logger_holder_base(const char* file, unsigned int line, typeindex::type_index logger_type) BOOST_NOEXCEPT :
4950
m_RegistrationFile(file),
50-
m_RegistrationLine(line)
51+
m_RegistrationLine(line),
52+
m_LoggerType(logger_type)
5153
{
5254
}
5355
virtual ~logger_holder_base() {}
54-
virtual std::type_info const& logger_type() const = 0;
5556
};
5657

5758
//! The actual logger holder class
@@ -63,11 +64,10 @@ struct BOOST_SYMBOL_VISIBLE logger_holder :
6364
LoggerT m_Logger;
6465

6566
logger_holder(const char* file, unsigned int line, LoggerT const& logger) :
66-
logger_holder_base(file, line),
67+
logger_holder_base(file, line, typeindex::type_id< LoggerT >()),
6768
m_Logger(logger)
6869
{
6970
}
70-
std::type_info const& logger_type() const { return typeid(LoggerT); }
7171
};
7272

7373
//! The class implements a global repository of tagged loggers
@@ -76,7 +76,7 @@ struct global_storage
7676
typedef shared_ptr< logger_holder_base >(*initializer_t)();
7777

7878
//! Finds or creates the logger and returns its holder
79-
BOOST_LOG_API static shared_ptr< logger_holder_base > get_or_init(std::type_info const& key, initializer_t initializer);
79+
BOOST_LOG_API static shared_ptr< logger_holder_base > get_or_init(typeindex::type_index key, initializer_t initializer);
8080

8181
// Non-constructible, non-copyable, non-assignable
8282
BOOST_DELETED_FUNCTION(global_storage())
@@ -86,8 +86,8 @@ struct global_storage
8686

8787
//! Throws the \c odr_violation exception
8888
BOOST_LOG_API BOOST_LOG_NORETURN void throw_odr_violation(
89-
std::type_info const& tag_type,
90-
std::type_info const& logger_type,
89+
typeindex::type_index tag_type,
90+
typeindex::type_index logger_type,
9191
logger_holder_base const& registered);
9292

9393
//! The class implements a logger singleton
@@ -116,18 +116,24 @@ struct logger_singleton :
116116
static void init_instance()
117117
{
118118
shared_ptr< logger_holder< logger_type > >& instance = base_type::get_instance();
119-
shared_ptr< logger_holder_base > holder = global_storage::get_or_init(
120-
typeid(boost::log::aux::visible_type< TagT >),
121-
&logger_singleton::construct_logger);
122-
instance = boost::dynamic_pointer_cast< logger_holder< logger_type > >(holder);
123-
if (!instance)
119+
const typeindex::type_index tag_type_index = typeindex::type_id< TagT >();
120+
shared_ptr< logger_holder_base > holder = global_storage::get_or_init(tag_type_index, &logger_singleton::construct_logger);
121+
const typeindex::type_index logger_type_index = typeindex::type_id< logger_type >();
122+
if (holder->m_LoggerType == logger_type_index)
123+
{
124+
// Note: dynamic_cast may fail here if logger_type is not visible (for example, with Clang on Linux, if the original logger
125+
// instance was initialized in a different DSO than where it's being queried). logger_holder default visibility doesn't
126+
// help since it is inhibited by the template parameter visibility.
127+
instance = boost::static_pointer_cast< logger_holder< logger_type > >(holder);
128+
}
129+
else
124130
{
125131
// In pure C++ this should never happen, since there cannot be two
126132
// different tag types that have equal type_infos. In real life it can
127133
// happen if the same-named tag is defined differently in two or more
128134
// dlls. This check is intended to detect such ODR violations. However, there
129135
// is no protection against different definitions of the logger type itself.
130-
throw_odr_violation(typeid(TagT), typeid(logger_type), *holder);
136+
throw_odr_violation(tag_type_index, logger_type_index, *holder);
131137
}
132138
}
133139

Collapse file

‎include/boost/log/support/exception.hpp‎

Copy file name to clipboardExpand all lines: include/boost/log/support/exception.hpp
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
#ifndef BOOST_LOG_SUPPORT_EXCEPTION_HPP_INCLUDED_
1616
#define BOOST_LOG_SUPPORT_EXCEPTION_HPP_INCLUDED_
1717

18+
#include <boost/type_index.hpp>
1819
#include <boost/exception/info.hpp>
1920
#include <boost/log/detail/config.hpp>
2021
#include <boost/log/attributes/attribute_name.hpp>
2122
#include <boost/log/attributes/named_scope.hpp>
22-
#include <boost/log/utility/type_info_wrapper.hpp>
2323
#include <boost/log/detail/header.hpp>
2424

2525
#ifdef BOOST_HAS_PRAGMA_ONCE
@@ -38,7 +38,7 @@ typedef error_info< struct attribute_name_info_tag, attribute_name > attribute_n
3838
/*!
3939
* Type info exception information
4040
*/
41-
typedef error_info< struct type_info_info_tag, type_info_wrapper > type_info_info;
41+
typedef error_info< struct type_info_info_tag, typeindex::type_index > type_info_info;
4242

4343
/*!
4444
* Parse position exception information
Collapse file

‎include/boost/log/utility/type_dispatch/dynamic_type_dispatcher.hpp‎

Copy file name to clipboardExpand all lines: include/boost/log/utility/type_dispatch/dynamic_type_dispatcher.hpp
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
#include <memory>
2020
#include <map>
2121
#include <boost/ref.hpp>
22+
#include <boost/type_index.hpp>
2223
#include <boost/smart_ptr/shared_ptr.hpp>
2324
#include <boost/smart_ptr/make_shared_object.hpp>
2425
#include <boost/log/detail/config.hpp>
25-
#include <boost/log/detail/visible_type.hpp>
26-
#include <boost/log/utility/type_info_wrapper.hpp>
2726
#include <boost/log/utility/type_dispatch/type_dispatcher.hpp>
2827
#include <boost/log/detail/header.hpp>
2928

@@ -78,7 +77,7 @@ class dynamic_type_dispatcher :
7877
#endif // BOOST_LOG_DOXYGEN_PASS
7978

8079
//! The dispatching map
81-
typedef std::map< type_info_wrapper, shared_ptr< callback_base > > dispatching_map;
80+
typedef std::map< typeindex::type_index, shared_ptr< callback_base > > dispatching_map;
8281
dispatching_map m_DispatchingMap;
8382

8483
public:
@@ -118,7 +117,7 @@ class dynamic_type_dispatcher :
118117
boost::shared_ptr< callback_base > p(
119118
boost::make_shared< callback_impl< T, VisitorT > >(boost::cref(visitor)));
120119

121-
type_info_wrapper wrapper(typeid(aux::visible_type< T >));
120+
typeindex::type_index wrapper(typeindex::type_id< T >());
122121
m_DispatchingMap[wrapper].swap(p);
123122
}
124123

@@ -132,11 +131,10 @@ class dynamic_type_dispatcher :
132131

133132
private:
134133
#ifndef BOOST_LOG_DOXYGEN_PASS
135-
static callback_base get_callback(type_dispatcher* p, std::type_info const& type)
134+
static callback_base get_callback(type_dispatcher* p, typeindex::type_index type)
136135
{
137136
dynamic_type_dispatcher* const self = static_cast< dynamic_type_dispatcher* >(p);
138-
type_info_wrapper wrapper(type);
139-
dispatching_map::iterator it = self->m_DispatchingMap.find(wrapper);
137+
dispatching_map::iterator it = self->m_DispatchingMap.find(type);
140138
if (it != self->m_DispatchingMap.end())
141139
return *it->second;
142140
else

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.