Skip to content
/ ports Public

Commit 761d3b8

Browse files
committed
Update to nlohmann-json 3.12.0
One test breaks because OpenBSD doesn't support LC_NUMERIC. Pull in an upstream fix for incorrect char8_t support with C++20 to unbreak the build of games/openrtc2 https://github.com/nlohmann/json/releases/tag/v3.11.3 https://github.com/nlohmann/json/releases/tag/v3.12.0 nlohmann/json#4736
1 parent 9661be6 commit 761d3b8

7 files changed

Lines changed: 146 additions & 4 deletions

textproc/nlohmann-json/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
COMMENT = JSON for modern C++
22

33
# the "release" contain only json.hpp, and we want tests and CMake config file
4-
V = 3.11.2
4+
V = 3.12.0
55
DIST_TUPLE = github nlohmann json v${V} .
66
PKGNAME = nlohmann-json-${V}
7-
REVISION = 0
87

98
TEST_DATA_DIR = tests/test_data
109
DIST_TUPLE += github nlohmann json_test_data v3.1.0 ${TEST_DATA_DIR}
@@ -29,6 +28,14 @@ NO_BUILD = Yes
2928
pre-test:
3029
@${MODCMAKE_BUILD_TARGET}
3130

31+
# One test fails due to lack of LC_NUMERIC support in OpenBSD:
32+
# 49: /usr/ports/pobj/nlohmann-json-3.12.0/json-3.12.0/tests/src/unit-locale-cpp.cpp:134:
33+
# 49: TEST CASE: locale-dependent test (LC_NUMERIC=de_DE)
34+
# 49: check if locale is properly set
35+
# 49:
36+
# 49: /usr/ports/pobj/nlohmann-json-3.12.0/json-3.12.0/tests/src/unit-locale-cpp.cpp:142: ERROR: CHECK( std::string(buffer.data()) == "12,34" ) is NOT correct!
37+
# 49: values: CHECK( 12.34 == 12,34 )
38+
3239
# overwrite target, devel/cmake MODULE cannot pass ctest(1) arguments
3340
do-test:
3441
# skip known to tail tests

