Prevent macros hiding casts from `const` pointers
This commit is contained in:
parent
c9366a2969
commit
7f32cf4605
Notes:
blender-bot
2023-02-14 10:15:23 +01:00
Referenced by issue #41318, OSL broken on Linux kubuntu 14.04
|
@ -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 */
|
||||
|
|
|
@ -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 -------------*/
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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))))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue