From a3c4b0f47d1a74fe228f3329de01f774a5e6b65f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 25 Aug 2012 20:16:08 +0000 Subject: make SWAP macros typesafe using CHECK_TYPE macro. Its unlikely you want to do short -> int, int -> float etc, conversion during swapping (if its needed we could have a non type checking macro). Double that the optimized assembler outbut using SWAP() remains unchanged from before. This exposed quite a few places where redundant type conversion was going on. Also remove curve.c's swapdata() and replace its use with swap_v3_v3() --- source/blender/blenlib/BLI_math_base.h | 24 +++++++++++++++++++++++- source/blender/blenlib/BLI_utildefines.h | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index b0e0d3cbf19..4a89776a52e 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -137,8 +137,30 @@ # endif #endif +/* Causes warning: + * incompatible types when assigning to type 'Foo' from type 'Bar' + * ... the compiler optimizes away the temp var */ +#ifndef CHECK_TYPE +#ifdef __GNUC__ +#define CHECK_TYPE(var, type) { \ + __typeof(var) *__tmp; \ + __tmp = (type *)NULL; \ + (void)__tmp; \ +} (void)0 +#else +#define CHECK_TYPE(var, type) +#endif +#endif + #ifndef SWAP -# define SWAP(type, a, b) { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } (void)0 +# define SWAP(type, a, b) { \ + type sw_ap; \ + CHECK_TYPE(a, type); \ + CHECK_TYPE(b, type); \ + sw_ap = (a); \ + (a) = (b); \ + (b) = sw_ap; \ +} (void)0 #endif #ifndef CLAMP diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 78d54defafd..8a459b9b07c 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -113,8 +113,30 @@ /* some math and copy defines */ +/* Causes warning: + * incompatible types when assigning to type 'Foo' from type 'Bar' + * ... the compiler optimizes away the temp var */ +#ifndef CHECK_TYPE +#ifdef __GNUC__ +#define CHECK_TYPE(var, type) { \ + __typeof(var) *__tmp; \ + __tmp = (type *)NULL; \ + (void)__tmp; \ +} (void)0 +#else +#define CHECK_TYPE(var, type) +#endif +#endif + #ifndef SWAP -# define SWAP(type, a, b) { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } (void)0 +# define SWAP(type, a, b) { \ + type sw_ap; \ + CHECK_TYPE(a, type); \ + CHECK_TYPE(b, type); \ + sw_ap = (a); \ + (a) = (b); \ + (b) = sw_ap; \ +} (void)0 #endif #define ABS(a) ( (a) < 0 ? (-(a)) : (a) ) -- cgit v1.2.3