1 From f917ed284c52ae12fb0d752c17141f355158470e Mon Sep 17 00:00:00 2001
2 From: Kohei Yoshida <kohei.yoshida@gmail.com>
3 Date: Tue, 2 Nov 2021 22:07:51 -0400
4 Subject: [PATCH] std::get<T>(...) may be flaky with some version of clang.
6 As workaround, use boost::variant and boost::get.
8 c.f. https://stackoverflow.com/questions/52521388/stdvariantget-does-not-compile-with-apple-llvm-10-0
10 include/orcus/config.hpp | 4 ++--
11 include/orcus/css_selector.hpp | 5 +++--
12 include/orcus/json_parser_thread.hpp | 4 ++--
13 include/orcus/sax_token_parser_thread.hpp | 5 +++--
14 include/orcus/spreadsheet/pivot.hpp | 7 ++++---
15 include/orcus/threaded_json_parser.hpp | 8 ++++----
16 include/orcus/threaded_sax_token_parser.hpp | 8 ++++----
17 src/liborcus/css_document_tree.cpp | 2 +-
18 src/liborcus/css_selector.cpp | 12 ++++++------
19 src/liborcus/orcus_csv.cpp | 4 ++--
20 src/orcus_csv_main.cpp | 2 +-
21 src/orcus_test_csv.cpp | 8 ++++----
22 src/orcus_test_xlsx.cpp | 4 ++--
23 src/parser/json_parser_thread.cpp | 8 ++++----
24 src/python/sheet_rows.cpp | 3 +++
25 15 files changed, 45 insertions(+), 39 deletions(-)
27 diff --git a/include/orcus/config.hpp b/include/orcus/config.hpp
28 index 17743e6a..fe9a7d81 100644
29 --- a/include/orcus/config.hpp
30 +++ b/include/orcus/config.hpp
32 #include "orcus/types.hpp"
36 +#include <boost/variant.hpp>
40 @@ -37,7 +37,7 @@ struct ORCUS_DLLPUBLIC config
43 // TODO: add config for other formats as needed.
44 - using data_type = std::variant<csv_config>;
45 + using data_type = boost::variant<csv_config>;
48 * Enable or disable runtime debug output to stdout or stderr.
49 diff --git a/include/orcus/css_selector.hpp b/include/orcus/css_selector.hpp
50 index 1e41d544..dafeddf5 100644
51 --- a/include/orcus/css_selector.hpp
52 +++ b/include/orcus/css_selector.hpp
54 #include "css_types.hpp"
59 #include <unordered_set>
60 #include <unordered_map>
62 +#include <boost/variant.hpp>
66 struct ORCUS_DLLPUBLIC css_simple_selector_t
67 @@ -73,7 +74,7 @@ struct ORCUS_DLLPUBLIC css_selector_t
69 struct ORCUS_DLLPUBLIC css_property_value_t
71 - using value_type = std::variant<std::string_view, css::rgba_color_t, css::hsla_color_t>;
72 + using value_type = boost::variant<std::string_view, css::rgba_color_t, css::hsla_color_t>;
74 css::property_value_t type;
76 diff --git a/include/orcus/json_parser_thread.hpp b/include/orcus/json_parser_thread.hpp
77 index 8328ef11..565008da 100644
78 --- a/include/orcus/json_parser_thread.hpp
79 +++ b/include/orcus/json_parser_thread.hpp
85 +#include <boost/variant.hpp>
89 @@ -47,7 +47,7 @@ enum class parse_token_t
91 struct ORCUS_PSR_DLLPUBLIC parse_token
93 - using value_type = std::variant<std::string_view, parse_error_value_t, double>;
94 + using value_type = boost::variant<std::string_view, parse_error_value_t, double>;
98 diff --git a/include/orcus/sax_token_parser_thread.hpp b/include/orcus/sax_token_parser_thread.hpp
99 index b3645735..e0842013 100644
100 --- a/include/orcus/sax_token_parser_thread.hpp
101 +++ b/include/orcus/sax_token_parser_thread.hpp
110 +#include <boost/variant.hpp>
115 @@ -36,7 +37,7 @@ enum class parse_token_t
117 struct ORCUS_PSR_DLLPUBLIC parse_token
119 - using value_type = std::variant<std::string_view, parse_error_value_t, const xml_token_element_t*>;
120 + using value_type = boost::variant<std::string_view, parse_error_value_t, const xml_token_element_t*>;
124 diff --git a/include/orcus/spreadsheet/pivot.hpp b/include/orcus/spreadsheet/pivot.hpp
125 index dee25596..fa091160 100644
126 --- a/include/orcus/spreadsheet/pivot.hpp
127 +++ b/include/orcus/spreadsheet/pivot.hpp
135 +#include <boost/variant.hpp>
140 @@ -36,7 +37,7 @@ using pivot_cache_indices_t = std::vector<size_t>;
142 struct ORCUS_SPM_DLLPUBLIC pivot_cache_record_value_t
144 - using value_type = std::variant<bool, double, std::size_t, std::string_view, date_time_t>;
145 + using value_type = boost::variant<bool, double, std::size_t, std::string_view, date_time_t>;
147 enum class record_type
149 @@ -66,7 +67,7 @@ using pivot_cache_record_t = std::vector<pivot_cache_record_value_t>;
151 struct ORCUS_SPM_DLLPUBLIC pivot_cache_item_t
153 - using value_type = std::variant<bool, double, std::string_view, date_time_t, error_value_t>;
154 + using value_type = boost::variant<bool, double, std::string_view, date_time_t, error_value_t>;
158 diff --git a/include/orcus/threaded_json_parser.hpp b/include/orcus/threaded_json_parser.hpp
159 index 51cdaced..3bf6e591 100644
160 --- a/include/orcus/threaded_json_parser.hpp
161 +++ b/include/orcus/threaded_json_parser.hpp
162 @@ -151,23 +151,23 @@ void threaded_json_parser<_Handler>::process_tokens(json::parse_tokens_t& tokens
165 case json::parse_token_t::number:
166 - m_handler.number(std::get<double>(t.value));
167 + m_handler.number(boost::get<double>(t.value));
169 case json::parse_token_t::object_key:
171 - auto s = std::get<std::string_view>(t.value);
172 + auto s = boost::get<std::string_view>(t.value);
173 m_handler.object_key(s.data(), s.size(), false);
176 case json::parse_token_t::string:
178 - auto s = std::get<std::string_view>(t.value);
179 + auto s = boost::get<std::string_view>(t.value);
180 m_handler.string(s.data(), s.size(), false);
183 case json::parse_token_t::parse_error:
185 - auto v = std::get<parse_error_value_t>(t.value);
186 + auto v = boost::get<parse_error_value_t>(t.value);
187 throw json::parse_error(std::string{v.str}, v.offset);
189 case json::parse_token_t::unknown:
190 diff --git a/include/orcus/threaded_sax_token_parser.hpp b/include/orcus/threaded_sax_token_parser.hpp
191 index 59ea967a..1b389be2 100644
192 --- a/include/orcus/threaded_sax_token_parser.hpp
193 +++ b/include/orcus/threaded_sax_token_parser.hpp
194 @@ -131,25 +131,25 @@ void threaded_sax_token_parser<_Handler>::process_tokens(const sax::parse_tokens
196 case sax::parse_token_t::start_element:
198 - const auto* elem = std::get<const xml_token_element_t*>(t.value);
199 + const auto* elem = boost::get<const xml_token_element_t*>(t.value);
200 m_handler.start_element(*elem);
203 case sax::parse_token_t::end_element:
205 - const auto* elem = std::get<const xml_token_element_t*>(t.value);
206 + const auto* elem = boost::get<const xml_token_element_t*>(t.value);
207 m_handler.end_element(*elem);
210 case sax::parse_token_t::characters:
212 - auto s = std::get<std::string_view>(t.value);
213 + auto s = boost::get<std::string_view>(t.value);
214 m_handler.characters(s, false);
217 case sax::parse_token_t::parse_error:
219 - auto v = std::get<parse_error_value_t>(t.value);
220 + auto v = boost::get<parse_error_value_t>(t.value);
221 throw sax::malformed_xml_error(std::string{v.str}, v.offset);
224 diff --git a/src/liborcus/css_document_tree.cpp b/src/liborcus/css_document_tree.cpp
225 index 46bf7e91..4b44edff 100644
226 --- a/src/liborcus/css_document_tree.cpp
227 +++ b/src/liborcus/css_document_tree.cpp
228 @@ -317,7 +317,7 @@ public:
230 // String value needs interning.
231 css_property_value_t interned = v;
232 - auto s = std::get<std::string_view>(v.value);
233 + auto s = boost::get<std::string_view>(v.value);
234 interned.value = m_sp.intern(s).first;
235 m_dest.push_back(interned);
237 diff --git a/src/liborcus/css_selector.cpp b/src/liborcus/css_selector.cpp
238 index b7b63f37..de522062 100644
239 --- a/src/liborcus/css_selector.cpp
240 +++ b/src/liborcus/css_selector.cpp
241 @@ -155,7 +155,7 @@ std::ostream& operator<< (std::ostream& os, const css_property_value_t& v)
243 case css::property_value_t::hsl:
245 - auto c = std::get<css::hsla_color_t>(v.value);
246 + auto c = boost::get<css::hsla_color_t>(v.value);
249 << (int)c.saturation << sep
250 @@ -165,7 +165,7 @@ std::ostream& operator<< (std::ostream& os, const css_property_value_t& v)
252 case css::property_value_t::hsla:
254 - auto c = std::get<css::hsla_color_t>(v.value);
255 + auto c = boost::get<css::hsla_color_t>(v.value);
258 << (int)c.saturation << sep
259 @@ -176,7 +176,7 @@ std::ostream& operator<< (std::ostream& os, const css_property_value_t& v)
261 case css::property_value_t::rgb:
263 - auto c = std::get<css::rgba_color_t>(v.value);
264 + auto c = boost::get<css::rgba_color_t>(v.value);
267 << (int)c.green << sep
268 @@ -186,7 +186,7 @@ std::ostream& operator<< (std::ostream& os, const css_property_value_t& v)
270 case css::property_value_t::rgba:
272 - auto c = std::get<css::rgba_color_t>(v.value);
273 + auto c = boost::get<css::rgba_color_t>(v.value);
276 << (int)c.green << sep
277 @@ -196,10 +196,10 @@ std::ostream& operator<< (std::ostream& os, const css_property_value_t& v)
280 case css::property_value_t::string:
281 - os << std::get<std::string_view>(v.value);
282 + os << boost::get<std::string_view>(v.value);
284 case css::property_value_t::url:
285 - os << "url(" << std::get<std::string_view>(v.value) << ")";
286 + os << "url(" << boost::get<std::string_view>(v.value) << ")";
288 case css::property_value_t::none:
290 diff --git a/src/liborcus/orcus_csv.cpp b/src/liborcus/orcus_csv.cpp
291 index 5c71bcf5..637308ab 100644
292 --- a/src/liborcus/orcus_csv.cpp
293 +++ b/src/liborcus/orcus_csv.cpp
294 @@ -63,7 +63,7 @@ public:
296 if (m_row >= mp_sheet->get_sheet_size().rows)
298 - auto csv = std::get<config::csv_config>(m_app_config.data);
299 + auto csv = boost::get<config::csv_config>(m_app_config.data);
301 if (!csv.split_to_multiple_sheets)
302 throw max_row_size_reached();
303 @@ -93,7 +93,7 @@ public:
305 void cell(const char* p, size_t n, bool transient)
307 - auto csv = std::get<config::csv_config>(m_app_config.data);
308 + auto csv = boost::get<config::csv_config>(m_app_config.data);
310 if (m_sheet == 0 && size_t(m_row) < csv.header_row_size)
312 diff --git a/src/orcus_csv_main.cpp b/src/orcus_csv_main.cpp
313 index 4f6d7173..446f2684 100644
314 --- a/src/orcus_csv_main.cpp
315 +++ b/src/orcus_csv_main.cpp
316 @@ -45,7 +45,7 @@ public:
318 virtual void map_to_config(config& opt, const po::variables_map& vm) override
320 - auto csv = std::get<config::csv_config>(opt.data);
321 + auto csv = boost::get<config::csv_config>(opt.data);
323 if (vm.count("row-header"))
324 csv.header_row_size = vm["row-header"].as<size_t>();
325 diff --git a/src/orcus_test_csv.cpp b/src/orcus_test_csv.cpp
326 index 310ace9d..0b9ba994 100644
327 --- a/src/orcus_test_csv.cpp
328 +++ b/src/orcus_test_csv.cpp
329 @@ -95,8 +95,8 @@ void test_csv_import_split_sheet()
330 std::cout << "checking " << path << "..." << std::endl;
332 config conf(format_t::csv);
333 - std::get<config::csv_config>(conf.data).header_row_size = 0;
334 - std::get<config::csv_config>(conf.data).split_to_multiple_sheets = true;
335 + boost::get<config::csv_config>(conf.data).header_row_size = 0;
336 + boost::get<config::csv_config>(conf.data).split_to_multiple_sheets = true;
338 // Set the row size to 11 to make sure the split occurs.
339 spreadsheet::range_size_t ss{11, 4};
340 @@ -126,7 +126,7 @@ void test_csv_import_split_sheet()
342 path.append("input.csv");
344 - std::get<config::csv_config>(conf.data).header_row_size = 1;
345 + boost::get<config::csv_config>(conf.data).header_row_size = 1;
347 spreadsheet::import_factory factory(doc);
348 orcus_csv app(&factory);
349 @@ -149,7 +149,7 @@ void test_csv_import_split_sheet()
351 // Re-import it again, but this time disable the splitting. The data should
352 // get trucated on the first sheet.
353 - std::get<config::csv_config>(conf.data).split_to_multiple_sheets = false;
354 + boost::get<config::csv_config>(conf.data).split_to_multiple_sheets = false;
357 path.append("input.csv");
358 diff --git a/src/orcus_test_xlsx.cpp b/src/orcus_test_xlsx.cpp
359 index 807c61e4..632fb1e7 100644
360 --- a/src/orcus_test_xlsx.cpp
361 +++ b/src/orcus_test_xlsx.cpp
362 @@ -1154,8 +1154,8 @@ void test_xlsx_pivot_group_by_numbers()
363 for (const pivot_cache_item_t& item : fld->items)
365 assert(item.type == pivot_cache_item_t::item_type::numeric);
366 - assert(*fld->min_value <= std::get<double>(item.value));
367 - assert(std::get<double>(item.value) <= *fld->max_value);
368 + assert(*fld->min_value <= boost::get<double>(item.value));
369 + assert(boost::get<double>(item.value) <= *fld->max_value);
372 // This field is also gruop field with 7 numeric intervals of width 2.
373 diff --git a/src/parser/json_parser_thread.cpp b/src/parser/json_parser_thread.cpp
374 index 36bbe6e6..65fb6255 100644
375 --- a/src/parser/json_parser_thread.cpp
376 +++ b/src/parser/json_parser_thread.cpp
377 @@ -237,19 +237,19 @@ std::ostream& operator<< (std::ostream& os, const parse_tokens_t& tokens)
378 os << "- null" << endl;
380 case parse_token_t::number:
381 - os << "- number (v=" << std::get<double>(t.value) << ")" << endl;
382 + os << "- number (v=" << boost::get<double>(t.value) << ")" << endl;
384 case parse_token_t::object_key:
385 - os << "- object_key (v=" << std::get<std::string_view>(t.value) << ")" << endl;
386 + os << "- object_key (v=" << boost::get<std::string_view>(t.value) << ")" << endl;
388 case parse_token_t::parse_error:
390 - auto v = std::get<parse_error_value_t>(t.value);
391 + auto v = boost::get<parse_error_value_t>(t.value);
392 os << "- parse_error (v=" << v.str << ", offset=" << v.offset << ")" << endl;
395 case parse_token_t::string:
396 - os << "- string (" << std::get<std::string_view>(t.value) << ")" << endl;
397 + os << "- string (" << boost::get<std::string_view>(t.value) << ")" << endl;
399 case parse_token_t::unknown:
400 os << "- unknown" << endl;
401 diff --git a/src/python/sheet_rows.cpp b/src/python/sheet_rows.cpp
402 index be495894..0d21ba71 100644
403 --- a/src/python/sheet_rows.cpp
404 +++ b/src/python/sheet_rows.cpp
405 @@ -135,7 +135,10 @@ PyObject* sheet_rows_iternext(PyObject* self)
408 case ixion::celltype_t::unknown:
410 + PyErr_SetString(PyExc_RuntimeError, "Unknown cell type.");