Merge pull request #859 from simdjson/jkeiser/vsquickstart

Eliminate Intellisense errors and warnings in new VS project
This commit is contained in:
John Keiser 2020-05-05 08:25:13 -07:00 committed by GitHub
commit 25fe6d7dde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 960 additions and 911 deletions

View File

@ -2,6 +2,7 @@
#define __BENCHMARKER_H #define __BENCHMARKER_H
#include "event_counter.h" #include "event_counter.h"
#include "simdjson.h" // For SIMDJSON_DISABLE_DEPRECATED_WARNINGS
#include <cassert> #include <cassert>
#include <cctype> #include <cctype>
@ -435,7 +436,11 @@ struct benchmarker {
void print(bool tabbed_output) const { void print(bool tabbed_output) const {
if (tabbed_output) { if (tabbed_output) {
char* filename_copy = (char*)malloc(strlen(filename)+1); char* filename_copy = (char*)malloc(strlen(filename)+1);
SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_DEPRECATED_WARNING // Validated CRT_SECURE safe here
strcpy(filename_copy, filename); strcpy(filename_copy, filename);
SIMDJSON_POP_DISABLE_WARNINGS
#if defined(__linux__) #if defined(__linux__)
char* base = ::basename(filename_copy); char* base = ::basename(filename_copy);
#else #else

View File

@ -11,9 +11,7 @@
#include "simdjson/common_defs.h" #include "simdjson/common_defs.h"
SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS
#if defined(_MSC_VER) && defined(__clang__) SIMDJSON_DISABLE_UNDESIRED_WARNINGS
SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
#endif
// Public API // Public API
#include "simdjson/simdjson_version.h" #include "simdjson/simdjson_version.h"

View File

@ -77,9 +77,12 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
#define unlikely(x) x #define unlikely(x) x
#endif #endif
#include <CppCoreCheck\Warnings.h>
#define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push )) #define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push ))
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 )) #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER )) #define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
// Get rid of Intellisense-only warnings (Code Analysis)
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996) #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
#define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop )) #define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
@ -113,6 +116,11 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable) SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable)
#define SIMDJSON_PRAGMA(P) _Pragma(#P) #define SIMDJSON_PRAGMA(P) _Pragma(#P)
#define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING) #define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
#if defined(SIMDJSON_CLANG_VISUAL_STUDIO)
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
#else
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
#endif
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations) #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
#define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop") #define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")

View File

