From 28db262b4758599e4161f4ff2c940d982b6d4fe8 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Sat, 15 Jul 2023 16:46:15 -0700 Subject: [PATCH] Make SIMDJSON_AMALGAMATED checking much stricter --- include/simdjson.h | 8 +- include/simdjson/amalgamated.h | 2 - include/simdjson/base.h | 2 +- .../simdjson/builtin/ondemand/amalgamated.h | 4 - include/simdjson/dom.h | 8 + include/simdjson/dom/amalgamated.h | 4 - include/simdjson/generic/amalgamated.h | 12 +- include/simdjson/generic/dependencies.h | 4 + .../simdjson/generic/ondemand/amalgamated.h | 6 +- include/simdjson/generic/ondemand/base.h | 1 - .../simdjson/generic/ondemand/dependencies.h | 4 + include/simdjson/ondemand.h | 9 +- singleheader/amalgamate.py | 2 - singleheader/simdjson.cpp | 703 +--------- singleheader/simdjson.h | 1171 ++++++++--------- src/arm64.cpp | 4 - src/fallback.cpp | 4 - src/generic/amalgamated.h | 6 +- src/generic/dependencies.h | 5 +- src/generic/stage1/amalgamated.h | 4 - src/generic/stage2/amalgamated.h | 4 - src/haswell.cpp | 5 - src/icelake.cpp | 11 +- src/ppc64.cpp | 4 - src/simdjson.cpp | 6 +- src/westmere.cpp | 5 - 26 files changed, 696 insertions(+), 1302 deletions(-) diff --git a/include/simdjson.h b/include/simdjson.h index 37ec8477e..70ecb6949 100644 --- a/include/simdjson.h +++ b/include/simdjson.h @@ -38,12 +38,18 @@ SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS +#include "simdjson/generic/dependencies.h" +#include "simdjson/generic/ondemand/dependencies.h" + +#define SIMDJSON_AMALGAMATED + #include "simdjson/amalgamated.h" #include "simdjson/dom/amalgamated.h" -#include "simdjson/generic/dependencies.h" #include "simdjson/builtin/amalgamated.h" #include "simdjson/builtin/ondemand/amalgamated.h" +#undef SIMDJSON_AMALGAMATED + SIMDJSON_POP_DISABLE_UNUSED_WARNINGS #endif // SIMDJSON_H diff --git a/include/simdjson/amalgamated.h b/include/simdjson/amalgamated.h index 180f643c7..b771dc398 100644 --- a/include/simdjson/amalgamated.h +++ b/include/simdjson/amalgamated.h @@ -1,8 +1,6 @@ #ifndef SIMDJSON_AMALGAMATED_H #define SIMDJSON_AMALGAMATED_H -#define SIMDJSON_AMALGAMATED - // This provides the public API for simdjson. // DOM and ondemand are amalgamated separately, in simdjson.h #include "simdjson/simdjson_version.h" diff --git a/include/simdjson/base.h b/include/simdjson/base.h index e62344fa7..067415cd6 100644 --- a/include/simdjson/base.h +++ b/include/simdjson/base.h @@ -4,7 +4,7 @@ */ #ifndef SIMDJSON_AMALGAMATED #if defined(SIMDJSON_IMPLEMENTATION) && (defined(SIMDJSON_SRC_SIMDJSON_CPP) || defined(SIMDJSON_H)) -#error "implementation-specific code included in simdjson.cpp or simdjson.h without amalgamating first!" +#error implementation-specific code included in simdjson.cpp or simdjson.h without amalgamating first! #endif #endif // SIMDJSON_AMALGAMATED #ifndef SIMDJSON_BASE_H diff --git a/include/simdjson/builtin/ondemand/amalgamated.h b/include/simdjson/builtin/ondemand/amalgamated.h index 91c138daf..35b94186e 100644 --- a/include/simdjson/builtin/ondemand/amalgamated.h +++ b/include/simdjson/builtin/ondemand/amalgamated.h @@ -1,10 +1,6 @@ #ifndef SIMDJSON_BUILTIN_ONDEMAND_AMALGAMATED_H #define SIMDJSON_BUILTIN_ONDEMAND_AMALGAMATED_H -#ifndef SIMDJSON_AMALGAMATED -#include "simdjson/builtin/amalgamated.h" -#endif // SIMDJSON_AMALGAMATED - #include "simdjson/builtin/begin.h" #include "simdjson/generic/ondemand/amalgamated.h" #include "simdjson/builtin/end.h" diff --git a/include/simdjson/dom.h b/include/simdjson/dom.h index 16c36c7be..af2c0ea95 100644 --- a/include/simdjson/dom.h +++ b/include/simdjson/dom.h @@ -1,6 +1,14 @@ #ifndef SIMDJSON_DOM_H #define SIMDJSON_DOM_H +#include "simdjson/generic/dependencies.h" +#include "simdjson/generic/ondemand/dependencies.h" + +#define SIMDJSON_AMALGAMATED + +#include "simdjson/amalgamated.h" #include "simdjson/dom/amalgamated.h" +#undef SIMDJSON_AMALGAMATED + #endif // SIMDJSON_DOM_H diff --git a/include/simdjson/dom/amalgamated.h b/include/simdjson/dom/amalgamated.h index f4b2caf30..7f1369eb9 100644 --- a/include/simdjson/dom/amalgamated.h +++ b/include/simdjson/dom/amalgamated.h @@ -1,10 +1,6 @@ #ifndef SIMDJSON_DOM_AMALGAMATED_H #define SIMDJSON_DOM_AMALGAMATED_H -#ifndef SIMDJSON_AMALGAMATED -#include "simdjson/amalgamated.h" -#endif // SIMDJSON_AMALGAMATED - #include "simdjson/dom/base.h" #include "simdjson/dom/array.h" #include "simdjson/dom/document_stream.h" diff --git a/include/simdjson/generic/amalgamated.h b/include/simdjson/generic/amalgamated.h index ad9b9a01d..4c4ff98f4 100644 --- a/include/simdjson/generic/amalgamated.h +++ b/include/simdjson/generic/amalgamated.h @@ -1,13 +1,5 @@ -#ifndef SIMDJSON_AMALGAMATED -#include "simdjson/amalgamated.h" -#include "simdjson/generic/dependencies.h" -#endif // SIMDJSON_AMALGAMATED - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif #include "simdjson/generic/base.h" diff --git a/include/simdjson/generic/dependencies.h b/include/simdjson/generic/dependencies.h index 4df5705ee..94a2d64f5 100644 --- a/include/simdjson/generic/dependencies.h +++ b/include/simdjson/generic/dependencies.h @@ -1,3 +1,7 @@ +#ifdef SIMDJSON_AMALGAMATED +#error simdjson/generic/dependencies.h must be included before defining SIMDJSON_AMALGAMATED! +#endif + #ifndef SIMDJSON_GENERIC_DEPENDENCIES_H #define SIMDJSON_GENERIC_DEPENDENCIES_H diff --git a/include/simdjson/generic/ondemand/amalgamated.h b/include/simdjson/generic/ondemand/amalgamated.h index e6d60583d..9ddee8cda 100644 --- a/include/simdjson/generic/ondemand/amalgamated.h +++ b/include/simdjson/generic/ondemand/amalgamated.h @@ -1,6 +1,6 @@ -#ifndef SIMDJSON_AMALGAMATED -#include "simdjson/generic/amalgamated.h" -#endif // SIMDJSON_AMALGAMATED +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/ondemand/dependencies.h must be included before simdjson/generic/ondemand/amalgamated.h! +#endif // Stuff other things depend on #include "simdjson/generic/ondemand/base.h" diff --git a/include/simdjson/generic/ondemand/base.h b/include/simdjson/generic/ondemand/base.h index 3236b34b3..1938cfc41 100644 --- a/include/simdjson/generic/ondemand/base.h +++ b/include/simdjson/generic/ondemand/base.h @@ -3,7 +3,6 @@ #ifndef SIMDJSON_AMALGAMATED #define SIMDJSON_GENERIC_ONDEMAND_BASE_H #include "simdjson/generic/base.h" -#include "simdjson/generic/ondemand/dependencies.h" #endif // SIMDJSON_AMALGAMATED namespace simdjson { diff --git a/include/simdjson/generic/ondemand/dependencies.h b/include/simdjson/generic/ondemand/dependencies.h index 92b123b59..445a8e8b4 100644 --- a/include/simdjson/generic/ondemand/dependencies.h +++ b/include/simdjson/generic/ondemand/dependencies.h @@ -1,3 +1,7 @@ +#ifdef SIMDJSON_AMALGAMATED +#error simdjson/generic/ondemand/dependencies.h must be included before defining SIMDJSON_AMALGAMATED! +#endif + #ifndef SIMDJSON_GENERIC_ONDEMAND_DEPENDENCIES_H #define SIMDJSON_GENERIC_ONDEMAND_DEPENDENCIES_H diff --git a/include/simdjson/ondemand.h b/include/simdjson/ondemand.h index 917d9dcca..a43a230a2 100644 --- a/include/simdjson/ondemand.h +++ b/include/simdjson/ondemand.h @@ -1,9 +1,14 @@ #ifndef SIMDJSON_ONDEMAND_H #define SIMDJSON_ONDEMAND_H -#include "simdjson/amalgamated.h" #include "simdjson/generic/dependencies.h" -#include "simdjson/builtin/amalgamated.h" +#include "simdjson/generic/ondemand/dependencies.h" + +#define SIMDJSON_AMALGAMATED + +#include "simdjson/amalgamated.h" #include "simdjson/builtin/ondemand/amalgamated.h" +#undef SIMDJSON_AMALGAMATED + #endif // SIMDJSON_ONDEMAND_H diff --git a/singleheader/amalgamate.py b/singleheader/amalgamate.py index be5492385..09f1506d2 100755 --- a/singleheader/amalgamate.py +++ b/singleheader/amalgamate.py @@ -145,8 +145,6 @@ class Amalgamator: self.write(f"/* amalgamation skipped (editor-only): {line} */") ignoring = False continue - else: - assert line == "#define SIMDJSON_AMALGAMATED", "{file} uses SIMDJSON_AMALGAMATED for unknown purpose: {line}" if ignoring: self.write(f"/* amalgamation skipped (editor-only): {line} */") diff --git a/singleheader/simdjson.cpp b/singleheader/simdjson.cpp index 1d0f093d5..f94e1f3ea 100644 --- a/singleheader/simdjson.cpp +++ b/singleheader/simdjson.cpp @@ -1,4 +1,4 @@ -/* auto-generated on 2023-07-14 20:57:24 -0700. Do not edit! */ +/* auto-generated on 2023-07-15 15:55:38 -0700. Do not edit! */ /* begin file src/simdjson.cpp */ #define SIMDJSON_SRC_SIMDJSON_CPP @@ -3840,6 +3840,11 @@ double from_chars(const char *first, const char *end) noexcept { * @file Base declarations for all simdjson headers * @private */ +/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ +/* amalgamation skipped (editor-only): #if defined(SIMDJSON_IMPLEMENTATION) && (defined(SIMDJSON_SRC_SIMDJSON_CPP) || defined(SIMDJSON_H)) */ +/* amalgamation skipped (editor-only): #error implementation-specific code included in simdjson.cpp or simdjson.h without amalgamating first! */ +/* amalgamation skipped (editor-only): #endif */ +/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ #ifndef SIMDJSON_BASE_H #define SIMDJSON_BASE_H @@ -6947,6 +6952,10 @@ const implementation * builtin_implementation() { /* end file src/implementation.cpp */ /* begin file include/simdjson/generic/dependencies.h */ +#ifdef SIMDJSON_AMALGAMATED +#error simdjson/generic/dependencies.h must be included before defining SIMDJSON_AMALGAMATED! +#endif + #ifndef SIMDJSON_GENERIC_DEPENDENCIES_H #define SIMDJSON_GENERIC_DEPENDENCIES_H @@ -7180,13 +7189,13 @@ inline std::ostream& operator<<(std::ostream& out, simdjson_result -#include -#include -#include - -namespace simdjson { - -class padded_string_view; - -/** - * String with extra allocation for ease of use with parser::parse() - * - * This is a move-only class, it cannot be copied. - */ -struct padded_string final { - - /** - * Create a new, empty padded string. - */ - explicit inline padded_string() noexcept; - /** - * Create a new padded string buffer. - * - * @param length the size of the string. - */ - explicit inline padded_string(size_t length) noexcept; - /** - * Create a new padded string by copying the given input. - * - * @param data the buffer to copy - * @param length the number of bytes to copy - */ - explicit inline padded_string(const char *data, size_t length) noexcept; - /** - * Create a new padded string by copying the given input. - * - * @param str_ the string to copy - */ - inline padded_string(const std::string & str_ ) noexcept; - /** - * Create a new padded string by copying the given input. - * - * @param sv_ the string to copy - */ - inline padded_string(std::string_view sv_) noexcept; - /** - * Move one padded string into another. - * - * The original padded string will be reduced to zero capacity. - * - * @param o the string to move. - */ - inline padded_string(padded_string &&o) noexcept; - /** - * Move one padded string into another. - * - * The original padded string will be reduced to zero capacity. - * - * @param o the string to move. - */ - inline padded_string &operator=(padded_string &&o) noexcept; - inline void swap(padded_string &o) noexcept; - ~padded_string() noexcept; - - /** - * The length of the string. - * - * Does not include padding. - */ - size_t size() const noexcept; - - /** - * The length of the string. - * - * Does not include padding. - */ - size_t length() const noexcept; - - /** - * The string data. - **/ - const char *data() const noexcept; - const uint8_t *u8data() const noexcept { return static_cast(static_cast(data_ptr));} - - /** - * The string data. - **/ - char *data() noexcept; - - /** - * Create a std::string_view with the same content. - */ - operator std::string_view() const; - - /** - * Create a padded_string_view with the same content. - */ - operator padded_string_view() const noexcept; - - /** - * Load this padded string from a file. - * - * @return IO_ERROR on error. Be mindful that on some 32-bit systems, - * the file size might be limited to 2 GB. - * - * @param path the path to the file. - **/ - inline static simdjson_result load(std::string_view path) noexcept; - -private: - padded_string &operator=(const padded_string &o) = delete; - padded_string(const padded_string &o) = delete; - - size_t viable_size{0}; - char *data_ptr{nullptr}; - -}; // padded_string - -/** - * Send padded_string instance to an output stream. - * - * @param out The output stream. - * @param s The padded_string instance. - * @throw if there is an error with the underlying output stream. simdjson itself will not throw. - */ -inline std::ostream& operator<<(std::ostream& out, const padded_string& s) { return out << s.data(); } - -#if SIMDJSON_EXCEPTIONS -/** - * Send padded_string instance to an output stream. - * - * @param out The output stream. - * @param s The padded_string instance. - * @throw simdjson_error if the result being printed has an error. If there is an error with the - * underlying output stream, that error will be propagated (simdjson_error will not be - * thrown). - */ -inline std::ostream& operator<<(std::ostream& out, simdjson_result &s) noexcept(false) { return out << s.value(); } -#endif - -} // namespace simdjson - -// This is deliberately outside of simdjson so that people get it without having to use the namespace -inline simdjson::padded_string operator "" _padded(const char *str, size_t len) { - return simdjson::padded_string(str, len); -} - -namespace simdjson { -namespace internal { - -// The allocate_padded_buffer function is a low-level function to allocate memory -// with padding so we can read past the "length" bytes safely. It is used by -// the padded_string class automatically. It returns nullptr in case -// of error: the caller should check for a null pointer. -// The length parameter is the maximum size in bytes of the string. -// The caller is responsible to free the memory (e.g., delete[] (...)). -inline char *allocate_padded_buffer(size_t length) noexcept; - -} // namespace internal -} // namespace simdjson - -#endif // SIMDJSON_PADDED_STRING_H -/* end file include/simdjson/padded_string.h */ -#include -#include -#include - -namespace simdjson { - -/** - * - * Minify the input string assuming that it represents a JSON string, does not parse or validate. - * This function is much faster than parsing a JSON string and then writing a minified version of it. - * However, it does not validate the input. It will merely return an error in simple cases (e.g., if - * there is a string that was never terminated). - * - * - * @param buf the json document to minify. - * @param len the length of the json document. - * @param dst the buffer to write the minified document to. *MUST* be allocated up to len bytes. - * @param dst_len the number of bytes written. Output only. - * @return the error code, or SUCCESS if there was no error. - */ -simdjson_warn_unused error_code minify(const char *buf, size_t len, char *dst, size_t &dst_len) noexcept; - -} // namespace simdjson - -#endif // SIMDJSON_MINIFY_H -/* end file include/simdjson/minify.h */ -/* skipped duplicate #include "simdjson/padded_string.h" */ -/* begin file include/simdjson/padded_string-inl.h */ -#ifndef SIMDJSON_INLINE_PADDED_STRING_H -#define SIMDJSON_INLINE_PADDED_STRING_H - -/* skipped duplicate #include "simdjson/padded_string.h" */ -/* skipped duplicate #include "simdjson/padded_string_view.h" */ - -#include - -namespace simdjson { -namespace internal { - -// The allocate_padded_buffer function is a low-level function to allocate memory -// with padding so we can read past the "length" bytes safely. It is used by -// the padded_string class automatically. It returns nullptr in case -// of error: the caller should check for a null pointer. -// The length parameter is the maximum size in bytes of the string. -// The caller is responsible to free the memory (e.g., delete[] (...)). -inline char *allocate_padded_buffer(size_t length) noexcept { - const size_t totalpaddedlength = length + SIMDJSON_PADDING; - if(totalpaddedlength(1UL<<20)) { - return nullptr; - } -#endif - - char *padded_buffer = new (std::nothrow) char[totalpaddedlength]; - if (padded_buffer == nullptr) { - return nullptr; - } - // We write nulls in the padded region to avoid having uninitialized - // content which may trigger warning for some sanitizers - std::memset(padded_buffer + length, 0, totalpaddedlength - length); - return padded_buffer; -} // allocate_padded_buffer() - -} // namespace internal - - -inline padded_string::padded_string() noexcept = default; -inline padded_string::padded_string(size_t length) noexcept - : viable_size(length), data_ptr(internal::allocate_padded_buffer(length)) { -} -inline padded_string::padded_string(const char *data, size_t length) noexcept - : viable_size(length), data_ptr(internal::allocate_padded_buffer(length)) { - if ((data != nullptr) && (data_ptr != nullptr)) { - std::memcpy(data_ptr, data, length); - } -} -// note: do not pass std::string arguments by value -inline padded_string::padded_string(const std::string & str_ ) noexcept - : viable_size(str_.size()), data_ptr(internal::allocate_padded_buffer(str_.size())) { - if (data_ptr != nullptr) { - std::memcpy(data_ptr, str_.data(), str_.size()); - } -} -// note: do pass std::string_view arguments by value -inline padded_string::padded_string(std::string_view sv_) noexcept - : viable_size(sv_.size()), data_ptr(internal::allocate_padded_buffer(sv_.size())) { - if(simdjson_unlikely(!data_ptr)) { - //allocation failed or zero size - viable_size = 0; - return; - } - if (sv_.size()) { - std::memcpy(data_ptr, sv_.data(), sv_.size()); - } -} -inline padded_string::padded_string(padded_string &&o) noexcept - : viable_size(o.viable_size), data_ptr(o.data_ptr) { - o.data_ptr = nullptr; // we take ownership -} - -inline padded_string &padded_string::operator=(padded_string &&o) noexcept { - delete[] data_ptr; - data_ptr = o.data_ptr; - viable_size = o.viable_size; - o.data_ptr = nullptr; // we take ownership - o.viable_size = 0; - return *this; -} - -inline void padded_string::swap(padded_string &o) noexcept { - size_t tmp_viable_size = viable_size; - char *tmp_data_ptr = data_ptr; - viable_size = o.viable_size; - data_ptr = o.data_ptr; - o.data_ptr = tmp_data_ptr; - o.viable_size = tmp_viable_size; -} - -inline padded_string::~padded_string() noexcept { - delete[] data_ptr; -} - -inline size_t padded_string::size() const noexcept { return viable_size; } - -inline size_t padded_string::length() const noexcept { return viable_size; } - -inline const char *padded_string::data() const noexcept { return data_ptr; } - -inline char *padded_string::data() noexcept { return data_ptr; } - -inline padded_string::operator std::string_view() const { return std::string_view(data(), length()); } - -inline padded_string::operator padded_string_view() const noexcept { - return padded_string_view(data(), length(), length() + SIMDJSON_PADDING); -} - -inline simdjson_result padded_string::load(std::string_view filename) noexcept { - // 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.data(), "rb"); - SIMDJSON_POP_DISABLE_WARNINGS - - if (fp == nullptr) { - return IO_ERROR; - } - - // Get the file size - int ret; -#if SIMDJSON_VISUAL_STUDIO && !SIMDJSON_IS_32BITS - ret = _fseeki64(fp, 0, SEEK_END); -#else - ret = std::fseek(fp, 0, SEEK_END); -#endif // _WIN64 - if(ret < 0) { - std::fclose(fp); - return IO_ERROR; - } -#if SIMDJSON_VISUAL_STUDIO && !SIMDJSON_IS_32BITS - __int64 llen = _ftelli64(fp); - if(llen == -1L) { - std::fclose(fp); - return IO_ERROR; - } -#else - long llen = std::ftell(fp); - if((llen < 0) || (llen == LONG_MAX)) { - std::fclose(fp); - return IO_ERROR; - } -#endif - - // Allocate the padded_string - size_t len = static_cast(llen); - padded_string s(len); - if (s.data() == nullptr) { - std::fclose(fp); - return MEMALLOC; - } - - // Read the padded_string - std::rewind(fp); - size_t bytes_read = std::fread(s.data(), 1, len, fp); - if (std::fclose(fp) != 0 || bytes_read != len) { - return IO_ERROR; - } - - return s; -} - -} // namespace simdjson - -#endif // SIMDJSON_INLINE_PADDED_STRING_H -/* end file include/simdjson/padded_string-inl.h */ -/* skipped duplicate #include "simdjson/padded_string_view.h" */ -/* begin file include/simdjson/padded_string_view-inl.h */ -#ifndef SIMDJSON_PADDED_STRING_VIEW_INL_H -#define SIMDJSON_PADDED_STRING_VIEW_INL_H - -/* skipped duplicate #include "simdjson/padded_string_view.h" */ - -namespace simdjson { - -inline padded_string_view::padded_string_view(const char* s, size_t len, size_t capacity) noexcept - : std::string_view(s, len), _capacity(capacity) -{ -} - -inline padded_string_view::padded_string_view(const uint8_t* s, size_t len, size_t capacity) noexcept - : padded_string_view(reinterpret_cast(s), len, capacity) -{ -} - -inline padded_string_view::padded_string_view(const std::string &s) noexcept - : std::string_view(s), _capacity(s.capacity()) -{ -} - -inline padded_string_view::padded_string_view(std::string_view s, size_t capacity) noexcept - : std::string_view(s), _capacity(capacity) -{ -} - -inline size_t padded_string_view::capacity() const noexcept { return _capacity; } - -inline size_t padded_string_view::padding() const noexcept { return capacity() - length(); } - -} // namespace simdjson - -#endif // SIMDJSON_PADDED_STRING_VIEW_INL_H -/* end file include/simdjson/padded_string_view-inl.h */ - -/* begin file include/simdjson/internal/simdprune_tables.h */ -#ifndef SIMDJSON_INTERNAL_SIMDPRUNE_TABLES_H -#define SIMDJSON_INTERNAL_SIMDPRUNE_TABLES_H - -/* skipped duplicate #include "simdjson/base.h" */ - -#include - -namespace simdjson { // table modified and copied from -namespace internal { // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetTable - -extern SIMDJSON_DLLIMPORTEXPORT const unsigned char BitsSetTable256mul2[256]; - -extern SIMDJSON_DLLIMPORTEXPORT const uint8_t pshufb_combine_table[272]; - -// 256 * 8 bytes = 2kB, easily fits in cache. -extern SIMDJSON_DLLIMPORTEXPORT const uint64_t thintable_epi8[256]; - -} // namespace internal -} // namespace simdjson - -#endif // SIMDJSON_INTERNAL_SIMDPRUNE_TABLES_H -/* end file include/simdjson/internal/simdprune_tables.h */ - -#endif // SIMDJSON_AMALGAMATED_H -/* end file include/simdjson/amalgamated.h */ - #if SIMDJSON_IMPLEMENTATION_ARM64 /* begin file src/arm64.cpp */ #ifndef SIMDJSON_SRC_ARM64_CPP #define SIMDJSON_SRC_ARM64_CPP -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - /* skipped duplicate #include "simdjson/arm64/implementation.h" */ /* begin file include/simdjson/arm64/amalgamated.h */ #ifndef SIMDJSON_ARM64_AMALGAMATED_H @@ -8535,16 +8062,8 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin /* end file include/simdjson/arm64/stringparsing_defs.h */ /* end file include/simdjson/arm64/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for arm64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for arm64 */ @@ -10392,16 +9911,15 @@ simdjson_inline implementation_simdjson_result_base::implementation_simdjson_ /* skipped duplicate #include "simdjson/arm64/stringparsing_defs.h" */ /* end file include/simdjson/arm64/begin.h */ /* begin file src/generic/amalgamated.h for arm64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_SRC_GENERIC_DEPENDENCIES_H) +#error generic/dependencies.h must be included before generic/amalgamated.h! +#endif /* begin file src/generic/base.h for arm64 */ #ifndef SIMDJSON_SRC_GENERIC_BASE_H /* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ /* amalgamation skipped (editor-only): #define SIMDJSON_SRC_GENERIC_BASE_H */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ /* amalgamation skipped (editor-only): #include "simdjson/generic/base.h" */ /* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ @@ -10471,10 +9989,6 @@ struct json_character_block { /* end file src/generic/json_character_block.h for arm64 */ /* end file src/generic/amalgamated.h for arm64 */ /* begin file src/generic/stage1/amalgamated.h for arm64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage1/base.h for arm64 */ #ifndef SIMDJSON_SRC_GENERIC_STAGE1_BASE_H @@ -11805,10 +11319,6 @@ bool generic_validate_utf8(const char * input, size_t length) { /* end file src/generic/stage1/utf8_validator.h for arm64 */ /* end file src/generic/stage1/amalgamated.h for arm64 */ /* begin file src/generic/stage2/amalgamated.h for arm64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage2/base.h for arm64 */ #ifndef SIMDJSON_SRC_GENERIC_STAGE2_BASE_H @@ -13174,10 +12684,6 @@ simdjson_warn_unused error_code dom_parser_implementation::parse(const uint8_t * #ifndef SIMDJSON_SRC_FALLBACK_CPP #define SIMDJSON_SRC_FALLBACK_CPP -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - /* skipped duplicate #include "simdjson/fallback/implementation.h" */ /* begin file include/simdjson/fallback/amalgamated.h */ #ifndef SIMDJSON_FALLBACK_AMALGAMATED_H @@ -13335,16 +12841,8 @@ static simdjson_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars /* end file include/simdjson/fallback/numberparsing_defs.h */ /* end file include/simdjson/fallback/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for fallback */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for fallback */ @@ -16788,11 +16286,6 @@ simdjson_warn_unused error_code dom_parser_implementation::parse(const uint8_t * #ifndef SIMDJSON_SRC_HASWELL_CPP #define SIMDJSON_SRC_HASWELL_CPP -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -/* skipped duplicate #include "generic/dependencies.h" */ /* skipped duplicate #include "simdjson/haswell/implementation.h" */ /* begin file include/simdjson/haswell/amalgamated.h */ #ifndef SIMDJSON_HASWELL_AMALGAMATED_H @@ -17037,7 +16530,29 @@ static simdjson_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars /* skipped duplicate #include "simdjson/haswell/intrinsics.h" */ /* skipped duplicate #include "simdjson/haswell/bitmanipulation.h" */ -/* skipped duplicate #include "simdjson/internal/simdprune_tables.h" */ +/* begin file include/simdjson/internal/simdprune_tables.h */ +#ifndef SIMDJSON_INTERNAL_SIMDPRUNE_TABLES_H +#define SIMDJSON_INTERNAL_SIMDPRUNE_TABLES_H + +/* skipped duplicate #include "simdjson/base.h" */ + +#include + +namespace simdjson { // table modified and copied from +namespace internal { // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetTable + +extern SIMDJSON_DLLIMPORTEXPORT const unsigned char BitsSetTable256mul2[256]; + +extern SIMDJSON_DLLIMPORTEXPORT const uint8_t pshufb_combine_table[272]; + +// 256 * 8 bytes = 2kB, easily fits in cache. +extern SIMDJSON_DLLIMPORTEXPORT const uint64_t thintable_epi8[256]; + +} // namespace internal +} // namespace simdjson + +#endif // SIMDJSON_INTERNAL_SIMDPRUNE_TABLES_H +/* end file include/simdjson/internal/simdprune_tables.h */ namespace simdjson { namespace haswell { @@ -17451,16 +16966,8 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin /* end file include/simdjson/haswell/stringparsing_defs.h */ /* end file include/simdjson/haswell/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for haswell */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for haswell */ @@ -19319,16 +18826,15 @@ SIMDJSON_TARGET_REGION("avx2,bmi,pclmul,lzcnt,popcnt") /* skipped duplicate #include "simdjson/haswell/stringparsing_defs.h" */ /* end file include/simdjson/haswell/begin.h */ /* begin file src/generic/amalgamated.h for haswell */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_SRC_GENERIC_DEPENDENCIES_H) +#error generic/dependencies.h must be included before generic/amalgamated.h! +#endif /* begin file src/generic/base.h for haswell */ #ifndef SIMDJSON_SRC_GENERIC_BASE_H /* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ /* amalgamation skipped (editor-only): #define SIMDJSON_SRC_GENERIC_BASE_H */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ /* amalgamation skipped (editor-only): #include "simdjson/generic/base.h" */ /* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ @@ -19398,10 +18904,6 @@ struct json_character_block { /* end file src/generic/json_character_block.h for haswell */ /* end file src/generic/amalgamated.h for haswell */ /* begin file src/generic/stage1/amalgamated.h for haswell */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage1/base.h for haswell */ #ifndef SIMDJSON_SRC_GENERIC_STAGE1_BASE_H @@ -20732,10 +20234,6 @@ bool generic_validate_utf8(const char * input, size_t length) { /* end file src/generic/stage1/utf8_validator.h for haswell */ /* end file src/generic/stage1/amalgamated.h for haswell */ /* begin file src/generic/stage2/amalgamated.h for haswell */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage2/base.h for haswell */ #ifndef SIMDJSON_SRC_GENERIC_STAGE2_BASE_H @@ -22103,10 +21601,6 @@ SIMDJSON_UNTARGET_REGION #ifndef SIMDJSON_SRC_ICELAKE_CPP #define SIMDJSON_SRC_ICELAKE_CPP -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - /* skipped duplicate #include "simdjson/icelake/implementation.h" */ /* begin file include/simdjson/icelake/amalgamated.h */ #ifndef SIMDJSON_ICELAKE_AMALGAMATED_H @@ -22736,16 +22230,8 @@ static simdjson_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars /* end file include/simdjson/icelake/numberparsing_defs.h */ /* end file include/simdjson/icelake/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for icelake */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for icelake */ @@ -24588,6 +24074,9 @@ SIMDJSON_UNTARGET_REGION #endif // SIMDJSON_ICELAKE_AMALGAMATED_H /* end file include/simdjson/icelake/amalgamated.h */ +// defining SIMDJSON_GENERIC_JSON_STRUCTURAL_INDEXER_CUSTOM_BIT_INDEXER allows us to provide our own bit_indexer::write +#define SIMDJSON_GENERIC_JSON_STRUCTURAL_INDEXER_CUSTOM_BIT_INDEXER + /* begin file include/simdjson/icelake/begin.h */ /* defining SIMDJSON_IMPLEMENTATION to "icelake": #define SIMDJSON_IMPLEMENTATION icelake */ /* skipped duplicate #include "simdjson/icelake/base.h" */ @@ -24604,16 +24093,15 @@ SIMDJSON_TARGET_REGION("avx512f,avx512dq,avx512cd,avx512bw,avx512vbmi,avx512vbmi /* skipped duplicate #include "simdjson/icelake/numberparsing_defs.h" */ /* end file include/simdjson/icelake/begin.h */ /* begin file src/generic/amalgamated.h for icelake */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_SRC_GENERIC_DEPENDENCIES_H) +#error generic/dependencies.h must be included before generic/amalgamated.h! +#endif /* begin file src/generic/base.h for icelake */ #ifndef SIMDJSON_SRC_GENERIC_BASE_H /* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ /* amalgamation skipped (editor-only): #define SIMDJSON_SRC_GENERIC_BASE_H */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ /* amalgamation skipped (editor-only): #include "simdjson/generic/base.h" */ /* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ @@ -24682,13 +24170,7 @@ struct json_character_block { #endif // SIMDJSON_SRC_GENERIC_JSON_CHARACTER_BLOCK_H /* end file src/generic/json_character_block.h for icelake */ /* end file src/generic/amalgamated.h for icelake */ -// defining SIMDJSON_GENERIC_JSON_STRUCTURAL_INDEXER_CUSTOM_BIT_INDEXER allows us to provide our own bit_indexer::write -#define SIMDJSON_GENERIC_JSON_STRUCTURAL_INDEXER_CUSTOM_BIT_INDEXER /* begin file src/generic/stage1/amalgamated.h for icelake */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage1/base.h for icelake */ #ifndef SIMDJSON_SRC_GENERIC_STAGE1_BASE_H @@ -26019,10 +25501,6 @@ bool generic_validate_utf8(const char * input, size_t length) { /* end file src/generic/stage1/utf8_validator.h for icelake */ /* end file src/generic/stage1/amalgamated.h for icelake */ /* begin file src/generic/stage2/amalgamated.h for icelake */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage2/base.h for icelake */ #ifndef SIMDJSON_SRC_GENERIC_STAGE2_BASE_H @@ -27210,6 +26688,8 @@ simdjson_inline void tape_builder::on_end_string(uint8_t *dst) noexcept { /* end file src/generic/stage2/tape_builder.h for icelake */ /* end file src/generic/stage2/amalgamated.h for icelake */ +#undef SIMDJSON_GENERIC_JSON_STRUCTURAL_INDEXER_CUSTOM_BIT_INDEXER + // // Stage 1 // @@ -27431,10 +26911,6 @@ SIMDJSON_UNTARGET_REGION #ifndef SIMDJSON_SRC_PPC64_CPP #define SIMDJSON_SRC_PPC64_CPP -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - /* skipped duplicate #include "simdjson/ppc64/implementation.h" */ /* begin file include/simdjson/ppc64/amalgamated.h */ #ifndef SIMDJSON_PPC64_AMALGAMATED_H @@ -28202,16 +27678,8 @@ backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) { /* end file include/simdjson/ppc64/stringparsing_defs.h */ /* end file include/simdjson/ppc64/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for ppc64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for ppc64 */ @@ -30059,16 +29527,15 @@ simdjson_inline implementation_simdjson_result_base::implementation_simdjson_ /* skipped duplicate #include "simdjson/ppc64/stringparsing_defs.h" */ /* end file include/simdjson/ppc64/begin.h */ /* begin file src/generic/amalgamated.h for ppc64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_SRC_GENERIC_DEPENDENCIES_H) +#error generic/dependencies.h must be included before generic/amalgamated.h! +#endif /* begin file src/generic/base.h for ppc64 */ #ifndef SIMDJSON_SRC_GENERIC_BASE_H /* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ /* amalgamation skipped (editor-only): #define SIMDJSON_SRC_GENERIC_BASE_H */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ /* amalgamation skipped (editor-only): #include "simdjson/generic/base.h" */ /* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ @@ -30138,10 +29605,6 @@ struct json_character_block { /* end file src/generic/json_character_block.h for ppc64 */ /* end file src/generic/amalgamated.h for ppc64 */ /* begin file src/generic/stage1/amalgamated.h for ppc64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage1/base.h for ppc64 */ #ifndef SIMDJSON_SRC_GENERIC_STAGE1_BASE_H @@ -31472,10 +30935,6 @@ bool generic_validate_utf8(const char * input, size_t length) { /* end file src/generic/stage1/utf8_validator.h for ppc64 */ /* end file src/generic/stage1/amalgamated.h for ppc64 */ /* begin file src/generic/stage2/amalgamated.h for ppc64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage2/base.h for ppc64 */ #ifndef SIMDJSON_SRC_GENERIC_STAGE2_BASE_H @@ -32818,11 +32277,6 @@ simdjson_warn_unused error_code dom_parser_implementation::parse(const uint8_t * #ifndef SIMDJSON_SRC_WESTMERE_CPP #define SIMDJSON_SRC_WESTMERE_CPP -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -/* skipped duplicate #include "generic/dependencies.h" */ /* skipped duplicate #include "simdjson/westmere/implementation.h" */ /* begin file include/simdjson/westmere/amalgamated.h */ #ifndef SIMDJSON_WESTMERE_AMALGAMATED_H @@ -33432,16 +32886,8 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin /* end file include/simdjson/westmere/stringparsing_defs.h */ /* end file include/simdjson/westmere/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for westmere */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for westmere */ @@ -35300,16 +34746,15 @@ SIMDJSON_TARGET_REGION("sse4.2,pclmul,popcnt") /* skipped duplicate #include "simdjson/westmere/stringparsing_defs.h" */ /* end file include/simdjson/westmere/begin.h */ /* begin file src/generic/amalgamated.h for westmere */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_SRC_GENERIC_DEPENDENCIES_H) +#error generic/dependencies.h must be included before generic/amalgamated.h! +#endif /* begin file src/generic/base.h for westmere */ #ifndef SIMDJSON_SRC_GENERIC_BASE_H /* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ /* amalgamation skipped (editor-only): #define SIMDJSON_SRC_GENERIC_BASE_H */ -/* amalgamation skipped (editor-only): #include "generic/dependencies.h" */ /* amalgamation skipped (editor-only): #include "simdjson/generic/base.h" */ /* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ @@ -35379,10 +34824,6 @@ struct json_character_block { /* end file src/generic/json_character_block.h for westmere */ /* end file src/generic/amalgamated.h for westmere */ /* begin file src/generic/stage1/amalgamated.h for westmere */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage1/base.h for westmere */ #ifndef SIMDJSON_SRC_GENERIC_STAGE1_BASE_H @@ -36713,10 +36154,6 @@ bool generic_validate_utf8(const char * input, size_t length) { /* end file src/generic/stage1/utf8_validator.h for westmere */ /* end file src/generic/stage1/amalgamated.h for westmere */ /* begin file src/generic/stage2/amalgamated.h for westmere */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - // Stuff other things depend on /* begin file src/generic/stage2/base.h for westmere */ #ifndef SIMDJSON_SRC_GENERIC_STAGE2_BASE_H @@ -38085,6 +37522,8 @@ SIMDJSON_UNTARGET_REGION /* end file src/westmere.cpp */ #endif +#undef SIMDJSON_AMALGAMATED + SIMDJSON_POP_DISABLE_UNUSED_WARNINGS /* end file src/simdjson.cpp */ diff --git a/singleheader/simdjson.h b/singleheader/simdjson.h index 387e6ef96..322ad3ecb 100644 --- a/singleheader/simdjson.h +++ b/singleheader/simdjson.h @@ -1,4 +1,4 @@ -/* auto-generated on 2023-07-14 20:57:24 -0700. Do not edit! */ +/* auto-generated on 2023-07-15 15:55:38 -0700. Do not edit! */ /* begin file include/simdjson.h */ #ifndef SIMDJSON_H #define SIMDJSON_H @@ -2302,48 +2302,35 @@ namespace std { SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS -/* begin file include/simdjson/amalgamated.h */ -#ifndef SIMDJSON_AMALGAMATED_H -#define SIMDJSON_AMALGAMATED_H +/* begin file include/simdjson/generic/dependencies.h */ +#ifdef SIMDJSON_AMALGAMATED +#error simdjson/generic/dependencies.h must be included before defining SIMDJSON_AMALGAMATED! +#endif -#define SIMDJSON_AMALGAMATED +#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H +#define SIMDJSON_GENERIC_DEPENDENCIES_H -// This provides the public API for simdjson. -// DOM and ondemand are amalgamated separately, in simdjson.h -/* begin file include/simdjson/simdjson_version.h */ -// /include/simdjson/simdjson_version.h automatically generated by release.py, -// do not change by hand -#ifndef SIMDJSON_SIMDJSON_VERSION_H -#define SIMDJSON_SIMDJSON_VERSION_H +// Internal headers needed for generics. +// All includes referencing simdjson headers *not* under simdjson/generic must be here! +// Otherwise, amalgamation will fail. +/* begin file include/simdjson/dom/document.h */ +#ifndef SIMDJSON_DOM_DOCUMENT_H +#define SIMDJSON_DOM_DOCUMENT_H -/** The version of simdjson being used (major.minor.revision) */ -#define SIMDJSON_VERSION "3.2.1" - -namespace simdjson { -enum { - /** - * The major version (MAJOR.minor.revision) of simdjson being used. - */ - SIMDJSON_VERSION_MAJOR = 3, - /** - * The minor version (major.MINOR.revision) of simdjson being used. - */ - SIMDJSON_VERSION_MINOR = 2, - /** - * The revision (major.minor.REVISION) of simdjson being used. - */ - SIMDJSON_VERSION_REVISION = 1 -}; -} // namespace simdjson - -#endif // SIMDJSON_SIMDJSON_VERSION_H -/* end file include/simdjson/simdjson_version.h */ +/* begin file include/simdjson/dom/base.h */ +#ifndef SIMDJSON_DOM_BASE_H +#define SIMDJSON_DOM_BASE_H /* begin file include/simdjson/base.h */ /** * @file Base declarations for all simdjson headers * @private */ +/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ +/* amalgamation skipped (editor-only): #if defined(SIMDJSON_IMPLEMENTATION) && (defined(SIMDJSON_SRC_SIMDJSON_CPP) || defined(SIMDJSON_H)) */ +/* amalgamation skipped (editor-only): #error implementation-specific code included in simdjson.cpp or simdjson.h without amalgamating first! */ +/* amalgamation skipped (editor-only): #endif */ +/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ #ifndef SIMDJSON_BASE_H #define SIMDJSON_BASE_H @@ -2710,6 +2697,536 @@ enum class tape_type; #endif // SIMDJSON_BASE_H /* end file include/simdjson/base.h */ +namespace simdjson { + +/** + * @brief A DOM API on top of the simdjson parser. + */ +namespace dom { + +/** The default batch size for parser.parse_many() and parser.load_many() */ +static constexpr size_t DEFAULT_BATCH_SIZE = 1000000; +/** + * Some adversary might try to set the batch size to 0 or 1, which might cause problems. + * We set a minimum of 32B since anything else is highly likely to be an error. In practice, + * most users will want a much larger batch size. + * + * All non-negative MINIMAL_BATCH_SIZE values should be 'safe' except that, obviously, no JSON + * document can ever span 0 or 1 byte and that very large values would create memory allocation issues. + */ +static constexpr size_t MINIMAL_BATCH_SIZE = 32; + +/** + * It is wasteful to allocate memory for tiny documents (e.g., 4 bytes). + */ +static constexpr size_t MINIMAL_DOCUMENT_CAPACITY = 32; + +class array; +class document; +class document_stream; +class element; +class key_value_pair; +class object; +class parser; + +} // namespace dom + +namespace internal { + +template +class string_builder; +class tape_ref; + +} // namespace internal + +} // namespace simdjson + +#endif // SIMDJSON_DOM_BASE_H +/* end file include/simdjson/dom/base.h */ + +namespace simdjson { +namespace dom { + +/** + * A parsed JSON document. + * + * This class cannot be copied, only moved, to avoid unintended allocations. + */ +class document { +public: + /** + * Create a document container with zero capacity. + * + * The parser will allocate capacity as needed. + */ + document() noexcept = default; + ~document() noexcept = default; + + /** + * Take another document's buffers. + * + * @param other The document to take. Its capacity is zeroed and it is invalidated. + */ + document(document &&other) noexcept = default; + /** @private */ + document(const document &) = delete; // Disallow copying + /** + * Take another document's buffers. + * + * @param other The document to take. Its capacity is zeroed. + */ + document &operator=(document &&other) noexcept = default; + /** @private */ + document &operator=(const document &) = delete; // Disallow copying + + /** + * Get the root element of this document as a JSON array. + */ + element root() const noexcept; + + /** + * @private Dump the raw tape for debugging. + * + * @param os the stream to output to. + * @return false if the tape is likely wrong (e.g., you did not parse a valid JSON). + */ + bool dump_raw_tape(std::ostream &os) const noexcept; + + /** @private Structural values. */ + std::unique_ptr tape{}; + + /** @private String values. + * + * Should be at least byte_capacity. + */ + std::unique_ptr string_buf{}; + /** @private Allocate memory to support + * input JSON documents of up to len bytes. + * + * When calling this function, you lose + * all the data. + * + * The memory allocation is strict: you + * can you use this function to increase + * or lower the amount of allocated memory. + * Passsing zero clears the memory. + */ + error_code allocate(size_t len) noexcept; + /** @private Capacity in bytes, in terms + * of how many bytes of input JSON we can + * support. + */ + size_t capacity() const noexcept; + + +private: + size_t allocated_capacity{0}; + friend class parser; +}; // class document + +} // namespace dom +} // namespace simdjson + +#endif // SIMDJSON_DOM_DOCUMENT_H +/* end file include/simdjson/dom/document.h */ +/* begin file include/simdjson/internal/jsoncharutils_tables.h */ +#ifndef SIMDJSON_INTERNAL_JSONCHARUTILS_TABLES_H +#define SIMDJSON_INTERNAL_JSONCHARUTILS_TABLES_H + +/* skipped duplicate #include "simdjson/base.h" */ + +#ifdef JSON_TEST_STRINGS +void found_string(const uint8_t *buf, const uint8_t *parsed_begin, + const uint8_t *parsed_end); +void found_bad_string(const uint8_t *buf); +#endif + +namespace simdjson { +namespace internal { +// structural chars here are +// they are { 0x7b } 0x7d : 0x3a [ 0x5b ] 0x5d , 0x2c (and NULL) +// we are also interested in the four whitespace characters +// space 0x20, linefeed 0x0a, horizontal tab 0x09 and carriage return 0x0d + +extern SIMDJSON_DLLIMPORTEXPORT const bool structural_or_whitespace_negated[256]; +extern SIMDJSON_DLLIMPORTEXPORT const bool structural_or_whitespace[256]; +extern SIMDJSON_DLLIMPORTEXPORT const uint32_t digit_to_val32[886]; + +} // namespace internal +} // namespace simdjson + +#endif // SIMDJSON_INTERNAL_JSONCHARUTILS_TABLES_H +/* end file include/simdjson/internal/jsoncharutils_tables.h */ +/* begin file include/simdjson/internal/numberparsing_tables.h */ +#ifndef SIMDJSON_INTERNAL_NUMBERPARSING_TABLES_H +#define SIMDJSON_INTERNAL_NUMBERPARSING_TABLES_H + +/* skipped duplicate #include "simdjson/base.h" */ + +namespace simdjson { +namespace internal { +/** + * The smallest non-zero float (binary64) is 2^-1074. + * We take as input numbers of the form w x 10^q where w < 2^64. + * We have that w * 10^-343 < 2^(64-344) 5^-343 < 2^-1076. + * However, we have that + * (2^64-1) * 10^-342 = (2^64-1) * 2^-342 * 5^-342 > 2^-1074. + * Thus it is possible for a number of the form w * 10^-342 where + * w is a 64-bit value to be a non-zero floating-point number. + ********* + * Any number of form w * 10^309 where w>= 1 is going to be + * infinite in binary64 so we never need to worry about powers + * of 5 greater than 308. + */ +constexpr int smallest_power = -342; +constexpr int largest_power = 308; + +/** + * Represents a 128-bit value. + * low: least significant 64 bits. + * high: most significant 64 bits. + */ +struct value128 { + uint64_t low; + uint64_t high; +}; + + +// Precomputed powers of ten from 10^0 to 10^22. These +// can be represented exactly using the double type. +extern SIMDJSON_DLLIMPORTEXPORT const double power_of_ten[]; + + +/** + * When mapping numbers from decimal to binary, + * we go from w * 10^q to m * 2^p but we have + * 10^q = 5^q * 2^q, so effectively + * we are trying to match + * w * 2^q * 5^q to m * 2^p. Thus the powers of two + * are not a concern since they can be represented + * exactly using the binary notation, only the powers of five + * affect the binary significand. + */ + + +// The truncated powers of five from 5^-342 all the way to 5^308 +// The mantissa is truncated to 128 bits, and +// never rounded up. Uses about 10KB. +extern SIMDJSON_DLLIMPORTEXPORT const uint64_t power_of_five_128[]; +} // namespace internal +} // namespace simdjson + +#endif // SIMDJSON_INTERNAL_NUMBERPARSING_TABLES_H +/* end file include/simdjson/internal/numberparsing_tables.h */ +/* begin file include/simdjson/padded_string_view.h */ +#ifndef SIMDJSON_PADDED_STRING_VIEW_H +#define SIMDJSON_PADDED_STRING_VIEW_H + +/* skipped duplicate #include "simdjson/portability.h" */ +/* skipped duplicate #include "simdjson/base.h" // for SIMDJSON_PADDING */ +/* skipped duplicate #include "simdjson/error.h" */ + +#include +#include +#include +#include + +namespace simdjson { + +/** + * User-provided string that promises it has extra padded bytes at the end for use with parser::parse(). + */ +class padded_string_view : public std::string_view { +private: + size_t _capacity; + +public: + /** Create an empty padded_string_view. */ + inline padded_string_view() noexcept = default; + + /** + * Promise the given buffer has at least SIMDJSON_PADDING extra bytes allocated to it. + * + * @param s The string. + * @param len The length of the string (not including padding). + * @param capacity The allocated length of the string, including padding. + */ + explicit inline padded_string_view(const char* s, size_t len, size_t capacity) noexcept; + /** overload explicit inline padded_string_view(const char* s, size_t len) noexcept */ + explicit inline padded_string_view(const uint8_t* s, size_t len, size_t capacity) noexcept; + + /** + * Promise the given string has at least SIMDJSON_PADDING extra bytes allocated to it. + * + * The capacity of the string will be used to determine its padding. + * + * @param s The string. + */ + explicit inline padded_string_view(const std::string &s) noexcept; + + /** + * Promise the given string_view has at least SIMDJSON_PADDING extra bytes allocated to it. + * + * @param s The string. + * @param capacity The allocated length of the string, including padding. + */ + explicit inline padded_string_view(std::string_view s, size_t capacity) noexcept; + + /** The number of allocated bytes. */ + inline size_t capacity() const noexcept; + + /** The amount of padding on the string (capacity() - length()) */ + inline size_t padding() const noexcept; + +}; // padded_string_view + +#if SIMDJSON_EXCEPTIONS +/** + * Send padded_string instance to an output stream. + * + * @param out The output stream. + * @param s The padded_string_view. + * @throw simdjson_error if the result being printed has an error. If there is an error with the + * underlying output stream, that error will be propagated (simdjson_error will not be + * thrown). + */ +inline std::ostream& operator<<(std::ostream& out, simdjson_result &s) noexcept(false) { return out << s.value(); } +#endif + +} // namespace simdjson + +#endif // SIMDJSON_PADDED_STRING_VIEW_H +/* end file include/simdjson/padded_string_view.h */ + +#endif // SIMDJSON_GENERIC_DEPENDENCIES_H +/* end file include/simdjson/generic/dependencies.h */ +/* begin file include/simdjson/generic/ondemand/dependencies.h */ +#ifdef SIMDJSON_AMALGAMATED +#error simdjson/generic/ondemand/dependencies.h must be included before defining SIMDJSON_AMALGAMATED! +#endif + +#ifndef SIMDJSON_GENERIC_ONDEMAND_DEPENDENCIES_H +#define SIMDJSON_GENERIC_ONDEMAND_DEPENDENCIES_H + +// Internal headers needed for ondemand generics. +// All includes not under simdjson/generic/ondemand must be here! +// Otherwise, amalgamation will fail. +/* skipped duplicate #include "simdjson/generic/dependencies.h" */ +/* begin file include/simdjson/padded_string.h */ +#ifndef SIMDJSON_PADDED_STRING_H +#define SIMDJSON_PADDED_STRING_H + +/* skipped duplicate #include "simdjson/portability.h" */ +/* skipped duplicate #include "simdjson/base.h" // for SIMDJSON_PADDING */ +/* skipped duplicate #include "simdjson/error.h" */ +#include +#include +#include +#include + +namespace simdjson { + +class padded_string_view; + +/** + * String with extra allocation for ease of use with parser::parse() + * + * This is a move-only class, it cannot be copied. + */ +struct padded_string final { + + /** + * Create a new, empty padded string. + */ + explicit inline padded_string() noexcept; + /** + * Create a new padded string buffer. + * + * @param length the size of the string. + */ + explicit inline padded_string(size_t length) noexcept; + /** + * Create a new padded string by copying the given input. + * + * @param data the buffer to copy + * @param length the number of bytes to copy + */ + explicit inline padded_string(const char *data, size_t length) noexcept; + /** + * Create a new padded string by copying the given input. + * + * @param str_ the string to copy + */ + inline padded_string(const std::string & str_ ) noexcept; + /** + * Create a new padded string by copying the given input. + * + * @param sv_ the string to copy + */ + inline padded_string(std::string_view sv_) noexcept; + /** + * Move one padded string into another. + * + * The original padded string will be reduced to zero capacity. + * + * @param o the string to move. + */ + inline padded_string(padded_string &&o) noexcept; + /** + * Move one padded string into another. + * + * The original padded string will be reduced to zero capacity. + * + * @param o the string to move. + */ + inline padded_string &operator=(padded_string &&o) noexcept; + inline void swap(padded_string &o) noexcept; + ~padded_string() noexcept; + + /** + * The length of the string. + * + * Does not include padding. + */ + size_t size() const noexcept; + + /** + * The length of the string. + * + * Does not include padding. + */ + size_t length() const noexcept; + + /** + * The string data. + **/ + const char *data() const noexcept; + const uint8_t *u8data() const noexcept { return static_cast(static_cast(data_ptr));} + + /** + * The string data. + **/ + char *data() noexcept; + + /** + * Create a std::string_view with the same content. + */ + operator std::string_view() const; + + /** + * Create a padded_string_view with the same content. + */ + operator padded_string_view() const noexcept; + + /** + * Load this padded string from a file. + * + * @return IO_ERROR on error. Be mindful that on some 32-bit systems, + * the file size might be limited to 2 GB. + * + * @param path the path to the file. + **/ + inline static simdjson_result load(std::string_view path) noexcept; + +private: + padded_string &operator=(const padded_string &o) = delete; + padded_string(const padded_string &o) = delete; + + size_t viable_size{0}; + char *data_ptr{nullptr}; + +}; // padded_string + +/** + * Send padded_string instance to an output stream. + * + * @param out The output stream. + * @param s The padded_string instance. + * @throw if there is an error with the underlying output stream. simdjson itself will not throw. + */ +inline std::ostream& operator<<(std::ostream& out, const padded_string& s) { return out << s.data(); } + +#if SIMDJSON_EXCEPTIONS +/** + * Send padded_string instance to an output stream. + * + * @param out The output stream. + * @param s The padded_string instance. + * @throw simdjson_error if the result being printed has an error. If there is an error with the + * underlying output stream, that error will be propagated (simdjson_error will not be + * thrown). + */ +inline std::ostream& operator<<(std::ostream& out, simdjson_result &s) noexcept(false) { return out << s.value(); } +#endif + +} // namespace simdjson + +// This is deliberately outside of simdjson so that people get it without having to use the namespace +inline simdjson::padded_string operator "" _padded(const char *str, size_t len) { + return simdjson::padded_string(str, len); +} + +namespace simdjson { +namespace internal { + +// The allocate_padded_buffer function is a low-level function to allocate memory +// with padding so we can read past the "length" bytes safely. It is used by +// the padded_string class automatically. It returns nullptr in case +// of error: the caller should check for a null pointer. +// The length parameter is the maximum size in bytes of the string. +// The caller is responsible to free the memory (e.g., delete[] (...)). +inline char *allocate_padded_buffer(size_t length) noexcept; + +} // namespace internal +} // namespace simdjson + +#endif // SIMDJSON_PADDED_STRING_H +/* end file include/simdjson/padded_string.h */ +/* skipped duplicate #include "simdjson/internal/jsoncharutils_tables.h" */ +/* skipped duplicate #include "simdjson/internal/numberparsing_tables.h" */ + +#endif // SIMDJSON_GENERIC_ONDEMAND_DEPENDENCIES_H +/* end file include/simdjson/generic/ondemand/dependencies.h */ + +#define SIMDJSON_AMALGAMATED + +/* begin file include/simdjson/amalgamated.h */ +#ifndef SIMDJSON_AMALGAMATED_H +#define SIMDJSON_AMALGAMATED_H + +// This provides the public API for simdjson. +// DOM and ondemand are amalgamated separately, in simdjson.h +/* begin file include/simdjson/simdjson_version.h */ +// /include/simdjson/simdjson_version.h automatically generated by release.py, +// do not change by hand +#ifndef SIMDJSON_SIMDJSON_VERSION_H +#define SIMDJSON_SIMDJSON_VERSION_H + +/** The version of simdjson being used (major.minor.revision) */ +#define SIMDJSON_VERSION "3.2.1" + +namespace simdjson { +enum { + /** + * The major version (MAJOR.minor.revision) of simdjson being used. + */ + SIMDJSON_VERSION_MAJOR = 3, + /** + * The minor version (major.MINOR.revision) of simdjson being used. + */ + SIMDJSON_VERSION_MINOR = 2, + /** + * The revision (major.minor.REVISION) of simdjson being used. + */ + SIMDJSON_VERSION_REVISION = 1 +}; +} // namespace simdjson + +#endif // SIMDJSON_SIMDJSON_VERSION_H +/* end file include/simdjson/simdjson_version.h */ + +/* skipped duplicate #include "simdjson/base.h" */ + /* skipped duplicate #include "simdjson/error.h" */ /* begin file include/simdjson/error-inl.h */ #ifndef SIMDJSON_INLINE_ERROR_H @@ -3416,176 +3933,7 @@ extern SIMDJSON_DLLIMPORTEXPORT internal::atomic_ptr& get_ #define SIMDJSON_MINIFY_H /* skipped duplicate #include "simdjson/base.h" */ -/* begin file include/simdjson/padded_string.h */ -#ifndef SIMDJSON_PADDED_STRING_H -#define SIMDJSON_PADDED_STRING_H - -/* skipped duplicate #include "simdjson/portability.h" */ -/* skipped duplicate #include "simdjson/base.h" // for SIMDJSON_PADDING */ -/* skipped duplicate #include "simdjson/error.h" */ -#include -#include -#include -#include - -namespace simdjson { - -class padded_string_view; - -/** - * String with extra allocation for ease of use with parser::parse() - * - * This is a move-only class, it cannot be copied. - */ -struct padded_string final { - - /** - * Create a new, empty padded string. - */ - explicit inline padded_string() noexcept; - /** - * Create a new padded string buffer. - * - * @param length the size of the string. - */ - explicit inline padded_string(size_t length) noexcept; - /** - * Create a new padded string by copying the given input. - * - * @param data the buffer to copy - * @param length the number of bytes to copy - */ - explicit inline padded_string(const char *data, size_t length) noexcept; - /** - * Create a new padded string by copying the given input. - * - * @param str_ the string to copy - */ - inline padded_string(const std::string & str_ ) noexcept; - /** - * Create a new padded string by copying the given input. - * - * @param sv_ the string to copy - */ - inline padded_string(std::string_view sv_) noexcept; - /** - * Move one padded string into another. - * - * The original padded string will be reduced to zero capacity. - * - * @param o the string to move. - */ - inline padded_string(padded_string &&o) noexcept; - /** - * Move one padded string into another. - * - * The original padded string will be reduced to zero capacity. - * - * @param o the string to move. - */ - inline padded_string &operator=(padded_string &&o) noexcept; - inline void swap(padded_string &o) noexcept; - ~padded_string() noexcept; - - /** - * The length of the string. - * - * Does not include padding. - */ - size_t size() const noexcept; - - /** - * The length of the string. - * - * Does not include padding. - */ - size_t length() const noexcept; - - /** - * The string data. - **/ - const char *data() const noexcept; - const uint8_t *u8data() const noexcept { return static_cast(static_cast(data_ptr));} - - /** - * The string data. - **/ - char *data() noexcept; - - /** - * Create a std::string_view with the same content. - */ - operator std::string_view() const; - - /** - * Create a padded_string_view with the same content. - */ - operator padded_string_view() const noexcept; - - /** - * Load this padded string from a file. - * - * @return IO_ERROR on error. Be mindful that on some 32-bit systems, - * the file size might be limited to 2 GB. - * - * @param path the path to the file. - **/ - inline static simdjson_result load(std::string_view path) noexcept; - -private: - padded_string &operator=(const padded_string &o) = delete; - padded_string(const padded_string &o) = delete; - - size_t viable_size{0}; - char *data_ptr{nullptr}; - -}; // padded_string - -/** - * Send padded_string instance to an output stream. - * - * @param out The output stream. - * @param s The padded_string instance. - * @throw if there is an error with the underlying output stream. simdjson itself will not throw. - */ -inline std::ostream& operator<<(std::ostream& out, const padded_string& s) { return out << s.data(); } - -#if SIMDJSON_EXCEPTIONS -/** - * Send padded_string instance to an output stream. - * - * @param out The output stream. - * @param s The padded_string instance. - * @throw simdjson_error if the result being printed has an error. If there is an error with the - * underlying output stream, that error will be propagated (simdjson_error will not be - * thrown). - */ -inline std::ostream& operator<<(std::ostream& out, simdjson_result &s) noexcept(false) { return out << s.value(); } -#endif - -} // namespace simdjson - -// This is deliberately outside of simdjson so that people get it without having to use the namespace -inline simdjson::padded_string operator "" _padded(const char *str, size_t len) { - return simdjson::padded_string(str, len); -} - -namespace simdjson { -namespace internal { - -// The allocate_padded_buffer function is a low-level function to allocate memory -// with padding so we can read past the "length" bytes safely. It is used by -// the padded_string class automatically. It returns nullptr in case -// of error: the caller should check for a null pointer. -// The length parameter is the maximum size in bytes of the string. -// The caller is responsible to free the memory (e.g., delete[] (...)). -inline char *allocate_padded_buffer(size_t length) noexcept; - -} // namespace internal -} // namespace simdjson - -#endif // SIMDJSON_PADDED_STRING_H -/* end file include/simdjson/padded_string.h */ +/* skipped duplicate #include "simdjson/padded_string.h" */ #include #include #include @@ -3618,85 +3966,7 @@ simdjson_warn_unused error_code minify(const char *buf, size_t len, char *dst, s #define SIMDJSON_INLINE_PADDED_STRING_H /* skipped duplicate #include "simdjson/padded_string.h" */ -/* begin file include/simdjson/padded_string_view.h */ -#ifndef SIMDJSON_PADDED_STRING_VIEW_H -#define SIMDJSON_PADDED_STRING_VIEW_H - -/* skipped duplicate #include "simdjson/portability.h" */ -/* skipped duplicate #include "simdjson/base.h" // for SIMDJSON_PADDING */ -/* skipped duplicate #include "simdjson/error.h" */ - -#include -#include -#include -#include - -namespace simdjson { - -/** - * User-provided string that promises it has extra padded bytes at the end for use with parser::parse(). - */ -class padded_string_view : public std::string_view { -private: - size_t _capacity; - -public: - /** Create an empty padded_string_view. */ - inline padded_string_view() noexcept = default; - - /** - * Promise the given buffer has at least SIMDJSON_PADDING extra bytes allocated to it. - * - * @param s The string. - * @param len The length of the string (not including padding). - * @param capacity The allocated length of the string, including padding. - */ - explicit inline padded_string_view(const char* s, size_t len, size_t capacity) noexcept; - /** overload explicit inline padded_string_view(const char* s, size_t len) noexcept */ - explicit inline padded_string_view(const uint8_t* s, size_t len, size_t capacity) noexcept; - - /** - * Promise the given string has at least SIMDJSON_PADDING extra bytes allocated to it. - * - * The capacity of the string will be used to determine its padding. - * - * @param s The string. - */ - explicit inline padded_string_view(const std::string &s) noexcept; - - /** - * Promise the given string_view has at least SIMDJSON_PADDING extra bytes allocated to it. - * - * @param s The string. - * @param capacity The allocated length of the string, including padding. - */ - explicit inline padded_string_view(std::string_view s, size_t capacity) noexcept; - - /** The number of allocated bytes. */ - inline size_t capacity() const noexcept; - - /** The amount of padding on the string (capacity() - length()) */ - inline size_t padding() const noexcept; - -}; // padded_string_view - -#if SIMDJSON_EXCEPTIONS -/** - * Send padded_string instance to an output stream. - * - * @param out The output stream. - * @param s The padded_string_view. - * @throw simdjson_error if the result being printed has an error. If there is an error with the - * underlying output stream, that error will be propagated (simdjson_error will not be - * thrown). - */ -inline std::ostream& operator<<(std::ostream& out, simdjson_result &s) noexcept(false) { return out << s.value(); } -#endif - -} // namespace simdjson - -#endif // SIMDJSON_PADDED_STRING_VIEW_H -/* end file include/simdjson/padded_string_view.h */ +/* skipped duplicate #include "simdjson/padded_string_view.h" */ #include @@ -3931,62 +4201,7 @@ extern SIMDJSON_DLLIMPORTEXPORT const uint64_t thintable_epi8[256]; #ifndef SIMDJSON_DOM_AMALGAMATED_H #define SIMDJSON_DOM_AMALGAMATED_H -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -/* begin file include/simdjson/dom/base.h */ -#ifndef SIMDJSON_DOM_BASE_H -#define SIMDJSON_DOM_BASE_H - -/* skipped duplicate #include "simdjson/base.h" */ - -namespace simdjson { - -/** - * @brief A DOM API on top of the simdjson parser. - */ -namespace dom { - -/** The default batch size for parser.parse_many() and parser.load_many() */ -static constexpr size_t DEFAULT_BATCH_SIZE = 1000000; -/** - * Some adversary might try to set the batch size to 0 or 1, which might cause problems. - * We set a minimum of 32B since anything else is highly likely to be an error. In practice, - * most users will want a much larger batch size. - * - * All non-negative MINIMAL_BATCH_SIZE values should be 'safe' except that, obviously, no JSON - * document can ever span 0 or 1 byte and that very large values would create memory allocation issues. - */ -static constexpr size_t MINIMAL_BATCH_SIZE = 32; - -/** - * It is wasteful to allocate memory for tiny documents (e.g., 4 bytes). - */ -static constexpr size_t MINIMAL_DOCUMENT_CAPACITY = 32; - -class array; -class document; -class document_stream; -class element; -class key_value_pair; -class object; -class parser; - -} // namespace dom - -namespace internal { - -template -class string_builder; -class tape_ref; - -} // namespace internal - -} // namespace simdjson - -#endif // SIMDJSON_DOM_BASE_H -/* end file include/simdjson/dom/base.h */ +/* skipped duplicate #include "simdjson/dom/base.h" */ /* begin file include/simdjson/dom/array.h */ #ifndef SIMDJSON_DOM_ARRAY_H #define SIMDJSON_DOM_ARRAY_H @@ -4224,97 +4439,7 @@ inline constexpr bool enable_view tape{}; - - /** @private String values. - * - * Should be at least byte_capacity. - */ - std::unique_ptr string_buf{}; - /** @private Allocate memory to support - * input JSON documents of up to len bytes. - * - * When calling this function, you lose - * all the data. - * - * The memory allocation is strict: you - * can you use this function to increase - * or lower the amount of allocated memory. - * Passsing zero clears the memory. - */ - error_code allocate(size_t len) noexcept; - /** @private Capacity in bytes, in terms - * of how many bytes of input JSON we can - * support. - */ - size_t capacity() const noexcept; - - -private: - size_t allocated_capacity{0}; - friend class parser; -}; // class document - -} // namespace dom -} // namespace simdjson - -#endif // SIMDJSON_DOM_DOCUMENT_H -/* end file include/simdjson/dom/document.h */ +/* skipped duplicate #include "simdjson/dom/document.h" */ namespace simdjson { @@ -9426,107 +9551,6 @@ simdjson_inline std::string_view string_builder::str() const { #endif // SIMDJSON_DOM_AMALGAMATED_H /* end file include/simdjson/dom/amalgamated.h */ -/* begin file include/simdjson/generic/dependencies.h */ -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#define SIMDJSON_GENERIC_DEPENDENCIES_H - -// Internal headers needed for generics. -// All includes referencing simdjson headers *not* under simdjson/generic must be here! -// Otherwise, amalgamation will fail. -/* skipped duplicate #include "simdjson/dom/document.h" */ -/* begin file include/simdjson/internal/jsoncharutils_tables.h */ -#ifndef SIMDJSON_INTERNAL_JSONCHARUTILS_TABLES_H -#define SIMDJSON_INTERNAL_JSONCHARUTILS_TABLES_H - -/* skipped duplicate #include "simdjson/base.h" */ - -#ifdef JSON_TEST_STRINGS -void found_string(const uint8_t *buf, const uint8_t *parsed_begin, - const uint8_t *parsed_end); -void found_bad_string(const uint8_t *buf); -#endif - -namespace simdjson { -namespace internal { -// structural chars here are -// they are { 0x7b } 0x7d : 0x3a [ 0x5b ] 0x5d , 0x2c (and NULL) -// we are also interested in the four whitespace characters -// space 0x20, linefeed 0x0a, horizontal tab 0x09 and carriage return 0x0d - -extern SIMDJSON_DLLIMPORTEXPORT const bool structural_or_whitespace_negated[256]; -extern SIMDJSON_DLLIMPORTEXPORT const bool structural_or_whitespace[256]; -extern SIMDJSON_DLLIMPORTEXPORT const uint32_t digit_to_val32[886]; - -} // namespace internal -} // namespace simdjson - -#endif // SIMDJSON_INTERNAL_JSONCHARUTILS_TABLES_H -/* end file include/simdjson/internal/jsoncharutils_tables.h */ -/* begin file include/simdjson/internal/numberparsing_tables.h */ -#ifndef SIMDJSON_INTERNAL_NUMBERPARSING_TABLES_H -#define SIMDJSON_INTERNAL_NUMBERPARSING_TABLES_H - -/* skipped duplicate #include "simdjson/base.h" */ - -namespace simdjson { -namespace internal { -/** - * The smallest non-zero float (binary64) is 2^-1074. - * We take as input numbers of the form w x 10^q where w < 2^64. - * We have that w * 10^-343 < 2^(64-344) 5^-343 < 2^-1076. - * However, we have that - * (2^64-1) * 10^-342 = (2^64-1) * 2^-342 * 5^-342 > 2^-1074. - * Thus it is possible for a number of the form w * 10^-342 where - * w is a 64-bit value to be a non-zero floating-point number. - ********* - * Any number of form w * 10^309 where w>= 1 is going to be - * infinite in binary64 so we never need to worry about powers - * of 5 greater than 308. - */ -constexpr int smallest_power = -342; -constexpr int largest_power = 308; - -/** - * Represents a 128-bit value. - * low: least significant 64 bits. - * high: most significant 64 bits. - */ -struct value128 { - uint64_t low; - uint64_t high; -}; - - -// Precomputed powers of ten from 10^0 to 10^22. These -// can be represented exactly using the double type. -extern SIMDJSON_DLLIMPORTEXPORT const double power_of_ten[]; - - -/** - * When mapping numbers from decimal to binary, - * we go from w * 10^q to m * 2^p but we have - * 10^q = 5^q * 2^q, so effectively - * we are trying to match - * w * 2^q * 5^q to m * 2^p. Thus the powers of two - * are not a concern since they can be represented - * exactly using the binary notation, only the powers of five - * affect the binary significand. - */ - - -// The truncated powers of five from 5^-342 all the way to 5^308 -// The mantissa is truncated to 128 bits, and -// never rounded up. Uses about 10KB. -extern SIMDJSON_DLLIMPORTEXPORT const uint64_t power_of_five_128[]; -} // namespace internal -} // namespace simdjson - -#endif // SIMDJSON_INTERNAL_NUMBERPARSING_TABLES_H -/* end file include/simdjson/internal/numberparsing_tables.h */ -/* skipped duplicate #include "simdjson/padded_string_view.h" */ - -#endif // SIMDJSON_GENERIC_DEPENDENCIES_H -/* end file include/simdjson/generic/dependencies.h */ /* begin file include/simdjson/builtin/amalgamated.h */ #ifndef SIMDJSON_BUILTIN_AMALGAMATED_H #define SIMDJSON_BUILTIN_AMALGAMATED_H @@ -10825,16 +10849,8 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin /* end file include/simdjson/arm64/stringparsing_defs.h */ /* end file include/simdjson/arm64/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for arm64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for arm64 */ @@ -12827,16 +12843,8 @@ static simdjson_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars /* end file include/simdjson/fallback/numberparsing_defs.h */ /* end file include/simdjson/fallback/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for fallback */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for fallback */ @@ -15330,16 +15338,8 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin /* end file include/simdjson/haswell/stringparsing_defs.h */ /* end file include/simdjson/haswell/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for haswell */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for haswell */ @@ -17810,16 +17810,8 @@ static simdjson_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars /* end file include/simdjson/icelake/numberparsing_defs.h */ /* end file include/simdjson/icelake/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for icelake */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for icelake */ @@ -20428,16 +20420,8 @@ backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) { /* end file include/simdjson/ppc64/stringparsing_defs.h */ /* end file include/simdjson/ppc64/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for ppc64 */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for ppc64 */ @@ -22882,16 +22866,8 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin /* end file include/simdjson/westmere/stringparsing_defs.h */ /* end file include/simdjson/westmere/begin.h */ /* begin file include/simdjson/generic/amalgamated.h for westmere */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/amalgamated.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/dependencies.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - -#ifndef SIMDJSON_AMALGAMATED_H -#error simdjson/amalgamated.h must be included before generic/amalgamated.h! -#endif -#ifndef SIMDJSON_GENERIC_DEPENDENCIES_H -#error simdjson/generic/dependencies.h must be included before generic/amalgamated.h! +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/dependencies.h must be included before simdjson/generic/amalgamated.h! #endif /* begin file include/simdjson/generic/base.h for westmere */ @@ -24743,10 +24719,6 @@ SIMDJSON_UNTARGET_REGION #ifndef SIMDJSON_BUILTIN_ONDEMAND_AMALGAMATED_H #define SIMDJSON_BUILTIN_ONDEMAND_AMALGAMATED_H -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/builtin/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ - /* begin file include/simdjson/builtin/begin.h */ /* skipped duplicate #include "simdjson/builtin.h" */ @@ -24833,9 +24805,9 @@ SIMDJSON_TARGET_REGION("sse4.2,pclmul,popcnt") #endif /* end file include/simdjson/builtin/begin.h */ /* begin file include/simdjson/generic/ondemand/amalgamated.h for SIMDJSON_BUILTIN_IMPLEMENTATION */ -/* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/amalgamated.h" */ -/* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_GENERIC_DEPENDENCIES_H) +#error simdjson/generic/ondemand/dependencies.h must be included before simdjson/generic/ondemand/amalgamated.h! +#endif // Stuff other things depend on /* begin file include/simdjson/generic/ondemand/base.h for SIMDJSON_BUILTIN_IMPLEMENTATION */ @@ -24844,7 +24816,6 @@ SIMDJSON_TARGET_REGION("sse4.2,pclmul,popcnt") /* amalgamation skipped (editor-only): #ifndef SIMDJSON_AMALGAMATED */ /* amalgamation skipped (editor-only): #define SIMDJSON_GENERIC_ONDEMAND_BASE_H */ /* amalgamation skipped (editor-only): #include "simdjson/generic/base.h" */ -/* amalgamation skipped (editor-only): #include "simdjson/generic/ondemand/dependencies.h" */ /* amalgamation skipped (editor-only): #endif // SIMDJSON_AMALGAMATED */ namespace simdjson { @@ -34307,6 +34278,8 @@ namespace simdjson { #endif // SIMDJSON_ONDEMAND_AMALGAMATED_H /* end file include/simdjson/builtin/ondemand/amalgamated.h */ +#undef SIMDJSON_AMALGAMATED + SIMDJSON_POP_DISABLE_UNUSED_WARNINGS #endif // SIMDJSON_H diff --git a/src/arm64.cpp b/src/arm64.cpp index c0addb346..cbdeccbfe 100644 --- a/src/arm64.cpp +++ b/src/arm64.cpp @@ -1,10 +1,6 @@ #ifndef SIMDJSON_SRC_ARM64_CPP #define SIMDJSON_SRC_ARM64_CPP -#ifndef SIMDJSON_AMALGAMATED -#include "generic/dependencies.h" -#endif // SIMDJSON_AMALGAMATED - #include "simdjson/arm64/implementation.h" #include "simdjson/arm64/amalgamated.h" diff --git a/src/fallback.cpp b/src/fallback.cpp index 11917bc42..1049c5e26 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -1,10 +1,6 @@ #ifndef SIMDJSON_SRC_FALLBACK_CPP #define SIMDJSON_SRC_FALLBACK_CPP -#ifndef SIMDJSON_AMALGAMATED -#include "generic/dependencies.h" -#endif // SIMDJSON_AMALGAMATED - #include "simdjson/fallback/implementation.h" #include "simdjson/fallback/amalgamated.h" diff --git a/src/generic/amalgamated.h b/src/generic/amalgamated.h index 27d630773..2f2297fcd 100644 --- a/src/generic/amalgamated.h +++ b/src/generic/amalgamated.h @@ -1,6 +1,6 @@ -#ifndef SIMDJSON_AMALGAMATED -#include "simdjson/generic/amalgamated.h" -#endif // SIMDJSON_AMALGAMATED +#if defined(SIMDJSON_AMALGAMATED) && !defined(SIMDJSON_SRC_GENERIC_DEPENDENCIES_H) +#error generic/dependencies.h must be included before generic/amalgamated.h! +#endif #include "generic/base.h" #include "generic/dom_parser_implementation.h" diff --git a/src/generic/dependencies.h b/src/generic/dependencies.h index 0e88f03ea..d8ad14255 100644 --- a/src/generic/dependencies.h +++ b/src/generic/dependencies.h @@ -1,7 +1,10 @@ +#ifdef SIMDJSON_AMALGAMATED +#error generic/dependencies.h must be included before defining SIMDJSON_AMALGAMATED! +#endif + #ifndef SIMDJSON_SRC_GENERIC_DEPENDENCIES_H #define SIMDJSON_SRC_GENERIC_DEPENDENCIES_H -#include "simdjson/generic/dependencies.h" #include "simdjson/internal/tape_type.h" #endif // SIMDJSON_SRC_GENERIC_DEPENDENCIES_H \ No newline at end of file diff --git a/src/generic/stage1/amalgamated.h b/src/generic/stage1/amalgamated.h index 9bc6a43d8..87958c301 100644 --- a/src/generic/stage1/amalgamated.h +++ b/src/generic/stage1/amalgamated.h @@ -1,7 +1,3 @@ -#ifndef SIMDJSON_AMALGAMATED -#include "generic/amalgamated.h" -#endif // SIMDJSON_AMALGAMATED - // Stuff other things depend on #include "generic/stage1/base.h" #include "generic/stage1/json_string_scanner.h" diff --git a/src/generic/stage2/amalgamated.h b/src/generic/stage2/amalgamated.h index 5750e5f5d..f8132192d 100644 --- a/src/generic/stage2/amalgamated.h +++ b/src/generic/stage2/amalgamated.h @@ -1,7 +1,3 @@ -#ifndef SIMDJSON_AMALGAMATED -#include "generic/amalgamated.h" -#endif // SIMDJSON_AMALGAMATED - // Stuff other things depend on #include "generic/stage2/base.h" #include "generic/stage2/tape_writer.h" diff --git a/src/haswell.cpp b/src/haswell.cpp index ddab4bc4c..02272a4bf 100644 --- a/src/haswell.cpp +++ b/src/haswell.cpp @@ -1,11 +1,6 @@ #ifndef SIMDJSON_SRC_HASWELL_CPP #define SIMDJSON_SRC_HASWELL_CPP -#ifndef SIMDJSON_AMALGAMATED -#include "generic/dependencies.h" -#endif // SIMDJSON_AMALGAMATED - -#include "generic/dependencies.h" #include "simdjson/haswell/implementation.h" #include "simdjson/haswell/amalgamated.h" diff --git a/src/icelake.cpp b/src/icelake.cpp index a7f0d2844..ee26133f2 100644 --- a/src/icelake.cpp +++ b/src/icelake.cpp @@ -1,20 +1,19 @@ #ifndef SIMDJSON_SRC_ICELAKE_CPP #define SIMDJSON_SRC_ICELAKE_CPP -#ifndef SIMDJSON_AMALGAMATED -#include "generic/dependencies.h" -#endif // SIMDJSON_AMALGAMATED - #include "simdjson/icelake/implementation.h" #include "simdjson/icelake/amalgamated.h" -#include "simdjson/icelake/begin.h" -#include "generic/amalgamated.h" // defining SIMDJSON_GENERIC_JSON_STRUCTURAL_INDEXER_CUSTOM_BIT_INDEXER allows us to provide our own bit_indexer::write #define SIMDJSON_GENERIC_JSON_STRUCTURAL_INDEXER_CUSTOM_BIT_INDEXER + +#include "simdjson/icelake/begin.h" +#include "generic/amalgamated.h" #include "generic/stage1/amalgamated.h" #include "generic/stage2/amalgamated.h" +#undef SIMDJSON_GENERIC_JSON_STRUCTURAL_INDEXER_CUSTOM_BIT_INDEXER + // // Stage 1 // diff --git a/src/ppc64.cpp b/src/ppc64.cpp index 8e7cc4f50..9718aeaef 100644 --- a/src/ppc64.cpp +++ b/src/ppc64.cpp @@ -1,10 +1,6 @@ #ifndef SIMDJSON_SRC_PPC64_CPP #define SIMDJSON_SRC_PPC64_CPP -#ifndef SIMDJSON_AMALGAMATED -#include "generic/dependencies.h" -#endif // SIMDJSON_AMALGAMATED - #include "simdjson/ppc64/implementation.h" #include "simdjson/ppc64/amalgamated.h" diff --git a/src/simdjson.cpp b/src/simdjson.cpp index c4cb8b621..fe8c812af 100644 --- a/src/simdjson.cpp +++ b/src/simdjson.cpp @@ -12,9 +12,11 @@ SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS #include "internal/simdprune_tables.cpp" #include "implementation.cpp" -#include "simdjson/amalgamated.h" +#include "simdjson/generic/dependencies.h" #include "generic/dependencies.h" +#define SIMDJSON_AMALGAMATED + #if SIMDJSON_IMPLEMENTATION_ARM64 #include "arm64.cpp" #endif @@ -34,5 +36,7 @@ SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS #include "westmere.cpp" #endif +#undef SIMDJSON_AMALGAMATED + SIMDJSON_POP_DISABLE_UNUSED_WARNINGS diff --git a/src/westmere.cpp b/src/westmere.cpp index eb0adcc14..6a23e5162 100644 --- a/src/westmere.cpp +++ b/src/westmere.cpp @@ -1,11 +1,6 @@ #ifndef SIMDJSON_SRC_WESTMERE_CPP #define SIMDJSON_SRC_WESTMERE_CPP -#ifndef SIMDJSON_AMALGAMATED -#include "generic/dependencies.h" -#endif // SIMDJSON_AMALGAMATED - -#include "generic/dependencies.h" #include "simdjson/westmere/implementation.h" #include "simdjson/westmere/amalgamated.h"