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:
Diffstat (limited to 'source/creator/creator.c')
-rw-r--r--source/creator/creator.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c
index b40718d1f7c..2ec4a2aa616 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -132,7 +132,6 @@ struct ApplicationState app_state = {
/** \name Application Level Callbacks
*
* Initialize callbacks for the modules that need them.
- *
* \{ */
static void callback_mem_error(const char *errorStr)
@@ -211,6 +210,41 @@ char **environ = NULL;
/** \} */
/* -------------------------------------------------------------------- */
+/** \name GMP Allocator Workaround
+ * \{ */
+
+#if (defined(WITH_TBB_MALLOC) && defined(_MSC_VER) && defined(NDEBUG) && defined(WITH_GMP)) || \
+ defined(DOXYGEN)
+# include "gmp.h"
+# include "tbb/scalable_allocator.h"
+
+void *gmp_alloc(size_t size)
+{
+ return scalable_malloc(size);
+}
+void *gmp_realloc(void *ptr, size_t old_size, size_t new_size)
+{
+ return scalable_realloc(ptr, new_size);
+}
+
+void gmp_free(void *ptr, size_t size)
+{
+ scalable_free(ptr);
+}
+/**
+ * Use TBB's scalable_allocator on Windows.
+ * `TBBmalloc` correctly captures all allocations already,
+ * however, GMP is built with MINGW since it doesn't build with MSVC,
+ * which TBB has issues hooking into automatically.
+ */
+void gmp_blender_init_allocator()
+{
+ mp_set_memory_functions(gmp_alloc, gmp_realloc, gmp_free);
+}
+#endif
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Main Function
* \{ */
@@ -343,6 +377,10 @@ int main(int argc,
CCL_init_logging(argv[0]);
#endif
+#if defined(WITH_TBB_MALLOC) && defined(_MSC_VER) && defined(NDEBUG) && defined(WITH_GMP)
+ gmp_blender_init_allocator();
+#endif
+
main_callback_setup();
#if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE) && !defined(WITH_HEADLESS)