Skip to content

Commit 0ba76ac

Browse files
lemireDaniel Lemire
and
Daniel Lemire
authored
This enables building the library under Visual Studio 2015 (simdjson#1002)
Co-authored-by: Daniel Lemire <[email protected]>
1 parent 8b661fe commit 0ba76ac

File tree

10 files changed

+63
-13
lines changed

10 files changed

+63
-13
lines changed

.appveyor.yml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ environment:
2020
platform: Win32
2121
CMAKE_ARGS: -A %Platform% -DSIMDJSON_BUILD_STATIC=OFF -DSIMDJSON_ENABLE_THREADS=ON # This should be the default. Testing anyway.
2222
CTEST_ARGS: -E checkperf
23+
- job_name: VS2015
24+
image: Visual Studio 2015
25+
CMAKE_ARGS: -A %Platform% -DSIMDJSON_BUILD_STATIC=ON -DSIMDJSON_ENABLE_THREADS=OFF
26+
CTEST_ARGS: -E checkperf
2327

2428
build_script:
2529
- mkdir build

cmake/simdjson-flags.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
7474

7575

7676
if(MSVC)
77+
if(${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v140")
78+
# Visual Studio 2015 issues warnings and we tolerate it, cmake -G"Visual Studio 14" ..
79+
target_compile_options(simdjson-internal-flags INTERFACE /W0 /sdl)
80+
else()
81+
# Recent version of Visual Studio expected (2017, 2019...). Prior versions are unsupported.
7782
target_compile_options(simdjson-internal-flags INTERFACE /WX /W3 /sdl)
83+
endif()
7884
else()
7985
target_compile_options(simdjson-internal-flags INTERFACE -fPIC)
8086
target_compile_options(simdjson-internal-flags INTERFACE -Werror -Wall -Wextra -Weffc++)

include/simdjson/common_defs.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
8181
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
8282
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
8383
// Get rid of Intellisense-only warnings (Code Analysis)
84-
// Though __has_include is C++17, it looks like it is supported in Visual Studio 2017 or better.
85-
// We are probably not supporting earlier version of Visual Studio in any case.
84+
// Though __has_include is C++17, it is supported in Visual Studio 2017 or better (_MSC_VER>=1910).
85+
#if defined(_MSC_VER) && (_MSC_VER>=1910)
8686
#if __has_include(<CppCoreCheck\Warnings.h>)
8787
#include <CppCoreCheck\Warnings.h>
8888
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
89-
#else
89+
#endif
90+
#endif
91+
92+
#ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
9093
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
9194
#endif
9295

include/simdjson/dom/parser.h

+5
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,12 @@ class parser {
391391
/**
392392
* The loaded buffer (reused each time load() is called)
393393
*/
394+
#if defined(_MSC_VER) && _MSC_VER < 1910
395+
// older versions of Visual Studio lack proper support for unique_ptr.
396+
std::unique_ptr<char[]> loaded_bytes;
397+
#else
394398
std::unique_ptr<char[], decltype(&aligned_free_char)> loaded_bytes;
399+
#endif
395400

396401
/** Capacity of loaded_bytes buffer. */
397402
size_t _loaded_bytes_capacity{0};

include/simdjson/inline/padded_string.h

+5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ inline char *allocate_padded_buffer(size_t length) noexcept {
2121
// return (char *) malloc(length + SIMDJSON_PADDING);
2222
// However, we might as well align to cache lines...
2323
size_t totalpaddedlength = length + SIMDJSON_PADDING;
24+
#if defined(_MSC_VER) && _MSC_VER < 1910
25+
// For legacy Visual Studio 2015 since it does not have proper C++11 support
26+
char *padded_buffer = new[totalpaddedlength];
27+
#else
2428
char *padded_buffer = aligned_malloc_char(64, totalpaddedlength);
29+
#endif
2530
#ifndef NDEBUG
2631
if (padded_buffer == nullptr) {
2732
return nullptr;

include/simdjson/inline/parser.h

+8
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ namespace dom {
1515
//
1616
// parser inline implementation
1717
//
18+
#if defined(_MSC_VER) && _MSC_VER < 1910
19+
// older versions of Visual Studio lack proper support for unique_ptr.
20+
really_inline parser::parser(size_t max_capacity) noexcept
21+
: _max_capacity{max_capacity},
22+
loaded_bytes(nullptr) {
23+
}
24+
#else
1825
really_inline parser::parser(size_t max_capacity) noexcept
1926
: _max_capacity{max_capacity},
2027
loaded_bytes(nullptr, &aligned_free_char) {
2128
}
29+
#endif
2230
really_inline parser::parser(parser &&other) noexcept = default;
2331
really_inline parser &parser::operator=(parser &&other) noexcept = default;
2432

include/simdjson/portability.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <cstdint>
66
#include <cstdlib>
77
#include <cfloat>
8-
8+
#include <cassert>
99

1010
#ifdef _MSC_VER
1111
#define SIMDJSON_VISUAL_STUDIO 1
@@ -232,7 +232,6 @@ static inline void aligned_free_char(char *mem_block) {
232232
233233
#else // NDEBUG
234234
235-
#include <cassert>
236235
#define SIMDJSON_UNREACHABLE() assert(0);
237236
#define SIMDJSON_ASSUME(COND) assert(COND)
238237

singleheader/amalgamate_demo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Sun 28 Jun 2020 12:39:28 EDT. Do not edit! */
1+
/* auto-generated on Sun 28 Jun 2020 20:08:45 EDT. Do not edit! */
22

33
#include <iostream>
44
#include "simdjson.h"

singleheader/simdjson.cpp

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

singleheader/simdjson.h

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Sun 28 Jun 2020 12:39:28 EDT. Do not edit! */
1+
/* auto-generated on Sun 28 Jun 2020 20:08:45 EDT. Do not edit! */
22
/* begin file include/simdjson.h */
33
#ifndef SIMDJSON_H
44
#define SIMDJSON_H
@@ -59,7 +59,7 @@
5959
#include <cstdint>
6060
#include <cstdlib>
6161
#include <cfloat>
62-
62+
#include <cassert>
6363

6464
#ifdef _MSC_VER
6565
#define SIMDJSON_VISUAL_STUDIO 1
@@ -286,7 +286,6 @@ static inline void aligned_free_char(char *mem_block) {
286286
287287
#else // NDEBUG
288288
289-
#include <cassert>
290289
#define SIMDJSON_UNREACHABLE() assert(0);
291290
#define SIMDJSON_ASSUME(COND) assert(COND)
292291
@@ -373,12 +372,15 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
373372
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
374373
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
375374
// Get rid of Intellisense-only warnings (Code Analysis)
376-
// Though __has_include is C++17, it looks like it is supported in Visual Studio 2017 or better.
377-
// We are probably not supporting earlier version of Visual Studio in any case.
375+
// Though __has_include is C++17, it is supported in Visual Studio 2017 or better (_MSC_VER>=1910).
376+
#if defined(_MSC_VER) && (_MSC_VER>=1910)
378377
#if __has_include(<CppCoreCheck\Warnings.h>)
379378
#include <CppCoreCheck\Warnings.h>
380379
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
381-
#else
380+
#endif
381+
#endif
382+
383+
#ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
382384
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
383385
#endif
384386
@@ -3673,7 +3675,12 @@ class parser {
36733675
/**
36743676
* The loaded buffer (reused each time load() is called)
36753677
*/
3678+
#if defined(_MSC_VER) && _MSC_VER < 1910
3679+
// older versions of Visual Studio lack proper support for unique_ptr.
3680+
std::unique_ptr<char[]> loaded_bytes;
3681+
#else
36763682
std::unique_ptr<char[], decltype(&aligned_free_char)> loaded_bytes;
3683+
#endif
36773684

36783685
/** Capacity of loaded_bytes buffer. */
36793686
size_t _loaded_bytes_capacity{0};
@@ -6779,7 +6786,12 @@ inline char *allocate_padded_buffer(size_t length) noexcept {
67796786
// return (char *) malloc(length + SIMDJSON_PADDING);
67806787
// However, we might as well align to cache lines...
67816788
size_t totalpaddedlength = length + SIMDJSON_PADDING;
6789+
#if defined(_MSC_VER) && _MSC_VER < 1910
6790+
// For legacy Visual Studio 2015 since it does not have proper C++11 support
6791+
char *padded_buffer = new[totalpaddedlength];
6792+
#else
67826793
char *padded_buffer = aligned_malloc_char(64, totalpaddedlength);
6794+
#endif
67836795
#ifndef NDEBUG
67846796
if (padded_buffer == nullptr) {
67856797
return nullptr;
@@ -7401,10 +7413,18 @@ namespace dom {
74017413
//
74027414
// parser inline implementation
74037415
//
7416+
#if defined(_MSC_VER) && _MSC_VER < 1910
7417+
// older versions of Visual Studio lack proper support for unique_ptr.
7418+
really_inline parser::parser(size_t max_capacity) noexcept
7419+
: _max_capacity{max_capacity},
7420+
loaded_bytes(nullptr) {
7421+
}
7422+
#else
74047423
really_inline parser::parser(size_t max_capacity) noexcept
74057424
: _max_capacity{max_capacity},
74067425
loaded_bytes(nullptr, &aligned_free_char) {
74077426
}
7427+
#endif
74087428
really_inline parser::parser(parser &&other) noexcept = default;
74097429
really_inline parser &parser::operator=(parser &&other) noexcept = default;
74107430

0 commit comments

Comments
 (0)