File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 4141
4242clean :
4343 rm -f src/* .o tests/* .o
44- rm -f bin/* tmp
44+ rm -f bin/*
45+ rm -rf tmp
4546
4647DEBUG = # -DDEBUG_DUMP
4748
Original file line number Diff line number Diff line change 7272#define STACKMAN_SP_ALIGN_UP (a ) (((intptr_t)((a)+STACKMAN_STACK_ALIGN-1) & ~(STACKMAN_STACK_ALIGN-1)))
7373
7474#if STACKMAN_STACK_DIR == 0
75- #define STACKMAN_SP_FURTHEST ((void*) ^ (intptr_t)-1 )
75+ #define STACKMAN_SP_FURTHEST ((void*) (intptr_t) -STACKMAN_STACK_ALIGN )
7676#define STACKMAN_SP_NEAREST ((void*) 0)
7777#define STACKMAN_SP_LS (a , b ) ((void*)(a) < (void*)(b)) /* to compare stack position */
7878#define STACKMAN_SP_LE (a , b ) ((void*)(a) <= (void*)(b)) /* to compare stack position */
8282#else
8383/* upwards growing stacks */
8484#define STACKMAN_SP_FURTHEST ((void*) 0)
85- #define STACKMAN_SP_NEAREST ((void*) ^ (intptr_t)-1 )
85+ #define STACKMAN_SP_NEAREST ((void*) (intptr_t) -STACKMAN_STACK_ALIGN )
8686#define STACKMAN_SP_LS (a , b ) ((void*)(a) > (void*)(b)) /* to compare stack position */
8787#define STACKMAN_SP_LE (a , b ) ((void*)(a) >= (void*)(b)) /* to compare stack position */
8888#define STACKMAN_SP_ADD (a , b ) ((a) - (b)) /* to add offset to stack pointer */
Original file line number Diff line number Diff line change @@ -254,6 +254,24 @@ void test_04(void)
254254
255255#endif
256256
257+ /* Test our various macros */
258+ void test_05 ()
259+ {
260+
261+ int local = 0 ;
262+ void * away = STACKMAN_SP_FURTHEST ;
263+ void * close = STACKMAN_SP_NEAREST ;
264+ assert (STACKMAN_SP_LE (& local , away ));
265+ assert (STACKMAN_SP_LS (& local , away ));
266+ assert (STACKMAN_SP_LE (close , & local ));
267+ assert (STACKMAN_SP_LS (close , & local ));
268+
269+ assert (STACKMAN_SP_LE (& local , & local ));
270+ assert (!STACKMAN_SP_LS (& local , & local ));
271+
272+ assert ((void * )STACKMAN_SP_ALIGN (away ) == away );
273+
274+ }
257275
258276int main (int argc , char * argv [])
259277{
@@ -269,5 +287,7 @@ int main(int argc, char*argv[])
269287 test_04 ();
270288 printf ("test_04 ok\n" );
271289#endif
290+ test_05 ();
291+ printf ("test_05 ok\n" );
272292 return 0 ;
273293}
You can’t perform that action at this time.
0 commit comments