mirror of
https://github.com/nlohmann/json.git
synced 2026-10-19 12:38:12 +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
+113719
-16
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,5 +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`, and `_ekmo` in version 3.13.0; see
|
version 3.12.0, and the ABI tags `_bics`, `_psp`, `_snul`, `_sbu8`, `_ekmo`, `_vns`, and `_vssse3` in version
|
||||||
|
3.13.0; see
|
||||||
[`nlohmann` Namespace](../../features/namespace.md#structure).
|
[`nlohmann` Namespace](../../features/namespace.md#structure).
|
||||||
@@ -23,6 +23,8 @@ The complete default namespace name is derived as follows:
|
|||||||
- [`JSON_STRICT_BINARY_UTF8`](../api/macros/json_strict_binary_utf8.md) defined non-zero appends `_sbu8`.
|
- [`JSON_STRICT_BINARY_UTF8`](../api/macros/json_strict_binary_utf8.md) defined non-zero appends `_sbu8`.
|
||||||
- [`JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS`](../api/macros/json_use_objects_for_enum_keyed_maps.md) defined non-zero
|
- [`JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS`](../api/macros/json_use_objects_for_enum_keyed_maps.md) defined non-zero
|
||||||
appends `_ekmo`.
|
appends `_ekmo`.
|
||||||
|
- [`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.
|
||||||
@@ -105,5 +107,7 @@ follows:
|
|||||||
- Added ABI tags `_bics` ([`JSON_BRACE_INIT_COPY_SEMANTICS`](../api/macros/json_brace_init_copy_semantics.md)), `_psp`
|
- Added ABI tags `_bics` ([`JSON_BRACE_INIT_COPY_SEMANTICS`](../api/macros/json_brace_init_copy_semantics.md)), `_psp`
|
||||||
([`JSON_PRECISE_STREAM_POSITION`](../api/macros/json_precise_stream_position.md)), `_snul`
|
([`JSON_PRECISE_STREAM_POSITION`](../api/macros/json_precise_stream_position.md)), `_snul`
|
||||||
([`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)), and `_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)) in version 3.13.0.
|
([`JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS`](../api/macros/json_use_objects_for_enum_keyed_maps.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.
|
||||||
@@ -102,14 +102,26 @@
|
|||||||
#define NLOHMANN_JSON_ABI_TAG_OBJECTS_FOR_ENUM_KEYED_MAPS
|
#define NLOHMANN_JSON_ABI_TAG_OBJECTS_FOR_ENUM_KEYED_MAPS
|
||||||
#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) json_abi ## a ## b ## c ## d ## e ## f ## g ## h
|
#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(a, b, c, d, e, f, g, h) \
|
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b, c, d, e, f, g, h, i, j) \
|
||||||
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c, d, e, f, g, h)
|
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c, d, e, f, g, h, i, j)
|
||||||
|
|
||||||
#define NLOHMANN_JSON_ABI_TAGS \
|
#define NLOHMANN_JSON_ABI_TAGS \
|
||||||
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
|
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
|
||||||
@@ -120,7 +132,9 @@
|
|||||||
NLOHMANN_JSON_ABI_TAG_PRECISE_STREAM_POSITION, \
|
NLOHMANN_JSON_ABI_TAG_PRECISE_STREAM_POSITION, \
|
||||||
NLOHMANN_JSON_ABI_TAG_STRICT_NUL_HANDLING, \
|
NLOHMANN_JSON_ABI_TAG_STRICT_NUL_HANDLING, \
|
||||||
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_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
+113664
File diff suppressed because it is too large.
Load diff
@@ -21,7 +21,9 @@ foreach(test default noversion)
|
|||||||
target_compile_definitions(abi_config_${test}_all_tags PRIVATE
|
target_compile_definitions(abi_config_${test}_all_tags PRIVATE
|
||||||
JSON_DIAGNOSTICS=1
|
JSON_DIAGNOSTICS=1
|
||||||
JSON_DIAGNOSTIC_POSITIONS=1
|
JSON_DIAGNOSTIC_POSITIONS=1
|
||||||
JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1)
|
JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=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
|
||||||
|
|||||||
@@ -52,6 +52,14 @@ TEST_CASE("default namespace")
|
|||||||
expected += "_ekmo";
|
expected += "_ekmo";
|
||||||
#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";
|
||||||
|
|||||||
@@ -53,6 +53,14 @@ TEST_CASE("default namespace without version component")
|
|||||||
expected += "_ekmo";
|
expected += "_ekmo";
|
||||||
#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