Skip to content

Fix some problems with macros #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/stackman.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down
20 changes: 20 additions & 0 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
{
Expand All @@ -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;
}