mirror of
https://github.com/nlohmann/json.git
synced 2026-10-21 13:38:16 +00:00
Encode JSON_VIEW_NO_SIMD and JSON_VIEW_USE_SSSE3 in the ABI namespace
Both macros select between definitions of the same inline functions, so translation units that disagree on them violated the ODR. Like the other ABI-affecting macros, they now add a tag to the inline namespace (_vns and _vssse3), and the docs replace the "Define consistently" warning with the usual ABI compatibility note. From gregmarr's review of #5628. nlohmann_json.natvis covers twice as many tags now, so it lists four times as many namespaces (14.7 MB instead of 3.4 MB). Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
9 files changed
+454711
-17
No files matched your search
@@ -14,10 +14,12 @@ The same input is accepted or rejected either way, with the same values, and err
|
|||||||
the speed differs. The macro exists for platforms whose compilers lack the intrinsics headers, and to test the portable
|
the speed differs. The macro exists for platforms whose compilers lack the intrinsics headers, and to test the portable
|
||||||
code.
|
code.
|
||||||
|
|
||||||
!!! warning "Define consistently"
|
!!! note "ABI compatibility"
|
||||||
|
|
||||||
The macro selects between two definitions of the same inline functions. It must therefore be defined identically for
|
The macro selects between two definitions of the same inline functions. Whether it is defined is encoded in the
|
||||||
**every** translation unit that includes `<nlohmann/json_view.hpp>`; prefer a compile definition on the target.
|
[namespace](../../features/namespace.md) (tag `_vns`), resulting in distinct symbol names. Translation units
|
||||||
|
compiled with and without it can therefore be linked into the same program without One Definition Rule (ODR)
|
||||||
|
violations, but they cannot exchange instances of library types.
|
||||||
|
|
||||||
## Default definition
|
## Default definition
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ Define the macro only together with a compiler option that enables SSSE3 (e.g. `
|
|||||||
has it), and only for programs that run on such CPUs. It saves the check of the CPU, which costs little. The same
|
has it), and only for programs that run on such CPUs. It saves the check of the CPU, which costs little. The same
|
||||||
input is accepted or rejected either way; only the speed of non-ASCII text differs.
|
input is accepted or rejected either way; only the speed of non-ASCII text differs.
|
||||||
|
|
||||||
!!! warning "Define consistently"
|
!!! note "ABI compatibility"
|
||||||
|
|
||||||
The macro selects between two definitions of the same inline functions. It must therefore be defined identically,
|
The macro selects between two definitions of the same inline functions. Whether it is defined is encoded in the
|
||||||
with the same compiler options, for **every** translation unit that includes `<nlohmann/json_view.hpp>`; mixing
|
[namespace](../../features/namespace.md) (tag `_vssse3`, on every architecture), resulting in distinct symbol
|
||||||
translation units that define it with ones that do not is an ODR violation. Prefer a compile definition on the
|
names. Translation units compiled with and without it can therefore be linked into the same program without One
|
||||||
target.
|
Definition Rule (ODR) violations, but they cannot exchange instances of library types.
|
||||||
|
|
||||||
## Default definition
|
## Default definition
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,6 @@ the library.
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.11.0. Changed inline namespace name in version 3.11.2. Added the ABI tag `_dp` in
|
- Added in version 3.11.0. Changed inline namespace name in version 3.11.2. Added the ABI tag `_dp` in
|
||||||
version 3.12.0, and the ABI tags `_bics`, `_psp`, `_snul`, `_sbu8`, `_ekmo`, `_dsbs`, and `_dufio` in version
|
version 3.12.0, and the ABI tags `_bics`, `_psp`, `_snul`, `_sbu8`, `_ekmo`, `_dsbs`, `_dufio`, `_vns`, and
|
||||||
3.13.0; see
|
`_vssse3` in version 3.13.0; see
|
||||||
[`nlohmann` Namespace](../../features/namespace.md#structure).
|
[`nlohmann` Namespace](../../features/namespace.md#structure).
|
||||||
@@ -27,6 +27,8 @@ The complete default namespace name is derived as follows:
|
|||||||
`_dsbs`.
|
`_dsbs`.
|
||||||
- [`JSON_DISABLE_UNLOCKED_FILE_IO`](../api/macros/json_disable_unlocked_file_io.md) defined non-zero appends
|
- [`JSON_DISABLE_UNLOCKED_FILE_IO`](../api/macros/json_disable_unlocked_file_io.md) defined non-zero appends
|
||||||
`_dufio`.
|
`_dufio`.
|
||||||
|
- [`JSON_VIEW_NO_SIMD`](../api/macros/json_view_no_simd.md) defined appends `_vns`.
|
||||||
|
- [`JSON_VIEW_USE_SSSE3`](../api/macros/json_view_use_ssse3.md) defined appends `_vssse3`.
|
||||||
- The inline namespace ends with the suffix `_v` followed by the 3 components of the version number separated by
|
- The inline namespace ends with the suffix `_v` followed by the 3 components of the version number separated by
|
||||||
underscores. To omit the version component, see [Disabling the version component](#disabling-the-version-component)
|
underscores. To omit the version component, see [Disabling the version component](#disabling-the-version-component)
|
||||||
below.
|
below.
|
||||||
@@ -111,5 +113,7 @@ follows:
|
|||||||
([`JSON_STRICT_NUL_HANDLING`](../api/macros/json_strict_nul_handling.md)), `_sbu8`
|
([`JSON_STRICT_NUL_HANDLING`](../api/macros/json_strict_nul_handling.md)), `_sbu8`
|
||||||
([`JSON_STRICT_BINARY_UTF8`](../api/macros/json_strict_binary_utf8.md)), `_ekmo`
|
([`JSON_STRICT_BINARY_UTF8`](../api/macros/json_strict_binary_utf8.md)), `_ekmo`
|
||||||
([`JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS`](../api/macros/json_use_objects_for_enum_keyed_maps.md)), `_dsbs`
|
([`JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS`](../api/macros/json_use_objects_for_enum_keyed_maps.md)), `_dsbs`
|
||||||
([`JSON_DISABLE_STREAM_BULK_SCAN`](../api/macros/json_disable_stream_bulk_scan.md)), and `_dufio`
|
([`JSON_DISABLE_STREAM_BULK_SCAN`](../api/macros/json_disable_stream_bulk_scan.md)), `_dufio`
|
||||||
([`JSON_DISABLE_UNLOCKED_FILE_IO`](../api/macros/json_disable_unlocked_file_io.md)) in version 3.13.0.
|
([`JSON_DISABLE_UNLOCKED_FILE_IO`](../api/macros/json_disable_unlocked_file_io.md)), `_vns`
|
||||||
|
([`JSON_VIEW_NO_SIMD`](../api/macros/json_view_no_simd.md)), and `_vssse3`
|
||||||
|
([`JSON_VIEW_USE_SSSE3`](../api/macros/json_view_use_ssse3.md)) in version 3.13.0.
|
||||||
@@ -122,14 +122,26 @@
|
|||||||
#define NLOHMANN_JSON_ABI_TAG_DISABLE_UNLOCKED_FILE_IO
|
#define NLOHMANN_JSON_ABI_TAG_DISABLE_UNLOCKED_FILE_IO
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef JSON_VIEW_NO_SIMD
|
||||||
|
#define NLOHMANN_JSON_ABI_TAG_VIEW_NO_SIMD _vns
|
||||||
|
#else
|
||||||
|
#define NLOHMANN_JSON_ABI_TAG_VIEW_NO_SIMD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JSON_VIEW_USE_SSSE3
|
||||||
|
#define NLOHMANN_JSON_ABI_TAG_VIEW_USE_SSSE3 _vssse3
|
||||||
|
#else
|
||||||
|
#define NLOHMANN_JSON_ABI_TAG_VIEW_USE_SSSE3
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
|
#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
|
||||||
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
|
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Construct the namespace ABI tags component
|
// Construct the namespace ABI tags component
|
||||||
#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c, d, e, f, g, h, i, j) json_abi ## a ## b ## c ## d ## e ## f ## g ## h ## i ## j
|
#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c, d, e, f, g, h, i, j, k, l) json_abi ## a ## b ## c ## d ## e ## f ## g ## h ## i ## j ## k ## l
|
||||||
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b, c, d, e, f, g, h, i, j) \
|
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b, c, d, e, f, g, h, i, j, k, l) \
|
||||||
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c, d, e, f, g, h, i, j)
|
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c, d, e, f, g, h, i, j, k, l)
|
||||||
|
|
||||||
#define NLOHMANN_JSON_ABI_TAGS \
|
#define NLOHMANN_JSON_ABI_TAGS \
|
||||||
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
|
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
|
||||||
@@ -142,7 +154,9 @@
|
|||||||
NLOHMANN_JSON_ABI_TAG_STRICT_BINARY_UTF8, \
|
NLOHMANN_JSON_ABI_TAG_STRICT_BINARY_UTF8, \
|
||||||
NLOHMANN_JSON_ABI_TAG_OBJECTS_FOR_ENUM_KEYED_MAPS, \
|
NLOHMANN_JSON_ABI_TAG_OBJECTS_FOR_ENUM_KEYED_MAPS, \
|
||||||
NLOHMANN_JSON_ABI_TAG_DISABLE_STREAM_BULK_SCAN, \
|
NLOHMANN_JSON_ABI_TAG_DISABLE_STREAM_BULK_SCAN, \
|
||||||
NLOHMANN_JSON_ABI_TAG_DISABLE_UNLOCKED_FILE_IO)
|
NLOHMANN_JSON_ABI_TAG_DISABLE_UNLOCKED_FILE_IO, \
|
||||||
|
NLOHMANN_JSON_ABI_TAG_VIEW_NO_SIMD, \
|
||||||
|
NLOHMANN_JSON_ABI_TAG_VIEW_USE_SSSE3)
|
||||||
|
|
||||||
// Construct the namespace version component
|
// Construct the namespace version component
|
||||||
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
|
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
|
||||||
|
|||||||
Generated
+454656
File diff suppressed because it is too large.
Load diff
@@ -23,7 +23,9 @@ foreach(test default noversion)
|
|||||||
JSON_DIAGNOSTIC_POSITIONS=1
|
JSON_DIAGNOSTIC_POSITIONS=1
|
||||||
JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1
|
JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1
|
||||||
JSON_DISABLE_STREAM_BULK_SCAN=1
|
JSON_DISABLE_STREAM_BULK_SCAN=1
|
||||||
JSON_DISABLE_UNLOCKED_FILE_IO=1)
|
JSON_DISABLE_UNLOCKED_FILE_IO=1
|
||||||
|
JSON_VIEW_NO_SIMD
|
||||||
|
JSON_VIEW_USE_SSSE3)
|
||||||
target_link_libraries(abi_config_${test}_all_tags PRIVATE abi_compat_main)
|
target_link_libraries(abi_config_${test}_all_tags PRIVATE abi_compat_main)
|
||||||
add_test(
|
add_test(
|
||||||
NAME test-abi_config_${test}_all_tags
|
NAME test-abi_config_${test}_all_tags
|
||||||
|
|||||||
@@ -60,6 +60,14 @@ TEST_CASE("default namespace")
|
|||||||
expected += "_dufio";
|
expected += "_dufio";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef JSON_VIEW_NO_SIMD
|
||||||
|
expected += "_vns";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JSON_VIEW_USE_SSSE3
|
||||||
|
expected += "_vssse3";
|
||||||
|
#endif
|
||||||
|
|
||||||
expected += "_v" STRINGIZE(NLOHMANN_JSON_VERSION_MAJOR);
|
expected += "_v" STRINGIZE(NLOHMANN_JSON_VERSION_MAJOR);
|
||||||
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_MINOR);
|
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_MINOR);
|
||||||
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json";
|
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json";
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ TEST_CASE("default namespace without version component")
|
|||||||
expected += "_dufio";
|
expected += "_dufio";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef JSON_VIEW_NO_SIMD
|
||||||
|
expected += "_vns";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JSON_VIEW_USE_SSSE3
|
||||||
|
expected += "_vssse3";
|
||||||
|
#endif
|
||||||
|
|
||||||
expected += "::basic_json";
|
expected += "::basic_json";
|
||||||
|
|
||||||
// fallback for Clang
|
// fallback for Clang
|
||||||
|
|||||||
Reference in new issue
Block a user