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:
authorSergey Sharybin <sergey@blender.org>2022-03-25 13:36:08 +0300
committerSergey Sharybin <sergey@blender.org>2022-03-25 13:45:50 +0300
commit0c33e84020deca84c987dffa1302651f59c27158 (patch)
tree7921c909a2e76fcc260bbbf2556fe4ffe4d91abd /source/blender/makesdna
parent03df72ee4e7e7f9893df73de426cdc3af1c7a676 (diff)
Fix compilation warnings after previous change
Thanks Jacques for finding solution for deprecation warning which was generated by GCC for constructor. The rest of the change is related on fixing memaccess warning which was happening when memset/memcpy was used directly on the DNA object pointer. Now there are two utility functions for this: - blender::dna::zero_memory - blender::dna::copy_memory
Diffstat (limited to 'source/blender/makesdna')
-rw-r--r--source/blender/makesdna/DNA_defs.h18
-rw-r--r--source/blender/makesdna/intern/dna_utils.c6
2 files changed, 23 insertions, 1 deletions
diff --git a/source/blender/makesdna/DNA_defs.h b/source/blender/makesdna/DNA_defs.h
index 283eacf1a16..bfeb809b369 100644
--- a/source/blender/makesdna/DNA_defs.h
+++ b/source/blender/makesdna/DNA_defs.h
@@ -67,6 +67,7 @@
/* Forward-declared here since there is no simple header file to be pulled for this functionality.
* Avoids pulling `string.h` from this header to get access to #memcpy. */
extern "C" void _DNA_internal_memcpy(void *dst, const void *src, size_t size);
+extern "C" void _DNA_internal_memzero(void *dst, size_t size);
namespace blender::dna::internal {
@@ -96,7 +97,8 @@ template<class T> class ShallowDataConstRef {
class_name &operator=(const class_name &other) = delete; \
class_name &operator=(class_name &&other) = delete; \
/* Support for shallow copy. */ \
- class_name(const blender::dna::internal::ShallowDataConstRef<class_name> ref) \
+ /* NOTE: Calling the default constructor works-around deprecated warning generated by GCC. */ \
+ class_name(const blender::dna::internal::ShallowDataConstRef<class_name> ref) : class_name() \
{ \
_DNA_internal_memcpy(this, ref.get_pointer(), sizeof(class_name)); \
} \
@@ -124,6 +126,20 @@ template<class T>
return internal::ShallowDataConstRef(other);
}
+/* Fill underlying memory used by DNA object with zeroes. */
+template<class T> inline void zero_memory(T &object)
+{
+ /* TODO(sergey): Consider adding static assert for T being a trivial type. */
+ _DNA_internal_memzero(&object, sizeof(T));
+}
+
+/* Copy memory from one DNA object to another. */
+template<class T> inline void copy_memory(T &dst, const T &src)
+{
+ /* TODO(sergey): Consider adding static assert for T being a trivial type. */
+ _DNA_internal_memcpy(&dst, &src, sizeof(T));
+}
+
} // namespace blender::dna
#endif
diff --git a/source/blender/makesdna/intern/dna_utils.c b/source/blender/makesdna/intern/dna_utils.c
index 560b91b925e..bc2584fe57a 100644
--- a/source/blender/makesdna/intern/dna_utils.c
+++ b/source/blender/makesdna/intern/dna_utils.c
@@ -319,4 +319,10 @@ void _DNA_internal_memcpy(void *dst, const void *src, const size_t size)
memcpy(dst, src, size);
}
+void _DNA_internal_memzero(void *dst, size_t size);
+void _DNA_internal_memzero(void *dst, const size_t size)
+{
+ memset(dst, 0, size);
+}
+
/** \} */