Skip to content

Commit 284944a

Browse files
committed
wip
1 parent f4d26b2 commit 284944a

File tree

10 files changed

+62
-54
lines changed

10 files changed

+62
-54
lines changed

doc/modules/ROOT/examples/shared_libs/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ add_compile_definitions(BOOST_OPENMETHOD_ENABLE_RUNTIME_CHECKS)
2424
# ------------------------------------------------------------------------------
2525
# dynamic loading, direct virtual_ptrs
2626

27+
if(UNIX)
28+
message(STATUS "Boost.OpenMethod: disabling symbol exports on POSIX (hidden visibility)")
29+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
30+
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
31+
endif()
32+
2733
add_executable(boost_openmethod-dynamic dynamic_main.cpp)
2834
set_target_properties(boost_openmethod-dynamic PROPERTIES ENABLE_EXPORTS ON)
2935
target_link_libraries(boost_openmethod-dynamic Boost::openmethod Boost::dll)

doc/modules/ROOT/examples/shared_libs/animals.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313

1414
#include <boost/openmethod/preamble.hpp>
1515

16+
#ifdef BOOST_CLANG
17+
#pragma clang diagnostic ignored "-Wundefined-var-template"
18+
#endif
19+
20+
#ifdef BOOST_GCC
21+
//#pragma GCC diagnostic ignored "-Wundefined-var-template"
22+
#endif
23+
1624
#ifdef LIBRARY_NAME
1725
#define ANIMALS_API boost::openmethod::declspec::dllexport
1826
#else

doc/modules/ROOT/examples/shared_libs/dynamic_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define LIBRARY_NAME "boost_openmethod-shared.dll"
99
#else
1010
#define LIBRARY_NAME "libboost_openmethod-shared.so"
11+
1112
#endif
1213
#endif
1314

include/boost/openmethod/core.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ struct use_class_aux<Registry, mp11::mp_list<Class, Bases...>>
360360
}
361361

362362
// coverity[uninit] - zero-initialized static storage
363-
Registry::st.classes.push_back(*this);
363+
Registry::storage::st.classes.push_back(*this);
364364
}
365365

366366
void resolve_type_ids() {
@@ -370,7 +370,7 @@ struct use_class_aux<Registry, mp11::mp_list<Class, Bases...>>
370370
}
371371

372372
~use_class_aux() {
373-
Registry::st.classes.remove(*this);
373+
Registry::storage::st.classes.remove(*this);
374374
}
375375
};
376376

@@ -2416,7 +2416,7 @@ method<Id, ReturnType(Parameters...), Registry>::method() {
24162416

24172417
// zero-initalized static variable
24182418
// coverity[uninit_use]
2419-
Registry::st.methods.push_back(*this);
2419+
Registry::storage::st.methods.push_back(*this);
24202420
}
24212421

