[Bf-blender-cvs] [a0d9f387bbc] functions: free types when Blender exits
Jacques Lucke
noreply at git.blender.org
Wed Aug 14 15:34:54 CEST 2019
Commit: a0d9f387bbc854488f71bb8e5b3feeea697833c9
Author: Jacques Lucke
Date: Wed Aug 14 15:20:33 2019 +0200
Branches: functions
https://developer.blender.org/rBa0d9f387bbc854488f71bb8e5b3feeea697833c9
free types when Blender exits
===================================================================
M source/blender/blenlib/BLI_vector.hpp
M source/blender/functions/FN_all-c.h
M source/blender/functions/initialize.cpp
M source/blender/functions/types/boolean.cpp
M source/blender/functions/types/boolean.hpp
M source/blender/functions/types/external.cpp
M source/blender/functions/types/external.hpp
M source/blender/functions/types/initialization.cpp
M source/blender/functions/types/initialization.hpp
M source/blender/functions/types/numeric.cpp
M source/blender/functions/types/numeric.hpp
M source/blender/windowmanager/CMakeLists.txt
M source/blender/windowmanager/intern/wm_init_exit.c
===================================================================
diff --git a/source/blender/blenlib/BLI_vector.hpp b/source/blender/blenlib/BLI_vector.hpp
index 45d01fe28ff..1037a18a5c7 100644
--- a/source/blender/blenlib/BLI_vector.hpp
+++ b/source/blender/blenlib/BLI_vector.hpp
@@ -281,13 +281,8 @@ template<typename T, uint N = 4> class Vector {
}
/**
- * Copy the elements of another vector to the end of this vector.
+ * Copy the elements of another array to the end of this vector.
*/
- void extend(const Vector &other)
- {
- this->extend(other.begin(), other.size());
- }
-
void extend(ArrayRef<T> array)
{
this->extend(array.begin(), array.size());
diff --git a/source/blender/functions/FN_all-c.h b/source/blender/functions/FN_all-c.h
index 2b4f3390a81..b970d8be2d5 100644
--- a/source/blender/functions/FN_all-c.h
+++ b/source/blender/functions/FN_all-c.h
@@ -12,6 +12,7 @@ extern "C" {
#endif
void FN_initialize(void);
+void FN_exit(void);
#ifdef __cplusplus
}
diff --git a/source/blender/functions/initialize.cpp b/source/blender/functions/initialize.cpp
index ee465cd0c04..a7a17469c89 100644
--- a/source/blender/functions/initialize.cpp
+++ b/source/blender/functions/initialize.cpp
@@ -5,3 +5,8 @@ void FN_initialize()
FN::initialize_llvm();
FN::Types::initialize_types();
}
+
+void FN_exit()
+{
+ FN::Types::uninitialize_types();
+}
diff --git a/source/blender/functions/types/boolean.cpp b/source/blender/functions/types/boolean.cpp
index 39d47f227ac..c2fe06bb1ef 100644
--- a/source/blender/functions/types/boolean.cpp
+++ b/source/blender/functions/types/boolean.cpp
@@ -33,13 +33,15 @@ class LLVMBool : public TrivialLLVMTypeInfo {
Type *TYPE_bool = nullptr;
Type *TYPE_bool_list = nullptr;
-void INIT_bool()
+void INIT_bool(Vector<Type *> &types_to_free)
{
TYPE_bool = new Type("Bool");
TYPE_bool->add_extension<CPPTypeInfoForType<bool>>();
TYPE_bool->add_extension<LLVMBool>();
TYPE_bool_list = new_list_type(TYPE_bool);
+
+ types_to_free.extend({TYPE_bool, TYPE_bool_list});
}
} // namespace Types
diff --git a/source/blender/functions/types/boolean.hpp b/source/blender/functions/types/boolean.hpp
index 622812eb524..c2a396139ab 100644
--- a/source/blender/functions/types/boolean.hpp
+++ b/source/blender/functions/types/boolean.hpp
@@ -5,7 +5,7 @@
namespace FN {
namespace Types {
-void INIT_bool();
+void INIT_bool(Vector<Type *> &types_to_free);
extern Type *TYPE_bool;
extern Type *TYPE_bool_list;
diff --git a/source/blender/functions/types/external.cpp b/source/blender/functions/types/external.cpp
index 1754d84673b..b316f11a048 100644
--- a/source/blender/functions/types/external.cpp
+++ b/source/blender/functions/types/external.cpp
@@ -11,7 +11,7 @@ namespace Types {
Type *TYPE_object = nullptr;
Type *TYPE_object_list = nullptr;
-void INIT_external()
+void INIT_external(Vector<Type *> &types_to_free)
{
TYPE_object = new Type("Object");
TYPE_object->add_extension<CPPTypeInfoForType<Object *>>();
@@ -19,6 +19,8 @@ void INIT_external()
[](void *value) { return value; }, [](void *UNUSED(value)) {}, []() { return nullptr; });
TYPE_object_list = new_list_type(TYPE_object);
+
+ types_to_free.extend({TYPE_object, TYPE_object_list});
}
} // namespace Types
diff --git a/source/blender/functions/types/external.hpp b/source/blender/functions/types/external.hpp
index a6149083377..c848cfd1d0c 100644
--- a/source/blender/functions/types/external.hpp
+++ b/source/blender/functions/types/external.hpp
@@ -5,7 +5,8 @@
namespace FN {
namespace Types {
-void INIT_external();
+void INIT_external(Vector<Type *> &types_to_free);
+
extern Type *TYPE_object;
extern Type *TYPE_object_list;
diff --git a/source/blender/functions/types/initialization.cpp b/source/blender/functions/types/initialization.cpp
index 75b3c427fce..5ccd06c7dbe 100644
--- a/source/blender/functions/types/initialization.cpp
+++ b/source/blender/functions/types/initialization.cpp
@@ -3,16 +3,21 @@
namespace FN {
namespace Types {
+Vector<Type *> types_to_free;
+
void initialize_types(void)
{
- INIT_bool();
- INIT_external();
- INIT_numeric();
+ INIT_bool(types_to_free);
+ INIT_external(types_to_free);
+ INIT_numeric(types_to_free);
}
-void free_types(void)
+void uninitialize_types(void)
{
- /* TODO */
+ for (Type *type : types_to_free) {
+ delete type;
+ }
+ types_to_free.clear_and_make_small();
}
} // namespace Types
diff --git a/source/blender/functions/types/initialization.hpp b/source/blender/functions/types/initialization.hpp
index e38fff3f84c..3f938c819d7 100644
--- a/source/blender/functions/types/initialization.hpp
+++ b/source/blender/functions/types/initialization.hpp
@@ -4,7 +4,7 @@ namespace FN {
namespace Types {
void initialize_types(void);
-void free_types(void);
+void uninitialize_types(void);
} // namespace Types
} // namespace FN
diff --git a/source/blender/functions/types/numeric.cpp b/source/blender/functions/types/numeric.cpp
index 86784408f9e..e6134c4cdc4 100644
--- a/source/blender/functions/types/numeric.cpp
+++ b/source/blender/functions/types/numeric.cpp
@@ -56,7 +56,7 @@ Type *TYPE_int32_list = nullptr;
Type *TYPE_float3_list = nullptr;
Type *TYPE_rgba_f_list = nullptr;
-void INIT_numeric()
+void INIT_numeric(Vector<Type *> &types_to_free)
{
TYPE_float = new Type("Float");
TYPE_float->add_extension<CPPTypeInfoForType<float>>();
@@ -80,6 +80,17 @@ void INIT_numeric()
TYPE_int32_list = new_list_type(TYPE_int32);
TYPE_float3_list = new_list_type(TYPE_float3);
TYPE_rgba_f_list = new_list_type(TYPE_rgba_f);
+
+ types_to_free.extend({
+ TYPE_float,
+ TYPE_int32,
+ TYPE_float3,
+ TYPE_rgba_f,
+ TYPE_float_list,
+ TYPE_int32_list,
+ TYPE_float3_list,
+ TYPE_rgba_f_list,
+ });
}
} // namespace Types
diff --git a/source/blender/functions/types/numeric.hpp b/source/blender/functions/types/numeric.hpp
index 7adcc9ac0fa..783f46bea62 100644
--- a/source/blender/functions/types/numeric.hpp
+++ b/source/blender/functions/types/numeric.hpp
@@ -9,7 +9,7 @@ namespace Types {
using BLI::float3;
using BLI::rgba_f;
-void INIT_numeric();
+void INIT_numeric(Vector<Type *> &types_to_free);
extern Type *TYPE_float;
extern Type *TYPE_int32;
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 64f506f03a8..5dbc2278b8f 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -36,6 +36,7 @@ set(INC
../makesdna
../makesrna
../nodes
+ ../functions
../render/extern/include
../../../intern/clog
../../../intern/ghost
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 6588b70f4af..e39f24ad398 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -133,6 +133,8 @@
#include "DRW_engine.h"
+#include "FN_all-c.h"
+
#ifdef WITH_OPENSUBDIV
# include "BKE_subsurf.h"
#endif
@@ -649,6 +651,8 @@ void WM_exit_ex(bContext *C, const bool do_python)
CLG_exit();
BKE_blender_atexit();
+
+ FN_exit();
BLI_temporary_buffers_free_all();
if (MEM_get_memory_blocks_in_use() != 0) {
More information about the Bf-blender-cvs
mailing list