[Bf-blender-cvs] [c82841878ac] mem-guardedalloc-cpp: separate out c++ header
Jacques Lucke
noreply at git.blender.org
Mon Jul 26 17:34:11 CEST 2021
Commit: c82841878ac2a8b9a9a885b7858f8797a81bce14
Author: Jacques Lucke
Date: Mon Jul 26 17:34:03 2021 +0200
Branches: mem-guardedalloc-cpp
https://developer.blender.org/rBc82841878ac2a8b9a9a885b7858f8797a81bce14
separate out c++ header
===================================================================
M intern/guardedalloc/MEM_guardedalloc.h
A intern/guardedalloc/MEM_guardedalloc.hh
M intern/libmv/intern/utildefines.h
M intern/opencolorio/fallback_impl.cc
M intern/opencolorio/ocio_impl.cc
M intern/opensubdiv/internal/base/memory.h
M source/blender/blenlib/BLI_allocator.hh
M source/blender/blenlib/intern/rand.cc
M source/blender/blenlib/intern/task_scheduler.cc
M source/blender/depsgraph/intern/depsgraph_relation.h
M source/blender/editors/asset/intern/asset_temp_id_consumer.cc
M source/blender/gpu/intern/gpu_shader_private.hh
M source/blender/gpu/opengl/gl_index_buffer.hh
M source/blender/gpu/opengl/gl_vertex_buffer.hh
===================================================================
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index 713b1fac788..fa4c08750ea 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -257,70 +257,4 @@ void MEM_use_guarded_allocator(void);
}
#endif /* __cplusplus */
-#ifdef __cplusplus
-/* Allocation functions (for C++ only). */
-# define MEM_CXX_CLASS_ALLOC_FUNCS(_id) \
- public: \
- void *operator new(size_t num_bytes) \
- { \
- return MEM_mallocN(num_bytes, _id); \
- } \
- void operator delete(void *mem) \
- { \
- if (mem) { \
- MEM_freeN(mem); \
- } \
- } \
- void *operator new[](size_t num_bytes) \
- { \
- return MEM_mallocN(num_bytes, _id "[]"); \
- } \
- void operator delete[](void *mem) \
- { \
- if (mem) { \
- MEM_freeN(mem); \
- } \
- } \
- void *operator new(size_t /*count*/, void *ptr) \
- { \
- return ptr; \
- } \
- /* This is the matching delete operator to the placement-new operator above. Both parameters \
- * will have the same value. Without this, we get the warning C4291 on windows. */ \
- void operator delete(void * /*ptr_to_free*/, void * /*ptr*/) \
- { \
- }
-
-/* Needed when type includes a namespace, then the namespace should not be
- * specified after ~, so using a macro fails. */
-template<class T> inline void OBJECT_GUARDED_DESTRUCTOR(T *what)
-{
- what->~T();
-}
-
-# if defined __GNUC__
-# define OBJECT_GUARDED_NEW(type, args...) new (MEM_mallocN(sizeof(type), __func__)) type(args)
-# else
-# define OBJECT_GUARDED_NEW(type, ...) \
- new (MEM_mallocN(sizeof(type), __FUNCTION__)) type(__VA_ARGS__)
-# endif
-# define OBJECT_GUARDED_DELETE(what, type) \
- { \
- if (what) { \
- OBJECT_GUARDED_DESTRUCTOR((type *)what); \
- MEM_freeN(what); \
- } \
- } \
- (void)0
-# define OBJECT_GUARDED_SAFE_DELETE(what, type) \
- { \
- if (what) { \
- OBJECT_GUARDED_DESTRUCTOR((type *)what); \
- MEM_freeN(what); \
- what = NULL; \
- } \
- } \
- (void)0
-#endif /* __cplusplus */
-
#endif /* __MEM_GUARDEDALLOC_H__ */
diff --git a/intern/guardedalloc/MEM_guardedalloc.hh b/intern/guardedalloc/MEM_guardedalloc.hh
new file mode 100644
index 00000000000..b80c00ce0cb
--- /dev/null
+++ b/intern/guardedalloc/MEM_guardedalloc.hh
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup MEM
+ *
+ * This extends `MEM_guardedalloc.h` with C++ features.
+ */
+
+#pragma once
+
+#include "MEM_guardedalloc.h"
+
+/* Allocation functions (for C++ only). */
+#define MEM_CXX_CLASS_ALLOC_FUNCS(_id) \
+ public: \
+ void *operator new(size_t num_bytes) \
+ { \
+ return MEM_mallocN(num_bytes, _id); \
+ } \
+ void operator delete(void *mem) \
+ { \
+ if (mem) { \
+ MEM_freeN(mem); \
+ } \
+ } \
+ void *operator new[](size_t num_bytes) \
+ { \
+ return MEM_mallocN(num_bytes, _id "[]"); \
+ } \
+ void operator delete[](void *mem) \
+ { \
+ if (mem) { \
+ MEM_freeN(mem); \
+ } \
+ } \
+ void *operator new(size_t /*count*/, void *ptr) \
+ { \
+ return ptr; \
+ } \
+ /* This is the matching delete operator to the placement-new operator above. Both parameters \
+ * will have the same value. Without this, we get the warning C4291 on windows. */ \
+ void operator delete(void * /*ptr_to_free*/, void * /*ptr*/) \
+ { \
+ }
+
+/* Needed when type includes a namespace, then the namespace should not be
+ * specified after ~, so using a macro fails. */
+template<class T> inline void OBJECT_GUARDED_DESTRUCTOR(T *what)
+{
+ what->~T();
+}
+
+#if defined __GNUC__
+# define OBJECT_GUARDED_NEW(type, args...) new (MEM_mallocN(sizeof(type), __func__)) type(args)
+#else
+# define OBJECT_GUARDED_NEW(type, ...) \
+ new (MEM_mallocN(sizeof(type), __FUNCTION__)) type(__VA_ARGS__)
+#endif
+#define OBJECT_GUARDED_DELETE(what, type) \
+ { \
+ if (what) { \
+ OBJECT_GUARDED_DESTRUCTOR((type *)what); \
+ MEM_freeN(what); \
+ } \
+ } \
+ (void)0
+#define OBJECT_GUARDED_SAFE_DELETE(what, type) \
+ { \
+ if (what) { \
+ OBJECT_GUARDED_DESTRUCTOR((type *)what); \
+ MEM_freeN(what); \
+ what = NULL; \
+ } \
+ } \
+ (void)0
diff --git a/intern/libmv/intern/utildefines.h b/intern/libmv/intern/utildefines.h
index 052052a1d76..5e67a6bd06b 100644
--- a/intern/libmv/intern/utildefines.h
+++ b/intern/libmv/intern/utildefines.h
@@ -26,7 +26,7 @@
#endif
#ifdef WITH_LIBMV_GUARDED_ALLOC
-# include "MEM_guardedalloc.h"
+# include "MEM_guardedalloc.hh"
# define LIBMV_OBJECT_NEW OBJECT_GUARDED_NEW
# define LIBMV_OBJECT_DELETE OBJECT_GUARDED_DELETE
# define LIBMV_OBJECT_DELETE OBJECT_GUARDED_DELETE
diff --git a/intern/opencolorio/fallback_impl.cc b/intern/opencolorio/fallback_impl.cc
index 9bbc9843e9d..d3b37bac0cb 100644
--- a/intern/opencolorio/fallback_impl.cc
+++ b/intern/opencolorio/fallback_impl.cc
@@ -23,7 +23,7 @@
#include "BLI_math_color.h"
#include "BLI_math_vector.h"
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
#include "ocio_impl.h"
diff --git a/intern/opencolorio/ocio_impl.cc b/intern/opencolorio/ocio_impl.cc
index 146d5d1a5a7..73a9505ab77 100644
--- a/intern/opencolorio/ocio_impl.cc
+++ b/intern/opencolorio/ocio_impl.cc
@@ -34,7 +34,7 @@
using namespace OCIO_NAMESPACE;
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
#include "BLI_math.h"
#include "BLI_math_color.h"
diff --git a/intern/opensubdiv/internal/base/memory.h b/intern/opensubdiv/internal/base/memory.h
index 176d9c14694..d39db725789 100644
--- a/intern/opensubdiv/internal/base/memory.h
+++ b/intern/opensubdiv/internal/base/memory.h
@@ -17,7 +17,7 @@
#ifndef OPENSUBDIV_BASE_MEMORY_H_
#define OPENSUBDIV_BASE_MEMORY_H_
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
namespace blender {
namespace opensubdiv {
diff --git a/source/blender/blenlib/BLI_allocator.hh b/source/blender/blenlib/BLI_allocator.hh
index 899c8499807..9482bddf0c0 100644
--- a/source/blender/blenlib/BLI_allocator.hh
+++ b/source/blender/blenlib/BLI_allocator.hh
@@ -40,7 +40,7 @@
#include <algorithm>
#include <stdlib.h>
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
#include "BLI_math_base.h"
#include "BLI_utildefines.h"
diff --git a/source/blender/blenlib/intern/rand.cc b/source/blender/blenlib/intern/rand.cc
index db5e08d37ce..5ee4d8573f5 100644
--- a/source/blender/blenlib/intern/rand.cc
+++ b/source/blender/blenlib/intern/rand.cc
@@ -26,7 +26,7 @@
#include <cstring>
#include <ctime>
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
#include "BLI_bitmap.h"
#include "BLI_math.h"
diff --git a/source/blender/blenlib/intern/task_scheduler.cc b/source/blender/blenlib/intern/task_scheduler.cc
index 69117e9dc7e..7ce388cc19b 100644
--- a/source/blender/blenlib/intern/task_scheduler.cc
+++ b/source/blender/blenlib/intern/task_scheduler.cc
@@ -20,7 +20,7 @@
* Task scheduler initialization.
*/
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
#include "BLI_task.h"
#include "BLI_threads.h"
diff --git a/source/blender/depsgraph/intern/depsgraph_relation.h b/source/blender/depsgraph/intern/depsgraph_relation.h
index 7154710e07e..594b3e9bd10 100644
--- a/source/blender/depsgraph/intern/depsgraph_relation.h
+++ b/source/blender/depsgraph/intern/depsgraph_relation.h
@@ -23,7 +23,7 @@
#pragma once
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
namespace blender {
namespace deg {
diff --git a/source/blender/editors/asset/intern/asset_temp_id_consumer.cc b/source/blender/editors/asset/intern/asset_temp_id_consumer.cc
index bed35fdeeb5..3d2f5f844d4 100644
--- a/source/blender/editors/asset/intern/asset_temp_id_consumer.cc
+++ b/source/blender/editors/asset/intern/asset_temp_id_consumer.cc
@@ -32,7 +32,7 @@
#include "BLO_readfile.h"
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
#include "ED_asset_handle.h"
#include "ED_asset_temp_id_consumer.h"
diff --git a/source/blender/gpu/intern/gpu_shader_private.hh b/source/blender/gpu/intern/gpu_shader_private.hh
index 65720e457d8..8002ca26fdb 100644
--- a/source/blender/gpu/intern/gpu_shader_private.hh
+++ b/source/blender/gpu/intern/gpu_shader_private.hh
@@ -20,6 +20,8 @@
#pragma once
+#include "MEM_guardedalloc.hh"
+
#include "BLI_span.hh"
#include "BLI_string_ref.hh"
diff --git a/source/blender/gpu/opengl/gl_index_buffer.hh b/source/blender/gpu/opengl/gl_index_buffer.hh
index 0dbdaa6d398..3a01b857e25 100644
--- a/source/blender/gpu/opengl/gl_index_buffer.hh
+++ b/source/blender/gpu/opengl/gl_index_buffer.hh
@@ -23,7 +23,7 @@
#pragma once
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
#include "gpu_index_buffer_private.hh"
diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.hh b/source/blender/gpu/opengl/gl_vertex_buffer.hh
index 6c38a2225b3..5cd34a82b18 100644
--- a/source/blender/gpu/opengl/gl_vertex_buffer.hh
+++ b/source/blender/gpu/opengl/gl_vertex_buffer.hh
@@ -23,7 +23,7 @@
#pragma once
-#include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.hh"
#include "glew-mx.h"
More information about the Bf-blender-cvs
mailing list