This enables building the library under Visual Studio 2015 (#1002)

Co-authored-by: Daniel Lemire <lemire@gmai.com>
This commit is contained in:
Daniel Lemire 2020-06-29 05:43:47 -07:00 committed by GitHub
parent 8b661fe556
commit 0ba76ac066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 63 additions and 13 deletions

View File

@ -20,6 +20,10 @@ environment:
platform: Win32
CMAKE_ARGS: -A %Platform% -DSIMDJSON_BUILD_STATIC=OFF -DSIMDJSON_ENABLE_THREADS=ON # This should be the default. Testing anyway.
CTEST_ARGS: -E checkperf
- job_name: VS2015
image: Visual Studio 2015
CMAKE_ARGS: -A %Platform% -DSIMDJSON_BUILD_STATIC=ON -DSIMDJSON_ENABLE_THREADS=OFF
CTEST_ARGS: -E checkperf
build_script:
- mkdir build

View File

@ -74,7 +74,13 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
if(MSVC)
if(${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v140")
# Visual Studio 2015 issues warnings and we tolerate it, cmake -G"Visual Studio 14" ..
target_compile_options(simdjson-internal-flags INTERFACE /W0 /sdl)
else()
# Recent version of Visual Studio expected (2017, 2019...). Prior versions are unsupported.
target_compile_options(simdjson-internal-flags INTERFACE /WX /W3 /sdl)
endif()
else()
target_compile_options(simdjson-internal-flags INTERFACE -fPIC)
target_compile_options(simdjson-internal-flags INTERFACE -Werror -Wall -Wextra -Weffc++)

View File

@ -81,12 +81,15 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
// Get rid of Intellisense-only warnings (Code Analysis)
// Though __has_include is C++17, it looks like it is supported in Visual Studio 2017 or better.
// We are probably not supporting earlier version of Visual Studio in any case.
// Though __has_include is C++17, it is supported in Visual Studio 2017 or better (_MSC_VER>=1910).
#if defined(_MSC_VER) && (_MSC_VER>=1910)
#if __has_include(<CppCoreCheck\Warnings.h>)
#include <CppCoreCheck\Warnings.h>
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
#else
#endif
#endif
#ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
#endif

View File

@ -391,7 +391,12 @@ private:
/**
* The loaded buffer (reused each time load() is called)
*/
#if defined(_MSC_VER) && _MSC_VER < 1910
// older versions of Visual Studio lack proper support for unique_ptr.
std::unique_ptr<char[]> loaded_bytes;
#else
std::unique_ptr<char[], decltype(&aligned_free_char)> loaded_bytes;
#endif
/** Capacity of loaded_bytes buffer. */
size_t _loaded_bytes_capacity{0};

View File

@ -21,7 +21,12 @@ inline char *allocate_padded_buffer(size_t length) noexcept {
// return (char *) malloc(length + SIMDJSON_PADDING);
// However, we might as well align to cache lines...
size_t totalpaddedlength = length + SIMDJSON_PADDING;
#if defined(_MSC_VER) && _MSC_VER < 1910
// For legacy Visual Studio 2015 since it does not have proper C++11 support
char *padded_buffer = new[totalpaddedlength];
#else
char *padded_buffer = aligned_malloc_char(64, totalpaddedlength);
#endif
#ifndef NDEBUG
if (padded_buffer == nullptr) {
return nullptr;

View File

@ -15,10 +15,18 @@ namespace dom {
//
// parser inline implementation
//
#if defined(_MSC_VER) && _MSC_VER < 1910
// older versions of Visual Studio lack proper support for unique_ptr.
really_inline parser::parser(size_t max_capacity) noexcept
: _max_capacity{max_capacity},
loaded_bytes(nullptr) {
}
#else
really_inline parser::parser(size_t max_capacity) noexcept
: _max_capacity{max_capacity},
loaded_bytes(nullptr, &aligned_free_char) {
}
#endif
really_inline parser::parser(parser &&other) noexcept = default;
really_inline parser &parser::operator=(parser &&other) noexcept = default;

View File

@ -5,7 +5,7 @@
#include <cstdint>
#include <cstdlib>
#include <cfloat>
#include <cassert>
#ifdef _MSC_VER
#define SIMDJSON_VISUAL_STUDIO 1
@ -232,7 +232,6 @@ static inline void aligned_free_char(char *mem_block) {
#else // NDEBUG
#include <cassert>
#define SIMDJSON_UNREACHABLE() assert(0);
#define SIMDJSON_ASSUME(COND) assert(COND)

View File

@ -1,4 +1,4 @@
/* auto-generated on Sun 28 Jun 2020 12:39:28 EDT. Do not edit! */
/* auto-generated on Sun 28 Jun 2020 20:08:45 EDT. Do not edit! */
#include <iostream>
#include "simdjson.h"

View File

@ -1,4 +1,4 @@
/* auto-generated on Sun 28 Jun 2020 12:39:28 EDT. Do not edit! */
/* auto-generated on Sun 28 Jun 2020 20:08:45 EDT. Do not edit! */
/* begin file src/simdjson.cpp */
#include "simdjson.h"

View File

@ -1,4 +1,4 @@
/* auto-generated on Sun 28 Jun 2020 12:39:28 EDT. Do not edit! */
/* auto-generated on Sun 28 Jun 2020 20:08:45 EDT. Do not edit! */
/* begin file include/simdjson.h */
#ifndef SIMDJSON_H
#define SIMDJSON_H
@ -59,7 +59,7 @@
#include <cstdint>
#include <cstdlib>
#include <cfloat>
#include <cassert>
#ifdef _MSC_VER
#define SIMDJSON_VISUAL_STUDIO 1
@ -286,7 +286,6 @@ static inline void aligned_free_char(char *mem_block) {
#else // NDEBUG
#include <cassert>
#define SIMDJSON_UNREACHABLE() assert(0);
#define SIMDJSON_ASSUME(COND) assert(COND)
@ -373,12 +372,15 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
// Get rid of Intellisense-only warnings (Code Analysis)
// Though __has_include is C++17, it looks like it is supported in Visual Studio 2017 or better.
// We are probably not supporting earlier version of Visual Studio in any case.
// Though __has_include is C++17, it is supported in Visual Studio 2017 or better (_MSC_VER>=1910).
#if defined(_MSC_VER) && (_MSC_VER>=1910)
#if __has_include(<CppCoreCheck\Warnings.h>)
#include <CppCoreCheck\Warnings.h>
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
#else
#endif
#endif
#ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
#endif
@ -3673,7 +3675,12 @@ private:
/**
* The loaded buffer (reused each time load() is called)
*/
#if defined(_MSC_VER) && _MSC_VER < 1910
// older versions of Visual Studio lack proper support for unique_ptr.
std::unique_ptr<char[]> loaded_bytes;
#else
std::unique_ptr<char[], decltype(&aligned_free_char)> loaded_bytes;
#endif
/** Capacity of loaded_bytes buffer. */
size_t _loaded_bytes_capacity{0};
@ -6779,7 +6786,12 @@ inline char *allocate_padded_buffer(size_t length) noexcept {
// return (char *) malloc(length + SIMDJSON_PADDING);
// However, we might as well align to cache lines...
size_t totalpaddedlength = length + SIMDJSON_PADDING;
#if defined(_MSC_VER) && _MSC_VER < 1910
// For legacy Visual Studio 2015 since it does not have proper C++11 support
char *padded_buffer = new[totalpaddedlength];
#else
char *padded_buffer = aligned_malloc_char(64, totalpaddedlength);
#endif
#ifndef NDEBUG
if (padded_buffer == nullptr) {
return nullptr;
@ -7401,10 +7413,18 @@ namespace dom {
//
// parser inline implementation
//
#if defined(_MSC_VER) && _MSC_VER < 1910
// older versions of Visual Studio lack proper support for unique_ptr.
really_inline parser::parser(size_t max_capacity) noexcept
: _max_capacity{max_capacity},
loaded_bytes(nullptr) {
}
#else
really_inline parser::parser(size_t max_capacity) noexcept
: _max_capacity{max_capacity},
loaded_bytes(nullptr, &aligned_free_char) {
}
#endif
really_inline parser::parser(parser &&other) noexcept = default;
really_inline parser &parser::operator=(parser &&other) noexcept = default;