FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix some problems with macros by kristjanvalur · Pull Request #3 · stackless-dev/stackman · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) No extension  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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;
}

Back | FazBrowse Home | New Git URL