forked from bartvdbraak/blender
Macros: prevent instantiation of args for type checks
also make CHECK_TYPE_INLINE more strict
This commit is contained in:
parent
cc28e02a85
commit
a039f2bfc4
@ -36,7 +36,7 @@
|
|||||||
# define _STACK_SWAP_TOTALLOC(stack_a, stack_b) SWAP(unsigned int, _##stack_a##_totalloc, _##stack_b##_totalloc)
|
# define _STACK_SWAP_TOTALLOC(stack_a, stack_b) SWAP(unsigned int, _##stack_a##_totalloc, _##stack_b##_totalloc)
|
||||||
#else
|
#else
|
||||||
# define STACK_DECLARE(stack) unsigned int _##stack##_index
|
# define STACK_DECLARE(stack) unsigned int _##stack##_index
|
||||||
# define STACK_INIT(stack, tot) ((void)stack, (void)((_##stack##_index) = 0), (void)(tot))
|
# define STACK_INIT(stack, tot) ((void)stack, (void)((_##stack##_index) = 0), (void)(0 ? tot : 0))
|
||||||
# define _STACK_SIZETEST(stack, off) (void)(stack), (void)(off)
|
# define _STACK_SIZETEST(stack, off) (void)(stack), (void)(off)
|
||||||
# define _STACK_SWAP_TOTALLOC(stack_a, stack_b) (void)(stack_a), (void)(stack_b)
|
# define _STACK_SWAP_TOTALLOC(stack_a, stack_b) (void)(stack_a), (void)(stack_b)
|
||||||
#endif
|
#endif
|
||||||
@ -57,9 +57,12 @@
|
|||||||
#define STACK_PEEK_PTR(stack) (BLI_assert(_##stack##_index), &((stack)[_##stack##_index - 1]))
|
#define STACK_PEEK_PTR(stack) (BLI_assert(_##stack##_index), &((stack)[_##stack##_index - 1]))
|
||||||
/** remove any item from the stack, take care, re-orders */
|
/** remove any item from the stack, take care, re-orders */
|
||||||
#define STACK_REMOVE(stack, i) \
|
#define STACK_REMOVE(stack, i) \
|
||||||
_STACK_BOUNDSTEST(stack, i); \
|
{ \
|
||||||
if (--_##stack##_index != i) { \
|
const unsigned int _i = i; \
|
||||||
stack[i] = stack[_##stack##_index]; \
|
_STACK_BOUNDSTEST(stack, _i); \
|
||||||
|
if (--_##stack##_index != _i) { \
|
||||||
|
stack[_i] = stack[_##stack##_index]; \
|
||||||
|
} \
|
||||||
} (void)0
|
} (void)0
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define STACK_SWAP(stack_a, stack_b) { \
|
#define STACK_SWAP(stack_a, stack_b) { \
|
||||||
|
@ -59,7 +59,6 @@
|
|||||||
#define VA_NARGS_CALL_OVERLOAD(name, ...) \
|
#define VA_NARGS_CALL_OVERLOAD(name, ...) \
|
||||||
_VA_NARGS_GLUE(_VA_NARGS_OVERLOAD_MACRO(name, _VA_NARGS_COUNT_MAX16(__VA_ARGS__)), (__VA_ARGS__))
|
_VA_NARGS_GLUE(_VA_NARGS_OVERLOAD_MACRO(name, _VA_NARGS_COUNT_MAX16(__VA_ARGS__)), (__VA_ARGS__))
|
||||||
|
|
||||||
|
|
||||||
/* useful for finding bad use of min/max */
|
/* useful for finding bad use of min/max */
|
||||||
#if 0
|
#if 0
|
||||||
/* gcc only */
|
/* gcc only */
|
||||||
@ -181,8 +180,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* can be used in simple macros */
|
/* can be used in simple macros */
|
||||||
#define CHECK_TYPE_INLINE(val, type) \
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
||||||
((void)(((type)0) != (val)))
|
# define CHECK_TYPE_INLINE(val, type) \
|
||||||
|
(void)((void)(((type)0) != (0 ? (val) : ((type)0))), \
|
||||||
|
_Generic((val), type: 0, const type: 0))
|
||||||
|
#else
|
||||||
|
# define CHECK_TYPE_INLINE(val, type) \
|
||||||
|
((void)(((type)0) != (0 ? (val) : ((type)0))))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CHECK_TYPE_NONCONST(var) { \
|
#define CHECK_TYPE_NONCONST(var) { \
|
||||||
void *non_const = 0 ? (var) : NULL; \
|
void *non_const = 0 ? (var) : NULL; \
|
||||||
|
@ -237,7 +237,7 @@ typedef struct PreviewImage {
|
|||||||
# undef GS
|
# undef GS
|
||||||
#endif
|
#endif
|
||||||
// #define GS(a) (*((short *)(a)))
|
// #define GS(a) (*((short *)(a)))
|
||||||
#define GS(a) (CHECK_TYPE_INLINE(a, const char *), (*((short *)(a))))
|
#define GS(a) (CHECK_TYPE_INLINE(a, char *), (*((short *)(a))))
|
||||||
|
|
||||||
#define ID_NEW(a) if ( (a) && (a)->id.newid ) (a) = (void *)(a)->id.newid
|
#define ID_NEW(a) if ( (a) && (a)->id.newid ) (a) = (void *)(a)->id.newid
|
||||||
#define ID_NEW_US(a) if ( (a)->id.newid) { (a) = (void *)(a)->id.newid; (a)->id.us++; }
|
#define ID_NEW_US(a) if ( (a)->id.newid) { (a) = (void *)(a)->id.newid; (a)->id.us++; }
|
||||||
|
Loading…
Reference in New Issue
Block a user