summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-devtools/jsoncpp
diff options
context:
space:
mode:
authorErnest Van Hoecke <ernest.vanhoecke@toradex.com>2026-05-13 18:35:11 +0200
committerKhem Raj <khem.raj@oss.qualcomm.com>2026-05-13 20:46:51 -0700
commit9be9388574bbddcd6f51ffa0f006e42a11ddcf81 (patch)
tree1cd11ded299f282ec620c450bc8b9b217ea59897 /meta-oe/recipes-devtools/jsoncpp
parent3608cfdc5b3374ffe31bae81ce25ec69d9d20252 (diff)
downloadmeta-openembedded-9be9388574bbddcd6f51ffa0f006e42a11ddcf81.tar.gz
jsoncpp: Fix C++11 ABI breakage when compiled with C++17
When jsoncpp is built with C++17, 1.9.7 drops several legacy overloads that C++11 consumers can still link against. Backport the upstream fix to restore compatibility. Fixes errors such as: | undefined reference to `Json::Value::operator[](char const*)' Patch can be dropped when we move to 1.9.8. Signed-off-by: Ernest Van Hoecke <ernest.vanhoecke@toradex.com> Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
Diffstat (limited to 'meta-oe/recipes-devtools/jsoncpp')
-rw-r--r--meta-oe/recipes-devtools/jsoncpp/jsoncpp/0001-Fix-C-11-ABI-breakage-when-compiled-with-C-17-1668-1.patch368
-rw-r--r--meta-oe/recipes-devtools/jsoncpp/jsoncpp_1.9.7.bb1
2 files changed, 369 insertions, 0 deletions
diff --git a/meta-oe/recipes-devtools/jsoncpp/jsoncpp/0001-Fix-C-11-ABI-breakage-when-compiled-with-C-17-1668-1.patch b/meta-oe/recipes-devtools/jsoncpp/jsoncpp/0001-Fix-C-11-ABI-breakage-when-compiled-with-C-17-1668-1.patch
new file mode 100644
index 0000000000..887bf14d2a
--- /dev/null
+++ b/meta-oe/recipes-devtools/jsoncpp/jsoncpp/0001-Fix-C-11-ABI-breakage-when-compiled-with-C-17-1668-1.patch
@@ -0,0 +1,368 @@
1From c67034e4b4c722579ee15fddb8e4af8f04252b08 Mon Sep 17 00:00:00 2001
2From: Jordan Bayles <bayles.jordan@gmail.com>
3Date: Thu, 9 Apr 2026 10:37:08 -0700
4Subject: [PATCH] Fix C++11 ABI breakage when compiled with C++17 #1668 (#1675)
5
6When JSONCPP_HAS_STRING_VIEW was defined, the library dropped the
7`const char*` and `const String&` overloads for `operator[]`, `get`,
8`removeMember`, and `isMember`, breaking ABI compatibility for projects
9consuming the library with C++11.
10
11This change unconditionally declares and defines the legacy overloads
12so they are always exported, restoring compatibility.
13
14This commit completely eliminates the ABI breakage that occurs across
15C++ standard boundaries when using `std::string_view`.
16
17Previously, when the library was built with C++17+, CMake would leak
18`JSONCPP_HAS_STRING_VIEW=1` as a PUBLIC definition. A C++11 consumer
19would receive this definition, attempt to parse the header, and fail
20with compiler errors because `std::string_view` is not available in
21their environment.
22
23Conversely, if the library was built in C++11 (without `string_view`
24symbols), a C++17 consumer would naturally define
25`JSONCPP_HAS_STRING_VIEW` based on `__cplusplus` inside `value.h`. The
26consumer would then call the declared `string_view` methods, resulting
27in linker errors because the methods weren't compiled into the library.
28
29By moving all `std::string_view` overloads directly into `value.h` as
30`inline` methods that delegate to the fundamental
31`const char*, const char*` methods:
321. The consumer's compiler dictates whether the overloads are visible
33 (via `__cplusplus >= 201703L`).
342. The consumer compiles the inline wrappers locally, removing any
35 reliance on the library's exported symbols for `std::string_view`.
363. CMake no longer needs to pollute the consumer's environment with
37 PUBLIC compile definitions.
38
39Backported only the library/header changes. Upstream CI and example
40test additions are omitted.
41
42Upstream-Status: Backport [https://github.com/open-source-parsers/jsoncpp/commit/c67034e4b4c722579ee15fddb8e4af8f04252b08]
43Signed-off-by: Ernest Van Hoecke <ernest.vanhoecke@toradex.com>
44---
45 include/json/value.h | 54 ++++++++++++++++++++----------
46 src/lib_json/CMakeLists.txt | 9 -----
47 src/lib_json/json_value.cpp | 66 -------------------------------------
48 3 files changed, 36 insertions(+), 93 deletions(-)
49
50diff --git a/include/json/value.h b/include/json/value.h
51index f32f45609365..2007e6b4251d 100644
52--- a/include/json/value.h
53+++ b/include/json/value.h
54@@ -357,7 +357,8 @@ public:
55 Value(const StaticString& value);
56 Value(const String& value);
57 #ifdef JSONCPP_HAS_STRING_VIEW
58- Value(std::string_view value);
59+ inline Value(std::string_view value)
60+ : Value(value.data(), value.data() + value.length()) {}
61 #endif
62 Value(bool value);
63 Value(std::nullptr_t ptr) = delete;
64@@ -405,7 +406,14 @@ public:
65 /** Get string_view of string-value.
66 * \return false if !string. (Seg-fault if str is NULL.)
67 */
68- bool getString(std::string_view* str) const;
69+ inline bool getString(std::string_view* str) const {
70+ char const* begin;
71+ char const* end;
72+ if (!getString(&begin, &end))
73+ return false;
74+ *str = std::string_view(begin, static_cast<size_t>(end - begin));
75+ return true;
76+ }
77 #endif
78 Int asInt() const;
79 UInt asUInt() const;
80@@ -496,12 +504,19 @@ public:
81 #ifdef JSONCPP_HAS_STRING_VIEW
82 /// Access an object value by name, create a null member if it does not exist.
83 /// \param key may contain embedded nulls.
84- Value& operator[](std::string_view key);
85+ inline Value& operator[](std::string_view key) {
86+ return resolveReference(key.data(), key.data() + key.length());
87+ }
88 /// Access an object value by name, returns null if there is no member with
89 /// that name.
90 /// \param key may contain embedded nulls.
91- const Value& operator[](std::string_view key) const;
92-#else
93+ inline const Value& operator[](std::string_view key) const {
94+ Value const* found = find(key.data(), key.data() + key.length());
95+ if (!found)
96+ return nullSingleton();
97+ return *found;
98+ }
99+#endif
100 /// Access an object value by name, create a null member if it does not exist.
101 /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
102 /// Exceeding that will cause an exception.
103@@ -516,7 +531,6 @@ public:
104 /// that name.
105 /// \param key may contain embedded nulls.
106 const Value& operator[](const String& key) const;
107-#endif
108 /** \brief Access an object value by name, create a null member if it does not
109 * exist.
110 *
111@@ -533,8 +547,10 @@ public:
112 #ifdef JSONCPP_HAS_STRING_VIEW
113 /// Return the member named key if it exist, defaultValue otherwise.
114 /// \note deep copy
115- Value get(std::string_view key, const Value& defaultValue) const;
116-#else
117+ inline Value get(std::string_view key, const Value& defaultValue) const {
118+ return get(key.data(), key.data() + key.length(), defaultValue);
119+ }
120+#endif
121 /// Return the member named key if it exist, defaultValue otherwise.
122 /// \note deep copy
123 Value get(const char* key, const Value& defaultValue) const;
124@@ -542,7 +558,6 @@ public:
125 /// \note deep copy
126 /// \param key may contain embedded nulls.
127 Value get(const String& key, const Value& defaultValue) const;
128-#endif
129 /// Return the member named key if it exist, defaultValue otherwise.
130 /// \note deep copy
131 /// \note key may contain embedded nulls.
132@@ -588,13 +603,14 @@ public:
133 /// \pre type() is objectValue or nullValue
134 /// \post type() is unchanged
135 #if JSONCPP_HAS_STRING_VIEW
136- void removeMember(std::string_view key);
137-#else
138+ inline void removeMember(std::string_view key) {
139+ removeMember(key.data(), key.data() + key.length(), nullptr);
140+ }
141+#endif
142 void removeMember(const char* key);
143 /// Same as removeMember(const char*)
144 /// \param key may contain embedded nulls.
145 void removeMember(const String& key);
146-#endif
147 /** \brief Remove the named map member.
148 *
149 * Update 'removed' iff removed.
150@@ -602,13 +618,14 @@ public:
151 * \return true iff removed (no exceptions)
152 */
153 #if JSONCPP_HAS_STRING_VIEW
154- bool removeMember(std::string_view key, Value* removed);
155-#else
156+ inline bool removeMember(std::string_view key, Value* removed) {
157+ return removeMember(key.data(), key.data() + key.length(), removed);
158+ }
159+#endif
160 bool removeMember(String const& key, Value* removed);
161 /// Same as removeMember(const char* begin, const char* end, Value* removed),
162 /// but 'key' is null-terminated.
163 bool removeMember(const char* key, Value* removed);
164-#endif
165 /// Same as removeMember(String const& key, Value* removed)
166 bool removeMember(const char* begin, const char* end, Value* removed);
167 /** \brief Remove the indexed array element.
168@@ -622,15 +639,16 @@ public:
169 #ifdef JSONCPP_HAS_STRING_VIEW
170 /// Return true if the object has a member named key.
171 /// \param key may contain embedded nulls.
172- bool isMember(std::string_view key) const;
173-#else
174+ inline bool isMember(std::string_view key) const {
175+ return isMember(key.data(), key.data() + key.length());
176+ }
177+#endif
178 /// Return true if the object has a member named key.
179 /// \note 'key' must be null-terminated.
180 bool isMember(const char* key) const;
181 /// Return true if the object has a member named key.
182 /// \param key may contain embedded nulls.
183 bool isMember(const String& key) const;
184-#endif
185 /// Same as isMember(String const& key)const
186 bool isMember(const char* begin, const char* end) const;
187
188diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt
189index 03e9335525ca..a0695e9eba83 100644
190--- a/src/lib_json/CMakeLists.txt
191+++ b/src/lib_json/CMakeLists.txt
192@@ -131,9 +131,6 @@ if(BUILD_SHARED_LIBS)
193
194 target_compile_features(${SHARED_LIB} PUBLIC ${REQUIRED_FEATURES})
195
196- if(JSONCPP_HAS_STRING_VIEW)
197- target_compile_definitions(${SHARED_LIB} PUBLIC JSONCPP_HAS_STRING_VIEW=1)
198- endif()
199
200 target_include_directories(${SHARED_LIB} PUBLIC
201 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
202@@ -168,9 +165,6 @@ if(BUILD_STATIC_LIBS)
203
204 target_compile_features(${STATIC_LIB} PUBLIC ${REQUIRED_FEATURES})
205
206- if(JSONCPP_HAS_STRING_VIEW)
207- target_compile_definitions(${STATIC_LIB} PUBLIC JSONCPP_HAS_STRING_VIEW=1)
208- endif()
209
210 target_include_directories(${STATIC_LIB} PUBLIC
211 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
212@@ -198,9 +192,6 @@ if(BUILD_OBJECT_LIBS)
213
214 target_compile_features(${OBJECT_LIB} PUBLIC ${REQUIRED_FEATURES})
215
216- if(JSONCPP_HAS_STRING_VIEW)
217- target_compile_definitions(${OBJECT_LIB} PUBLIC JSONCPP_HAS_STRING_VIEW=1)
218- endif()
219
220 target_include_directories(${OBJECT_LIB} PUBLIC
221 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
222diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp
223index 74f77896fa7b..a8eb72d6b75f 100644
224--- a/src/lib_json/json_value.cpp
225+++ b/src/lib_json/json_value.cpp
226@@ -441,14 +441,6 @@ Value::Value(const String& value) {
227 value.data(), static_cast<unsigned>(value.length()));
228 }
229
230-#ifdef JSONCPP_HAS_STRING_VIEW
231-Value::Value(std::string_view value) {
232- initBasic(stringValue, true);
233- value_.string_ = duplicateAndPrefixStringValue(
234- value.data(), static_cast<unsigned>(value.length()));
235-}
236-#endif
237-
238 Value::Value(const StaticString& value) {
239 initBasic(stringValue);
240 value_.string_ = const_cast<char*>(value.c_str());
241@@ -656,21 +648,6 @@ bool Value::getString(char const** begin, char const** end) const {
242 return true;
243 }
244
245-#ifdef JSONCPP_HAS_STRING_VIEW
246-bool Value::getString(std::string_view* str) const {
247- if (type() != stringValue)
248- return false;
249- if (value_.string_ == nullptr)
250- return false;
251- const char* begin;
252- unsigned length;
253- decodePrefixedString(this->isAllocated(), this->value_.string_, &length,
254- &begin);
255- *str = std::string_view(begin, length);
256- return true;
257-}
258-#endif
259-
260 String Value::asString() const {
261 switch (type()) {
262 case nullValue:
263@@ -1190,17 +1167,6 @@ Value* Value::demand(char const* begin, char const* end) {
264 "objectValue or nullValue");
265 return &resolveReference(begin, end);
266 }
267-#ifdef JSONCPP_HAS_STRING_VIEW
268-const Value& Value::operator[](std::string_view key) const {
269- Value const* found = find(key.data(), key.data() + key.length());
270- if (!found)
271- return nullSingleton();
272- return *found;
273-}
274-Value& Value::operator[](std::string_view key) {
275- return resolveReference(key.data(), key.data() + key.length());
276-}
277-#else
278 const Value& Value::operator[](const char* key) const {
279 Value const* found = find(key, key + strlen(key));
280 if (!found)
281@@ -1221,7 +1187,6 @@ Value& Value::operator[](const char* key) {
282 Value& Value::operator[](const String& key) {
283 return resolveReference(key.data(), key.data() + key.length());
284 }
285-#endif
286
287 Value& Value::operator[](const StaticString& key) {
288 return resolveReference(key.c_str());
289@@ -1261,18 +1226,12 @@ Value Value::get(char const* begin, char const* end,
290 Value const* found = find(begin, end);
291 return !found ? defaultValue : *found;
292 }
293-#ifdef JSONCPP_HAS_STRING_VIEW
294-Value Value::get(std::string_view key, const Value& defaultValue) const {
295- return get(key.data(), key.data() + key.length(), defaultValue);
296-}
297-#else
298 Value Value::get(char const* key, Value const& defaultValue) const {
299 return get(key, key + strlen(key), defaultValue);
300 }
301 Value Value::get(String const& key, Value const& defaultValue) const {
302 return get(key.data(), key.data() + key.length(), defaultValue);
303 }
304-#endif
305
306 bool Value::removeMember(const char* begin, const char* end, Value* removed) {
307 if (type() != objectValue) {
308@@ -1288,31 +1247,13 @@ bool Value::removeMember(const char* begin, const char* end, Value* removed) {
309 value_.map_->erase(it);
310 return true;
311 }
312-#ifdef JSONCPP_HAS_STRING_VIEW
313-bool Value::removeMember(std::string_view key, Value* removed) {
314- return removeMember(key.data(), key.data() + key.length(), removed);
315-}
316-#else
317 bool Value::removeMember(const char* key, Value* removed) {
318 return removeMember(key, key + strlen(key), removed);
319 }
320 bool Value::removeMember(String const& key, Value* removed) {
321 return removeMember(key.data(), key.data() + key.length(), removed);
322 }
323-#endif
324-
325-#ifdef JSONCPP_HAS_STRING_VIEW
326-void Value::removeMember(std::string_view key) {
327- JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
328- "in Json::Value::removeMember(): requires objectValue");
329- if (type() == nullValue)
330- return;
331
332- CZString actualKey(key.data(), unsigned(key.length()),
333- CZString::noDuplication);
334- value_.map_->erase(actualKey);
335-}
336-#else
337 void Value::removeMember(const char* key) {
338 JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
339 "in Json::Value::removeMember(): requires objectValue");
340@@ -1323,7 +1264,6 @@ void Value::removeMember(const char* key) {
341 value_.map_->erase(actualKey);
342 }
343 void Value::removeMember(const String& key) { removeMember(key.c_str()); }
344-#endif
345
346 bool Value::removeIndex(ArrayIndex index, Value* removed) {
347 if (type() != arrayValue) {
348@@ -1353,18 +1293,12 @@ bool Value::isMember(char const* begin, char const* end) const {
349 Value const* value = find(begin, end);
350 return nullptr != value;
351 }
352-#ifdef JSONCPP_HAS_STRING_VIEW
353-bool Value::isMember(std::string_view key) const {
354- return isMember(key.data(), key.data() + key.length());
355-}
356-#else
357 bool Value::isMember(char const* key) const {
358 return isMember(key, key + strlen(key));
359 }
360 bool Value::isMember(String const& key) const {
361 return isMember(key.data(), key.data() + key.length());
362 }
363-#endif
364
365 Value::Members Value::getMemberNames() const {
366 JSON_ASSERT_MESSAGE(
367--
3682.43.0
diff --git a/meta-oe/recipes-devtools/jsoncpp/jsoncpp_1.9.7.bb b/meta-oe/recipes-devtools/jsoncpp/jsoncpp_1.9.7.bb
index 797f093f33..354f4e9115 100644
--- a/meta-oe/recipes-devtools/jsoncpp/jsoncpp_1.9.7.bb
+++ b/meta-oe/recipes-devtools/jsoncpp/jsoncpp_1.9.7.bb
@@ -15,6 +15,7 @@ PE = "1"
15 15
16SRCREV = "3455302847cf1e4671f1d8f5fa953fd46a7b1404" 16SRCREV = "3455302847cf1e4671f1d8f5fa953fd46a7b1404"
17SRC_URI = "git://github.com/open-source-parsers/jsoncpp;branch=master;protocol=https;tag=${PV} \ 17SRC_URI = "git://github.com/open-source-parsers/jsoncpp;branch=master;protocol=https;tag=${PV} \
18 file://0001-Fix-C-11-ABI-breakage-when-compiled-with-C-17-1668-1.patch \
18 file://run-ptest \ 19 file://run-ptest \
19 " 20 "
20 21