@ -339,7 +339,11 @@ inline bool parser::dump_raw_tape(std::ostream &os) const noexcept {
inline simdjson_result<size_t> parser::read_file(const std::string &path) noexcept { inline simdjson_result<size_t> parser::read_file(const std::string &path) noexcept {
// Open the file // Open the file
SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
std::FILE *fp = std::fopen(path.c_str(), "rb"); std::FILE *fp = std::fopen(path.c_str(), "rb");
SIMDJSON_POP_DISABLE_WARNINGS
if (fp == nullptr) { if (fp == nullptr) {
return IO_ERROR; return IO_ERROR;
} }

View File

@ -102,7 +102,11 @@ inline padded_string::operator std::string_view() const { return std::string_vie
inline simdjson_result<padded_string> padded_string::load(const std::string &filename) noexcept { inline simdjson_result<padded_string> padded_string::load(const std::string &filename) noexcept {
// Open the file // Open the file
SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
std::FILE *fp = std::fopen(filename.c_str(), "rb"); std::FILE *fp = std::fopen(filename.c_str(), "rb");
SIMDJSON_POP_DISABLE_WARNINGS
if (fp == nullptr) { if (fp == nullptr) {
return IO_ERROR; return IO_ERROR;
} }

View File

@ -39,7 +39,6 @@ add_library(simdjson-internal-flags INTERFACE)
target_link_libraries(simdjson-internal-flags INTERFACE simdjson-flags) target_link_libraries(simdjson-internal-flags INTERFACE simdjson-flags)
if(MSVC) if(MSVC)
target_compile_options(simdjson-internal-flags INTERFACE /nologo /D_CRT_SECURE_NO_WARNINGS)
target_compile_options(simdjson-internal-flags INTERFACE /WX /W3 /sdl) target_compile_options(simdjson-internal-flags INTERFACE /WX /W3 /sdl)
else() else()
target_compile_options(simdjson-internal-flags INTERFACE -fPIC) target_compile_options(simdjson-internal-flags INTERFACE -fPIC)

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* auto-generated on Mon 27 Apr 2020 21:20:37 EDT. Do not edit! */ /* auto-generated on Mon May 4 11:46:14 PDT 2020. Do not edit! */
/* begin file simdjson.h */ /* begin file include/simdjson.h */
#ifndef SIMDJSON_H #ifndef SIMDJSON_H
#define SIMDJSON_H #define SIMDJSON_H
@ -9,7 +9,7 @@
* Check the [README.md](https://github.com/lemire/simdjson/blob/master/README.md#simdjson--parsing-gigabytes-of-json-per-second). * Check the [README.md](https://github.com/lemire/simdjson/blob/master/README.md#simdjson--parsing-gigabytes-of-json-per-second).
*/ */
/* begin file simdjson/compiler_check.h */ /* begin file include/simdjson/compiler_check.h */
#ifndef SIMDJSON_COMPILER_CHECK_H #ifndef SIMDJSON_COMPILER_CHECK_H
#define SIMDJSON_COMPILER_CHECK_H #define SIMDJSON_COMPILER_CHECK_H
@ -45,13 +45,13 @@
#endif #endif
#endif // SIMDJSON_COMPILER_CHECK_H #endif // SIMDJSON_COMPILER_CHECK_H
/* end file */ /* end file include/simdjson/compiler_check.h */
/* begin file simdjson/common_defs.h */ /* begin file include/simdjson/common_defs.h */
#ifndef SIMDJSON_COMMON_DEFS_H #ifndef SIMDJSON_COMMON_DEFS_H
#define SIMDJSON_COMMON_DEFS_H #define SIMDJSON_COMMON_DEFS_H
#include <cassert> #include <cassert>
/* begin file simdjson/portability.h */ /* begin file include/simdjson/portability.h */
#ifndef SIMDJSON_PORTABILITY_H #ifndef SIMDJSON_PORTABILITY_H
#define SIMDJSON_PORTABILITY_H #define SIMDJSON_PORTABILITY_H
@ -201,8 +201,13 @@ compiling for a known 64-bit platform."
// regular visual studio and clang under visual studio. // regular visual studio and clang under visual studio.
// clang under Windows has _stricmp (like visual studio) but not strcasecmp (as clang normally has) // clang under Windows has _stricmp (like visual studio) but not strcasecmp (as clang normally has)
#define simdjson_strcasecmp _stricmp #define simdjson_strcasecmp _stricmp
#define simdjson_strncasecmp _strnicmp
#else #else
// The strcasecmp, strncasecmp, and strcasestr functions do not work with multibyte strings (e.g. UTF-8).
// So they are only useful for ASCII in our context.
// https://www.gnu.org/software/libunistring/manual/libunistring.html#char-_002a-strings
#define simdjson_strcasecmp strcasecmp #define simdjson_strcasecmp strcasecmp
#define simdjson_strncasecmp strncasecmp
#endif #endif
namespace simdjson { namespace simdjson {
@ -248,7 +253,7 @@ static inline void aligned_free_char(char *mem_block) {
} }
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_PORTABILITY_H #endif // SIMDJSON_PORTABILITY_H
/* end file */ /* end file include/simdjson/portability.h */
namespace simdjson { namespace simdjson {
@ -323,9 +328,12 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
#define unlikely(x) x #define unlikely(x) x
#endif #endif
#include <CppCoreCheck\Warnings.h>
#define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push )) #define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push ))
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 )) #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER )) #define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
// Get rid of Intellisense-only warnings (Code Analysis)
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996) #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
#define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop )) #define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
@ -359,6 +367,11 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable) SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable)
#define SIMDJSON_PRAGMA(P) _Pragma(#P) #define SIMDJSON_PRAGMA(P) _Pragma(#P)
#define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING) #define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
#if defined(SIMDJSON_CLANG_VISUAL_STUDIO)
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
#else
#define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
#endif
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations) #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
#define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop") #define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")
@ -423,7 +436,7 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
// //
#ifndef SIMDJSON_HAS_STRING_VIEW #ifndef SIMDJSON_HAS_STRING_VIEW
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
/* begin file simdjson/nonstd/string_view.hpp */ /* begin file include/simdjson/nonstd/string_view.hpp */
// Copyright 2017-2019 by Martin Moene // Copyright 2017-2019 by Martin Moene
// //
// string-view lite, a C++17-like string_view for C++98 and later. // string-view lite, a C++17-like string_view for C++98 and later.
@ -1953,7 +1966,7 @@ nssv_RESTORE_WARNINGS()
#endif // nssv_HAVE_STD_STRING_VIEW #endif // nssv_HAVE_STD_STRING_VIEW
#endif // NONSTD_SV_LITE_H_INCLUDED #endif // NONSTD_SV_LITE_H_INCLUDED
/* end file */ /* end file include/simdjson/nonstd/string_view.hpp */
SIMDJSON_POP_DISABLE_WARNINGS SIMDJSON_POP_DISABLE_WARNINGS
namespace std { namespace std {
@ -1963,15 +1976,13 @@ namespace std {
#undef SIMDJSON_HAS_STRING_VIEW // We are not going to need this macro anymore. #undef SIMDJSON_HAS_STRING_VIEW // We are not going to need this macro anymore.
#endif // SIMDJSON_COMMON_DEFS_H #endif // SIMDJSON_COMMON_DEFS_H
/* end file */ /* end file include/simdjson/nonstd/string_view.hpp */
SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS
#if defined(_MSC_VER) && defined(__clang__) SIMDJSON_DISABLE_UNDESIRED_WARNINGS
SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
#endif
// Public API // Public API
/* begin file simdjson/simdjson_version.h */ /* begin file include/simdjson/simdjson_version.h */
// /include/simdjson/simdjson_version.h automatically generated by release.py, // /include/simdjson/simdjson_version.h automatically generated by release.py,
// do not change by hand // do not change by hand
#ifndef SIMDJSON_SIMDJSON_VERSION_H #ifndef SIMDJSON_SIMDJSON_VERSION_H
@ -1998,8 +2009,8 @@ enum {
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_SIMDJSON_VERSION_H #endif // SIMDJSON_SIMDJSON_VERSION_H
/* end file */ /* end file include/simdjson/simdjson_version.h */
/* begin file simdjson/error.h */ /* begin file include/simdjson/error.h */
#ifndef SIMDJSON_ERROR_H #ifndef SIMDJSON_ERROR_H
#define SIMDJSON_ERROR_H #define SIMDJSON_ERROR_H
@ -2232,8 +2243,8 @@ inline const std::string &error_message(int error) noexcept;
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_ERROR_H #endif // SIMDJSON_ERROR_H
/* end file */ /* end file include/simdjson/error.h */
/* begin file simdjson/padded_string.h */ /* begin file include/simdjson/padded_string.h */
#ifndef SIMDJSON_PADDED_STRING_H #ifndef SIMDJSON_PADDED_STRING_H
#define SIMDJSON_PADDED_STRING_H #define SIMDJSON_PADDED_STRING_H
@ -2373,8 +2384,8 @@ inline char *allocate_padded_buffer(size_t length) noexcept;
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_PADDED_STRING_H #endif // SIMDJSON_PADDED_STRING_H
/* end file */ /* end file include/simdjson/padded_string.h */
/* begin file simdjson/implementation.h */ /* begin file include/simdjson/implementation.h */
#ifndef SIMDJSON_IMPLEMENTATION_H #ifndef SIMDJSON_IMPLEMENTATION_H
#define SIMDJSON_IMPLEMENTATION_H #define SIMDJSON_IMPLEMENTATION_H
@ -2382,7 +2393,7 @@ inline char *allocate_padded_buffer(size_t length) noexcept;
#include <string> #include <string>
#include <atomic> #include <atomic>
#include <vector> #include <vector>
/* begin file simdjson/document.h */ /* begin file include/simdjson/document.h */
#ifndef SIMDJSON_DOCUMENT_H #ifndef SIMDJSON_DOCUMENT_H
#define SIMDJSON_DOCUMENT_H #define SIMDJSON_DOCUMENT_H
@ -2391,7 +2402,7 @@ inline char *allocate_padded_buffer(size_t length) noexcept;
#include <string> #include <string>
#include <limits> #include <limits>
#include <sstream> #include <sstream>
/* begin file simdjson/simdjson.h */ /* begin file include/simdjson/simdjson.h */
/** /**
* @file * @file
* @deprecated We'll be removing this file so it isn't confused with the top level simdjson.h * @deprecated We'll be removing this file so it isn't confused with the top level simdjson.h
@ -2401,7 +2412,7 @@ inline char *allocate_padded_buffer(size_t length) noexcept;
#endif // SIMDJSON_H #endif // SIMDJSON_H
/* end file */ /* end file include/simdjson/simdjson.h */
namespace simdjson { namespace simdjson {
namespace dom { namespace dom {
@ -2706,6 +2717,7 @@ public:
/** /**
* Get the value associated with the given key in a case-insensitive manner. * Get the value associated with the given key in a case-insensitive manner.
* It is only guaranteed to work over ASCII inputs.
* *
* Note: The key will be matched against **unescaped** JSON. * Note: The key will be matched against **unescaped** JSON.
* *
@ -3731,7 +3743,7 @@ public:
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_DOCUMENT_H #endif // SIMDJSON_DOCUMENT_H
/* end file */ /* end file include/simdjson/simdjson.h */
namespace simdjson { namespace simdjson {
@ -3963,8 +3975,8 @@ extern SIMDJSON_DLLIMPORTEXPORT internal::atomic_ptr<const implementation> activ
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_IMPLEMENTATION_H #endif // SIMDJSON_IMPLEMENTATION_H
/* end file */ /* end file include/simdjson/simdjson.h */
/* begin file simdjson/document_stream.h */ /* begin file include/simdjson/document_stream.h */
#ifndef SIMDJSON_DOCUMENT_STREAM_H #ifndef SIMDJSON_DOCUMENT_STREAM_H
#define SIMDJSON_DOCUMENT_STREAM_H #define SIMDJSON_DOCUMENT_STREAM_H
@ -4111,16 +4123,16 @@ private:
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_DOCUMENT_STREAM_H #endif // SIMDJSON_DOCUMENT_STREAM_H
/* end file */ /* end file include/simdjson/document_stream.h */
// // Deprecated API // // Deprecated API
/* begin file simdjson/jsonparser.h */ /* begin file include/simdjson/jsonparser.h */
// TODO Remove this -- deprecated API and files // TODO Remove this -- deprecated API and files
#ifndef SIMDJSON_JSONPARSER_H #ifndef SIMDJSON_JSONPARSER_H
#define SIMDJSON_JSONPARSER_H #define SIMDJSON_JSONPARSER_H
/* begin file simdjson/parsedjson.h */ /* begin file include/simdjson/parsedjson.h */
// TODO Remove this -- deprecated API and files // TODO Remove this -- deprecated API and files
#ifndef SIMDJSON_PARSEDJSON_H #ifndef SIMDJSON_PARSEDJSON_H
@ -4136,8 +4148,8 @@ using ParsedJson [[deprecated("Use dom::parser instead")]] = dom::parser;
} // namespace simdjson } // namespace simdjson
#endif #endif
/* end file */ /* end file include/simdjson/parsedjson.h */
/* begin file simdjson/jsonioutil.h */ /* begin file include/simdjson/jsonioutil.h */
#ifndef SIMDJSON_JSONIOUTIL_H #ifndef SIMDJSON_JSONIOUTIL_H
#define SIMDJSON_JSONIOUTIL_H #define SIMDJSON_JSONIOUTIL_H
@ -4163,7 +4175,7 @@ inline padded_string get_corpus(const char *path) {
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_JSONIOUTIL_H #endif // SIMDJSON_JSONIOUTIL_H
/* end file */ /* end file include/simdjson/jsonioutil.h */
namespace simdjson { namespace simdjson {
@ -4273,8 +4285,8 @@ dom::parser build_parsed_json(const char *buf) noexcept = delete;
} // namespace simdjson } // namespace simdjson
#endif #endif
/* end file */ /* end file include/simdjson/jsonioutil.h */
/* begin file simdjson/parsedjson_iterator.h */ /* begin file include/simdjson/parsedjson_iterator.h */
// TODO Remove this -- deprecated API and files // TODO Remove this -- deprecated API and files
#ifndef SIMDJSON_PARSEDJSON_ITERATOR_H #ifndef SIMDJSON_PARSEDJSON_ITERATOR_H
@ -4287,7 +4299,7 @@ dom::parser build_parsed_json(const char *buf) noexcept = delete;
#include <limits> #include <limits>
#include <stdexcept> #include <stdexcept>
/* begin file simdjson/internal/jsonformatutils.h */ /* begin file include/simdjson/internal/jsonformatutils.h */
#ifndef SIMDJSON_INTERNAL_JSONFORMATUTILS_H #ifndef SIMDJSON_INTERNAL_JSONFORMATUTILS_H
#define SIMDJSON_INTERNAL_JSONFORMATUTILS_H #define SIMDJSON_INTERNAL_JSONFORMATUTILS_H
@ -4353,7 +4365,7 @@ inline std::ostream& operator<<(std::ostream& out, const escape_json_string &une
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_INTERNAL_JSONFORMATUTILS_H #endif // SIMDJSON_INTERNAL_JSONFORMATUTILS_H
/* end file */ /* end file include/simdjson/internal/jsonformatutils.h */
namespace simdjson { namespace simdjson {
@ -4608,10 +4620,10 @@ public:
} // namespace simdjson } // namespace simdjson
#endif #endif
/* end file */ /* end file include/simdjson/internal/jsonformatutils.h */
// // Inline functions // // Inline functions
/* begin file simdjson/inline/document.h */ /* begin file include/simdjson/inline/document.h */
#ifndef SIMDJSON_INLINE_DOCUMENT_H #ifndef SIMDJSON_INLINE_DOCUMENT_H
#define SIMDJSON_INLINE_DOCUMENT_H #define SIMDJSON_INLINE_DOCUMENT_H
@ -4948,7 +4960,11 @@ inline bool parser::dump_raw_tape(std::ostream &os) const noexcept {
inline simdjson_result<size_t> parser::read_file(const std::string &path) noexcept { inline simdjson_result<size_t> parser::read_file(const std::string &path) noexcept {
// Open the file // Open the file
SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
std::FILE *fp = std::fopen(path.c_str(), "rb"); std::FILE *fp = std::fopen(path.c_str(), "rb");
SIMDJSON_POP_DISABLE_WARNINGS
if (fp == nullptr) { if (fp == nullptr) {
return IO_ERROR; return IO_ERROR;
} }
@ -5295,10 +5311,10 @@ inline simdjson_result<element> object::at_key_case_insensitive(const std::strin
for (iterator field = begin(); field != end_field; ++field) { for (iterator field = begin(); field != end_field; ++field) {
auto field_key = field.key(); auto field_key = field.key();
if (key.length() == field_key.length()) { if (key.length() == field_key.length()) {
bool equal = true; // See For case-insensitive string comparisons, avoid char-by-char functions
for (size_t i=0; i<field_key.length(); i++) { // https://lemire.me/blog/2020/04/30/for-case-insensitive-string-comparisons-avoid-char-by-char-functions/
equal = equal && std::tolower(key[i]) != std::tolower(field_key[i]); // Note that it might be worth rolling our own strncasecmp function, with vectorization.
} const bool equal = (simdjson_strncasecmp(key.data(), field_key.data(), key.length()) == 0);
if (equal) { return field.value(); } if (equal) { return field.value(); }
} }
} }
@ -5784,8 +5800,8 @@ inline std::string_view internal::tape_ref::get_string_view() const noexcept {
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_INLINE_DOCUMENT_H #endif // SIMDJSON_INLINE_DOCUMENT_H
/* end file */ /* end file include/simdjson/inline/document.h */
/* begin file simdjson/inline/document_stream.h */ /* begin file include/simdjson/inline/document_stream.h */
#ifndef SIMDJSON_INLINE_DOCUMENT_STREAM_H #ifndef SIMDJSON_INLINE_DOCUMENT_STREAM_H
#define SIMDJSON_INLINE_DOCUMENT_STREAM_H #define SIMDJSON_INLINE_DOCUMENT_STREAM_H
@ -6071,8 +6087,8 @@ inline error_code document_stream::json_parse() noexcept {
} // namespace dom } // namespace dom
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_INLINE_DOCUMENT_STREAM_H #endif // SIMDJSON_INLINE_DOCUMENT_STREAM_H
/* end file */ /* end file include/simdjson/inline/document_stream.h */
/* begin file simdjson/inline/error.h */ /* begin file include/simdjson/inline/error.h */
#ifndef SIMDJSON_INLINE_ERROR_H #ifndef SIMDJSON_INLINE_ERROR_H
#define SIMDJSON_INLINE_ERROR_H #define SIMDJSON_INLINE_ERROR_H
@ -6211,8 +6227,8 @@ really_inline simdjson_result<T>::simdjson_result() noexcept
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_INLINE_ERROR_H #endif // SIMDJSON_INLINE_ERROR_H
/* end file */ /* end file include/simdjson/inline/error.h */
/* begin file simdjson/inline/padded_string.h */ /* begin file include/simdjson/inline/padded_string.h */
#ifndef SIMDJSON_INLINE_PADDED_STRING_H #ifndef SIMDJSON_INLINE_PADDED_STRING_H
#define SIMDJSON_INLINE_PADDED_STRING_H #define SIMDJSON_INLINE_PADDED_STRING_H
@ -6315,7 +6331,11 @@ inline padded_string::operator std::string_view() const { return std::string_vie
inline simdjson_result<padded_string> padded_string::load(const std::string &filename) noexcept { inline simdjson_result<padded_string> padded_string::load(const std::string &filename) noexcept {
// Open the file // Open the file
SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
std::FILE *fp = std::fopen(filename.c_str(), "rb"); std::FILE *fp = std::fopen(filename.c_str(), "rb");
SIMDJSON_POP_DISABLE_WARNINGS
if (fp == nullptr) { if (fp == nullptr) {
return IO_ERROR; return IO_ERROR;
} }
@ -6352,8 +6372,8 @@ inline simdjson_result<padded_string> padded_string::load(const std::string &fil
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_INLINE_PADDED_STRING_H #endif // SIMDJSON_INLINE_PADDED_STRING_H
/* end file */ /* end file include/simdjson/inline/padded_string.h */
/* begin file simdjson/inline/parsedjson_iterator.h */ /* begin file include/simdjson/inline/parsedjson_iterator.h */
#ifndef SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H #ifndef SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H
#define SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H #define SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H
@ -6837,9 +6857,9 @@ SIMDJSON_POP_DISABLE_WARNINGS
} // namespace simdjson } // namespace simdjson
#endif // SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H #endif // SIMDJSON_INLINE_PARSEDJSON_ITERATOR_H
/* end file */ /* end file include/simdjson/inline/parsedjson_iterator.h */
SIMDJSON_POP_DISABLE_WARNINGS SIMDJSON_POP_DISABLE_WARNINGS
#endif // SIMDJSON_H #endif // SIMDJSON_H
/* end file */ /* end file include/simdjson/inline/parsedjson_iterator.h */

View File

@ -122,7 +122,11 @@ const implementation *available_implementation_list::detect_best_supported() con
} }
const implementation *detect_best_supported_implementation_on_first_use::set_best() const noexcept { const implementation *detect_best_supported_implementation_on_first_use::set_best() const noexcept {
SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
char *force_implementation_name = getenv("SIMDJSON_FORCE_IMPLEMENTATION"); char *force_implementation_name = getenv("SIMDJSON_FORCE_IMPLEMENTATION");
SIMDJSON_POP_DISABLE_WARNINGS
if (force_implementation_name) { if (force_implementation_name) {
auto force_implementation = available_implementations[force_implementation_name]; auto force_implementation = available_implementations[force_implementation_name];
if (!force_implementation) { if (!force_implementation) {

View File

@ -1,11 +1,11 @@
#include "simdjson.h" #include "simdjson.h"
#if defined(SIMDJSON_CLANG_VISUAL_STUDIO) SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include) SIMDJSON_DISABLE_UNDESIRED_WARNINGS
#endif
#include "error.cpp" #include "error.cpp"
#include "implementation.cpp" #include "implementation.cpp"
#include "stage1_find_marks.cpp" #include "stage1_find_marks.cpp"
#include "stage2_build_tape.cpp" #include "stage2_build_tape.cpp"
SIMDJSON_POP_DISABLE_WARNINGS

View File

@ -74,8 +74,8 @@ namespace number_tests {
uint64_t maxulp = 0; uint64_t maxulp = 0;
for (int i = -1075; i < 1024; ++i) {// large negative values should be zero. for (int i = -1075; i < 1024; ++i) {// large negative values should be zero.
double expected = pow(2, i); double expected = pow(2, i);
auto n = sprintf(buf, "%.*e", std::numeric_limits<double>::max_digits10 - 1, expected); size_t n = snprintf(buf, sizeof(buf), "%.*e", std::numeric_limits<double>::max_digits10 - 1, expected);
buf[n] = '\0'; if (n >= sizeof(buf)) { abort(); }
fflush(NULL); fflush(NULL);
auto [actual, error] = parser.parse(buf, n).get<double>(); auto [actual, error] = parser.parse(buf, n).get<double>();
if (error) { std::cerr << error << std::endl; return false; } if (error) { std::cerr << error << std::endl; return false; }
@ -167,8 +167,8 @@ namespace number_tests {
char buf[1024]; char buf[1024];
simdjson::dom::parser parser; simdjson::dom::parser parser;
for (int i = -1000000; i <= 308; ++i) {// large negative values should be zero. for (int i = -1000000; i <= 308; ++i) {// large negative values should be zero.
auto n = sprintf(buf,"1e%d", i); size_t n = snprintf(buf, sizeof(buf), "1e%d", i);
buf[n] = '\0'; if (n >= sizeof(buf)) { abort(); }
fflush(NULL); fflush(NULL);
auto [actual, error] = parser.parse(buf, n).get<double>(); auto [actual, error] = parser.parse(buf, n).get<double>();
@ -275,19 +275,22 @@ namespace document_tests {
std::vector<std::string> data; std::vector<std::string> data;
char buf[1024]; char buf[1024];
for (size_t i = 0; i < n_records; ++i) { for (size_t i = 0; i < n_records; ++i) {
auto n = sprintf(buf, size_t n = snprintf(buf, sizeof(buf),
"{\"id\": %zu, \"name\": \"name%zu\", \"gender\": \"%s\", " "{\"id\": %zu, \"name\": \"name%zu\", \"gender\": \"%s\", "
"\"school\": {\"id\": %zu, \"name\": \"school%zu\"}}", "\"school\": {\"id\": %zu, \"name\": \"school%zu\"}}",
i, i, (i % 2) ? "male" : "female", i % 10, i % 10); i, i, (i % 2) ? "male" : "female", i % 10, i % 10);
if (n >= sizeof(buf)) { abort(); }
data.emplace_back(std::string(buf, n)); data.emplace_back(std::string(buf, n));
} }
for (size_t i = 0; i < n_records; ++i) { for (size_t i = 0; i < n_records; ++i) {
auto n = sprintf(buf, "{\"counter\": %f, \"array\": [%s]}", static_cast<double>(i) * 3.1416, size_t n = snprintf(buf, sizeof(buf), "{\"counter\": %f, \"array\": [%s]}", static_cast<double>(i) * 3.1416,
(i % 2) ? "true" : "false"); (i % 2) ? "true" : "false");
if (n >= sizeof(buf)) { abort(); }
data.emplace_back(std::string(buf, n)); data.emplace_back(std::string(buf, n));
} }
for (size_t i = 0; i < n_records; ++i) { for (size_t i = 0; i < n_records; ++i) {
auto n = sprintf(buf, "{\"number\": %e}", static_cast<double>(i) * 10000.31321321); size_t n = snprintf(buf, sizeof(buf), "{\"number\": %e}", static_cast<double>(i) * 10000.31321321);
if (n >= sizeof(buf)) { abort(); }
data.emplace_back(std::string(buf, n)); data.emplace_back(std::string(buf, n));
} }
data.emplace_back(std::string("true")); data.emplace_back(std::string("true"));
@ -396,10 +399,12 @@ namespace document_stream_tests {
std::string data; std::string data;
char buf[1024]; char buf[1024];
for (size_t i = 0; i < n_records; ++i) { for (size_t i = 0; i < n_records; ++i) {
auto n = sprintf(buf, size_t n = snprintf(buf,
sizeof(buf),
"{\"id\": %zu, \"name\": \"name%zu\", \"gender\": \"%s\", " "{\"id\": %zu, \"name\": \"name%zu\", \"gender\": \"%s\", "
"\"ete\": {\"id\": %zu, \"name\": \"eventail%zu\"}}", "\"ete\": {\"id\": %zu, \"name\": \"eventail%zu\"}}",
i, i, (i % 2) ? "homme" : "femme", i % 10, i % 10); i, i, (i % 2) ? "homme" : "femme", i % 10, i % 10);
if (n >= sizeof(buf)) { abort(); }
data += std::string(buf, n); data += std::string(buf, n);
} }
for(size_t batch_size = 1000; batch_size < 2000; batch_size += (batch_size>1050?10:1)) { for(size_t batch_size = 1000; batch_size < 2000; batch_size += (batch_size>1050?10:1)) {
@ -444,10 +449,12 @@ namespace document_stream_tests {
std::string data; std::string data;
char buf[1024]; char buf[1024];
for (size_t i = 0; i < n_records; ++i) { for (size_t i = 0; i < n_records; ++i) {
auto n = sprintf(buf, size_t n = snprintf(buf,
sizeof(buf),
"{\"id\": %zu, \"name\": \"name%zu\", \"gender\": \"%s\", " "{\"id\": %zu, \"name\": \"name%zu\", \"gender\": \"%s\", "
"\"été\": {\"id\": %zu, \"name\": \"éventail%zu\"}}", "\"été\": {\"id\": %zu, \"name\": \"éventail%zu\"}}",
i, i, (i % 2) ? "" : "", i % 10, i % 10); i, i, (i % 2) ? "" : "", i % 10, i % 10);
if (n >= sizeof(buf)) { abort(); }
data += std::string(buf, n); data += std::string(buf, n);
} }
for(size_t batch_size = 1000; batch_size < 2000; batch_size += (batch_size>1050?10:1)) { for(size_t batch_size = 1000; batch_size < 2000; batch_size += (batch_size>1050?10:1)) {

View File

@ -55,15 +55,11 @@ bool validate(const char *dirname) {
if (has_extension(name, extension)) { if (has_extension(name, extension)) {
printf("validating: file %s ", name); printf("validating: file %s ", name);
fflush(nullptr); fflush(nullptr);
size_t filelen = strlen(name); size_t namelen = strlen(name);
char *fullpath = static_cast<char *>(malloc(dirlen + filelen + 1 + 1)); size_t fullpathlen = dirlen + 1 + namelen + 1;
strcpy(fullpath, dirname); char *fullpath = static_cast<char *>(malloc(fullpathlen));
if (needsep) { snprintf(fullpath, fullpathlen, "%s%s%s", dirname, needsep ? "/" : "", name);
fullpath[dirlen] = '/';
strcpy(fullpath + dirlen + 1, name);
} else {
strcpy(fullpath + dirlen, name);
}
auto [p, error] = simdjson::padded_string::load(fullpath); auto [p, error] = simdjson::padded_string::load(fullpath);
if (error) { if (error) {
std::cerr << "Could not load the file " << fullpath << std::endl; std::cerr << "Could not load the file " << fullpath << std::endl;

View File

@ -63,16 +63,10 @@ bool validate(const char *dirname) {
/* Finding the file path */ /* Finding the file path */
printf("validating: file %s ", name); printf("validating: file %s ", name);
fflush(nullptr); fflush(nullptr);
size_t filelen = strlen(name); size_t namelen = strlen(name);
char *fullpath = static_cast<char *>(malloc(dirlen + filelen + 1 + 1)); size_t fullpathlen = dirlen + 1 + namelen + 1;
strcpy(fullpath, dirname); char *fullpath = static_cast<char *>(malloc(fullpathlen));
if (needsep) { snprintf(fullpath, fullpathlen, "%s%s%s", dirname, needsep ? "/" : "", name);
fullpath[dirlen] = '/';
strcpy(fullpath + dirlen + 1, name);
} else {
strcpy(fullpath + dirlen, name);
}
/* The actual test*/ /* The actual test*/
auto [json, error] = simdjson::padded_string::load(fullpath); auto [json, error] = simdjson::padded_string::load(fullpath);

View File

@ -1,4 +1,6 @@
add_library(simdjson-windows-headers INTERFACE) add_library(simdjson-windows-headers INTERFACE)
if(MSVC) if(MSVC)
target_include_directories(simdjson-windows-headers INTERFACE .) target_include_directories(simdjson-windows-headers INTERFACE .)
# getopt.h triggers bogus CRT_SECURE warnings. If you include them, you need this.
target_compile_definitions(simdjson-windows-headers INTERFACE _CRT_SECURE_NO_WARNINGS)
endif() endif()