diff options
author | Sergey Sharybin <sergey@blender.org> | 2022-03-25 13:36:08 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-03-25 13:45:50 +0300 |
commit | 0c33e84020deca84c987dffa1302651f59c27158 (patch) | |
tree | 7921c909a2e76fcc260bbbf2556fe4ffe4d91abd | |
parent | 03df72ee4e7e7f9893df73de426cdc3af1c7a676 (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
-rw-r--r-- | source/blender/blenkernel/intern/mesh_convert.cc | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.cc | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_defs.h | 18 | ||||
-rw-r--r-- | source/blender/makesdna/intern/dna_utils.c | 6 |
4 files changed, 29 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc index 1be2d06ce61..fc484e73967 100644 --- a/source/blender/blenkernel/intern/mesh_convert.cc +++ b/source/blender/blenkernel/intern/mesh_convert.cc @@ -911,9 +911,9 @@ static void curve_to_mesh_eval_ensure(Object &object) * So we create temporary copy of the object which will use same data as the original bevel, but * will have no modifiers. */ Object bevel_object; - memset(&bevel_object, 0, sizeof(bevel_object)); + blender::dna::zero_memory(bevel_object); if (curve.bevobj != nullptr) { - memcpy(&bevel_object, curve.bevobj, sizeof(bevel_object)); + blender::dna::copy_memory(bevel_object, *curve.bevobj); BLI_listbase_clear(&bevel_object.modifiers); BKE_object_runtime_reset(&bevel_object); curve.bevobj = &bevel_object; @@ -921,9 +921,9 @@ static void curve_to_mesh_eval_ensure(Object &object) /* Same thing for taper. */ Object taper_object; - memset(&taper_object, 0, sizeof(taper_object)); + blender::dna::zero_memory(taper_object); if (curve.taperobj != nullptr) { - memcpy(&taper_object, curve.taperobj, sizeof(taper_object)); + blender::dna::copy_memory(taper_object, *curve.taperobj); BLI_listbase_clear(&taper_object.modifiers); BKE_object_runtime_reset(&taper_object); curve.taperobj = &taper_object; @@ -1068,7 +1068,7 @@ static Mesh *mesh_new_from_mesh_object_with_layers(Depsgraph *depsgraph, } Object object_for_eval; - memcpy(&object_for_eval, object, sizeof(object_for_eval)); + blender::dna::zero_memory(object_for_eval); if (object_for_eval.runtime.data_orig != nullptr) { object_for_eval.data = object_for_eval.runtime.data_orig; } diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc index 6d1eac5af49..098b7c52664 100644 --- a/source/blender/blenkernel/intern/object.cc +++ b/source/blender/blenkernel/intern/object.cc @@ -1236,7 +1236,7 @@ IDTypeInfo IDType_ID_OB = { void BKE_object_workob_clear(Object *workob) { - memset(workob, 0, sizeof(Object)); + blender::dna::zero_memory(*workob); workob->scale[0] = workob->scale[1] = workob->scale[2] = 1.0f; workob->dscale[0] = workob->dscale[1] = workob->dscale[2] = 1.0f; 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); +} + /** \} */ |