Skip to content

Commit e6369df

Browse files
committed
support dynamic loading on Windows
1 parent a754e07 commit e6369df

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int main() {
5959
try {
6060
std::cout << "Before loading the shared library.\n";
6161

62-
boost::openmethod::initialize();
62+
boost::openmethod::initialize(trace::from_env());
6363
BOOST_ASSERT(default_registry::static_vptr<Carnivore> != nullptr);
6464

6565
std::cout << "cow meets wolf -> "
@@ -79,7 +79,7 @@ int main() {
7979
boost::dll::shared_library lib(
8080
boost::dll::program_location().parent_path() / LIBRARY_NAME,
8181
boost::dll::load_mode::rtld_now);
82-
boost::openmethod::initialize();
82+
boost::openmethod::initialize(trace::from_env());
8383

8484
std::cout << "cow meets wolf -> "
8585
<< meet(*std::make_unique<Cow>(), *std::make_unique<Wolf>())
@@ -102,7 +102,7 @@ int main() {
102102
std::cout << "\nAfter unloading the shared library.\n";
103103

104104
lib.unload();
105-
boost::openmethod::initialize();
105+
boost::openmethod::initialize(trace::from_env());
106106

107107
std::cout << "cow meets wolf -> "
108108
<< meet(*std::make_unique<Cow>(), *std::make_unique<Wolf>())

include/boost/openmethod/initialize.hpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,6 @@ struct initialize_policies<Registry, mp11::mp_list<Policies...>> {
100100
}
101101
};
102102

103-
// template<typename Registry, typename Policy, typename... Policies>
104-
// struct initialize_policies<Registry, mp11::mp_list<Policy, Policies...>> {
105-
// template<typename Context, typename Options>
106-
// static void fn(const Context& ctx, const Options& options) {
107-
// initialize_policy<Policy, Registry>(ctx, options);
108-
// initialize_policies<Registry, mp11::mp_list<Policies...>>::fn(
109-
// ctx, options);
110-
// }
111-
// };
112-
113-
// template<typename Registry>
114-
// struct initialize_policies<Registry, mp11::mp_list<>> {
115-
// template<typename Context, typename Options>
116-
// static void fn(const Context& ctx, const Options& options) {
117-
// }
118-
// };
119-
120103
inline void merge_into(boost::dynamic_bitset<>& a, boost::dynamic_bitset<>& b) {
121104
if (b.size() < a.size()) {
122105
b.resize(a.size());
@@ -679,7 +662,9 @@ void registry<Policies...>::compiler<Options...>::augment_classes() {
679662
{
680663
indent _(tr);
681664
++tr << type_name(cr.type) << ": "
682-
<< range{cr.first_base, cr.last_base} << "\n";
665+
<< range{cr.first_base, cr.last_base}
666+
<< ", type = " << cr.type << ", &vptr = " << &cr.vptr()
667+
<< "\n";
683668
}
684669

685670
auto& rtc = class_map[rtti::type_index(cr.type)];
@@ -688,7 +673,18 @@ void registry<Policies...>::compiler<Options...>::augment_classes() {
688673
rtc = &classes.emplace_back();
689674
}
690675

691-
rtc->ci.push_back(&cr);
676+
bool new_type_id = true;
677+
678+
for (auto ci : rtc->ci) {
679+
if (ci->type == cr.type) {
680+
new_type_id = false;
681+
break;
682+
}
683+
}
684+
685+
if (new_type_id) {
686+
rtc->ci.push_back(&cr);
687+
}
692688
}
693689
}
694690

include/boost/openmethod/policies/fast_perfect_hash.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void fast_perfect_hash::fn<Registry>::initialize_aux(
186186

187187
std::uniform_int_distribution<std::size_t> uniform_dist;
188188

189-
for (std::size_t pass = 0; pass < 4; ++pass, ++M) {
189+
for (std::size_t pass = 0; pass < 5; ++pass, ++M) {
190190
hash_fn.shift = 8 * sizeof(type_id) - M;
191191
auto hash_size = 1 << M;
192192
hash_fn.min_value = (std::numeric_limits<std::size_t>::max)();
@@ -200,7 +200,7 @@ void fast_perfect_hash::fn<Registry>::initialize_aux(
200200
std::size_t attempts = 0;
201201
buckets.resize(hash_size);
202202

203-
while (attempts < 100000) {
203+
while (attempts < 1'00'000) {
204204
std::fill(
205205
buckets.begin(), buckets.end(), type_id(detail::uintptr_max));
206206
++attempts;
@@ -266,8 +266,8 @@ void fast_perfect_hash::fn<Registry>::check(std::size_t index, type_id type) {
266266

267267
template<class Registry, class Stream>
268268
auto fast_perfect_hash::search_error::write(Stream& os) const -> void {
269-
os << "could not find hash factors after " << attempts << "s using "
270-
<< buckets << " buckets\n";
269+
os << "could not find hash factors after " << attempts
270+
<< " attempts using up to " << buckets << " buckets\n";
271271
}
272272

273273
} // namespace policies

0 commit comments

Comments
 (0)