Fix threading warning discovered with MSVC -Wall

MSVC in -Wall mode creates approximately 6,500 warnings. 5,000+ of which are
from the std library. The one gem was the potential for threading issues with
the initilization of a function scoped static.

This fixes that.
This commit is contained in:
Jason Turner
2014-05-09 17:46:06 -06:00
parent c2d08457ad
commit 5f2796868b
2 changed files with 12 additions and 8 deletions

View File

@@ -55,7 +55,7 @@ namespace chaiscript
const std::string &t_type_name, const std::string &t_type_name,
const Proxy_Function &t_func) const Proxy_Function &t_func)
: Proxy_Function_Base(t_func->get_param_types()), : Proxy_Function_Base(t_func->get_param_types()),
m_type_name(t_type_name), m_func(t_func) m_type_name(t_type_name), m_func(t_func), m_doti(user_type<Dynamic_Object>())
{ {
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); && "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
@@ -66,7 +66,7 @@ namespace chaiscript
const Proxy_Function &t_func, const Proxy_Function &t_func,
const Type_Info &t_ti) const Type_Info &t_ti)
: Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)), : Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)),
m_type_name(t_type_name), m_func(t_func), m_ti(new Type_Info(t_ti)) m_type_name(t_type_name), m_func(t_func), m_ti(new Type_Info(t_ti)), m_doti(user_type<Dynamic_Object>())
{ {
assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0)
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); && "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
@@ -74,6 +74,8 @@ namespace chaiscript
virtual ~Dynamic_Object_Function() {} virtual ~Dynamic_Object_Function() {}
Dynamic_Object_Function &operator=(const Dynamic_Object_Function) = delete;
virtual bool operator==(const Proxy_Function_Base &f) const virtual bool operator==(const Proxy_Function_Base &f) const
{ {
const Dynamic_Object_Function *df = dynamic_cast<const Dynamic_Object_Function *>(&f); const Dynamic_Object_Function *df = dynamic_cast<const Dynamic_Object_Function *>(&f);
@@ -140,11 +142,10 @@ namespace chaiscript
return types; return types;
} }
static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name, bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name,
const std::shared_ptr<Type_Info> &ti, const Dynamic_Cast_Conversions &t_conversions) const std::shared_ptr<Type_Info> &ti, const Dynamic_Cast_Conversions &t_conversions) const
{ {
static Type_Info doti = user_type<Dynamic_Object>(); if (bv.get_type_info().bare_equal(m_doti))
if (bv.get_type_info().bare_equal(doti))
{ {
try { try {
const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bv, &t_conversions); const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bv, &t_conversions);
@@ -163,8 +164,8 @@ namespace chaiscript
} }
static bool dynamic_object_typename_match(const std::vector<Boxed_Value> &bvs, const std::string &name, bool dynamic_object_typename_match(const std::vector<Boxed_Value> &bvs, const std::string &name,
const std::shared_ptr<Type_Info> &ti, const Dynamic_Cast_Conversions &t_conversions) const std::shared_ptr<Type_Info> &ti, const Dynamic_Cast_Conversions &t_conversions) const
{ {
if (bvs.size() > 0) if (bvs.size() > 0)
{ {
@@ -177,6 +178,8 @@ namespace chaiscript
std::string m_type_name; std::string m_type_name;
Proxy_Function m_func; Proxy_Function m_func;
std::shared_ptr<Type_Info> m_ti; std::shared_ptr<Type_Info> m_ti;
const Type_Info m_doti;
}; };

View File

@@ -15,6 +15,7 @@
#include <stdexcept> #include <stdexcept>
#include <vector> #include <vector>
#include <functional>
namespace chaiscript namespace chaiscript
{ {