From 15542970281433925942efc111dd895652e569f7 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 31 Mar 2017 00:11:04 +0300 Subject: [PATCH] Fix gc.h compliance to strict ANSI (pthreads) If -std=cXX option is passed to gcc/clang then sigset_t is undefined, thus GC_pthread_sigmask declaration should be omitted. However, this symbol should be available during GC source code audit by cppcheck. * include/gc_pthread_redirects.h [!GC_NO_PTHREAD_SIGMASK] (GC_pthread_sigmask): Declare only if GC_PTHREAD_SIGMASK_NEEDED or _POSIX_C_SOURCE >= 199506 or _XOPEN_SOURCE >= 500. * tests/test.c [CPPCHECK] (GC_PTHREAD_SIGMASK_NEEDED): Define (before include gc.h). * tests/test.c [CPPCHECK && !_GNU_SOURCE] (_GNU_SOURCE): Likewise. --- include/gc_pthread_redirects.h | 4 +++- tests/test.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/gc_pthread_redirects.h b/include/gc_pthread_redirects.h index 21e2808d..4e7964bd 100644 --- a/include/gc_pthread_redirects.h +++ b/include/gc_pthread_redirects.h @@ -42,7 +42,9 @@ GC_API void *GC_dlopen(const char * /* path */, int /* mode */); # endif /* !GC_NO_DLOPEN */ -# ifndef GC_NO_PTHREAD_SIGMASK +# if !defined(GC_NO_PTHREAD_SIGMASK) \ + && (defined(GC_PTHREAD_SIGMASK_NEEDED) \ + || _POSIX_C_SOURCE >= 199506L || _XOPEN_SOURCE >= 500) # include GC_API int GC_pthread_sigmask(int /* how */, const sigset_t *, sigset_t * /* oset */); diff --git a/tests/test.c b/tests/test.c index 9fe1671c..c6a9e860 100644 --- a/tests/test.c +++ b/tests/test.c @@ -29,6 +29,12 @@ # define GC_DEBUG #endif +#ifdef CPPCHECK +# define GC_PTHREAD_SIGMASK_NEEDED +# ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +# endif +#endif #undef GC_NO_THREAD_REDIRECTS #include "gc.h" -- 2.40.0