diff --git a/Makefile b/Makefile index e9b8e68..14e3240 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,8 @@ lib: clean: rm -f src/*.o tests/*.o - rm -f bin/* tmp + rm -f bin/* + rm -rf tmp DEBUG = #-DDEBUG_DUMP diff --git a/src/stackman.h b/src/stackman.h index defd15f..4a2bf78 100644 --- a/src/stackman.h +++ b/src/stackman.h @@ -72,7 +72,7 @@ #define STACKMAN_SP_ALIGN_UP(a) (((intptr_t)((a)+STACKMAN_STACK_ALIGN-1) & ~(STACKMAN_STACK_ALIGN-1))) #if STACKMAN_STACK_DIR == 0 -#define STACKMAN_SP_FURTHEST ((void*) ^(intptr_t)-1) +#define STACKMAN_SP_FURTHEST ((void*) (intptr_t) -STACKMAN_STACK_ALIGN) #define STACKMAN_SP_NEAREST ((void*) 0) #define STACKMAN_SP_LS(a, b) ((void*)(a) < (void*)(b)) /* to compare stack position */ #define STACKMAN_SP_LE(a, b) ((void*)(a) <= (void*)(b)) /* to compare stack position */ @@ -82,7 +82,7 @@ #else /* upwards growing stacks */ #define STACKMAN_SP_FURTHEST ((void*) 0) -#define STACKMAN_SP_NEAREST ((void*) ^(intptr_t)-1) +#define STACKMAN_SP_NEAREST ((void*) (intptr_t) -STACKMAN_STACK_ALIGN) #define STACKMAN_SP_LS(a, b) ((void*)(a) > (void*)(b)) /* to compare stack position */ #define STACKMAN_SP_LE(a, b) ((void*)(a) >= (void*)(b)) /* to compare stack position */ #define STACKMAN_SP_ADD(a, b) ((a) - (b)) /* to add offset to stack pointer */ diff --git a/tests/test.c b/tests/test.c index a3efd23..6ed3cb0 100644 --- a/tests/test.c +++ b/tests/test.c @@ -254,6 +254,24 @@ void test_04(void) #endif +/* Test our various macros */ +void test_05() +{ + + int local=0; + void *away = STACKMAN_SP_FURTHEST; + void *close = STACKMAN_SP_NEAREST; + assert(STACKMAN_SP_LE(&local, away)); + assert(STACKMAN_SP_LS(&local, away)); + assert(STACKMAN_SP_LE(close, &local)); + assert(STACKMAN_SP_LS(close, &local)); + + assert(STACKMAN_SP_LE(&local, &local)); + assert(!STACKMAN_SP_LS(&local, &local)); + + assert((void*)STACKMAN_SP_ALIGN(away) == away); + +} int main(int argc, char*argv[]) { @@ -269,5 +287,7 @@ int main(int argc, char*argv[]) test_04(); printf("test_04 ok\n"); #endif + test_05(); + printf("test_05 ok\n"); return 0; }