[Bf-blender-cvs] [3c1e75a2301] master: Functions: make asserts more correct
Jacques Lucke
noreply at git.blender.org
Tue Sep 21 17:51:53 CEST 2021
Commit: 3c1e75a2301c352dac72b1742cdd8efa2b335d6e
Author: Jacques Lucke
Date: Tue Sep 21 17:50:53 2021 +0200
Branches: master
https://developer.blender.org/rB3c1e75a2301c352dac72b1742cdd8efa2b335d6e
Functions: make asserts more correct
It is valid to e.g. copy construct an integer in the same place,
because it is a trivial type. It does not work for types like std::string.
This fixes a crash reported in D12584 where it would copy a buffer
into itself. We should probably also avoid doing this copy alltogether
but that can be done separately.
===================================================================
M source/blender/functions/FN_cpp_type.hh
M source/blender/functions/FN_cpp_type_make.hh
===================================================================
diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh
index 7277bf99c12..643b2fc1f28 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -96,6 +96,7 @@ class CPPType : NonCopyable, NonMovable {
int64_t size_ = 0;
int64_t alignment_ = 0;
uintptr_t alignment_mask_ = 0;
+ bool is_trivial_ = false;
bool is_trivially_destructible_ = false;
bool has_special_member_functions_ = false;
@@ -340,7 +341,6 @@ class CPPType : NonCopyable, NonMovable {
*/
void copy_assign(const void *src, void *dst) const
{
- BLI_assert(src != dst);
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
@@ -371,7 +371,7 @@ class CPPType : NonCopyable, NonMovable {
*/
void copy_construct(const void *src, void *dst) const
{
- BLI_assert(src != dst);
+ BLI_assert(src != dst || is_trivial_);
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
@@ -402,7 +402,6 @@ class CPPType : NonCopyable, NonMovable {
*/
void move_assign(void *src, void *dst) const
{
- BLI_assert(src != dst);
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
@@ -433,7 +432,7 @@ class CPPType : NonCopyable, NonMovable {
*/
void move_construct(void *src, void *dst) const
{
- BLI_assert(src != dst);
+ BLI_assert(src != dst || is_trivial_);
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
@@ -464,7 +463,7 @@ class CPPType : NonCopyable, NonMovable {
*/
void relocate_assign(void *src, void *dst) const
{
- BLI_assert(src != dst);
+ BLI_assert(src != dst || is_trivial_);
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
@@ -495,7 +494,7 @@ class CPPType : NonCopyable, NonMovable {
*/
void relocate_construct(void *src, void *dst) const
{
- BLI_assert(src != dst);
+ BLI_assert(src != dst || is_trivial_);
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
diff --git a/source/blender/functions/FN_cpp_type_make.hh b/source/blender/functions/FN_cpp_type_make.hh
index 088f6b469f4..74dbcabf81a 100644
--- a/source/blender/functions/FN_cpp_type_make.hh
+++ b/source/blender/functions/FN_cpp_type_make.hh
@@ -195,6 +195,7 @@ CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name)
debug_name_ = debug_name;
size_ = (int64_t)sizeof(T);
alignment_ = (int64_t)alignof(T);
+ is_trivial_ = std::is_trivial_v<T>;
is_trivially_destructible_ = std::is_trivially_destructible_v<T>;
if constexpr (std::is_default_constructible_v<T>) {
default_construct_ = default_construct_cb<T>;
More information about the Bf-blender-cvs
mailing list