Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-06-24 17:50:12 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-06-24 17:50:12 +0400
commitd19d1b549746238c4c1a694a8d3781a1fd0cf49d (patch)
treee6a2b33fc35785e0f0827b42fd05b862baca4317 /source/blender/blenlib/BLI_utildefines.h
parent77616cbe1150293ee04880e71bc1bd71ba4e4204 (diff)
Add MEMCPY_STRUCT_OFS macro for copying values after a struct member
use for DM_to_mesh to avoid clobbering the ListBase
Diffstat (limited to 'source/blender/blenlib/BLI_utildefines.h')
-rw-r--r--source/blender/blenlib/BLI_utildefines.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 4333ef1ce3f..c464bcdd0a9 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -384,6 +384,21 @@
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
#endif
+/* Like offsetof(typeof(), member), for non-gcc compilers */
+#define OFFSETOF_STRUCT(_struct, _member) \
+ ((((char *)&((_struct)->_member)) - ((char *)(_struct))) + sizeof((_struct)->_member))
+
+/* memcpy, skipping the first part of a struct,
+ * ensures 'struct_dst' isn't const and that the offset can be computed at compile time */
+#define MEMCPY_STRUCT_OFS(struct_dst, struct_src, member) { \
+ void *_not_const = struct_dst; \
+ (void)_not_const; \
+ ((void)(struct_dst == struct_src), \
+ memcpy((char *)(struct_dst) + OFFSETOF_STRUCT(struct_dst, member), \
+ (char *)(struct_src) + OFFSETOF_STRUCT(struct_dst, member), \
+ sizeof(*(struct_dst)) - OFFSETOF_STRUCT(struct_dst, member))); \
+} (void)0
+
/* Warning-free macros for storing ints in pointers. Use these _only_
* for storing an int in a pointer, not a pointer in an int (64bit)! */
#define SET_INT_IN_POINTER(i) ((void *)(intptr_t)(i))