From e02c8b4dac81e49924012f4458bcd5b2600ef55f Mon Sep 17 00:00:00 2001 From: Carl-Johan Waldeck Date: Wed, 11 Nov 2020 20:43:56 +0100 Subject: [PATCH 1/3] Link with libargp in macOS environment MacOS does not include the argp library at default. It may be installed via homebrew and needs to be linked to the build. --- libscu-c/Makefile.scu | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libscu-c/Makefile.scu b/libscu-c/Makefile.scu index e5e095f..1f32452 100644 --- a/libscu-c/Makefile.scu +++ b/libscu-c/Makefile.scu @@ -16,8 +16,17 @@ build: $(TESTCASES) clean:: rm -f $(TESTCASES) $(patsubst %,%.o,$(TESTCASES)) $(patsubst %,valgrind.%.log,$(TESTCASES)) + +LDFLAGS:=-L$(SCU_DIR)/libscu-c/ -lscu-c + +ifeq ($(shell uname), Darwin) + # libargp may be installed with homebrew + # brew install argp-standalone + LDFLAGS+=-largp +endif + $(TESTCASES): %:%.o $(SCU_DIR)/libscu-c/libscu-c.a - $(CC) -o $@ $< -L$(SCU_DIR)/libscu-c/ -lscu-c + $(CC) -o $@ $< $(LDFLAGS) $(SCU_DIR)/libscu-c/libscu-c.a: make -C $(SCU_DIR)/libscu-c From 0d647fed89e5c59941c9d4ed71e4695cdc9097ae Mon Sep 17 00:00:00 2001 From: Carl-Johan Waldeck Date: Wed, 11 Nov 2020 20:55:14 +0100 Subject: [PATCH 2/3] Use pthread_self() as thread id to support macOS syscall(SYS_gettid) is not supported on macOS. To mitigate this instead use pthread_self() to get an id for the current thread. While not unique globally, it's unique within the same process which should serve the purposes here sufficiently. --- libscu-c/Makefile.scu | 2 +- libscu-c/src/scu.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libscu-c/Makefile.scu b/libscu-c/Makefile.scu index 1f32452..886721c 100644 --- a/libscu-c/Makefile.scu +++ b/libscu-c/Makefile.scu @@ -17,7 +17,7 @@ clean:: rm -f $(TESTCASES) $(patsubst %,%.o,$(TESTCASES)) $(patsubst %,valgrind.%.log,$(TESTCASES)) -LDFLAGS:=-L$(SCU_DIR)/libscu-c/ -lscu-c +LDFLAGS:=-L$(SCU_DIR)/libscu-c/ -lscu-c -lpthread ifeq ($(shell uname), Darwin) # libargp may be installed with homebrew diff --git a/libscu-c/src/scu.c b/libscu-c/src/scu.c index b0d60d3..4ba90e8 100644 --- a/libscu-c/src/scu.c +++ b/libscu-c/src/scu.c @@ -1,10 +1,10 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -296,13 +296,13 @@ _scu_get_time_diff(struct timespec startt, struct timespec endt) } static bool _scu_fatal_assert_jmpbuf_valid; -static pid_t _scu_fatal_assert_allowed_thread_id; +static pthread_t _scu_fatal_assert_allowed_thread_id; static jmp_buf _scu_fatal_assert_jmpbuf; -static pid_t +static pthread_t _scu_get_current_thread_id(void) { - return syscall(SYS_gettid); + return pthread_self(); } void From 7859cf1367aed12717c3fa77daf5bb58147e5df2 Mon Sep 17 00:00:00 2001 From: Carl-Johan Waldeck Date: Mon, 10 Apr 2023 12:06:22 +0000 Subject: [PATCH 3/3] Use void cast instead of self-assignement Self-assignment cause warnings in clang. Use void cast instead, once again silencing the warnigns. --- examples/initfail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/initfail.c b/examples/initfail.c index 546b001..7f223c3 100644 --- a/examples/initfail.c +++ b/examples/initfail.c @@ -2,7 +2,7 @@ int main(int argc, char **argv) { - argc = argc; - argv = argv; + (void) argc; + (void) argv; return 1; }