textproc/nlohmann-json/distinfo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SHA256 (nlohmann-json-v3.11.2.tar.gz) = 1p+d62p14lgEZcbExREbicTcL6lOOoX80v/NmhQ9knM=
1+
SHA256 (nlohmann-json-v3.12.0.tar.gz) = S5LrDAbRBoP3RHzpQGy5fNS0U74Y1yeTIPey8CXBAYc=
22
SHA256 (nlohmann-json_test_data-v3.1.0.tar.gz) = iEseIfOM/WpiwVnxt+Co9RaK5dqqOE7U3AwPpmYPIb0=
3-
SIZE (nlohmann-json-v3.11.2.tar.gz) = 8097673
3+
SIZE (nlohmann-json-v3.12.0.tar.gz) = 9678593
44
SIZE (nlohmann-json_test_data-v3.1.0.tar.gz) = 115036393
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
https://github.com/nlohmann/json/pull/4736/commits/34868f90149de02432ea758a29227a6ad74f098c
2+
3+
Index: include/nlohmann/detail/conversions/from_json.hpp
4+
--- include/nlohmann/detail/conversions/from_json.hpp.orig
5+
+++ include/nlohmann/detail/conversions/from_json.hpp
6+
@@ -540,7 +540,10 @@ inline void from_json(const BasicJsonType& j, std_fs::
7+
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
8+
}
9+
const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
10+
-#ifdef JSON_HAS_CPP_20
11+
+ // Checking for C++20 standard or later can be insufficient in case the
12+
+ // library support for char8_t is either incomplete or was disabled
13+
+ // altogether. Use the __cpp_lib_char8_t feature test instead.
14+
+#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
15+
p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size()));
16+
#else
17+
p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
https://github.com/nlohmann/json/pull/4736/commits/34868f90149de02432ea758a29227a6ad74f098c
2+
3+
Index: include/nlohmann/detail/conversions/to_json.hpp
4+
--- include/nlohmann/detail/conversions/to_json.hpp.orig
5+
+++ include/nlohmann/detail/conversions/to_json.hpp
6+
@@ -15,7 +15,8 @@
7+
8+
#include <algorithm> // copy
9+
#include <iterator> // begin, end
10+
-#include <string> // string
11+
+#include <memory> // allocator_traits
12+
+#include <string> // basic_string, char_traits
13+
#include <tuple> // tuple, get
14+
#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
15+
#include <utility> // move, forward, declval, pair
16+
@@ -440,15 +441,21 @@ inline void to_json(BasicJsonType& j, const T& t)
17+
}
18+
19+
#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
20+
+#if defined(__cpp_lib_char8_t)
21+
+template<typename BasicJsonType, typename Tr, typename Allocator>
22+
+inline void to_json(BasicJsonType& j, const std::basic_string<char8_t, Tr, Allocator>& s)
23+
+{
24+
+ using OtherAllocator = typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
25+
+ j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator());
26+
+}
27+
+#endif
28+
+
29+
template<typename BasicJsonType>
30+
inline void to_json(BasicJsonType& j, const std_fs::path& p)
31+
{
32+
-#ifdef JSON_HAS_CPP_20
33+
- const std::u8string s = p.u8string();
34+
- j = std::string(s.begin(), s.end());
35+
-#else
36+
- j = p.u8string(); // returns std::string in C++17
37+
-#endif
38+
+ // Returns either a std::string or a std::u8string depending whether library
39+
+ // support for char8_t is enabled.
40+
+ j = p.u8string();
41+
}
42+
#endif
43+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
https://github.com/nlohmann/json/pull/4736/commits/34868f90149de02432ea758a29227a6ad74f098c
2+
3+
Index: single_include/nlohmann/json.hpp
4+
--- single_include/nlohmann/json.hpp.orig
5+
+++ single_include/nlohmann/json.hpp
6+
@@ -5325,7 +5325,10 @@ inline void from_json(const BasicJsonType& j, std_fs::
7+
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
8+
}
9+
const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
10+
-#ifdef JSON_HAS_CPP_20
11+
+ // Checking for C++20 standard or later can be insufficient in case the
12+
+ // library support for char8_t is either incomplete or was disabled
13+
+ // altogether. Use the __cpp_lib_char8_t feature test instead.
14+
+#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
15+
p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size()));
16+
#else
17+
p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20
18+
@@ -5380,7 +5383,8 @@ NLOHMANN_JSON_NAMESPACE_END
19+
20+
#include <algorithm> // copy
21+
#include <iterator> // begin, end
22+
-#include <string> // string
23+
+#include <memory> // allocator_traits
24+
+#include <string> // basic_string, char_traits
25+
#include <tuple> // tuple, get
26+
#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
27+
#include <utility> // move, forward, declval, pair
28+
@@ -6087,15 +6091,21 @@ inline void to_json(BasicJsonType& j, const T& t)
29+
}
30+
31+
#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
32+
+#if defined(__cpp_lib_char8_t)
33+
+template<typename BasicJsonType, typename Tr, typename Allocator>
34+
+inline void to_json(BasicJsonType& j, const std::basic_string<char8_t, Tr, Allocator>& s)
35+
+{
36+
+ using OtherAllocator = typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
37+
+ j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator());
38+
+}
39+
+#endif
40+
+
41+
template<typename BasicJsonType>
42+
inline void to_json(BasicJsonType& j, const std_fs::path& p)
43+
{
44+
-#ifdef JSON_HAS_CPP_20
45+
- const std::u8string s = p.u8string();
46+
- j = std::string(s.begin(), s.end());
47+
-#else
48+
- j = p.u8string(); // returns std::string in C++17
49+
-#endif
50+
+ // Returns either a std::string or a std::u8string depending whether library
51+
+ // support for char8_t is enabled.
52+
+ j = p.u8string();
53+
}
54+
#endif
55+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
https://github.com/nlohmann/json/pull/4736/commits/34868f90149de02432ea758a29227a6ad74f098c
2+
3+
Index: tests/src/unit-deserialization.cpp
4+
--- tests/src/unit-deserialization.cpp.orig
5+
+++ tests/src/unit-deserialization.cpp
6+
@@ -1134,9 +1134,10 @@ TEST_CASE("deserialization")
7+
}
8+
}
9+
10+
-// select the types to test - char8_t is only available in C++20
11+
+// select the types to test - char8_t is only available since C++20 if and only
12+
+// if __cpp_char8_t is defined.
13+
#define TYPE_LIST(...) __VA_ARGS__
14+
-#ifdef JSON_HAS_CPP_20
15+
+#if defined(__cpp_char8_t) && (__cpp_char8_t >= 201811L)
16+
#define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t, char8_t)
17+
#else
18+
#define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t)

textproc/nlohmann-json/pkg/PLIST

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ include/nlohmann/detail/iterators/iteration_proxy.hpp
2323
include/nlohmann/detail/iterators/iterator_traits.hpp
2424
include/nlohmann/detail/iterators/json_reverse_iterator.hpp
2525
include/nlohmann/detail/iterators/primitive_iterator.hpp
26+
include/nlohmann/detail/json_custom_base_class.hpp
2627
include/nlohmann/detail/json_pointer.hpp
2728
include/nlohmann/detail/json_ref.hpp
2829
include/nlohmann/detail/macro_scope.hpp
@@ -44,6 +45,7 @@ include/nlohmann/detail/output/output_adapters.hpp
4445
include/nlohmann/detail/output/serializer.hpp
4546
include/nlohmann/detail/string_concat.hpp
4647
include/nlohmann/detail/string_escape.hpp
48+
include/nlohmann/detail/string_utils.hpp
4749
include/nlohmann/detail/value_t.hpp
4850
include/nlohmann/json.hpp
4951
include/nlohmann/json_fwd.hpp

0 commit comments

Comments
 (0)