From dd040ba44605da3d186e76add85926423b588a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Mon, 18 May 2020 11:38:36 +0200 Subject: [PATCH 1/4] tests: Fix test_double_serializer without thread-local storage. --- tests/test_double_serializer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_double_serializer.c b/tests/test_double_serializer.c index 71ec8ec..8b2487a 100644 --- a/tests/test_double_serializer.c +++ b/tests/test_double_serializer.c @@ -59,6 +59,7 @@ int main() #else // Just fake it up, so the output matches. printf("obj.to_string(with thread format)=%s\n", "T0.52X"); + printf("obj.to_string(long thread format)=%s\n", "Ttttttttttttt0.52xxxxxxxxxxxxxxxxxxX"); printf("obj.to_string(back to global format)=%s\n", "x0.524y"); #endif if (json_c_set_serialization_double_format(NULL, JSON_C_OPTION_GLOBAL) < 0) From 78642dcb9b9b58bd0111ffba5e46b9346b8d486b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Mon, 18 May 2020 11:38:58 +0200 Subject: [PATCH 2/4] CMake: Add an option to disable the use of thread-local storage. Using thread-local storage may not be desired in all environments and/or use-cases, thus there should be an option to disable its use on purpose. Fixes #451. --- CMakeLists.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 254d324..180d6e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed" option(ENABLE_THREADING "Enable partial threading support." OFF) option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF) option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function" OFF) +option(DISABLE_THREAD_LOCAL_STORAGE "Disable Thread-Local Storage (HAVE___THREAD)" OFF) if (UNIX OR MINGW OR CYGWIN) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) @@ -217,14 +218,16 @@ check_c_source_compiles( "int main() { int i, x = 0; i = __sync_add_and_fetch(&x,1); return x; }" HAVE_ATOMIC_BUILTINS) -check_c_source_compiles( - "__thread int x = 0; int main() { return 0; }" - HAVE___THREAD) +if (NOT DISABLE_THREAD_LOCAL_STORAGE) + check_c_source_compiles( + "__thread int x = 0; int main() { return 0; }" + HAVE___THREAD) -if (HAVE___THREAD) - set(SPEC___THREAD __thread) -elseif (MSVC) - set(SPEC___THREAD __declspec(thread)) + if (HAVE___THREAD) + set(SPEC___THREAD __thread) + elseif (MSVC) + set(SPEC___THREAD __declspec(thread)) + endif() endif() # Hardware random number is not available on Windows? Says, config.h.win32. Best to preserve compatibility. From 76dd99abb24780d1f2a770d2534829aa76798492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Mon, 18 May 2020 12:26:47 +0200 Subject: [PATCH 3/4] CMake: Re-format config-option block and re-order it alphabetically. --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 180d6e9..901eb6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,11 +83,11 @@ COMMAND make package_source ) # Enable or disable features. By default, all features are turned off. -option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed" OFF) -option(ENABLE_THREADING "Enable partial threading support." OFF) -option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF) -option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function" OFF) -option(DISABLE_THREAD_LOCAL_STORAGE "Disable Thread-Local Storage (HAVE___THREAD)" OFF) +option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function." OFF) +option(DISABLE_THREAD_LOCAL_STORAGE "Disable using Thread-Local Storage (HAVE___THREAD)." OFF) +option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors." OFF) +option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed." OFF) +option(ENABLE_THREADING "Enable partial threading support." OFF) if (UNIX OR MINGW OR CYGWIN) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) From a85d2395fff0c806fe86f0446fb9ff1bbf2cb8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Mon, 18 May 2020 12:39:38 +0200 Subject: [PATCH 4/4] README: Update configuration options for CMake. --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f5a7ee3..5cabd9d 100644 --- a/README.md +++ b/README.md @@ -93,16 +93,17 @@ CMake Options The json-c library is built with [CMake](https://cmake.org/cmake-tutorial/), which can take a few options. -Variable | Type | Description ----------------------|--------|-------------- -CMAKE_INSTALL_PREFIX | String | The install location. -CMAKE_BUILD_TYPE | String | Defaults to "debug" -BUILD_SHARED_LIBS | Bool | The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library only. -BUILD_STATIC_LIBS | Bool | The default build generates a static (lib/a) library. Set this to OFF to create a shared library only. -ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed -ENABLE_THREADING | Bool | Enable partial threading support -DISABLE_WERROR | Bool | Disable use of -Werror -DISABLE_BSYMBOLIC | Bool | Disable use of -Bsymbolic-functions +Variable | Type | Description +-----------------------------|--------|-------------- +CMAKE_INSTALL_PREFIX | String | The install location. +CMAKE_BUILD_TYPE | String | Defaults to "debug". +BUILD_SHARED_LIBS | Bool | The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library only. +BUILD_STATIC_LIBS | Bool | The default build generates a static (lib/a) library. Set this to OFF to create a shared library only. +DISABLE_BSYMBOLIC | Bool | Disable use of -Bsymbolic-functions. +DISABLE_THREAD_LOCAL_STORAGE | Bool | Disable use of Thread-Local Storage (HAVE___THREAD). +DISABLE_WERROR | Bool | Disable use of -Werror. +ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed. +ENABLE_THREADING | Bool | Enable partial threading support. Pass these options as `-D` on CMake's command-line.