Updating main branch for legacy libc++ support (#1288)

* Updating main branch for legacy libc++ support

* Adopting

* Removing unnecessary math header.

* Updating the single-header files so we can pass the new tests.

* Portable infinite-value detection is hard.

* Working toward disabling boost json selectively.

* Selectively disabling Boost JSON

* More work toward selectively disabling boost json.
This commit is contained in:
Daniel Lemire 2020-11-04 12:24:42 -05:00 committed by GitHub
parent 921c79f26f
commit 218c274090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 8726 additions and 672 deletions

View File

@ -367,6 +367,27 @@ steps:
- ctest $CTEST_FLAGS
---
kind: pipeline
name: libcpp-clang7
platform: { os: linux, arch: amd64 }
steps:
- name: Build and Test
image: conanio/clang7
user: root
environment:
CC: clang-7
CXX: clang++-7
BUILD_FLAGS: -- -j
CMAKE_FLAGS: -DSIMDJSON_BUILD_STATIC=ON
CTEST_FLAGS: -j4 --output-on-failure -E checkperf
CXXFLAGS: -stdlib=libc++
commands:
- mkdir build
- cd build
- cmake $CMAKE_FLAGS ..
- cmake --build . $BUILD_FLAGS
- ctest $CTEST_FLAGS
---
kind: pipeline
name: noexceptions-gcc9
platform: { os: linux, arch: amd64 }
steps:

View File

@ -27,8 +27,16 @@ SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
#include <nlohmann/json.hpp>
using json = nlohmann::json;
#if defined(__clang__)
// Under some clang/libc++ configurations, boost json fails
// to build.
#define DISABLE_BOOST_JSON
#endif
#ifndef DISABLE_BOOST_JSON
#include <boost/json/parser.hpp>
#include <boost/json/monotonic_resource.hpp>
#endif
#ifdef ALLPARSER
@ -175,7 +183,7 @@ bool bench(const char *filename, bool verbose, bool just_data,
std::memcpy(buffer, p.data(), p.size()) &&
(buffer[p.size()] = '\0'),
repeat, volume, !just_data);
#ifndef DISABLE_BOOST_JSON
{
const boost::json::string_view sv(p.data(), p.size());
boost::json::parser p;
@ -191,6 +199,7 @@ bool bench(const char *filename, bool verbose, bool just_data,
BEST_TIME("Boost.json", execute(sv), false, , repeat, volume, !just_data);
}
#endif
{
auto execute = [&p]() -> bool {

View File

@ -67,17 +67,25 @@ if ((Git_FOUND) AND SIMDJSON_GIT AND (SIMDJSON_IS_UNDER_GIT))
add_library(competition-ujson4c ujson4c/src/ujdecode.c)
target_include_directories(competition-ujson4c PUBLIC ujson4c/3rdparty ujson4c/src)
initialize_submodule(boost.json)
add_library(boostjson boost.json/src/src.cpp)
target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE)
target_include_directories(boostjson PUBLIC boost.json/include)
# Boost JSON is not compatible with some clang/libc++ configurations.
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
initialize_submodule(boost.json)
add_library(boostjson boost.json/src/src.cpp)
target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE)
target_include_directories(boostjson PUBLIC boost.json/include)
endif()
initialize_submodule(yyjson)
add_library(yyjson yyjson/src/yyjson.c)
target_include_directories(yyjson PUBLIC yyjson/src)
add_library(competition-core INTERFACE)
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn boostjson yyjson)
# Boost JSON is not compatible with some clang/libc++ configurations.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn yyjson)
else()
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn boostjson yyjson)
endif()
add_library(competition-all INTERFACE)
target_link_libraries(competition-all INTERFACE competition-core competition-jsoncppdist competition-json11 competition-fastjson competition-gason competition-ujson4c)

View File

@ -1,5 +1,4 @@
#include "simdjson/internal/numberparsing_tables.h"
#include <cmath>
#include <limits>
namespace simdjson {
@ -292,8 +291,20 @@ simdjson_really_inline bool compute_float_64(int64_t power, uint64_t i, bool neg
// one digit.
static bool parse_float_fallback(const uint8_t *ptr, double *outDouble) {
*outDouble = simdjson::internal::from_chars((const char *)ptr);
// We do not accept infinite values.
if (!std::isfinite(*outDouble)) {
// We do not accept infinite values. Detecting finite values in a portable manner is ridiculously hard.
//
// Next line would be nice but if fails under Visual Studio with error C2589: '(': illegal token on right side of '::'
// despite the fact that we have '#include <limits>' above.
// if ((*outDouble > std::numeric_limits<double>::max()) || (*outDouble < std::numeric_limits<double>::lowest())) {
//
// Next line would be better but it mysteriously fails under legacy/old libc++ libraries.
// See https://github.com/simdjson/simdjson/issues/1286
//if (!std::isfinite(*outDouble)) {
//
// So we use the following that ought to work under all systems.
// (Note that I also tried hexadecimal floats but it failed under some systems too.)
//
if ((*outDouble > 1.7976931348623157E+308) || (*outDouble < -1.7976931348623157E+308)) {
return false;
}
return true;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
#include <cmath>
#include <limits>
namespace simdjson {
namespace internal {

View File

@ -1,4 +1,3 @@
#include <cmath>
#include <cstring>
#include <cstdint>
#include <array>
@ -914,8 +913,7 @@ format. Returns an iterator pointing past-the-end of the decimal representation.
*/
char *to_chars(char *first, const char *last, double value) {
static_cast<void>(last); // maybe unused - fix warning
// Use signbit(value) instead of (value < 0) since signbit works for -0.
if (std::signbit(value)) {
if (value <= -0) {
value = -value;
*first++ = '-';
}