Fix mistake: static initialization code cannot access other static objects.

Specifically, the eid->type() call depends on the order of linking.
develop
Alexander Gavrilov 2012-03-29 22:56:06 +04:00
parent 0c2c94fa92
commit ec48405f0a
2 changed files with 7 additions and 3 deletions

@ -36,6 +36,7 @@ namespace df {
pointer_identity identity_traits<void*>::identity; pointer_identity identity_traits<void*>::identity;
stl_ptr_vector_identity identity_traits<std::vector<void*> >::identity; stl_ptr_vector_identity identity_traits<std::vector<void*> >::identity;
stl_bit_vector_identity identity_traits<std::vector<bool> >::identity; stl_bit_vector_identity identity_traits<std::vector<bool> >::identity;
bit_array_identity identity_traits<BitArray<int> >::identity;
buffer_container_identity buffer_container_identity::base_instance; buffer_container_identity buffer_container_identity::base_instance;

@ -500,6 +500,11 @@ namespace df
static container_identity *get(); static container_identity *get();
}; };
template<> struct identity_traits<BitArray<int> > {
static bit_array_identity identity;
static bit_container_identity *get() { return &identity; }
};
template<class T> struct identity_traits<BitArray<T> > { template<class T> struct identity_traits<BitArray<T> > {
static bit_container_identity *get(); static bit_container_identity *get();
}; };
@ -553,9 +558,7 @@ namespace df
template<class T> template<class T>
inline bit_container_identity *identity_traits<BitArray<T> >::get() { inline bit_container_identity *identity_traits<BitArray<T> >::get() {
static type_identity *eid = identity_traits<T>::get(); static bit_array_identity identity(identity_traits<T>::get());
static enum_identity *reid = eid->type() == DFHack::IDTYPE_ENUM ? (enum_identity*)eid : NULL;
static bit_array_identity identity(reid);
return &identity; return &identity;
} }