Revert "Work around coverity crash"

This reverts commit bb0d100513.

Conflicts:
	include/chaiscript/dispatchkit/dispatchkit.hpp
	include/chaiscript/dispatchkit/type_info.hpp
This commit is contained in:
Jason Turner
2015-05-30 15:47:22 -06:00
parent 023a3edf40
commit 61d5e2ad85
2 changed files with 49 additions and 45 deletions

View File

@@ -300,6 +300,13 @@ namespace chaiscript
class Type_Conversions class Type_Conversions
{ {
public: public:
struct Less_Than
{
bool operator()(const std::type_info *t_lhs, const std::type_info *t_rhs) const
{
return *t_lhs != *t_rhs && t_lhs->before(*t_rhs);
}
};
Type_Conversions() Type_Conversions()
: m_mutex(), : m_mutex(),
@@ -322,7 +329,7 @@ namespace chaiscript
{ {
} }
const std::set<std::type_index> &thread_cache() const const std::set<const std::type_info *, Less_Than> &thread_cache() const
{ {
auto &cache = *m_thread_cache; auto &cache = *m_thread_cache;
if (cache.size() != m_num_types) if (cache.size() != m_num_types)
@@ -459,9 +466,9 @@ namespace chaiscript
mutable chaiscript::detail::threading::shared_mutex m_mutex; mutable chaiscript::detail::threading::shared_mutex m_mutex;
std::set<std::shared_ptr<detail::Type_Conversion_Base>> m_conversions; std::set<std::shared_ptr<detail::Type_Conversion_Base>> m_conversions;
std::set<std::type_index> m_convertableTypes; std::set<const std::type_info *, Less_Than> m_convertableTypes;
std::atomic_size_t m_num_types; std::atomic_size_t m_num_types;
mutable chaiscript::detail::threading::Thread_Storage<std::set<std::type_index>> m_thread_cache; mutable chaiscript::detail::threading::Thread_Storage<std::set<const std::type_info *, Less_Than>> m_thread_cache;
mutable chaiscript::detail::threading::Thread_Storage<Conversion_Saves> m_conversion_saves; mutable chaiscript::detail::threading::Thread_Storage<Conversion_Saves> m_conversion_saves;
}; };

View File

@@ -10,7 +10,6 @@
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
#include <typeinfo> #include <typeinfo>
#include <typeindex>
#include <string> #include <string>
namespace chaiscript namespace chaiscript
@@ -29,12 +28,9 @@ namespace chaiscript
/// \brief Compile time deduced information about a type /// \brief Compile time deduced information about a type
class Type_Info class Type_Info
{ {
private:
class Undef {};
public: public:
Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
bool t_is_arithmetic, const std::type_index &t_ti, const std::type_index &t_bare_ti) bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti)
: m_type_info(t_ti), m_bare_type_info(t_bare_ti), : m_type_info(t_ti), m_bare_type_info(t_bare_ti),
m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer), m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer),
m_is_void(t_is_void), m_is_arithmetic(t_is_arithmetic), m_is_void(t_is_void), m_is_arithmetic(t_is_arithmetic),
@@ -42,8 +38,8 @@ namespace chaiscript
{ {
} }
Type_Info() CHAISCRIPT_CONSTEXPR Type_Info()
: m_type_info(typeid(Type_Info::Undef)), m_bare_type_info(typeid(Type_Info::Undef)), : m_type_info(nullptr), m_bare_type_info(nullptr),
m_is_const(false), m_is_reference(false), m_is_pointer(false), m_is_const(false), m_is_reference(false), m_is_pointer(false),
m_is_void(false), m_is_arithmetic(false), m_is_void(false), m_is_arithmetic(false),
m_is_undef(true) m_is_undef(true)
@@ -59,45 +55,46 @@ namespace chaiscript
Type_Info& operator=(const Type_Info&) = default; Type_Info& operator=(const Type_Info&) = default;
bool operator<(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT CHAISCRIPT_CONSTEXPR bool operator<(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
{ {
return m_type_info < ti.m_type_info; return m_type_info < ti.m_type_info;
} }
bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
{ {
return ti.m_type_info == m_type_info; return ti.m_type_info == m_type_info
|| (ti.m_type_info && m_type_info && *ti.m_type_info == *m_type_info);
} }
bool operator==(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT CHAISCRIPT_CONSTEXPR bool operator==(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT
{ {
return !m_is_undef return m_type_info != nullptr && (*m_type_info) == ti;
&& m_type_info == ti;
} }
bool bare_equal(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT CHAISCRIPT_CONSTEXPR bool bare_equal(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT
{ {
return ti.m_bare_type_info == m_bare_type_info; return ti.m_bare_type_info == m_bare_type_info
|| (ti.m_bare_type_info && m_bare_type_info && *ti.m_bare_type_info == *m_bare_type_info);
} }
bool bare_equal_type_info(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT CHAISCRIPT_CONSTEXPR bool bare_equal_type_info(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT
{ {
return !m_is_undef return m_bare_type_info != nullptr
&& m_bare_type_info == ti; && (*m_bare_type_info) == ti;
} }
bool is_const() const CHAISCRIPT_NOEXCEPT { return m_is_const; } CHAISCRIPT_CONSTEXPR bool is_const() const CHAISCRIPT_NOEXCEPT { return m_is_const; }
bool is_reference() const CHAISCRIPT_NOEXCEPT { return m_is_reference; } CHAISCRIPT_CONSTEXPR bool is_reference() const CHAISCRIPT_NOEXCEPT { return m_is_reference; }
bool is_void() const CHAISCRIPT_NOEXCEPT { return m_is_void; } CHAISCRIPT_CONSTEXPR bool is_void() const CHAISCRIPT_NOEXCEPT { return m_is_void; }
bool is_arithmetic() const CHAISCRIPT_NOEXCEPT { return m_is_arithmetic; } CHAISCRIPT_CONSTEXPR bool is_arithmetic() const CHAISCRIPT_NOEXCEPT { return m_is_arithmetic; }
bool is_undef() const CHAISCRIPT_NOEXCEPT { return m_is_undef; } CHAISCRIPT_CONSTEXPR bool is_undef() const CHAISCRIPT_NOEXCEPT { return m_is_undef || m_bare_type_info == nullptr; }
bool is_pointer() const CHAISCRIPT_NOEXCEPT { return m_is_pointer; } CHAISCRIPT_CONSTEXPR bool is_pointer() const CHAISCRIPT_NOEXCEPT { return m_is_pointer; }
std::string name() const std::string name() const
{ {
if (!m_is_undef) if (m_type_info)
{ {
return m_type_info.name(); return m_type_info->name();
} else { } else {
return ""; return "";
} }
@@ -105,22 +102,22 @@ namespace chaiscript
std::string bare_name() const std::string bare_name() const
{ {
if (!m_is_undef) if (m_bare_type_info)
{ {
return m_bare_type_info.name(); return m_bare_type_info->name();
} else { } else {
return ""; return "";
} }
} }
const std::type_index &bare_type_info() const CHAISCRIPT_CONSTEXPR const std::type_info *bare_type_info() const
{ {
return m_bare_type_info; return m_bare_type_info;
} }
private: private:
std::type_index m_type_info; const std::type_info *m_type_info;
std::type_index m_bare_type_info; const std::type_info *m_bare_type_info;
bool m_is_const; bool m_is_const;
bool m_is_reference; bool m_is_reference;
bool m_is_pointer; bool m_is_pointer;
@@ -142,8 +139,8 @@ namespace chaiscript
return Type_Info(std::is_const<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::value, std::is_reference<T>::value, std::is_pointer<T>::value, return Type_Info(std::is_const<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
std::is_void<T>::value, std::is_void<T>::value,
std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value, std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value,
typeid(T), &typeid(T),
typeid(typename Bare_Type<T>::type)); &typeid(typename Bare_Type<T>::type));
} }
}; };
@@ -157,8 +154,8 @@ namespace chaiscript
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value, return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
std::is_void<T>::value, std::is_void<T>::value,
std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value, std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value,
typeid(std::shared_ptr<T> ), &typeid(std::shared_ptr<T> ),
typeid(typename Bare_Type<T>::type)); &typeid(typename Bare_Type<T>::type));
} }
}; };
@@ -172,8 +169,8 @@ namespace chaiscript
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value, return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
std::is_void<T>::value, std::is_void<T>::value,
std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value, std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value,
typeid(const std::shared_ptr<T> &), &typeid(const std::shared_ptr<T> &),
typeid(typename Bare_Type<T>::type)); &typeid(typename Bare_Type<T>::type));
} }
}; };
@@ -187,8 +184,8 @@ namespace chaiscript
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value, return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
std::is_void<T>::value, std::is_void<T>::value,
std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value, std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value,
typeid(std::reference_wrapper<T> ), &typeid(std::reference_wrapper<T> ),
typeid(typename Bare_Type<T>::type)); &typeid(typename Bare_Type<T>::type));
} }
}; };
@@ -202,8 +199,8 @@ namespace chaiscript
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value, return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
std::is_void<T>::value, std::is_void<T>::value,
std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value, std::is_arithmetic<T>::value && !std::is_same<typename std::remove_const<T>::type, bool>::value,
typeid(const std::reference_wrapper<T> &), &typeid(const std::reference_wrapper<T> &),
typeid(typename Bare_Type<T>::type)); &typeid(typename Bare_Type<T>::type));
} }
}; };