From b2cb485268b1290b6c0984c328fd5ffbddfada78 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 6 Feb 2020 13:15:48 -0600 Subject: Provide C99/POSIX.1 format strings PRI[doux]{8,16,32,64,MAX,PTR} on systems that are missing . --- src/H5public.h | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/H5public.h b/src/H5public.h index 86a1fbb..3312cf4 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -51,7 +51,45 @@ # endif #endif #ifdef H5_HAVE_INTTYPES_H -# include /* For uint64_t on some platforms */ +# include /* C99/POSIX.1 header for uint64_t, PRIu64 */ +#else /* H5_HAVE_INTTYPES_H */ +/* The following definitions should be suitable for 64-bit Windows, which is + * LLP64, and for 32-bit Windows, which is ILP32. Those are the only + * platforms where is likely to be missing. VS2015 and later + * *may* provide these definitions. + */ +#ifdef _WIN64 +# define PRIdPTR "lld" +# define PRIoPTR "llo" +# define PRIuPTR "llu" +# define PRIxPTR "llx" +#else /* _WIN64 */ +# define PRIdPTR "ld" +# define PRIoPTR "lo" +# define PRIuPTR "lu" +# define PRIxPTR "lx" +#endif /* _WIN64 */ + +# define PRId8 "d" +# define PRIo8 "o" +# define PRIu8 "u" +# define PRIx8 "x" +# define PRId16 "d" +# define PRIo16 "o" +# define PRIu16 "u" +# define PRIx16 "x" +# define PRId32 "d" +# define PRIo32 "o" +# define PRIu32 "u" +# define PRIx32 "x" +# define PRId64 "lld" +# define PRIo64 "llo" +# define PRIu64 "llu" +# define PRIx64 "llx" +# define PRIdMAX "lld" +# define PRIoMAX "llo" +# define PRIuMAX "llu" +# define PRIxMAX "llx" #endif #ifdef H5_HAVE_STDDEF_H # include -- cgit v0.12 From c7ad81b0ea0eab3a48a13b094aad65587f30aa27 Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 7 Feb 2020 14:45:08 -0600 Subject: Provide local copies of err(3)- and errx(3)-alike functions for Visual Studio compatibility. --- test/thread_id.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/test/thread_id.c b/test/thread_id.c index 9b289fa..21be12d 100644 --- a/test/thread_id.c +++ b/test/thread_id.c @@ -18,7 +18,6 @@ * 3 No two threads share an ID during their lifetimes. * 4 A thread's ID is available for reuse as soon as it is joined. */ -#include /* * Include required headers. This file tests internal library functions, @@ -26,10 +25,41 @@ */ #include "testhdf5.h" +static void my_errx(int, const char *, ...) H5_ATTR_FORMAT(printf, 2, 3); + +static void +my_errx(int code, const char *fmt, ...) +{ + va_list ap; + + (void)fprintf(stderr, "thread_id: "); + va_start(ap, fmt); + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + (void)fputc('\n', stderr); + exit(code); +} + #if defined(H5_HAVE_THREADSAFE) && !defined(H5_HAVE_WIN_THREADS) +static void my_err(int, const char *, ...) H5_ATTR_FORMAT(printf, 2, 3); + +static void +my_err(int code, const char *fmt, ...) +{ + va_list ap; + int errno_copy = errno; + + (void)fprintf(stderr, "thread_id: "); + va_start(ap, fmt); + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + (void)fprintf(stderr, ": %s\n", strerror(errno_copy)); + exit(code); +} + #define threads_failure(_call, _result) do { \ - errx(EXIT_FAILURE, "%s.%d: " #_call ": %s", __func__, \ + my_errx(EXIT_FAILURE, "%s.%d: " #_call ": %s", __func__, \ __LINE__, strerror(_result)); \ } while (false) @@ -52,13 +82,13 @@ atomic_printf(const char *fmt, ...) va_end(ap); if (nprinted == -1) - err(EXIT_FAILURE, "%s.%d: vsnprintf", __func__, __LINE__); + my_err(EXIT_FAILURE, "%s.%d: vsnprintf", __func__, __LINE__); else if (nprinted >= (ssize_t)sizeof(buf)) - errx(EXIT_FAILURE, "%s.%d: vsnprintf overflowed", __func__, __LINE__); + my_errx(EXIT_FAILURE, "%s.%d: vsnprintf overflowed", __func__, __LINE__); nwritten = write(STDOUT_FILENO, buf, (size_t)nprinted); if (nwritten < nprinted) { - errx(EXIT_FAILURE, "%s.%d: write error or short write", + my_errx(EXIT_FAILURE, "%s.%d: write error or short write", __func__, __LINE__); } } @@ -114,7 +144,7 @@ main(void) * mutex, etc. */ if (H5open() != SUCCEED) - errx(EXIT_FAILURE, "%s.%d: H5open failed", __func__, __LINE__); + my_errx(EXIT_FAILURE, "%s.%d: H5open failed", __func__, __LINE__); if ((rc = pthread_mutex_init(&used_lock, NULL)) == -1) threads_failure(pthread_mutex_init, rc); @@ -144,7 +174,7 @@ main(void) for (i = 0; i < NTHREADS; i++) { if (!used[i]) // access synchronized by thread create/join - errx(EXIT_FAILURE, "thread ID %d did not run.", i + 1); + my_errx(EXIT_FAILURE, "thread ID %d did not run.", i + 1); } } if ((rc = pthread_barrier_destroy(&barrier)) != 0) -- cgit v0.12 From 39fd512fe7475590598541e494d4cef82c452ac8 Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 7 Feb 2020 14:57:46 -0600 Subject: Make sure that H5TS_thread_id() is available as either a function or a macro in all configurations. Previously it was neither declared nor defined in --disable-threadsafety builds. The compiler's warning got lost in the noise---I first saw the issue because my -Werror branch stopped compiling cold---and the tests still linked and ran. --- src/H5TS.c | 9 --------- src/H5private.h | 8 +++++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/H5TS.c b/src/H5TS.c index 7a801e2..9503e05 100644 --- a/src/H5TS.c +++ b/src/H5TS.c @@ -639,13 +639,4 @@ H5TS_create_thread(void *(*func)(void *), H5TS_attr_t *attr, void *udata) } /* H5TS_create_thread */ -#else /* H5_HAVE_THREADSAFE */ - -uint64_t -H5TS_thread_id(void) -{ - return 0; -} - #endif /* H5_HAVE_THREADSAFE */ - diff --git a/src/H5private.h b/src/H5private.h index f0f3687..2f5a727 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1897,12 +1897,14 @@ H5_DLL double H5_trace(const double *calltime, const char *func, const char *typ /* global library version information string */ extern char H5_lib_vers_info_g[]; +/* Include required thread-safety header, always, for the H5TS_thread_id() + * definition. + */ +#include "H5TSprivate.h" + /* Lock headers */ #ifdef H5_HAVE_THREADSAFE -/* Include required thread-safety header */ -#include "H5TSprivate.h" - /* replacement structure for original global variable */ typedef struct H5_api_struct { H5TS_mutex_t init_lock; /* API entrance mutex */ -- cgit v0.12 From 3d2c0d7b0d3d41d88552d13d482bd264ec4e6269 Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 10 Feb 2020 13:31:56 -0600 Subject: Delete unhelpful comment per Jordan's question. --- src/H5private.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/H5private.h b/src/H5private.h index 2f5a727..700fe8a 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1897,9 +1897,6 @@ H5_DLL double H5_trace(const double *calltime, const char *func, const char *typ /* global library version information string */ extern char H5_lib_vers_info_g[]; -/* Include required thread-safety header, always, for the H5TS_thread_id() - * definition. - */ #include "H5TSprivate.h" /* Lock headers */ -- cgit v0.12 From b4697f969295245840350e17d75d92a0fdd7e7a9 Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 12 Feb 2020 14:07:47 -0600 Subject: Use HD prefix. --- test/thread_id.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/thread_id.c b/test/thread_id.c index 21be12d..af36625 100644 --- a/test/thread_id.c +++ b/test/thread_id.c @@ -32,12 +32,12 @@ my_errx(int code, const char *fmt, ...) { va_list ap; - (void)fprintf(stderr, "thread_id: "); - va_start(ap, fmt); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fputc('\n', stderr); - exit(code); + (void)HDfprintf(stderr, "thread_id: "); + HDva_start(ap, fmt); + (void)HDvfprintf(stderr, fmt, ap); + HDva_end(ap); + (void)HDfputc('\n', stderr); + HDexit(code); } #if defined(H5_HAVE_THREADSAFE) && !defined(H5_HAVE_WIN_THREADS) @@ -50,17 +50,17 @@ my_err(int code, const char *fmt, ...) va_list ap; int errno_copy = errno; - (void)fprintf(stderr, "thread_id: "); - va_start(ap, fmt); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, ": %s\n", strerror(errno_copy)); - exit(code); + (void)HDfprintf(stderr, "thread_id: "); + HDva_start(ap, fmt); + (void)HDvfprintf(stderr, fmt, ap); + HDva_end(ap); + (void)HDfprintf(stderr, ": %s\n", HDstrerror(errno_copy)); + HDexit(code); } #define threads_failure(_call, _result) do { \ my_errx(EXIT_FAILURE, "%s.%d: " #_call ": %s", __func__, \ - __LINE__, strerror(_result)); \ + __LINE__, HDstrerror(_result)); \ } while (false) #define NTHREADS 5 -- cgit v0.12