Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-07-17 15:15:06 +0300
committerJacques Lucke <jacques@blender.org>2020-07-17 15:15:06 +0300
commit267923604754a50064c04a925a841a6714253d72 (patch)
treefc55f50254c428b1c94f760988d7cd9a5c9f75cf /source/blender/functions
parent3ef59121a49b986700747469850e02f6420ee8aa (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/functions')
-rw-r--r--source/blender/functions/CMakeLists.txt1
-rw-r--r--source/blender/functions/FN_cpp_type.hh11
-rw-r--r--source/blender/functions/FN_cpp_types.hh48
-rw-r--r--source/blender/functions/intern/cpp_types.cc2
4 files changed, 5 insertions, 57 deletions
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"