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
|
* @brief Default constructor
|
||||||
*/
|
*/
|
||||||
cell_list_const_iterator (cell_list_iterator<cell_type> iter)
|
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
|
* @brief Equality
|
||||||
|
|
|
||||||
|
|
@ -23,35 +23,36 @@
|
||||||
|
|
||||||
#include "tlClassRegistry.h"
|
#include "tlClassRegistry.h"
|
||||||
|
|
||||||
#include <map>
|
#include <unordered_map>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <typeindex>
|
||||||
|
|
||||||
namespace tl
|
namespace tl
|
||||||
{
|
{
|
||||||
|
|
||||||
struct ti_compare_f
|
typedef std::map<std::type_index, RegistrarBase *> inst_map_type;
|
||||||
{
|
|
||||||
bool operator() (const std::type_info *a, const std::type_info *b) const
|
|
||||||
{
|
|
||||||
return a->before (*b);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::map<const std::type_info *, RegistrarBase *, ti_compare_f> inst_map_type;
|
// Used to fix https://en.cppreference.com/w/cpp/language/siof segfault
|
||||||
static inst_map_type s_inst_map;
|
// 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)
|
TL_PUBLIC void set_registrar_instance_by_type (const std::type_info &ti, RegistrarBase *rb)
|
||||||
{
|
{
|
||||||
if (rb) {
|
if (rb) {
|
||||||
s_inst_map[&ti] = rb;
|
s_inst_map()[std::type_index(ti)] = rb;
|
||||||
} else {
|
} 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)
|
TL_PUBLIC RegistrarBase *registrar_instance_by_type (const std::type_info &ti)
|
||||||
{
|
{
|
||||||
inst_map_type::const_iterator im = s_inst_map.find (&ti);
|
inst_map_type map = s_inst_map();
|
||||||
if (im != s_inst_map.end ()) {
|
inst_map_type::const_iterator im = map.find (std::type_index(ti));
|
||||||
|
if (im != map.end ()) {
|
||||||
return im->second;
|
return im->second;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue