diff options
-rw-r--r-- | source/blender/blenkernel/BKE_idprop.h | 24 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idprop.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 6 | ||||
-rw-r--r-- | source/blender/bmesh/bmesh_class.h | 8 | ||||
-rw-r--r-- | source/blender/editors/include/BIF_gl.h | 20 |
5 files changed, 49 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index 3cf944fa236..0f3f4ef1018 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -121,11 +121,27 @@ void IDP_ClearProperty(IDProperty *prop); void IDP_UnlinkProperty(struct IDProperty *prop); #define IDP_Int(prop) ((prop)->data.val) -#define IDP_Float(prop) (*(float *)&(prop)->data.val) -#define IDP_Double(prop) (*(double *)&(prop)->data.val) -#define IDP_String(prop) ((char *) (prop)->data.pointer) #define IDP_Array(prop) ((prop)->data.pointer) -#define IDP_IDPArray(prop) ((IDProperty *) (prop)->data.pointer) +/* C11 const correctness for casts */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +# define IDP_Float(prop) _Generic(prop, \ + IDProperty *: (*(float *)&(prop)->data.val), \ + const IDProperty *: (*(const float *)&(prop)->data.val)) +# define IDP_Double(prop) _Generic(prop, \ + IDProperty *: (*(double *)&(prop)->data.val), \ + const IDProperty *: (*(const double *)&(prop)->data.val)) +# define IDP_String(prop) _Generic(prop, \ + IDProperty *: ((char *) (prop)->data.pointer), \ + const IDProperty *: ((const char *) (prop)->data.pointer)) +# define IDP_IDPArray(prop) _Generic(prop, \ + IDProperty *: ((IDProperty *) (prop)->data.pointer), \ + const IDProperty *: ((const IDProperty *) (prop)->data.pointer)) +#else +# define IDP_Float(prop) (*(float *)&(prop)->data.val) +# define IDP_Double(prop) (*(double *)&(prop)->data.val) +# define IDP_String(prop) ((char *) (prop)->data.pointer) +# define IDP_IDPArray(prop) ((IDProperty *) (prop)->data.pointer) +#endif #ifdef DEBUG /* for printout only */ diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 3188676fb6c..95bfd72c9df 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -64,7 +64,7 @@ static char idp_size_table[] = { /** \name IDP Array API * \{ */ -#define GETPROP(prop, i) (((IDProperty *)(prop)->data.pointer) + (i)) +#define GETPROP(prop, i) &(IDP_IDPArray(prop)[i]) /* --------- property array type -------------*/ diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 564b31f974a..5937880665d 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -174,10 +174,16 @@ (void)__tmp; \ })) +#define CHECK_TYPE_NONCONST(var) { \ + void *non_const = ((__typeof(var))NULL); \ + (void)non_const; \ +} (void)0 + #else # define CHECK_TYPE(var, type) # define CHECK_TYPE_PAIR(var_a, var_b) # define CHECK_TYPE_PAIR_INLINE(var_a, var_b) (void)0 +# define CHECK_TYPE_NONCONST(var) (void)0 #endif /* can be used in simple macros */ diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h index 01745396cd1..39359b97a4e 100644 --- a/source/blender/bmesh/bmesh_class.h +++ b/source/blender/bmesh/bmesh_class.h @@ -285,8 +285,8 @@ extern void bpy_bm_generic_invalidate(struct BPy_BMGeneric *self); typedef bool (*BMElemFilterFunc)(BMElem *, void *user_data); /* defines */ -#define BM_ELEM_CD_SET_INT(ele, offset, f) \ - { assert(offset != -1); *((int *)((char *)(ele)->head.data + (offset))) = (f); } (void)0 +#define BM_ELEM_CD_SET_INT(ele, offset, f) { CHECK_TYPE_NONCONST(ele); \ + assert(offset != -1); *((int *)((char *)(ele)->head.data + (offset))) = (f); } (void)0 #define BM_ELEM_CD_GET_INT(ele, offset) \ (assert(offset != -1), *((int *)((char *)(ele)->head.data + (offset)))) @@ -294,8 +294,8 @@ typedef bool (*BMElemFilterFunc)(BMElem *, void *user_data); #define BM_ELEM_CD_GET_VOID_P(ele, offset) \ (assert(offset != -1), (void *)((char *)(ele)->head.data + (offset))) -#define BM_ELEM_CD_SET_FLOAT(ele, offset, f) \ - { assert(offset != -1); *((float *)((char *)(ele)->head.data + (offset))) = (f); } (void)0 +#define BM_ELEM_CD_SET_FLOAT(ele, offset, f) { CHECK_TYPE_NONCONST(ele); \ + assert(offset != -1); *((float *)((char *)(ele)->head.data + (offset))) = (f); } (void)0 #define BM_ELEM_CD_GET_FLOAT(ele, offset) \ (assert(offset != -1), *((float *)((char *)(ele)->head.data + (offset)))) diff --git a/source/blender/editors/include/BIF_gl.h b/source/blender/editors/include/BIF_gl.h index 477a7c0ce17..4258bbcd359 100644 --- a/source/blender/editors/include/BIF_gl.h +++ b/source/blender/editors/include/BIF_gl.h @@ -58,8 +58,24 @@ * */ void cpack(unsigned int x); -#define glMultMatrixf(x) glMultMatrixf( (float *)(x)) -#define glLoadMatrixf(x) glLoadMatrixf( (float *)(x)) + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +# define glMultMatrixf(x) \ + glMultMatrixf(_Generic(x, \ + float *: (float *)(x), \ + float (*)[4]: (float *)(x), \ + const float *: (float *)(x), \ + const float (*)[4]: (float *)(x)) \ +) +# define glLoadMatrixf(x) \ + glLoadMatrixf(_Generic(x, \ + float *: (float *)(x), \ + float (*)[4]: (float *)(x)) \ +) +#else +# define glMultMatrixf(x) glMultMatrixf((float *)(x)) +# define glLoadMatrixf(x) glLoadMatrixf((float *)(x)) +#endif #define GLA_PIXEL_OFS 0.375f |