Skip to content

Commit 6892258

Browse files
committed
Fix some problems with macros
1 parent dd3c568 commit 6892258

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ lib:
4141

4242
clean:
4343
rm -f src/*.o tests/*.o
44-
rm -f bin/* tmp
44+
rm -f bin/*
45+
rm -rf tmp
4546

4647
DEBUG = #-DDEBUG_DUMP
4748

src/stackman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
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 */
@@ -82,7 +82,7 @@
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 */

tests/test.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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

258276
int 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
}

0 commit comments

Comments
 (0)