Page Menu
Home
Search
Configure Global Search
Log In
Paste
P2846
(An Untitled Masterwork)
Active
Public
Actions
Authored by
Sergey Sharybin (sergey)
on Mar 23 2022, 10:55 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Tags
None
Subscribers
None
diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc
index 40c6fbcf67e..0fc70511728 100644
--- a/source/blender/blenkernel/intern/mesh_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_convert.cc
@@ -910,7 +910,7 @@ 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 = {{nullptr}};
+ Object bevel_object = Object::MakeZero();
if (curve.bevobj != nullptr) {
memcpy(&bevel_object, curve.bevobj, sizeof(bevel_object));
BLI_listbase_clear(&bevel_object.modifiers);
@@ -919,7 +919,7 @@ static void curve_to_mesh_eval_ensure(Object &object)
}
/* Same thing for taper. */
- Object taper_object = {{nullptr}};
+ Object taper_object = Object::MakeZero();
if (curve.taperobj != nullptr) {
memcpy(&taper_object, curve.taperobj, sizeof(taper_object));
BLI_listbase_clear(&taper_object.modifiers);
diff --git a/source/blender/makesdna/DNA_defs.h b/source/blender/makesdna/DNA_defs.h
index b4230209dd5..942e1d34628 100644
--- a/source/blender/makesdna/DNA_defs.h
+++ b/source/blender/makesdna/DNA_defs.h
@@ -8,6 +8,13 @@
#pragma once
+#ifdef __cplusplus
+/* Used for explicit implementation of constructor and assignment operators.
+ * Rather annoying to pull this header from here. Alternative would be to have DNA_memcpy which
+ * will be provided via bf_dna library. */
+# include <string.h>
+#endif
+
/* makesdna ignores */
#ifdef DNA_DEPRECATED_ALLOW
/* allow use of deprecated items */
@@ -41,6 +48,46 @@
# endif
#endif
+#ifndef __cplusplus
+# define DNA_OBJECT_COMMON(class_name)
+#else
+/* Define explicit constructor and assignment operators which will do the same thing as the
+ * implicitly defined ones, but will not generate deprecation warnings.
+ *
+ * The deprecation warnings happens with Apple Clang from the implicitly defined constructors and
+ * assignment operators. */
+# define DNA_OBJECT_COMMON(class_name) \
+ static class_name MakeZero() \
+ { \
+ class_name obj; \
+ memset(&obj, 0, sizeof(class_name)); \
+ return obj; \
+ } \
+ class_name() = default; \
+ class_name(const class_name &other) \
+ { \
+ memcpy(this, &other, sizeof(class_name)); \
+ } \
+ class_name(class_name &&other) noexcept \
+ { \
+ memcpy(this, &other, sizeof(class_name)); \
+ } \
+ class_name &operator=(const class_name &other) \
+ { \
+ if (this != &other) { \
+ memcpy(this, &other, sizeof(class_name)); \
+ } \
+ return *this; \
+ } \
+ class_name &operator=(class_name &&other) \
+ { \
+ if (this != &other) { \
+ memcpy(this, &other, sizeof(class_name)); \
+ } \
+ return *this; \
+ }
+#endif
+
/* hrmf, we need a better include then this */
#include "../blenlib/BLI_sys_types.h" /* needed for int64_t only! */
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 9e0bf7dcc5a..c64239789e2 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -233,6 +233,8 @@ enum eObjectLineArt_Flags {
};
typedef struct Object {
+ DNA_OBJECT_COMMON(Object);
+
ID id;
/** Animation data (must be immediately after id for utilities to use it). */
struct AnimData *adt;
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index 0d2f265a9b5..5e4c23a9249 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -620,6 +620,7 @@ static int preprocess_include(char *maindata, const int maindata_len)
int newlen = 0;
comment = 0;
a = maindata_len;
+ bool skip_until_semicolon = false;
while (a--) {
if (cp[0] == '/' && cp[1] == '*') {
@@ -646,6 +647,17 @@ static int preprocess_include(char *maindata, const int maindata_len)
a -= 13;
cp += 13;
}
+ else if (match_identifier(cp, "DNA_OBJECT_COMMON")) {
+ /* single values are skipped already, so decrement 1 less */
+ a -= 16;
+ cp += 16;
+ skip_until_semicolon = true;
+ }
+ else if (skip_until_semicolon) {
+ if (cp[0] == ';') {
+ skip_until_semicolon = false;
+ }
+ }
else {
md[0] = cp[0];
md++;
Event Timeline
Sergey Sharybin (sergey)
created this paste.
Mar 23 2022, 10:55 AM
Sergey Sharybin (sergey)
created this object with edit policy "Administrators".
Log In to Comment