From 16e560147c6715f7dfdb0f10ced0bac3c6af8504 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Tue, 29 Jul 2014 11:56:59 -0400 Subject: [PATCH] further refinement of auto-detecting integer types --- src/unity_internals.h | 60 ++++++++++++++++++++++--------------- targets/gcc_32.yml | 3 ++ targets/gcc_64.yml | 3 ++ targets/gcc_auto_limits.yml | 46 ++++++++++++++++++++++++++++ targets/gcc_auto_sizeof.yml | 47 +++++++++++++++++++++++++++++ targets/gcc_auto_stdint.yml | 45 ++++++++++++++++++++++++++++ 6 files changed, 180 insertions(+), 24 deletions(-) create mode 100644 targets/gcc_auto_limits.yml create mode 100644 targets/gcc_auto_sizeof.yml create mode 100644 targets/gcc_auto_stdint.yml diff --git a/src/unity_internals.h b/src/unity_internals.h index 2d047b1..9e6e321 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -10,18 +10,29 @@ #include #include -// Unity attempts to determine sizeof(various types) -// based on UINT_MAX, ULONG_MAX, etc. These are typically -// defined in limits.h. -#ifdef UNITY_USE_LIMITS_H -#include -#endif -// As a fallback, hope that including stdint.h will -// provide this information. +// Unity Attempts to Auto-Detect Integer Types +// Attempt 1: UINT_MAX, ULONG_MAX, etc in +// Attempt 2: UINT_MAX, ULONG_MAX, etc in +// Attempt 3: Deduced from sizeof() macros #ifndef UNITY_EXCLUDE_STDINT_H #include #endif +#ifndef UNITY_EXCLUDE_LIMITS_H +#include +#endif + +#ifndef UNITY_EXCLUDE_SIZEOF +#ifndef UINT_MAX +#define UINT_MAX (sizeof(unsigned int) * 256 - 1) +#endif +#ifndef ULONG_MAX +#define ULONG_MAX (sizeof(unsigned long) * 256 - 1) +#endif +#ifndef UINTPTR_MAX +#define UINTPTR_MAX ULONG_MAX //apparently this is not a constant expression: (sizeof(unsigned int *) * 256 - 1) +#endif +#endif //------------------------------------------------------- // Guess Widths If Not Specified //------------------------------------------------------- @@ -38,9 +49,6 @@ #define UNITY_INT_WIDTH (32) #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) #define UNITY_INT_WIDTH (64) - #ifndef UNITY_SUPPORT_64 - #define UNITY_SUPPORT_64 - #endif #endif #endif #endif @@ -59,9 +67,6 @@ #define UNITY_LONG_WIDTH (32) #elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) #define UNITY_LONG_WIDTH (64) - #ifndef UNITY_SUPPORT_64 - #define UNITY_SUPPORT_64 - #endif #endif #endif #endif @@ -80,9 +85,6 @@ #define UNITY_POINTER_WIDTH (32) #elif (UINTPTR_MAX <= 0xFFFFFFFFFFFFFFFF) #define UNITY_POINTER_WIDTH (64) - #ifndef UNITY_SUPPORT_64 - #define UNITY_SUPPORT_64 - #endif #endif #endif #endif @@ -94,9 +96,6 @@ #define UNITY_POINTER_WIDTH (32) #elif (INTPTR_MAX <= 0x7FFFFFFFFFFFFFFF) #define UNITY_POINTER_WIDTH (64) - #ifndef UNITY_SUPPORT_64 - #define UNITY_SUPPORT_64 - #endif #endif #endif #endif @@ -105,7 +104,7 @@ #endif //------------------------------------------------------- -// Int Support +// Int Support (Define types based on detected sizes) //------------------------------------------------------- #if (UNITY_INT_WIDTH == 32) @@ -130,6 +129,17 @@ // 64-bit Support //------------------------------------------------------- +#ifndef UNITY_SUPPORT_64 +#if UNITY_LONG_WIDTH > 32 +#define UNITY_SUPPORT_64 +#endif +#endif +#ifndef UNITY_SUPPORT_64 +#if UNITY_POINTER_WIDTH > 32 +#define UNITY_SUPPORT_64 +#endif +#endif + #ifndef UNITY_SUPPORT_64 //No 64-bit Support @@ -161,9 +171,6 @@ typedef _US64 _U_SINT; typedef _UU32 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32 #elif (UNITY_POINTER_WIDTH == 64) -#ifndef UNITY_SUPPORT_64 -#error "You've Specified 64-bit pointers without enabling 64-bit Support. Define UNITY_SUPPORT_64" -#endif typedef _UU64 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64 #elif (UNITY_POINTER_WIDTH == 16) @@ -184,12 +191,17 @@ typedef _US64 _U_SINT; #ifdef UNITY_EXCLUDE_FLOAT //No Floating Point Support +#undef UNITY_INCLUDE_FLOAT #undef UNITY_FLOAT_PRECISION #undef UNITY_FLOAT_TYPE #undef UNITY_FLOAT_VERBOSE #else +#ifndef UNITY_INCLUDE_FLOAT +#define UNITY_INCLUDE_FLOAT +#endif + //Floating Point Support #ifndef UNITY_FLOAT_PRECISION #define UNITY_FLOAT_PRECISION (0.00001f) diff --git a/targets/gcc_32.yml b/targets/gcc_32.yml index f9d1318..5f46c60 100644 --- a/targets/gcc_32.yml +++ b/targets/gcc_32.yml @@ -19,6 +19,9 @@ compiler: defines: prefix: '-D' items: + - UNITY_EXCLUDE_STDINT_H + - UNITY_EXCLUDE_LIMITS_H + - UNITY_EXCLUDE_SIZEOF - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_TEST_CASES object_files: diff --git a/targets/gcc_64.yml b/targets/gcc_64.yml index e49e268..6d8dda2 100644 --- a/targets/gcc_64.yml +++ b/targets/gcc_64.yml @@ -19,6 +19,9 @@ compiler: defines: prefix: '-D' items: + - UNITY_EXCLUDE_STDINT_H + - UNITY_EXCLUDE_LIMITS_H + - UNITY_EXCLUDE_SIZEOF - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_TEST_CASES - UNITY_SUPPORT_64 diff --git a/targets/gcc_auto_limits.yml b/targets/gcc_auto_limits.yml new file mode 100644 index 0000000..c06cf75 --- /dev/null +++ b/targets/gcc_auto_limits.yml @@ -0,0 +1,46 @@ +compiler: + path: gcc + source_path: 'src/' + unit_tests_path: &unit_tests_path 'test/' + build_path: &build_path 'build/' + options: + - '-c' + - '-m64' + - '-Wall' + - '-Wno-address' + - '-std=c99' + - '-pedantic' + includes: + prefix: '-I' + items: + - 'src/' + - '../src/' + - *unit_tests_path + defines: + prefix: '-D' + items: + - UNITY_EXCLUDE_STDINT_H + - UNITY_INCLUDE_DOUBLE + - UNITY_SUPPORT_TEST_CASES + - UNITY_SUPPORT_64 + object_files: + prefix: '-o' + extension: '.o' + destination: *build_path +linker: + path: gcc + options: + - -lm + - '-m64' + includes: + prefix: '-I' + object_files: + path: *build_path + extension: '.o' + bin_files: + prefix: '-o' + extension: '.exe' + destination: *build_path +colour: true +:unity: + :plugins: [] diff --git a/targets/gcc_auto_sizeof.yml b/targets/gcc_auto_sizeof.yml new file mode 100644 index 0000000..aa7c279 --- /dev/null +++ b/targets/gcc_auto_sizeof.yml @@ -0,0 +1,47 @@ +compiler: + path: gcc + source_path: 'src/' + unit_tests_path: &unit_tests_path 'test/' + build_path: &build_path 'build/' + options: + - '-c' + - '-m64' + - '-Wall' + - '-Wno-address' + - '-std=c99' + - '-pedantic' + includes: + prefix: '-I' + items: + - 'src/' + - '../src/' + - *unit_tests_path + defines: + prefix: '-D' + items: + - UNITY_EXCLUDE_STDINT_H + - UNITY_EXCLUDE_LIMTIS_H + - UNITY_INCLUDE_DOUBLE + - UNITY_SUPPORT_TEST_CASES + - UNITY_SUPPORT_64 + object_files: + prefix: '-o' + extension: '.o' + destination: *build_path +linker: + path: gcc + options: + - -lm + - '-m64' + includes: + prefix: '-I' + object_files: + path: *build_path + extension: '.o' + bin_files: + prefix: '-o' + extension: '.exe' + destination: *build_path +colour: true +:unity: + :plugins: [] diff --git a/targets/gcc_auto_stdint.yml b/targets/gcc_auto_stdint.yml new file mode 100644 index 0000000..e49e268 --- /dev/null +++ b/targets/gcc_auto_stdint.yml @@ -0,0 +1,45 @@ +compiler: + path: gcc + source_path: 'src/' + unit_tests_path: &unit_tests_path 'test/' + build_path: &build_path 'build/' + options: + - '-c' + - '-m64' + - '-Wall' + - '-Wno-address' + - '-std=c99' + - '-pedantic' + includes: + prefix: '-I' + items: + - 'src/' + - '../src/' + - *unit_tests_path + defines: + prefix: '-D' + items: + - UNITY_INCLUDE_DOUBLE + - UNITY_SUPPORT_TEST_CASES + - UNITY_SUPPORT_64 + object_files: + prefix: '-o' + extension: '.o' + destination: *build_path +linker: + path: gcc + options: + - -lm + - '-m64' + includes: + prefix: '-I' + object_files: + path: *build_path + extension: '.o' + bin_files: + prefix: '-o' + extension: '.exe' + destination: *build_path +colour: true +:unity: + :plugins: [] -- GitLab