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:🧬:zero_memory - blender:🧬:copy_memory
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user