[Bf-blender-cvs] [17882988042] master: Cleanup: Strict compiler warning in Cycles
Sergey Sharybin
noreply at git.blender.org
Wed Jan 19 12:01:53 CET 2022
Commit: 17882988042e3b8adeffbc2072a5a457cb6efb52
Author: Sergey Sharybin
Date: Wed Jan 19 11:59:51 2022 +0100
Branches: master
https://developer.blender.org/rB17882988042e3b8adeffbc2072a5a457cb6efb52
Cleanup: Strict compiler warning in Cycles
The ustring is not a trivially copyable object from the C++ standard
point of view, so using memcpy on it is strictly wrong. In practice,
however, this is OK since it is just a thin wrapper around char*.
For now use explicit cast to void* same as it was done in other places
of ccl::array implementation. But also localize the place where memory
copy happens to make it easier to support proper non-trivial C++
objects in the future.
===================================================================
M intern/cycles/util/array.h
===================================================================
diff --git a/intern/cycles/util/array.h b/intern/cycles/util/array.h
index 4c905b09138..1c5e3e8d4ec 100644
--- a/intern/cycles/util/array.h
+++ b/intern/cycles/util/array.h
@@ -64,7 +64,7 @@ template<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> class arra
else {
data_ = mem_allocate(from.datasize_);
if (from.datasize_ > 0) {
- memcpy(data_, from.data_, from.datasize_ * sizeof(T));
+ mem_copy(data_, from.data_, from.datasize_);
}
datasize_ = from.datasize_;
capacity_ = datasize_;
@@ -76,7 +76,7 @@ template<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> class arra
if (this != &from) {
resize(from.size());
if (datasize_ > 0) {
- memcpy((void *)data_, from.data_, datasize_ * sizeof(T));
+ mem_copy(data_, from.data_, datasize_);
}
}
@@ -88,7 +88,7 @@ template<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> class arra
resize(from.size());
if (from.size() > 0 && datasize_ > 0) {
- memcpy(data_, &from[0], datasize_ * sizeof(T));
+ mem_copy(data_, from.data(), datasize_);
}
return *this;
@@ -161,8 +161,7 @@ template<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> class arra
return NULL;
}
else if (data_ != NULL) {
- memcpy(
- (void *)newdata, data_, ((datasize_ < newsize) ? datasize_ : newsize) * sizeof(T));
+ mem_copy(newdata, data_, ((datasize_ < newsize) ? datasize_ : newsize));
mem_free(data_, capacity_);
}
data_ = newdata;
@@ -246,7 +245,7 @@ template<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> class arra
if (newcapacity > capacity_) {
T *newdata = mem_allocate(newcapacity);
if (data_ != NULL) {
- memcpy(newdata, data_, ((datasize_ < newcapacity) ? datasize_ : newcapacity) * sizeof(T));
+ mem_copy(newdata, data_, ((datasize_ < newcapacity) ? datasize_ : newcapacity));
mem_free(data_, capacity_);
}
data_ = newdata;
@@ -280,7 +279,7 @@ template<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> class arra
if (from.size()) {
size_t old_size = size();
resize(old_size + from.size());
- memcpy(data_ + old_size, from.data(), sizeof(T) * from.size());
+ mem_copy(data_ + old_size, from.data(), from.size());
}
}
@@ -308,6 +307,11 @@ template<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> class arra
}
}
+ inline void mem_copy(T *mem_to, const T *mem_from, const size_t N)
+ {
+ memcpy((void *)mem_to, mem_from, sizeof(T) * N);
+ }
+
T *data_;
size_t datasize_;
size_t capacity_;
More information about the Bf-blender-cvs
mailing list