mirror of https://github.com/KLayout/klayout.git
Merge remote-tracking branch 'quantamhd/fix_segfault' into wip
This commit is contained in:
commit
5a6ea0148a
|
|
@ -192,8 +192,13 @@ public:
|
|||
* @brief Default constructor
|
||||
*/
|
||||
cell_list_const_iterator (cell_list_iterator<cell_type> iter)
|
||||
: mp_cell (& (*iter))
|
||||
{ }
|
||||
{
|
||||
if (iter == cell_list_iterator<cell_type>()) {
|
||||
mp_cell = nullptr;
|
||||
} else {
|
||||
mp_cell = &(*iter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Equality
|
||||
|
|
|
|||
|
|
@ -23,35 +23,36 @@
|
|||
|
||||
#include "tlClassRegistry.h"
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <typeinfo>
|
||||
#include <typeindex>
|
||||
|
||||
namespace tl
|
||||
{
|
||||
|
||||
struct ti_compare_f
|
||||
{
|
||||
bool operator() (const std::type_info *a, const std::type_info *b) const
|
||||
{
|
||||
return a->before (*b);
|
||||
}
|
||||
};
|
||||
typedef std::map<std::type_index, RegistrarBase *> inst_map_type;
|
||||
|
||||
typedef std::map<const std::type_info *, RegistrarBase *, ti_compare_f> inst_map_type;
|
||||
static inst_map_type s_inst_map;
|
||||
// Used to fix https://en.cppreference.com/w/cpp/language/siof segfault
|
||||
// on some systems.
|
||||
inst_map_type& s_inst_map() {
|
||||
static inst_map_type s_inst_map;
|
||||
return s_inst_map;
|
||||
}
|
||||
|
||||
TL_PUBLIC void set_registrar_instance_by_type (const std::type_info &ti, RegistrarBase *rb)
|
||||
{
|
||||
if (rb) {
|
||||
s_inst_map[&ti] = rb;
|
||||
s_inst_map()[std::type_index(ti)] = rb;
|
||||
} else {
|
||||
s_inst_map.erase (&ti);
|
||||
s_inst_map().erase (std::type_index(ti));
|
||||
}
|
||||
}
|
||||
|
||||
TL_PUBLIC RegistrarBase *registrar_instance_by_type (const std::type_info &ti)
|
||||
{
|
||||
inst_map_type::const_iterator im = s_inst_map.find (&ti);
|
||||
if (im != s_inst_map.end ()) {
|
||||
inst_map_type map = s_inst_map();
|
||||
inst_map_type::const_iterator im = map.find (std::type_index(ti));
|
||||
if (im != map.end ()) {
|
||||
return im->second;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue