Compare commits

..
Author SHA1 Message Date
dependabot[bot] f11db53d42 build(deps): bump lukka/get-cmake from 4.5.0 to 4.5.1
Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.5.0 to 4.5.1.
- [Release notes](https://github.com/lukka/get-cmake/releases)
- [Changelog](https://github.com/lukka/get-cmake/blob/main/RELEASE_PROCESS.md)
- [Commits](https://github.com/lukka/get-cmake/compare/16e8153a8b4918849d92aad131befe67a3705daa...a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4)

---
updated-dependencies:
- dependency-name: lukka/get-cmake
  dependency-version: 4.5.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-11-30 15:56:30 +00:00
6 changed files with 31 additions and 216 deletions

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Check that the target is big-endian - name: Check that the target is big-endian
run: echo | s390x-linux-gnu-g++ -dM -E - | grep -q '__BYTE_ORDER__ __ORDER_BIG_ENDIAN__' run: echo | s390x-linux-gnu-g++ -dM -E - | grep -q '__BYTE_ORDER__ __ORDER_BIG_ENDIAN__'
- name: Run CMake - name: Run CMake
+18 -18
View File
@@ -25,7 +25,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -38,7 +38,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Check that Meson and pkg-config offer the CMake options - name: Check that Meson and pkg-config offer the CMake options
run: make check_build_options run: make check_build_options
- name: Install Meson - name: Install Meson
@@ -92,7 +92,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -123,7 +123,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -142,7 +142,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -168,7 +168,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -244,7 +244,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: CXX=g++-${{ matrix.compiler }} cmake -S . -B build -DJSON_CI=On run: CXX=g++-${{ matrix.compiler }} cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -262,7 +262,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -279,7 +279,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Disable filesystem support (std::filesystem is unusable) for clang 7 / 8 / 9 / 10 - name: Disable filesystem support (std::filesystem is unusable) for clang 7 / 8 / 9 / 10
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV" run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }} if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
@@ -299,7 +299,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -319,7 +319,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build with libc++ - name: Build with libc++
@@ -346,7 +346,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -369,7 +369,7 @@ jobs:
run: apt-get update ; apt-get install -y unzip run: apt-get update ; apt-get install -y unzip
# The module test uses `import std;`, which needs CMake 4.5 or newer. # The module test uses `import std;`, which needs CMake 4.5 or newer.
- name: Get CMake 4.5+ and ninja - name: Get CMake 4.5+ and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
with: with:
cmakeVersion: '^4.5.0' cmakeVersion: '^4.5.0'
# Clang: the std library module is provided by libc++ (the image's libstdc++ # Clang: the std library module is provided by libc++ (the image's libstdc++
@@ -395,7 +395,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -412,7 +412,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -426,7 +426,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DJSON_CI=On run: cmake -S . -B build -DJSON_CI=On
- name: Build - name: Build
@@ -446,7 +446,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -GNinja run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -GNinja
- name: Build - name: Build
@@ -487,7 +487,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Check that the job runs natively on arm64 - name: Check that the job runs natively on arm64
run: uname -m && test "$(uname -m)" = aarch64 run: uname -m && test "$(uname -m)" = aarch64
- name: Run CMake - name: Run CMake
+2 -2
View File
@@ -90,7 +90,7 @@ jobs:
with: with:
persist-credentials: false persist-credentials: false
- name: Get latest CMake and ninja - name: Get latest CMake and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
- name: Set extra CXX_FLAGS for latest std_version - name: Set extra CXX_FLAGS for latest std_version
# /wd5285 silences C5285 emitted by the bundled third-party doctest.h, which # /wd5285 silences C5285 emitted by the bundled third-party doctest.h, which
# specializes std::tuple (newly diagnosed by the VS2026 v145 toolset) # specializes std::tuple (newly diagnosed by the VS2026 v145 toolset)
@@ -214,7 +214,7 @@ jobs:
persist-credentials: false persist-credentials: false
# The module test uses `import std;`, which needs CMake 4.5 or newer. # The module test uses `import std;`, which needs CMake 4.5 or newer.
- name: Get CMake 4.5+ and ninja - name: Get CMake 4.5+ and ninja
uses: lukka/get-cmake@16e8153a8b4918849d92aad131befe67a3705daa # v4.5.0 uses: lukka/get-cmake@a1a8216777d3cbbf5602c73b9ddd3e98257ecdc4 # v4.5.1
with: with:
cmakeVersion: '^4.5.0' cmakeVersion: '^4.5.0'
# CMAKE_CXX_FLAGS replaces CMake's MSVC defaults (which include /EHsc), and # CMAKE_CXX_FLAGS replaces CMake's MSVC defaults (which include /EHsc), and
+5 -84
View File
@@ -10,17 +10,8 @@
#include <algorithm> // max #include <algorithm> // max
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdint> // uint64_t
#ifndef JSON_NO_IO #ifndef JSON_NO_IO
#include <cstdio> // FILE, fread, ftell #include <cstdio> // FILE, fread
#if defined(_WIN32)
#include <stdio.h> // _fileno, _ftelli64 // NOLINT(hicpp-deprecated-headers,modernize-deprecated-headers)
#include <sys/types.h> // (for sys/stat.h)
#include <sys/stat.h> // _fstat64, _S_IFMT, _S_IFREG
#elif defined(__unix__) || defined(__APPLE__)
#include <stdio.h> // fileno // NOLINT(hicpp-deprecated-headers,modernize-deprecated-headers)
#include <sys/stat.h> // fstat, S_ISREG
#endif
#endif #endif
#include <istream> // istream, streambuf #include <istream> // istream, streambuf
#include <string> // basic_string, char_traits, string #include <string> // basic_string, char_traits, string
@@ -140,26 +131,6 @@ adapter_input<typename std::decay<Adapter>::type> make_adapter_input(Adapter&& i
return {std::forward<Adapter>(ia)}; return {std::forward<Adapter>(ia)};
} }
/// the size of a read block, and the least room offered to a read: one page,
/// the usual size of a filesystem block. It is a conventional size, not a tuned
/// one: it only has to be large enough that a read is never tiny and that the
/// read which finds the end of the input needs no regrowth of the string
constexpr std::size_t read_block_size() noexcept
{
return 4096;
}
/// make room for at least n characters in buf: never asks for less than its
/// capacity, because before C++20 such a request may shrink the string (as
/// libstdc++ before GCC 11 does) and move its characters
inline void reserve_at_least(std::string& buf, std::size_t n)
{
if (n > buf.capacity())
{
buf.reserve(n);
}
}
/// append the rest of a stream: its characters need no conversion, so they are /// append the rest of a stream: its characters need no conversion, so they are
/// read in blocks from the stream buffer, straight into buf (reusing its /// read in blocks from the stream buffer, straight into buf (reusing its
/// capacity). As the library's stream adapter, this reads the stream buffer /// capacity). As the library's stream adapter, this reads the stream buffer
@@ -171,20 +142,10 @@ inline void append_stream(std::string& buf, std::istream& is)
{ {
return; return;
} }
// room for the rest when the stream buffer knows how much is left (for a
// file with libstdc++, the rest of the file), and for the read that finds
// the end: the input is then read in one block, without a reallocation and
// copy at each doubling of the string (only a hint: the loop below reads
// what is there)
const std::streamsize rest = sb->in_avail();
if (rest > 0 && static_cast<std::size_t>(rest) < buf.max_size() - buf.size() - read_block_size())
{
reserve_at_least(buf, buf.size() + static_cast<std::size_t>(rest) + read_block_size());
}
for (;;) for (;;)
{ {
const std::size_t used = buf.size(); const std::size_t used = buf.size();
const std::size_t room = (std::max)(buf.capacity() - used, read_block_size()); const std::size_t room = (std::max)(buf.capacity() - used, std::size_t{4096});
buf.resize(used + room); buf.resize(used + room);
const std::streamsize got = sb->sgetn(&buf[used], static_cast<std::streamsize>(room)); const std::streamsize got = sb->sgetn(&buf[used], static_cast<std::streamsize>(room));
buf.resize(used + static_cast<std::size_t>((std::max)(got, std::streamsize{0}))); buf.resize(used + static_cast<std::size_t>((std::max)(got, std::streamsize{0})));
@@ -207,55 +168,15 @@ struct is_c_stream
{}; {};
#ifndef JSON_NO_IO #ifndef JSON_NO_IO
/// the number of bytes left in a C stream that is a regular file (from its
/// size and position), 0 for anything else and on other systems: a hint for
/// the room to reserve; f is not null
inline std::uint64_t file_rest(std::FILE* f) noexcept
{
#if defined(_WIN32)
struct _stat64 st {};
if (::_fstat64(_fileno(f), &st) == 0 && (st.st_mode & _S_IFMT) == _S_IFREG)
{
const auto here = ::_ftelli64(f);
if (here >= 0 && st.st_size > here)
{
return static_cast<std::uint64_t>(st.st_size - here);
}
}
#elif defined(__unix__) || defined(__APPLE__)
struct stat st {};
if (::fstat(fileno(f), &st) == 0 && S_ISREG(st.st_mode))
{
const auto here = std::ftell(f);
if (here >= 0 && st.st_size > here)
{
return static_cast<std::uint64_t>(st.st_size - here);
}
}
#else
static_cast<void>(f);
#endif
return 0;
}
/// append the rest of a C stream: in blocks with fread, not character by /// append the rest of a C stream: in blocks with fread, not character by
/// character (the library's file adapter reads with fgetc), and in one block /// character (the library's file adapter reads with fgetc);
/// when it is a regular file of known size; f is not null /// f is not null
inline void append_file(std::string& buf, std::FILE* f) inline void append_file(std::string& buf, std::FILE* f)
{ {
// room for the rest of a regular file and the byte that shows its end:
// the file is then read in one block, without a reallocation and copy at
// each doubling of the string (only a hint: the loop below reads what is
// there)
const std::uint64_t rest = file_rest(f);
if (rest > 0 && rest < buf.max_size() - buf.size() - 1)
{
reserve_at_least(buf, buf.size() + static_cast<std::size_t>(rest) + 1);
}
for (;;) for (;;)
{ {
const std::size_t used = buf.size(); const std::size_t used = buf.size();
const std::size_t room = (std::max)(buf.capacity() - used, read_block_size()); const std::size_t room = (std::max)(buf.capacity() - used, std::size_t{4096});
buf.resize(used + room); buf.resize(used + room);
const std::size_t got = std::fread(&buf[used], 1, room, f); const std::size_t got = std::fread(&buf[used], 1, room, f);
buf.resize(used + got); buf.resize(used + got);
+5 -84
View File
@@ -7956,17 +7956,8 @@ NLOHMANN_JSON_NAMESPACE_END
#include <algorithm> // max #include <algorithm> // max
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdint> // uint64_t
#ifndef JSON_NO_IO #ifndef JSON_NO_IO
#include <cstdio> // FILE, fread, ftell #include <cstdio> // FILE, fread
#if defined(_WIN32)
#include <stdio.h> // _fileno, _ftelli64 // NOLINT(hicpp-deprecated-headers,modernize-deprecated-headers)
#include <sys/types.h> // (for sys/stat.h)
#include <sys/stat.h> // _fstat64, _S_IFMT, _S_IFREG
#elif defined(__unix__) || defined(__APPLE__)
#include <stdio.h> // fileno // NOLINT(hicpp-deprecated-headers,modernize-deprecated-headers)
#include <sys/stat.h> // fstat, S_ISREG
#endif
#endif #endif
#include <istream> // istream, streambuf #include <istream> // istream, streambuf
#include <string> // basic_string, char_traits, string #include <string> // basic_string, char_traits, string
@@ -8087,26 +8078,6 @@ adapter_input<typename std::decay<Adapter>::type> make_adapter_input(Adapter&& i
return {std::forward<Adapter>(ia)}; return {std::forward<Adapter>(ia)};
} }
/// the size of a read block, and the least room offered to a read: one page,
/// the usual size of a filesystem block. It is a conventional size, not a tuned
/// one: it only has to be large enough that a read is never tiny and that the
/// read which finds the end of the input needs no regrowth of the string
constexpr std::size_t read_block_size() noexcept
{
return 4096;
}
/// make room for at least n characters in buf: never asks for less than its
/// capacity, because before C++20 such a request may shrink the string (as
/// libstdc++ before GCC 11 does) and move its characters
inline void reserve_at_least(std::string& buf, std::size_t n)
{
if (n > buf.capacity())
{
buf.reserve(n);
}
}
/// append the rest of a stream: its characters need no conversion, so they are /// append the rest of a stream: its characters need no conversion, so they are
/// read in blocks from the stream buffer, straight into buf (reusing its /// read in blocks from the stream buffer, straight into buf (reusing its
/// capacity). As the library's stream adapter, this reads the stream buffer /// capacity). As the library's stream adapter, this reads the stream buffer
@@ -8118,20 +8089,10 @@ inline void append_stream(std::string& buf, std::istream& is)
{ {
return; return;
} }
// room for the rest when the stream buffer knows how much is left (for a
// file with libstdc++, the rest of the file), and for the read that finds
// the end: the input is then read in one block, without a reallocation and
// copy at each doubling of the string (only a hint: the loop below reads
// what is there)
const std::streamsize rest = sb->in_avail();
if (rest > 0 && static_cast<std::size_t>(rest) < buf.max_size() - buf.size() - read_block_size())
{
reserve_at_least(buf, buf.size() + static_cast<std::size_t>(rest) + read_block_size());
}
for (;;) for (;;)
{ {
const std::size_t used = buf.size(); const std::size_t used = buf.size();
const std::size_t room = (std::max)(buf.capacity() - used, read_block_size()); const std::size_t room = (std::max)(buf.capacity() - used, std::size_t{4096});
buf.resize(used + room); buf.resize(used + room);
const std::streamsize got = sb->sgetn(&buf[used], static_cast<std::streamsize>(room)); const std::streamsize got = sb->sgetn(&buf[used], static_cast<std::streamsize>(room));
buf.resize(used + static_cast<std::size_t>((std::max)(got, std::streamsize{0}))); buf.resize(used + static_cast<std::size_t>((std::max)(got, std::streamsize{0})));
@@ -8154,55 +8115,15 @@ struct is_c_stream
{}; {};
#ifndef JSON_NO_IO #ifndef JSON_NO_IO
/// the number of bytes left in a C stream that is a regular file (from its
/// size and position), 0 for anything else and on other systems: a hint for
/// the room to reserve; f is not null
inline std::uint64_t file_rest(std::FILE* f) noexcept
{
#if defined(_WIN32)
struct _stat64 st {};
if (::_fstat64(_fileno(f), &st) == 0 && (st.st_mode & _S_IFMT) == _S_IFREG)
{
const auto here = ::_ftelli64(f);
if (here >= 0 && st.st_size > here)
{
return static_cast<std::uint64_t>(st.st_size - here);
}
}
#elif defined(__unix__) || defined(__APPLE__)
struct stat st {};
if (::fstat(fileno(f), &st) == 0 && S_ISREG(st.st_mode))
{
const auto here = std::ftell(f);
if (here >= 0 && st.st_size > here)
{
return static_cast<std::uint64_t>(st.st_size - here);
}
}
#else
static_cast<void>(f);
#endif
return 0;
}
/// append the rest of a C stream: in blocks with fread, not character by /// append the rest of a C stream: in blocks with fread, not character by
/// character (the library's file adapter reads with fgetc), and in one block /// character (the library's file adapter reads with fgetc);
/// when it is a regular file of known size; f is not null /// f is not null
inline void append_file(std::string& buf, std::FILE* f) inline void append_file(std::string& buf, std::FILE* f)
{ {
// room for the rest of a regular file and the byte that shows its end:
// the file is then read in one block, without a reallocation and copy at
// each doubling of the string (only a hint: the loop below reads what is
// there)
const std::uint64_t rest = file_rest(f);
if (rest > 0 && rest < buf.max_size() - buf.size() - 1)
{
reserve_at_least(buf, buf.size() + static_cast<std::size_t>(rest) + 1);
}
for (;;) for (;;)
{ {
const std::size_t used = buf.size(); const std::size_t used = buf.size();
const std::size_t room = (std::max)(buf.capacity() - used, read_block_size()); const std::size_t room = (std::max)(buf.capacity() - used, std::size_t{4096});
buf.resize(used + room); buf.resize(used + room);
const std::size_t got = std::fread(&buf[used], 1, room, f); const std::size_t got = std::fread(&buf[used], 1, room, f);
buf.resize(used + got); buf.resize(used + got);
-27
View File
@@ -535,33 +535,6 @@ TEST_CASE("json_view")
CHECK_THROWS_AS(from_null = json_document::parse(static_cast<std::FILE*>(nullptr)), json::parse_error&); CHECK_THROWS_AS(from_null = json_document::parse(static_cast<std::FILE*>(nullptr)), json::parse_error&);
} }
// a regular file is read in one block, from its position to its end
std::FILE* tail_file = std::tmpfile(); // NOLINT(cppcoreguidelines-owning-memory)
if (tail_file != nullptr)
{
const std::string prefix = "garbage ";
CHECK(std::fwrite(prefix.data(), 1, prefix.size(), tail_file) == prefix.size());
CHECK(std::fwrite(text.data(), 1, text.size(), tail_file) == text.size());
CHECK(std::fseek(tail_file, static_cast<long>(prefix.size()), SEEK_SET) == 0);
#if defined(_WIN32) || defined(__unix__) || defined(__APPLE__)
CHECK(nlohmann::detail::view::file_rest(tail_file) == text.size());
#endif
const json_document from_tail = json_document::parse(tail_file);
CHECK(from_tail.source() == text);
CHECK(from_tail.root().materialize() == json::parse(text));
CHECK(nlohmann::detail::view::file_rest(tail_file) == 0);
CHECK(std::fclose(tail_file) == 0); // NOLINT(cppcoreguidelines-owning-memory)
}
// a stream is read from its position to its end as well, in one block
// when its buffer knows how much is left
std::istringstream tail_stream("garbage " + text);
tail_stream.seekg(8);
const json_document from_tail_stream = json_document::parse(tail_stream);
CHECK(from_tail_stream.source() == text);
CHECK(from_tail_stream.root().materialize() == json::parse(text));
CHECK(tail_stream.eof());
// a stream without a buffer is an empty input // a stream without a buffer is an empty input
std::istream no_buffer(nullptr); std::istream no_buffer(nullptr);
CHECK(json_document::parse(no_buffer, false).is_discarded()); CHECK(json_document::parse(no_buffer, false).is_discarded());