summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Hawicz <erh+git@nimenees.com>2020-05-18 10:25:54 -0400
committerGitHub <noreply@github.com>2020-05-18 10:25:54 -0400
commita8a0590921730f4bb98fe0d8f7369a5fc2c79560 (patch)
tree38ae52c75f383e4a051945f3663a62158292181e
parent5b15c7567d05a6ad834c96461766340c187dfcc9 (diff)
parenta85d2395fff0c806fe86f0446fb9ff1bbf2cb8e5 (diff)
downloadjson-c-a8a0590921730f4bb98fe0d8f7369a5fc2c79560.tar.gz
Merge pull request #617 from besser82/topic/besser82/option_disable_tls
Add an option to disable the use of thread-local storage.
-rw-r--r--CMakeLists.txt25
-rw-r--r--README.md21
-rw-r--r--tests/test_double_serializer.c1
3 files changed, 26 insertions, 21 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 254d324..901eb6e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,10 +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_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)
@@ -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.
diff --git a/README.md b/README.md
index f5a7ee3..5cabd9d 100644
--- a/README.md
+++ b/README.md
@@ -93,16 +93,17 @@ CMake Options <a name="CMake"></a>
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.
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)