24222422
template<
@@ -2436,7 +2436,7 @@ void method<Id, ReturnType(Parameters...), Registry>::resolve_type_ids() {
24362436
template<
24372437
typename Id, typename... Parameters, typename ReturnType, class Registry>
24382438
method<Id, ReturnType(Parameters...), Registry>::~method() {
2439-
Registry::st.methods.remove(*this);
2439+
Registry::storage::st.methods.remove(*this);
24402440
}
24412441

24422442
// -----------------------------------------------------------------------------

include/boost/openmethod/initialize.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ template<class... Options>
486486
void registry<Policies...>::compiler<Options...>::initialize() {
487487
compile();
488488
install_global_tables();
489-
registry<Policies...>::st.initialized = true;
489+
registry<Policies...>::storage::st.initialized = true;
490490
}
491491

492492
#ifdef _MSC_VER
@@ -555,7 +555,7 @@ void registry<Policies...>::compiler<Options...>::augment_classes() {
555555
// The standard does not guarantee that there is exactly one
556556
// type_info object per class. However, it guarantees that the
557557
// type_index for a class has a unique value.
558-
for (auto& cr : registry::st.classes) {
558+
for (auto& cr : registry::storage::st.classes) {
559559
if constexpr (has_deferred_static_rtti) {
560560
static_cast<deferred_class_info&>(cr).resolve_type_ids();
561561
}
@@ -585,7 +585,7 @@ void registry<Policies...>::compiler<Options...>::augment_classes() {
585585
// All known classes now have exactly one associated class_* in the
586586
// map. Collect the bases.
587587

588-
for (auto& cr : registry::st.classes) {
588+
for (auto& cr : registry::storage::st.classes) {
589589
auto rtc = class_map[rtti::type_index(cr.type)];
590590

591591
for (auto& base : range{cr.first_base, cr.last_base}) {
@@ -714,14 +714,14 @@ void registry<Policies...>::compiler<Options...>::augment_methods() {
714714
using namespace policies;
715715
using namespace detail;
716716

717-
methods.resize(registry::st.methods.size());
717+
methods.resize(registry::storage::st.methods.size());
718718

719719
++tr << "Methods:\n";
720720
indent _(tr);
721721

722722
auto meth_iter = methods.begin();
723723

724-
for (auto& meth_info : registry::st.methods) {
724+
for (auto& meth_info : registry::storage::st.methods) {
725725
if constexpr (has_deferred_static_rtti) {
726726
static_cast<deferred_method_info&>(meth_info).resolve_type_ids();
727727
}
@@ -1424,7 +1424,7 @@ void registry<Policies...>::compiler<Options...>::write_global_data() {
14241424
vptr::initialize(*this, options);
14251425
}
14261426

1427-
new_dispatch_data.swap(st.dispatch_data);
1427+
new_dispatch_data.swap(storage::st.dispatch_data);
14281428
}
14291429

14301430
template<class... Policies>
@@ -1665,8 +1665,8 @@ auto registry<Policies...>::finalize(Options... opts) -> void {
16651665
}
16661666
});
16671667

1668-
dispatch_data.clear();
1669-
st.initialized = false;
1668+
storage::st.dispatch_data.clear();
1669+
storage::st.initialized = false;
16701670
}
16711671

16721672
//! Release resources held by registry.

include/boost/openmethod/macros.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ struct va_args<ReturnType, Other> {
3030
using return_type = ReturnType;
3131
using registry =
3232
std::conditional_t<is_registry<Other>, Other, macro_default_registry>;
33-
using attributes =
34-
std::conditional_t<std::is_base_of_v<attributes, Other>, Other, void>;
33+
using attributes = std::conditional_t<
34+
std::is_base_of_v<attributes_base, Other>, Other, void>;
3535
};
3636

3737
template<class ReturnType, class T, class U>
3838
struct va_args<ReturnType, T, U> {
3939
using return_type = ReturnType;
4040
using registry = std::conditional_t<is_registry<T>, T, U>;
4141
using attributes =
42-
std::conditional_t<std::is_base_of_v<attributes, T>, T, U>;
42+
std::conditional_t<std::is_base_of_v<attributes_base, T>, T, U>;
4343
};
4444

4545
template<class ReturnType>
@@ -74,8 +74,8 @@ struct va_args<ReturnType> {
7474
::boost::openmethod::detail::va_args<__VA_ARGS__>::registry>
7575

7676
#define BOOST_OPENMETHOD_DETAIL_STORAGE_CLASS(NAME, ARGS, ...) \
77-
auto boost_openmethod_attributes( \
78-
BOOST_OPENMETHOD_TYPE(NAME, ARGS, __VA_ARGS__) &) \
77+
auto boost_openmethod_attributes( \
78+
BOOST_OPENMETHOD_TYPE(NAME, ARGS, __VA_ARGS__)&) \
7979
-> ::boost::openmethod::detail::va_args<__VA_ARGS__>::attributes;
8080

8181
#define BOOST_OPENMETHOD(NAME, ARGS, ...) \

include/boost/openmethod/policies/default_error_handler.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ struct default_error_handler : error_handler {
8585
//! The type of the error handler function object.
8686
using function_type = std::function<void(const error_variant& error)>;
8787

88-
using handler_storage = detail::global_state_handler<function_type, Registry>;
88+
using handler_storage =
89+
detail::global_state_handler<function_type, Registry>;
8990

9091
//! Calls a function with the error object, wrapped in an @ref
9192
//! error_variant.
@@ -106,7 +107,8 @@ struct default_error_handler : error_handler {
106107
//! @return The previous function.
107108
// coverity[auto_causes_copy]
108109
static auto set(function_type new_handler) -> function_type {
109-
return std::exchange(handler_storage::handler, std::move(new_handler));
110+
return std::exchange(
111+
handler_storage::handler, std::move(new_handler));
110112
}
111113

112114
//! The default error handler function.
@@ -125,7 +127,6 @@ struct default_error_handler : error_handler {
125127
Registry::output::os << "\n";
126128
}
127129
}
128-
129130
};
130131
};
131132

include/boost/openmethod/preamble.hpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <boost/openmethod/detail/static_list.hpp>
55

6+
#include <boost/config.hpp>
67
#include <boost/mp11/algorithm.hpp>
78
#include <boost/mp11/bind.hpp>
89
#include <boost/preprocessor/cat.hpp>
@@ -738,8 +739,8 @@ struct TypeHashFn {
738739
//! blueprint.
739740
//! @return A pair containing the minimum and maximum hash values.
740741
template<class Context>
741-
static auto initialize(const Context& ctx)
742-
-> std::pair<std::size_t, std::size_t>;
742+
static auto
743+
initialize(const Context& ctx) -> std::pair<std::size_t, std::size_t>;
743744

744745
//! Hash a `type_id`.
745746
//!
@@ -924,36 +925,34 @@ struct initialize_aux;
924925
// -----------------------------------------------------------------------------
925926
// attributes
926927

927-
struct attributes {};
928-
struct no_attributes : attributes {};
928+
struct attributes_base {};
929+
930+
struct no_attributes : attributes_base {};
931+
929932
struct declspec {
930-
struct dllexport : attributes {};
931-
struct dllimport : attributes {};
933+
struct dllexport : attributes_base {};
934+
struct dllimport : attributes_base {};
932935
};
933936

934-
struct visibility {
935-
struct hidden : attributes {};
936-
struct default_ : attributes {};
937-
};
938937
namespace detail {
939938

940-
#define BOOST_OPENMETHOD_DETAIL_MAKE_SYMBOL_WITH_ATTRIBUTES(ID) \
939+
#define BOOST_OPENMETHOD_DETAIL_MAKE_SYMBOL_WITH_ATTRIBUTES(ID, ...) \
941940
template<class Type, class Guide = Type&, typename = void> \
942941
struct BOOST_PP_CAT(global_state_, ID) { \
943942
using attributes = no_attributes; \
944943
static Type ID; \
945944
}; \
946945
\
947946
template<class Type, class Guide, typename Enable> \
948-
Type BOOST_PP_CAT(global_state_, ID)<Type, Guide, Enable>::ID; \
947+
Type BOOST_PP_CAT(global_state_, ID)<Type, Guide, Enable>::ID __VA_ARGS__; \
949948
\
950949
template<class Type, class Guide> \
951950
struct BOOST_PP_CAT(global_state_, ID)< \
952951
Type, Guide, \
953952
std::enable_if_t< \
954953
std::is_same_v<get_attributes<Guide>, declspec::dllexport>>> { \
955954
using attributes = declspec::dllexport; \
956-
static __declspec(dllexport) Type ID; \
955+
static BOOST_SYMBOL_EXPORT Type ID __VA_ARGS__; \
957956
}; \
958957
\
959958
template<class Type, class Guide> \
@@ -968,7 +967,7 @@ namespace detail {
968967
std::enable_if_t< \
969968
std::is_same_v<get_attributes<Guide>, declspec::dllimport>>> { \
970969
using attributes = declspec::dllimport; \
971-
static __declspec(dllimport) Type ID; \
970+
static BOOST_SYMBOL_IMPORT Type ID; \
972971
}
973972

974973
template<typename Type>
@@ -1045,13 +1044,12 @@ struct attributes_guide final : attributes {
10451044
//!
10461045
//! @see @ref policies
10471046
template<class... Policy>
1048-
class registry
1049-
: public detail::registry_base,
1050-
public detail::global_state_st<
1051-
detail::registry_state<registry<Policy...>>,
1052-
typename detail::find_first_derived_of<
1053-
policies::attributes, mp11::mp_list<Policy...>,
1054-
policies::attributes_guide<registry<Policy...>>>::guide_type> {
1047+
class registry : public detail::registry_base {
1048+
using storage = detail::global_state_st<
1049+
detail::registry_state<registry<Policy...>>,
1050+
typename detail::find_first_derived_of<
1051+
policies::attributes, mp11::mp_list<Policy...>,
1052+
policies::attributes_guide<registry<Policy...>>>::guide_type>;
10551053

10561054
template<class...>
10571055
friend struct detail::use_class_aux;
@@ -1061,6 +1059,11 @@ class registry
10611059
public:
10621060
//! The type of this registry.
10631061
using registry_type = registry;
1062+
using attributes = typename storage::attributes;
1063+
1064+
static const void* id() {
1065+
return static_cast<const void*>(&storage::st);
1066+
}
10641067

10651068
template<class... Options>
10661069
struct compiler;
@@ -1170,7 +1173,7 @@ vptr_type registry<Policies...>::static_vptr;
11701173
template<class... Policies>
11711174
void registry<Policies...>::require_initialized() {
11721175
if constexpr (registry::has_runtime_checks) {
1173-
if (!st.initialized) {
1176+
if (!storage::st.initialized) {
11741177
if constexpr (registry::has_error_handler) {
11751178
error_handler::error(not_initialized());
11761179
}

test/test_class_registration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ BOOST_AUTO_TEST_CASE(registry_own_state) {
2626
using r1 = test_registry_<__COUNTER__>;
2727
using r2 = test_registry_<__COUNTER__>;
2828
static_assert(!std::is_same_v<r1::registry_type, r2::registry_type>);
29-
BOOST_CHECK_NE((void*)&r1::st, (void*)&r2::st);
29+
BOOST_CHECK_NE(r1::id(), r2::id());
3030
}
3131

3232
namespace TEST_NS {

test/test_dispatch.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,6 @@ BOOST_AUTO_TEST_CASE(simple) {
335335
BOOST_TEST(
336336
times(diag, 2) == string_pair(DIAGONAL_SCALAR, MATRIX_SCALAR));
337337
}
338-
339-
if constexpr (std::is_same_v<test_registry::vptr, policies::vptr_vector>) {
340-
BOOST_TEST(
341-
!detail::vptr_vector_vptrs<test_registry::registry_type>.empty());
342-
finalize<test_registry>();
343-
static_assert(detail::has_finalize_aux<
344-
void, test_registry::policy<policies::vptr>,
345-
std::tuple<>>::value);
346-
BOOST_TEST(
347-
detail::vptr_vector_vptrs<test_registry::registry_type>.empty());
348-
}
349338
}
350339

351340
} // namespace TEST_NS

0 commit comments

Comments
 (0)