Skip to content

Commit 18c3914

Browse files
committed
Switch to vector from set because the static member set causes crashes on clang and g++ compiled binaries at startup (msvc is fine).
1 parent 3c65dd1 commit 18c3914

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

rice/Data_Type.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ namespace Rice
175175
// Typed Data support
176176
static inline rb_data_type_t* rb_data_type_ = nullptr;
177177

178-
// Track unbound instances (ie, declared variables of type Data_Type<T>
179-
// before define_class is called)
180-
static inline std::set<Data_Type<T>*>unbound_instances_;
178+
static inline std::set<Data_Type<T>*>& unbound_instances();
181179
};
182180

183181
//! Define a new data class in the namespace given by module.

rice/Data_Type.ipp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ namespace Rice
5959
// Now register with the type registry
6060
detail::Registries::instance.types.add<T>(klass_, rb_data_type_);
6161

62-
auto iter = Data_Type<T>::unbound_instances_.begin();
63-
while (iter != Data_Type<T>::unbound_instances_.end())
62+
auto instances = unbound_instances();
63+
for (auto instance: instances)
6464
{
65-
(*iter)->set_value(klass);
66-
iter = Data_Type<T>::unbound_instances_.erase(iter);
65+
instance->set_value(klass);
6766
}
67+
instances.clear();
6868

6969
return Data_Type<T>();
7070
}
@@ -84,12 +84,22 @@ namespace Rice
8484
rb_data_type_ = nullptr;
8585
}
8686

87+
// Track unbound instances (ie, declared variables of type Data_Type<T>
88+
// before define_class is called). We can't simply use a static inline
89+
// member because it sometimes crashes clang and gcc (msvc seems fine)
90+
template<typename T>
91+
inline std::set<Data_Type<T>*>& Data_Type<T>::unbound_instances()
92+
{
93+
static std::set<Data_Type<T>*> unbound_instances;
94+
return unbound_instances;
95+
}
96+
8797
template<typename T>
8898
inline Data_Type<T>::Data_Type() : Class(klass_ == Qnil ? rb_cObject : klass_)
8999
{
90100
if (!is_bound())
91101
{
92-
this->unbound_instances_.insert(this);
102+
unbound_instances().insert(this);
93103
}
94104
}
95105

0 commit comments

Comments
 (0)