diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-17 15:15:06 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-17 15:15:06 +0300 |
commit | 267923604754a50064c04a925a841a6714253d72 (patch) | |
tree | fc55f50254c428b1c94f760988d7cd9a5c9f75cf /source/blender | |
parent | 3ef59121a49b986700747469850e02f6420ee8aa (diff) |
Cleanup: avoid static initialization order issues when accessing CPPTypes
Instead of depending on static initialization order of globals use
static variables within functions. Those are initialized on first use.
This is every so slighly less efficient, but avoids a full class of problems.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/simulation.cc | 1 | ||||
-rw-r--r-- | source/blender/functions/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/functions/FN_cpp_type.hh | 11 | ||||
-rw-r--r-- | source/blender/functions/FN_cpp_types.hh | 48 | ||||
-rw-r--r-- | source/blender/functions/intern/cpp_types.cc | 2 | ||||
-rw-r--r-- | source/blender/simulation/intern/simulation_update.cc | 3 |
6 files changed, 6 insertions, 60 deletions
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index cec3547a3f3..1ac987d130d 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -54,7 +54,6 @@ #include "BLT_translation.h" #include "FN_attributes_ref.hh" -#include "FN_cpp_types.hh" #include "FN_multi_function_network_evaluation.hh" #include "FN_multi_function_network_optimization.hh" diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt index 0ec531dea0d..2686275e898 100644 --- a/source/blender/functions/CMakeLists.txt +++ b/source/blender/functions/CMakeLists.txt @@ -38,7 +38,6 @@ set(SRC FN_array_spans.hh FN_attributes_ref.hh FN_cpp_type.hh - FN_cpp_types.hh FN_generic_vector_array.hh FN_multi_function.hh FN_multi_function_builder.hh diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh index 7ec60809194..ce02bfd05be 100644 --- a/source/blender/functions/FN_cpp_type.hh +++ b/source/blender/functions/FN_cpp_type.hh @@ -788,15 +788,12 @@ inline std::unique_ptr<const CPPType> create_cpp_type(StringRef name, const T &d } // namespace blender::fn #define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME) \ - static TYPE_NAME default_value_##IDENTIFIER; \ - static std::unique_ptr<const blender::fn::CPPType> CPPTYPE_##IDENTIFIER##_owner = \ - blender::fn::create_cpp_type<TYPE_NAME>(STRINGIFY(IDENTIFIER), default_value_##IDENTIFIER); \ - const blender::fn::CPPType &CPPType_##IDENTIFIER = *CPPTYPE_##IDENTIFIER##_owner; \ template<> const blender::fn::CPPType &blender::fn::CPPType::get<TYPE_NAME>() \ { \ - /* This can happen when trying to access a CPPType during static storage initialization. */ \ - BLI_assert(CPPTYPE_##IDENTIFIER##_owner.get() != nullptr); \ - return CPPType_##IDENTIFIER; \ + static TYPE_NAME default_value; \ + static std::unique_ptr<const CPPType> cpp_type = blender::fn::create_cpp_type<TYPE_NAME>( \ + STRINGIFY(IDENTIFIER), default_value); \ + return *cpp_type; \ } #endif /* __FN_CPP_TYPE_HH__ */ diff --git a/source/blender/functions/FN_cpp_types.hh b/source/blender/functions/FN_cpp_types.hh deleted file mode 100644 index 63f6b49885f..00000000000 --- a/source/blender/functions/FN_cpp_types.hh +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef __FN_CPP_TYPES_HH__ -#define __FN_CPP_TYPES_HH__ - -/** \file - * \ingroup fn - * - * This header provides convenient access to CPPType instances for some core types like integer - * types. - */ - -#include "FN_cpp_type.hh" - -namespace blender::fn { - -extern const CPPType &CPPType_bool; - -extern const CPPType &CPPType_float; -extern const CPPType &CPPType_float3; -extern const CPPType &CPPType_float4x4; - -extern const CPPType &CPPType_int32; -extern const CPPType &CPPType_uint32; -extern const CPPType &CPPType_uint8; - -extern const CPPType &CPPType_Color4f; -extern const CPPType &CPPType_Color4b; - -extern const CPPType &CPPType_string; - -} // namespace blender::fn - -#endif /* __FN_CPP_TYPES_HH__ */ diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc index 052278afd65..3bf4683d815 100644 --- a/source/blender/functions/intern/cpp_types.cc +++ b/source/blender/functions/intern/cpp_types.cc @@ -14,7 +14,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "FN_cpp_types.hh" +#include "FN_cpp_type.hh" #include "BLI_color.hh" #include "BLI_float2.hh" diff --git a/source/blender/simulation/intern/simulation_update.cc b/source/blender/simulation/intern/simulation_update.cc index 918d433cb3d..95c7b122e7c 100644 --- a/source/blender/simulation/intern/simulation_update.cc +++ b/source/blender/simulation/intern/simulation_update.cc @@ -34,7 +34,6 @@ #include "NOD_node_tree_multi_function.hh" #include "FN_attributes_ref.hh" -#include "FN_cpp_types.hh" #include "FN_multi_function_network_evaluation.hh" #include "FN_multi_function_network_optimization.hh" @@ -108,7 +107,7 @@ static Map<const fn::MFOutputSocket *, std::string> deduplicate_attribute_nodes( Array<std::string> attribute_names{amount, NoInitialization()}; for (uint i : IndexRange(amount)) { params.add_uninitialized_single_output( - fn::GMutableSpan(fn::CPPType_string, attribute_names.data() + i, 1)); + fn::GMutableSpan(fn::CPPType::get<std::string>(), attribute_names.data() + i, 1)); } fn::MFContextBuilder context; |