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.
This commit is contained in:
parent
8a23d91a50
commit
1788298804
|
@ -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_;
|
||||
|
|
Loading…
Reference in New Issue