pax_global_header00006660000000000000000000000064150533667650014532gustar00rootroot0000000000000052 comment=aa8c946cfbe2aba29016bc9c9ddc8713cb00173b ijl-orjson-aa8c946/000077500000000000000000000000001505336676500142415ustar00rootroot00000000000000ijl-orjson-aa8c946/.gitattributes000066400000000000000000000000431505336676500171310ustar00rootroot00000000000000include/yyjson/* linguist-vendored ijl-orjson-aa8c946/.github/000077500000000000000000000000001505336676500156015ustar00rootroot00000000000000ijl-orjson-aa8c946/.github/actions/000077500000000000000000000000001505336676500172415ustar00rootroot00000000000000ijl-orjson-aa8c946/.github/actions/manylinux/000077500000000000000000000000001505336676500212655ustar00rootroot00000000000000ijl-orjson-aa8c946/.github/actions/manylinux/action.yaml000066400000000000000000000023701505336676500234300ustar00rootroot00000000000000name: manylinux inputs: arch: required: true interpreter: required: true features: required: true compatibility: required: true publish: required: true runs: using: "composite" steps: - name: Build and test shell: bash run: | set -eou pipefail mkdir dist export PYTHON="${{ inputs.interpreter }}" if [[ "${PYTHON}" == *t ]]; then export PYTHON_PACKAGE="$(echo ${PYTHON} | sed 's/.$//')-freethreading" else export PYTHON_PACKAGE="${PYTHON}" fi export TARGET="${{ inputs.arch }}-unknown-linux-gnu" export PATH="$PWD/.venv:$HOME/.cargo/bin:$PATH" ./script/install-fedora source "${VENV}/bin/activate" maturin build \ --release \ --strip \ --features="${{ inputs.features }}" \ --compatibility="${{ inputs.compatibility }}" \ --interpreter="${PYTHON}" \ --target="${TARGET}" uv pip install ${CARGO_TARGET_DIR}/wheels/orjson*.whl export PYTHONMALLOC="debug" pytest -v test ./integration/run thread ./integration/run http ./integration/run init cp ${CARGO_TARGET_DIR}/wheels/orjson*.whl dist ijl-orjson-aa8c946/.github/workflows/000077500000000000000000000000001505336676500176365ustar00rootroot00000000000000ijl-orjson-aa8c946/.github/workflows/artifact.yaml000066400000000000000000000650471505336676500223330ustar00rootroot00000000000000name: artifact on: push env: CARGO_UNSTABLE_SPARSE_REGISTRY: "true" FORCE_COLOR: "1" PIP_DISABLE_PIP_VERSION_CHECK: "1" RUST_TOOLCHAIN: "nightly-2025-08-10" UNSAFE_PYO3_BUILD_FREE_THREADED: "1" UNSAFE_PYO3_SKIP_VERSION_CHECK: "1" UV_LINK_MODE: "copy" jobs: sdist: runs-on: ubuntu-24.04 timeout-minutes: 10 strategy: fail-fast: false env: RUST_TOOLCHAIN: "1.85" # MSRV steps: - uses: actions/setup-python@v5 with: python-version: "3.13" - name: rustup stable run: | curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain "${RUST_TOOLCHAIN}" -y rustup default "${RUST_TOOLCHAIN}" - uses: actions/checkout@v4 - name: Cargo.toml and pyproject.toml version must match run: ./script/check-version - run: python3 -m pip install --user --upgrade pip "maturin>=1,<2" wheel - name: Vendor dependencies run: | maturin build cargo fetch mkdir .cargo cp ci/sdist.toml .cargo/config.toml cargo vendor include/cargo --versioned-dirs - run: maturin sdist --out=dist - run: python3 -m pip install --user dist/orjson*.tar.gz env: CARGO_NET_OFFLINE: "true" - run: python3 -m pip install --user -r test/requirements.txt -r integration/requirements.txt mypy - run: pytest -v test env: PYTHONMALLOC: "debug" - run: ./integration/run thread - run: ./integration/run http - run: ./integration/run init - run: ./integration/run typestubs - name: Store sdist uses: actions/upload-artifact@v4 with: name: orjson_sdist path: dist overwrite: true retention-days: 1 if-no-files-found: "error" compression-level: 0 manylinux_amd64: runs-on: ubuntu-24.04 container: image: fedora:rawhide timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ { interpreter: 'python3.14t', compatibility: "manylinux_2_34", publish: false }, { interpreter: 'python3.14', compatibility: "manylinux_2_34", publish: true }, { interpreter: 'python3.13', compatibility: "manylinux_2_17", publish: true }, { interpreter: 'python3.12', compatibility: "manylinux_2_17", publish: true }, { interpreter: 'python3.11', compatibility: "manylinux_2_17", publish: true }, { interpreter: 'python3.10', compatibility: "manylinux_2_17", publish: true }, { interpreter: 'python3.9', compatibility: "manylinux_2_17", publish: true }, ] env: CARGO_TARGET_DIR: "/tmp/orjson" CC: "clang" CFLAGS: "-O2 -fstrict-aliasing -fno-plt -emit-llvm" LDFLAGS: "-fuse-ld=lld -Wl,-plugin-opt=also-emit-llvm -Wl,--as-needed -Wl,-zrelro,-znow" RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld -C linker-plugin-lto -C lto=fat -C link-arg=-Wl,-zrelro,-znow -Z mir-opt-level=4 -Z threads=4 -D warnings" VENV: ".venv" steps: - name: CPU info run: cat /proc/cpuinfo - run: dnf install --setopt=install_weak_deps=false -y git - uses: actions/checkout@v4 - name: Build and test uses: ./.github/actions/manylinux with: arch: "x86_64" interpreter: "${{ matrix.python.interpreter }}" features: "avx512,yyjson" compatibility: "${{ matrix.python.compatibility }}" publish: "${{ matrix.python.publish }}" - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: "orjson_manylinux_amd64_${{ matrix.python.interpreter }}_${{ matrix.python.compatibility }}" path: dist overwrite: true retention-days: 1 - name: Debug env: CARGO_TARGET_DIR: "/tmp/orjson" ORJSON_FEATURES: "avx512,yyjson" PYTHON: "${{ matrix.python.interpreter }}" TARGET: "x86_64-unknown-linux-gnu" run: | export PATH="$PWD/.venv:$HOME/.cargo/bin:$PATH" source .venv/bin/activate script/debug manylinux_aarch64: runs-on: ubuntu-24.04-arm container: image: fedora:rawhide timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ { interpreter: 'python3.14t', compatibility: "manylinux_2_34", publish: false }, { interpreter: 'python3.14', compatibility: "manylinux_2_34", publish: true }, { interpreter: 'python3.13', compatibility: "manylinux_2_17", publish: true }, { interpreter: 'python3.12', compatibility: "manylinux_2_17", publish: true }, { interpreter: 'python3.11', compatibility: "manylinux_2_17", publish: true }, { interpreter: 'python3.10', compatibility: "manylinux_2_17", publish: true }, { interpreter: 'python3.9', compatibility: "manylinux_2_17", publish: true }, ] env: CARGO_TARGET_DIR: "/tmp/orjson" CC: "clang" CFLAGS: "-O2 -fstrict-aliasing -fno-plt -emit-llvm" LDFLAGS: "-fuse-ld=lld -Wl,-plugin-opt=also-emit-llvm -Wl,--as-needed -Wl,-zrelro,-znow" RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld -C linker-plugin-lto -C lto=fat -C link-arg=-Wl,-zrelro,-znow -Z mir-opt-level=4 -Z threads=4 -D warnings" VENV: ".venv" steps: - name: CPU info run: cat /proc/cpuinfo - run: dnf install --setopt=install_weak_deps=false -y git - uses: actions/checkout@v4 - name: Build and test uses: ./.github/actions/manylinux with: arch: "aarch64" interpreter: "${{ matrix.python.interpreter }}" features: "generic_simd,yyjson" compatibility: "${{ matrix.python.compatibility }}" publish: "${{ matrix.python.publish }}" - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: "orjson_manylinux_aarch64_${{ matrix.python.interpreter }}_${{ matrix.python.compatibility }}" path: dist overwrite: true retention-days: 1 - name: Debug env: CARGO_TARGET_DIR: "/tmp/orjson" ORJSON_FEATURES: "generic_simd,yyjson" PYTHON: "${{ matrix.python.interpreter }}" TARGET: "aarch64-unknown-linux-gnu" run: | export PATH="$PWD/.venv:$HOME/.cargo/bin:$PATH" source .venv/bin/activate script/debug manylinux_cross: runs-on: ubuntu-24.04 timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ # { interpreter: 'python3.14', abi: 'cp314-cp314', manylinux: 'manylinux_2_34', publish: true }, { interpreter: 'python3.13', abi: 'cp313-cp313', manylinux: 'manylinux_2_17', publish: true }, { interpreter: 'python3.12', abi: 'cp312-cp312', manylinux: 'manylinux_2_17', publish: true }, { interpreter: 'python3.11', abi: 'cp311-cp311', manylinux: 'manylinux_2_17', publish: true }, { interpreter: 'python3.10', abi: 'cp310-cp310', manylinux: 'manylinux_2_17', publish: true }, { interpreter: 'python3.9', abi: 'cp39-cp39', manylinux: 'manylinux_2_17', publish: true }, ] target: [ { arch: 'i686', cflags: '-Os -fstrict-aliasing', features: 'yyjson', rustflags: '-Z mir-opt-level=4 -C lto=fat -D warnings', target: 'i686-unknown-linux-gnu', }, { arch: 'armv7', cflags: '-Os -fstrict-aliasing', features: 'yyjson', rustflags: '-Z mir-opt-level=4 -C lto=fat -D warnings -C opt-level=s', target: 'armv7-unknown-linux-gnueabihf', }, { arch: 'ppc64le', cflags: '-Os -fstrict-aliasing', features: 'generic_simd,yyjson', rustflags: '-Z mir-opt-level=4 -C lto=fat -D warnings', target: 'powerpc64le-unknown-linux-gnu', }, { arch: 's390x', cflags: '-Os -fstrict-aliasing -march=z10', features: 'yyjson', rustflags: '-Z mir-opt-level=4 -C lto=fat -D warnings -C target-cpu=z10', target: 's390x-unknown-linux-gnu', }, ] steps: - uses: actions/checkout@v4 - name: build-std run: | mkdir .cargo cp ci/config.toml .cargo/config.toml - name: Build uses: PyO3/maturin-action@v1 env: PYO3_CROSS_LIB_DIR: "/opt/python/${{ matrix.python.abi }}" CFLAGS: "${{ matrix.target.cflags }}" LDFLAGS: "-Wl,--as-needed" RUSTFLAGS: "${{ matrix.target.rustflags }}" with: target: "${{ matrix.target.target }}" rust-toolchain: "${{ env.RUST_TOOLCHAIN }}" rustup-components: rust-src manylinux: "${{ matrix.python.manylinux }}" args: --release --strip --out=dist --features=${{ matrix.target.features }} -i ${{ matrix.python.interpreter }} - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: "orjson_manylinux_${{ matrix.target.arch }}_${{ matrix.python.interpreter }}" path: dist overwrite: true retention-days: 1 if-no-files-found: "error" compression-level: 0 - name: setup-qemu-container if: "matrix.target.arch == 's390x'" uses: sandervocke/setup-qemu-container@v1 with: container: registry.fedoraproject.org/fedora:42 arch: ${{ matrix.target.arch }} podman_args: "-v .:/orjson -v /tmp:/tmp --workdir /orjson" - name: setup-shell-wrapper uses: sandervocke/setup-shell-wrapper@v1 - name: Emulated Test if: "matrix.target.arch == 's390x'" shell: wrap-shell {0} env: WRAP_SHELL: run-in-container.sh run: | set -eou pipefail dnf install --setopt=install_weak_deps=false -y ${{ matrix.python.interpreter }} python3-uv uv venv --python ${{ matrix.python.interpreter }} source .venv/bin/activate uv pip install -r test/requirements.txt uv pip install dist/orjson*.whl pytest -v test musllinux_amd64: runs-on: ubuntu-24.04 timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ { version: '3.14', pytest: '1', publish: true }, { version: '3.13', pytest: '1', publish: true }, { version: '3.12', pytest: '1', publish: true }, { version: '3.11', pytest: '0', publish: true }, { version: '3.10', pytest: '0', publish: true }, { version: '3.9', pytest: '0', publish: true }, ] platform: - target: x86_64-unknown-linux-musl arch: x86_64 platform: linux/amd64 features: avx512,unwind,yyjson - target: i686-unknown-linux-musl arch: i686 platform: linux/386 features: unwind,yyjson steps: - uses: actions/checkout@v4 - name: build-std run: | mkdir .cargo cp ci/config.toml .cargo/config.toml - name: Build uses: PyO3/maturin-action@v1 env: CC: "gcc" CFLAGS: "-O2" LDFLAGS: "-Wl,--as-needed" RUSTFLAGS: "-C lto=fat -Z mir-opt-level=4 -Z threads=2 -D warnings -C target-feature=-crt-static" with: rust-toolchain: "${{ env.RUST_TOOLCHAIN }}" rustup-components: rust-src target: "${{ matrix.platform.target }}" manylinux: musllinux_1_2 args: --release --strip --out=dist --features=${{ matrix.platform.features }} -i python${{ matrix.python.version }} - name: Test uses: addnab/docker-run-action@v3 with: image: "quay.io/pypa/musllinux_1_2_${{ matrix.platform.arch }}:2025.07.25-1" options: -v ${{ github.workspace }}:/io -w /io run: | apk add tzdata sed -i '/^psutil/d' test/requirements.txt # missing 3.11, 3.12 wheels sed -i '/^numpy/d' test/requirements.txt python${{ matrix.python.version }} -m venv venv venv/bin/pip install -U pip wheel venv/bin/pip install orjson --no-index --find-links dist/ --force-reinstall # segfault on starting pytest after January 2025 on 3.11 and older; artifact works fine if [ ${{ matrix.python.pytest }} == '1' ]; then venv/bin/pip install -r test/requirements.txt PYTHONMALLOC="debug" venv/bin/python -m pytest -v test fi - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: orjson_musllinux_${{ matrix.platform.arch }}_${{ matrix.python.version }} path: dist overwrite: true retention-days: 1 if-no-files-found: "error" compression-level: 0 musllinux_aarch64: runs-on: ubuntu-24.04-arm timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ { version: '3.14', publish: true }, { version: '3.13', publish: true }, { version: '3.12', publish: true }, { version: '3.11', publish: true }, { version: '3.10', publish: true }, { version: '3.9', publish: true }, ] platform: - target: aarch64-unknown-linux-musl arch: aarch64 platform: linux/arm64 features: generic_simd,unwind,yyjson - target: armv7-unknown-linux-musleabihf arch: armv7l platform: linux/arm/v7 features: yyjson steps: - uses: actions/checkout@v4 - name: build-std run: | mkdir .cargo cp ci/config.toml .cargo/config.toml - name: Build uses: PyO3/maturin-action@v1 env: CC: "gcc" CFLAGS: "-O2" LDFLAGS: "-Wl,--as-needed" RUSTFLAGS: "-C lto=fat -Z mir-opt-level=4 -Z threads=2 -D warnings -C target-feature=-crt-static" with: rust-toolchain: "${{ env.RUST_TOOLCHAIN }}" rustup-components: rust-src target: "${{ matrix.platform.target }}" manylinux: musllinux_1_2 args: --release --strip --out=dist --features=${{ matrix.platform.features }} -i python${{ matrix.python.version }} - name: Test uses: addnab/docker-run-action@v3 with: image: "quay.io/pypa/musllinux_1_2_${{ matrix.platform.arch }}:2025.07.25-1" options: -v ${{ github.workspace }}:/io -w /io run: | apk add tzdata sed -i '/^psutil/d' test/requirements.txt # missing 3.11, 3.12 wheels sed -i '/^numpy/d' test/requirements.txt python${{ matrix.python.version }} -m venv venv venv/bin/pip install -U pip wheel venv/bin/pip install -r test/requirements.txt venv/bin/pip install orjson --no-index --find-links dist/ --force-reinstall export PYTHONMALLOC="debug" venv/bin/python -m pytest -v test - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: orjson_musllinux_${{ matrix.platform.arch }}_${{ matrix.python.version }} path: dist overwrite: true retention-days: 1 if-no-files-found: "error" compression-level: 0 macos_aarch64: runs-on: macos-15 timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ { version: '3.14', macosx_target: "15.0", publish: true }, { version: '3.13', macosx_target: "15.0", publish: true }, { version: '3.12', macosx_target: "15.0", publish: true }, { version: '3.11', macosx_target: "15.0", publish: true }, ] env: CC: "clang" LDFLAGS: "-Wl,--as-needed" CFLAGS: "-O2 -fstrict-aliasing -fno-plt -mcpu=apple-m1 -mtune=generic" RUSTFLAGS: "-Z mir-opt-level=4 -Z threads=3 -D warnings" PATH: "/Users/runner/work/orjson/orjson/.venv/bin:/Users/runner/.cargo/bin:/usr/local/opt/curl/bin:/usr/local/bin:/usr/local/sbin:/Users/runner/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin" steps: - name: CPU info run: sysctl -a | grep brand - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: allow-prereleases: true python-version: "${{ matrix.python.version }}" - uses: dtolnay/rust-toolchain@master with: toolchain: "${{ env.RUST_TOOLCHAIN }}" targets: "aarch64-apple-darwin" components: "rust-src" - name: Build environment run: | cargo fetch --target aarch64-apple-darwin & export PATH=$HOME/.cargo/bin:$HOME/.local/bin:$PATH curl -LsSf https://astral.sh/uv/install.sh | sh uv venv --python python${{ matrix.python.version }} uv pip install --upgrade "maturin>=1,<2" -r test/requirements.txt -r integration/requirements.txt mkdir .cargo cp ci/config.toml .cargo/config.toml - name: maturin run: | export PATH=$HOME/.cargo/bin:$HOME/.local/bin:$PATH MACOSX_DEPLOYMENT_TARGET="${{ matrix.python.macosx_target }}" \ PYO3_CROSS_LIB_DIR=$(python -c "import sysconfig;print(sysconfig.get_config_var('LIBDIR'))") \ maturin build \ --release \ --strip \ --features=generic_simd,yyjson \ --interpreter python${{ matrix.python.version }} \ --target=aarch64-apple-darwin uv pip install target/wheels/orjson*.whl - run: pytest -v test env: PYTHONMALLOC: "debug" - run: source .venv/bin/activate && ./integration/run thread - run: source .venv/bin/activate && ./integration/run http - run: source .venv/bin/activate && ./integration/run init - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: orjson_macos_aarch64_${{ matrix.python.version }} path: target/wheels overwrite: true retention-days: 1 if-no-files-found: "error" compression-level: 0 macos_universal2_aarch64: runs-on: macos-15 timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ { version: '3.14', macosx_target: "10.15", publish: true }, { version: '3.13', macosx_target: "10.15", publish: true }, { version: '3.12', macosx_target: "10.15", publish: true }, { version: '3.11', macosx_target: "10.15", publish: true }, { version: '3.10', macosx_target: "10.15", publish: true }, { version: '3.9', macosx_target: "10.15", publish: true }, ] env: CC: "clang" CFLAGS: "-O2 -fstrict-aliasing" LDFLAGS: "-Wl,--as-needed" CFLAGS_x86_64_apple_darwin: "-O2 -fstrict-aliasing -fno-plt -march=x86-64-v2 -mtune=generic" CFLAGS_aarch64_apple_darwin: "-O2 -fstrict-aliasing -fno-plt -mcpu=apple-m1 -mtune=generic" RUSTFLAGS: "-C lto=fat -Z mir-opt-level=4 -Z threads=3 -D warnings" PATH: "/Users/runner/work/orjson/orjson/.venv/bin:/Users/runner/.cargo/bin:/usr/local/opt/curl/bin:/usr/local/bin:/usr/local/sbin:/Users/runner/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin" steps: - name: CPU info run: sysctl -a | grep brand - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: allow-prereleases: true python-version: "${{ matrix.python.version }}" - uses: dtolnay/rust-toolchain@master with: toolchain: "${{ env.RUST_TOOLCHAIN }}" targets: "aarch64-apple-darwin, x86_64-apple-darwin" components: "rust-src" - name: Build environment run: | cargo fetch --target aarch64-apple-darwin & export PATH=$HOME/.cargo/bin:$HOME/.local/bin:$PATH curl -LsSf https://astral.sh/uv/install.sh | sh uv venv --python python${{ matrix.python.version }} uv pip install --upgrade "maturin>=1,<2" -r test/requirements.txt -r integration/requirements.txt mkdir .cargo cp ci/config.toml .cargo/config.toml - name: maturin run: | export PATH=$HOME/.cargo/bin:$HOME/.local/bin:$PATH MACOSX_DEPLOYMENT_TARGET="${{ matrix.python.macosx_target }}" \ PYO3_CROSS_LIB_DIR=$(python -c "import sysconfig;print(sysconfig.get_config_var('LIBDIR'))") \ maturin build \ --release \ --strip \ --features=generic_simd,yyjson \ --interpreter python${{ matrix.python.version }} \ --target=universal2-apple-darwin uv pip install target/wheels/orjson*.whl - run: pytest -v test env: PYTHONMALLOC: "debug" - run: source .venv/bin/activate && ./integration/run thread - run: source .venv/bin/activate && ./integration/run http - run: source .venv/bin/activate && ./integration/run init - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: orjson_universal2_aarch64_${{ matrix.python.version }} path: target/wheels overwrite: true retention-days: 1 if-no-files-found: "error" compression-level: 0 windows_amd64: runs-on: windows-2025 timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ { version: '3.14', publish: true }, { version: '3.13', publish: true }, { version: '3.12', publish: true }, { version: '3.11', publish: true }, { version: '3.10', publish: true }, { version: '3.9', publish: true }, ] platform: [ { arch: "x64", target: "x86_64-pc-windows-msvc", features: "avx512,yyjson" }, { arch: "x86", target: "i686-pc-windows-msvc", features: "yyjson" }, ] env: CFLAGS: "-O2" LDFLAGS: "-Wl,--as-needed" RUSTFLAGS: "-C lto=fat -Z mir-opt-level=4 -D warnings" steps: - name: CPU info shell: pwsh run: Get-WmiObject -Class Win32_Processor -ComputerName. | Select-Object -Property Name, NumberOfCores, NumberOfLogicalProcessors - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: allow-prereleases: true python-version: "${{ matrix.python.version }}" architecture: "${{ matrix.platform.arch }}" - uses: dtolnay/rust-toolchain@master with: toolchain: "${{ env.RUST_TOOLCHAIN }}" targets: "${{ matrix.platform.target }}" components: "rust-src" - name: Build environment run: | cargo fetch --target "${{ matrix.platform.target }}" & python.exe -m pip install --upgrade pip "maturin>=1,<2" wheel python.exe -m pip install -r test\requirements.txt mkdir .cargo cp ci\config.toml .cargo\config.toml - name: maturin run: | maturin.exe build --release --strip --features="${{ matrix.platform.features }}" --target="${{ matrix.platform.target }}" python.exe -m pip install orjson --no-index --find-links target\wheels - run: python.exe -m pytest -s -rxX -v test env: PYTHONMALLOC: "debug" - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: orjson_windows_amd64_${{ matrix.platform.arch }}_${{ matrix.python.version }} path: target\wheels overwrite: true retention-days: 1 if-no-files-found: "error" compression-level: 0 windows_aarch64: runs-on: windows-11-arm timeout-minutes: 10 strategy: fail-fast: false matrix: python: [ { version: '3.14', publish: true }, { version: '3.13', publish: true }, { version: '3.12', publish: true }, { version: '3.11', publish: true }, ] env: CFLAGS: "-O2" LDFLAGS: "-Wl,--as-needed" RUSTFLAGS: "-Z mir-opt-level=4 -D warnings" TARGET: "aarch64-pc-windows-msvc" steps: - name: CPU info shell: pwsh run: Get-WmiObject -Class Win32_Processor -ComputerName. | Select-Object -Property Name, NumberOfCores, NumberOfLogicalProcessors - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: allow-prereleases: true python-version: "${{ matrix.python.version }}" architecture: "arm64" # from maturin - shell: pwsh run: | Invoke-WebRequest -Uri "https://static.rust-lang.org/rustup/dist/$env:TARGET/rustup-init.exe" -OutFile rustup-init.exe .\rustup-init.exe --default-toolchain "$env:RUST_TOOLCHAIN-$env:TARGET" --profile minimal --component rust-src -y "$env:USERPROFILE\.cargo\bin" | Out-File -Append -Encoding ascii $env:GITHUB_PATH "CARGO_HOME=$env:USERPROFILE\.cargo" | Out-File -Append -Encoding ascii $env:GITHUB_ENV - name: Build environment run: | cargo fetch --target "$" & python.exe -m sysconfig python.exe -m pip install --upgrade pip "maturin>=1,<2" wheel python.exe -m pip install -r test\requirements.txt mkdir .cargo cp ci\config.toml .cargo\config.toml - name: maturin run: | maturin.exe build --release --strip --features=generic_simd --target="$env:TARGET" python.exe -m pip install orjson --no-index --find-links target\wheels - run: python.exe -m pytest -s -rxX -v test env: PYTHONMALLOC: "debug" - name: Store wheels if: matrix.python.publish == true uses: actions/upload-artifact@v4 with: name: orjson_windows_aarch64_${{ matrix.python.version }} path: target\wheels overwrite: true retention-days: 1 if-no-files-found: "error" compression-level: 0 pypi: name: PyPI runs-on: ubuntu-24.04 timeout-minutes: 10 needs: [ macos_aarch64, macos_universal2_aarch64, manylinux_aarch64, manylinux_amd64, manylinux_cross, musllinux_aarch64, musllinux_amd64, sdist, windows_aarch64, windows_amd64, ] environment: name: PyPI url: https://pypi.org/p/orjson permissions: id-token: write steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: merge-multiple: true path: dist/ pattern: orjson_* - run: ls -1 dist/ - uses: actions/setup-python@v5 with: python-version: "3.13" - run: ./script/check-pypi dist - name: Publish distribution to PyPI if: "startsWith(github.ref, 'refs/tags/')" uses: pypa/gh-action-pypi-publish@release/v1 with: attestations: true packages-dir: dist skip-existing: true verbose: true ijl-orjson-aa8c946/.github/workflows/lint.yaml000066400000000000000000000007451505336676500214760ustar00rootroot00000000000000name: lint on: push env: FORCE_COLOR: "1" PIP_DISABLE_PIP_VERSION_CHECK: "1" jobs: lint: runs-on: ubuntu-24.04 steps: - uses: actions/setup-python@v5 with: python-version: "3.13" - run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=default -y - run: pip install -U "ruff>=0.12,<0.13" "mypy==1.16.0" - uses: actions/checkout@v4 - run: cargo fmt - run: ./script/lint - run: git diff --exit-code ijl-orjson-aa8c946/.github/workflows/stale.yaml000066400000000000000000000004501505336676500216310ustar00rootroot00000000000000name: stale on: schedule: - cron: '0 8 * * *' permissions: issues: write pull-requests: write jobs: stale: runs-on: ubuntu-24.04 steps: - uses: actions/stale@v9 with: days-before-stale: 7 days-before-close: 1 exempt-assignees: ijl ijl-orjson-aa8c946/.github/workflows/unusual.yaml000066400000000000000000000032331505336676500222170ustar00rootroot00000000000000name: unusual on: push env: CARGO_UNSTABLE_SPARSE_REGISTRY: "true" FORCE_COLOR: "1" PIP_DISABLE_PIP_VERSION_CHECK: "1" jobs: unusual: runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: profile: [ { rust: "1.85", features: "" }, # MSRV { rust: "nightly-2025-08-10", features: "--features=generic_simd" }, ] python: [ { version: '3.13' }, { version: '3.12' }, { version: '3.9' }, ] env: ORJSON_DISABLE_YYJSON: "1" CARGO_UNSTABLE_SPARSE_REGISTRY: "true" UNSAFE_PYO3_SKIP_VERSION_CHECK: "1" steps: - run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain ${{ matrix.profile.rust }} --profile minimal -y - uses: actions/setup-python@v5 with: python-version: '${{ matrix.python.version }}' - run: python -m pip install --user --upgrade pip "maturin>=1,<2" wheel - uses: actions/checkout@v4 - name: build run: | PATH="$HOME/.cargo/bin:$PATH" maturin build --release \ --out=dist \ --profile=dev \ --interpreter python${{ matrix.python.version }} \ --target=x86_64-unknown-linux-gnu ${{ matrix.profile.features }} - run: python -m pip install --user dist/orjson*.whl - run: python -m pip install --user -r test/requirements.txt -r integration/requirements.txt - run: pytest -s -rxX -v test timeout-minutes: 4 env: PYTHONMALLOC: "debug" - run: ./integration/run thread timeout-minutes: 2 - run: ./integration/run http timeout-minutes: 2 - run: ./integration/run init timeout-minutes: 2 ijl-orjson-aa8c946/.gitignore000066400000000000000000000001761505336676500162350ustar00rootroot00000000000000*.patch /.benchmarks /.coverage /.mypy_cache /.pytest_cache /.venv* /build /include/cargo /perf.* /target /vendor __pycache__ ijl-orjson-aa8c946/CHANGELOG.md000066400000000000000000000571261505336676500160650ustar00rootroot00000000000000# Changelog ## 3.11.3 - 2025-08-26 ### Fixed - Fix PyPI project metadata when using maturin 1.9.2 or later. ## 3.11.2 - 2025-08-12 ### Fixed - Fix build using Rust 1.89 on amd64. ### Changed - Build now depends on Rust 1.85 or later instead of 1.82. ## 3.11.1 - 2025-07-25 ### Changed - Publish PyPI wheels for CPython 3.14. ### Fixed - Fix `str` on big-endian architectures. This was introduced in 3.11.0. ## 3.11.0 - 2025-07-15 ### Changed - Use a deserialization buffer allocated per request instead of a shared buffer allocated on import. - ABI compatibility with CPython 3.14 beta 4. ## 3.10.18 - 2025-04-29 ### Fixed - Fix incorrect escaping of the vertical tabulation character. This was introduced in 3.10.17. ## 3.10.17 - 2025-04-29 ### Changed - Publish PyPI Windows aarch64/arm64 wheels. - ABI compatibility with CPython 3.14 alpha 7. - Fix incompatibility running on Python 3.13 using WASM. ## 3.10.16 - 2025-03-24 ### Changed - Improve performance of serialization on amd64 machines with AVX-512. - ABI compatibility with CPython 3.14 alpha 6. - Drop support for Python 3.8. - Publish additional PyPI wheels for macOS that target only aarch64, macOS 15, and recent Python. ## 3.10.15 - 2025-01-08 ### Changed - Publish PyPI manylinux aarch64 wheels built and tested on aarch64. - Publish PyPI musllinux aarch64 and arm7l wheels built and tested on aarch64. - Publish PyPI manylinux Python 3.13 wheels for i686, arm7l, ppc64le, and s390x. ## 3.10.14 - 2024-12-29 ### Changed - Specify build system dependency on `maturin>=1,<2` again. - Allocate memory using `PyMem_Malloc()` and similar APIs for integration with pymalloc, mimalloc, and tracemalloc. - Source distribution does not ship compressed test documents and relevant tests skip if fixtures are not present. - Build now depends on Rust 1.82 or later instead of 1.72. ## 3.10.13 - 2024-12-29 ### Changed - Fix compatibility with maturin introducing a breaking change in 1.8.0 and specify a fixed version of maturin. Projects relying on any previous version being buildable from source by end users (via PEP 517) must upgrade to at least this version. ## 3.10.12 - 2024-11-23 ### Changed - Publish PyPI manylinux i686 wheels. - Publish PyPI musllinux i686 and arm7l wheels. - Publish PyPI macOS wheels for Python 3.10 or later built on macOS 15. - Publish PyPI Windows wheels using trusted publishing. ## 3.10.11 - 2024-11-01 ### Changed - Improve performance of UUIDs. - Publish PyPI wheels with trusted publishing and PEP 740 attestations. - Include text of licenses for vendored dependencies. ## 3.10.10 - 2024-10-22 ### Fixed - Fix `int` serialization on `s390x`. This was introduced in 3.10.8. ### Changed - Publish aarch64 manylinux_2_17 wheel for 3.13 to PyPI. ## 3.10.9 - 2024-10-19 ### Fixed - Fix `int` serialization on 32-bit Python 3.8, 3.9, 3.10. This was introduced in 3.10.8. ## 3.10.8 - 2024-10-19 ### Changed - `int` serialization no longer chains `OverflowError` to the the `__cause__` attribute of `orjson.JSONEncodeError` when range exceeded. - Compatibility with CPython 3.14 alpha 1. - Improve performance. ## 3.10.7 - 2024-08-08 ### Changed - Improve performance of stable Rust amd64 builds. ## 3.10.6 - 2024-07-02 ### Changed - Improve performance. ## 3.10.5 - 2024-06-13 ### Changed - Improve performance. ## 3.10.4 - 2024-06-10 ### Changed - Improve performance. ## 3.10.3 - 2024-05-03 ### Changed - `manylinux` amd64 builds include runtime-detected AVX-512 `str` implementation. - Tests now compatible with numpy v2. ## 3.10.2 - 2024-05-01 ### Fixed - Fix crash serializing `str` introduced in 3.10.1. ### Changed - Improve performance. - Drop support for arm7. ## 3.10.1 - 2024-04-15 ### Fixed - Serializing `numpy.ndarray` with non-native endianness raises `orjson.JSONEncodeError`. ### Changed - Improve performance of serializing. ## 3.10.0 - 2024-03-27 ### Changed - Support serializing `numpy.float16` (`numpy.half`). - sdist uses metadata 2.3 instead of 2.1. - Improve Windows PyPI builds. ## 3.9.15 - 2024-02-23 ### Fixed - Implement recursion limit of 1024 on `orjson.loads()`. - Use byte-exact read on `str` formatting SIMD path to avoid crash. ## 3.9.14 - 2024-02-14 ### Fixed - Fix crash serializing `str` introduced in 3.9.11. ### Changed - Build now depends on Rust 1.72 or later. ## 3.9.13 - 2024-02-03 ### Fixed - Serialization `str` escape uses only 128-bit SIMD. - Fix compatibility with CPython 3.13 alpha 3. ### Changed - Publish `musllinux_1_2` instead of `musllinux_1_1` wheels. - Serialization uses small integer optimization in CPython 3.12 or later. ## 3.9.12 - 2024-01-18 ### Changed - Update benchmarks in README. ### Fixed - Minimal `musllinux_1_1` build due to sporadic CI failure. ## 3.9.11 - 2024-01-18 ### Changed - Improve performance of serializing. `str` is significantly faster. Documents using `dict`, `list`, and `tuple` are somewhat faster. ## 3.9.10 - 2023-10-26 ### Fixed - Fix debug assert failure on 3.12 `--profile=dev` build. ## 3.9.9 - 2023-10-12 ### Changed - `orjson` module metadata explicitly marks subinterpreters as not supported. ## 3.9.8 - 2023-10-10 ### Changed - Improve performance. - Drop support for Python 3.7. ## 3.9.7 - 2023-09-08 ### Fixed - Fix crash in `orjson.loads()` due to non-reentrant handling of persistent buffer. This was introduced in 3.9.3. - Handle some FFI removals in CPython 3.13. ## 3.9.6 - 2023-09-07 ### Fixed - Fix numpy reference leak on unsupported array dtype. - Fix numpy.datetime64 reference handling. ### Changed - Minor performance improvements. ## 3.9.5 - 2023-08-16 ### Fixed - Remove futex from module import and initialization path. ## 3.9.4 - 2023-08-07 ### Fixed - Fix hash builder using default values. - Fix non-release builds of orjson copying large deserialization buffer from stack to heap. This was introduced in 3.9.3. ## 3.9.3 - 2023-08-06 ### Fixed - Fix compatibility with CPython 3.12. ### Changed - Support i686/x86 32-bit Python installs on Windows. ## 3.9.2 - 2023-07-07 ### Fixed - Fix the `__cause__` exception on `orjson.JSONEncodeError` possibly being denormalized, i.e., of type `str` instead of `Exception`. ## 3.9.1 - 2023-06-09 ### Fixed - Fix memory leak on chained tracebacks of exceptions raised in `default`. This was introduced in 3.8.12. ## 3.9.0 - 2023-06-01 ### Added - `orjson.Fragment` includes already-serialized JSON in a document. ## 3.8.14 - 2023-05-25 ### Changed - PyPI `manylinux` wheels are compiled for `x86-64` instead of `x86-64-v2`. ## 3.8.13 - 2023-05-23 ### Changed - Source distribution contains all source code required for an offline build. - PyPI macOS wheels use a `MACOSX_DEPLOYMENT_TARGET` of 10.15 instead of 11. - Build uses maturin v1. ## 3.8.12 - 2023-05-07 ### Changed - Exceptions raised in `default` are now chained as the `__cause__` attribute on `orjson.JSONEncodeError`. ## 3.8.11 - 2023-04-27 ### Changed - `orjson.loads()` on an empty document has a specific error message. - PyPI `manylinux_2_28_x86_64` wheels are compiled for `x86-64-v2`. - PyPI macOS wheels are only `universal2` and compiled for `x86-64-v2` and `apple-m1`. ## 3.8.10 - 2023-04-09 ### Fixed - Fix compatibility with CPython 3.12.0a7. - Fix compatibility with big-endian architectures. - Fix crash in serialization. ### Changed - Publish musllinux 3.11 wheels. - Publish s390x wheels. ## 3.8.9 - 2023-03-28 ### Fixed - Fix parallel initialization of orjson. ## 3.8.8 - 2023-03-20 ### Changed - Publish ppc64le wheels. ## 3.8.7 - 2023-02-28 ### Fixed - Use serialization backend introduced in 3.8.4 only on well-tested platforms such as glibc, macOS by default. ## 3.8.6 - 2023-02-09 ### Fixed - Fix crash serializing when using musl libc. ### Changed - Make `python-dateutil` optional in tests. - Handle failure to load system timezones in tests. ## 3.8.5 - 2023-01-10 ### Fixed - Fix `orjson.dumps()` invalid output on Windows. ## 3.8.4 - 2023-01-04 ### Changed - Improve performance. ## 3.8.3 - 2022-12-02 ### Fixed - `orjson.dumps()` accepts `option=None` per `Optional[int]` type. ## 3.8.2 - 2022-11-20 ### Fixed - Fix tests on 32-bit for `numpy.intp` and `numpy.uintp`. ### Changed - Build now depends on rustc 1.60 or later. - Support building with maturin 0.13 or 0.14. ## 3.8.1 - 2022-10-25 ### Changed - Build maintenance for Python 3.11. ## 3.8.0 - 2022-08-27 ### Changed - Support serializing `numpy.int16` and `numpy.uint16`. ## 3.7.12 - 2022-08-14 ### Fixed - Fix datetime regression tests for tzinfo 2022b. ### Changed - Improve performance. ## 3.7.11 - 2022-07-31 ### Fixed - Revert `dict` iterator implementation introduced in 3.7.9. ## 3.7.10 - 2022-07-30 ### Fixed - Fix serializing `dict` with deleted final item. This was introduced in 3.7.9. ## 3.7.9 - 2022-07-29 ### Changed - Improve performance of serializing. - Improve performance of serializing pretty-printed (`orjson.OPT_INDENT_2`) to be much nearer to compact. - Improve performance of deserializing `str` input. - orjson now requires Rust 1.57 instead of 1.54 to build. ## 3.7.8 - 2022-07-19 ### Changed - Build makes best effort instead of requiring "--features". - Build using maturin 0.13. ## 3.7.7 - 2022-07-06 ### Changed - Support Python 3.11. ## 3.7.6 - 2022-07-03 ### Changed - Handle unicode changes in CPython 3.12. - Build PyPI macOS wheels on 10.15 instead of 12 for compatibility. ## 3.7.5 - 2022-06-28 ### Fixed - Fix issue serializing dicts that had keys popped and replaced. This was introduced in 3.7.4. ## 3.7.4 - 2022-06-28 ### Changed - Improve performance. ### Fixed - Fix deallocation of `orjson.JSONDecodeError`. ## 3.7.3 - 2022-06-23 ## Changed - Improve build. - Publish aarch64 musllinux wheels. ## 3.7.2 - 2022-06-07 ## Changed - Improve deserialization performance. ## 3.7.1 - 2022-06-03 ### Fixed - Type stubs for `orjson.JSONDecodeError` now inherit from `json.JSONDecodeError` instead of `ValueError` - Null-terminate the internal buffer of `orjson.dumps()` output. ## 3.7.0 - 2022-06-03 ### Changed - Improve deserialization performance significantly through the use of a new backend. PyPI wheels for manylinux_2_28 and macOS have it enabled. Packagers are advised to see the README. ## 3.6.9 - 2022-06-01 ### Changed - Improve serialization and deserialization performance. ## 3.6.8 - 2022-04-15 ### Fixed - Fix serialization of `numpy.datetime64("NaT")` to raise on an unsupported type. ## 3.6.7 - 2022-02-14 ### Changed - Improve performance of deserializing almost-empty documents. - Publish arm7l `manylinux_2_17` wheels to PyPI. - Publish amd4 `musllinux_1_1` wheels to PyPI. ### Fixed - Fix build requiring `python` on `PATH`. ## 3.6.6 - 2022-01-21 ### Changed - Improve performance of serializing `datetime.datetime` using `tzinfo` that are `zoneinfo.ZoneInfo`. ### Fixed - Fix invalid indexing in line and column number reporting in `JSONDecodeError`. - Fix `orjson.OPT_STRICT_INTEGER` not raising an error on values exceeding a 64-bit integer maximum. ## 3.6.5 - 2021-12-05 ### Fixed - Fix build on macOS aarch64 CPython 3.10. - Fix build issue on 32-bit. ## 3.6.4 - 2021-10-01 ### Fixed - Fix serialization of `dataclass` inheriting from `abc.ABC` and using `__slots__`. - Decrement refcount for numpy `PyArrayInterface`. - Fix build on recent versions of Rust nightly. ## 3.6.3 - 2021-08-20 ### Fixed - Fix build on aarch64 using the Rust stable channel. ## 3.6.2 - 2021-08-17 ### Changed - `orjson` now compiles on Rust stable 1.54.0 or above. Use of some SIMD usage is now disabled by default and packagers are advised to add `--cargo-extra-args="--features=unstable-simd"` to the `maturin build` command if they continue to use nightly. - `orjson` built with `--features=unstable-simd` adds UTF-8 validation implementations that use AVX2 or SSE4.2. - Drop support for Python 3.6. ## 3.6.1 - 2021-08-04 ### Changed - `orjson` now includes a `pyi` type stubs file. - Publish manylinux_2_24 wheels instead of manylinux2014. ### Fixed - Fix compilation on latest Rust nightly. ## 3.6.0 - 2021-07-08 ### Added - `orjson.dumps()` serializes `numpy.datetime64` instances as RFC 3339 strings. ## 3.5.4 - 2021-06-30 ### Fixed - Fix memory leak serializing `datetime.datetime` with `tzinfo`. - Fix wrong error message when serializing an unsupported numpy type without default specified. ### Changed - Publish python3.10 and python3.9 manylinux_2_24 wheels. ## 3.5.3 - 2021-06-01 ### Fixed - `orjson.JSONDecodeError` now has `pos`, `lineno`, and `colno`. - Fix build on recent versions of Rust nightly. ## 3.5.2 - 2021-04-15 ### Changed - Improve serialization and deserialization performance. - `orjson.dumps()` serializes individual `numpy.bool_` objects. ## 3.5.1 - 2021-03-06 ### Changed - Publish `universal2` wheels for macOS supporting Apple Silicon (aarch64). ## 3.5.0 - 2021-02-24 ### Added - `orjson.loads()` supports reading from `memoryview` objects. ### Fixed - `datetime.datetime` and `datetime.date` zero pad years less than 1000 to four digits. - sdist pins maturin 0.9.0 to avoid breaks in later 0.9.x. ### Changed - `orjson.dumps()` when given a non-C contiguous `numpy.ndarray` has an error message suggesting to use `default`. ## 3.4.8 - 2021-02-04 ### Fixed - aarch64 manylinux2014 wheels are now compatible with glibc 2.17. ### Changed - Fix build warnings on ppcle64. ## 3.4.7 - 2021-01-19 ### Changed - Use vectorcall APIs for method calls on python3.9 and above. - Publish python3.10 wheels for Linux on amd64 and aarch64. ## 3.4.6 - 2020-12-07 ### Fixed - Fix compatibility with debug builds of CPython. ## 3.4.5 - 2020-12-02 ### Fixed - Fix deserializing long strings on processors without AVX2. ## 3.4.4 - 2020-11-25 ### Changed - `orjson.dumps()` serializes integers up to a 64-bit unsigned integer's maximum. It was previously the maximum of a 64-bit signed integer. ## 3.4.3 - 2020-10-30 ### Fixed - Fix regression in parsing similar `dict` keys. ## 3.4.2 - 2020-10-29 ### Changed - Improve deserialization performance. - Publish Windows python3.9 wheel. - Disable unsupported SIMD features on non-x86, non-ARM targets ## 3.4.1 - 2020-10-20 ### Fixed - Fix `orjson.dumps.__module__` and `orjson.loads.__module__` not being the `str` "orjson". ### Changed - Publish macos python3.9 wheel. - More packaging documentation. ## 3.4.0 - 2020-09-25 ### Added - Serialize `numpy.uint8` and `numpy.int8` instances. ### Fixed - Fix serializing `numpy.empty()` instances. ### Changed - No longer publish `manylinux1` wheels due to tooling dropping support. ## 3.3.1 - 2020-08-17 ### Fixed - Fix failure to deserialize some latin1 strings on some platforms. This was introduced in 3.2.0. - Fix annotation of optional parameters on `orjson.dumps()` for `help()`. ### Changed - Publish `manylinux2014` wheels for amd64 in addition to `manylinux1`. ## 3.3.0 - 2020-07-24 ### Added - `orjson.dumps()` now serializes individual numpy floats and integers, e.g., `numpy.float64(1.0)`. - `orjson.OPT_PASSTHROUGH_DATACLASS` causes `orjson.dumps()` to pass `dataclasses.dataclass` instances to `default`. ## 3.2.2 - 2020-07-13 ### Fixed - Fix serializing `dataclasses.dataclass` that have no attributes. ### Changed - Improve deserialization performance of `str`. ## 3.2.1 - 2020-07-03 ### Fixed - Fix `orjson.dumps(..., **{})` raising `TypeError` on python3.6. ## 3.2.0 - 2020-06-30 ### Added - `orjson.OPT_APPEND_NEWLINE` appends a newline to output. ### Changed - Improve deserialization performance of `str`. ## 3.1.2 - 2020-06-23 ### Fixed - Fix serializing zero-dimension `numpy.ndarray`. ## 3.1.1 - 2020-06-20 ### Fixed - Fix repeated serialization of `str` that are ASCII-only and have a legacy (non-compact) layout. ## 3.1.0 - 2020-06-08 ### Added - `orjson.OPT_PASSTHROUGH_SUBCLASS` causes `orjson.dumps()` to pass subclasses of builtin types to `default` so the caller can customize the output. - `orjson.OPT_PASSTHROUGH_DATETIME` causes `orjson.dumps()` to pass `datetime` objects to `default` so the caller can customize the output. ## 3.0.2 - 2020-05-27 ### Changed - `orjson.dumps()` does not serialize `dataclasses.dataclass` attributes that begin with a leading underscore, e.g., `_attr`. This is because of the Python idiom that a leading underscores marks an attribute as "private." - `orjson.dumps()` does not serialize `dataclasses.dataclass` attributes that are `InitVar` or `ClassVar` whether using `__slots__` or not. ## 3.0.1 - 2020-05-19 ### Fixed - `orjson.dumps()` raises an exception if the object to be serialized is not given as a positional argument. `orjson.dumps({})` is intended and ok while `orjson.dumps(obj={})` is an error. This makes it consistent with the documentation, `help()` annotation, and type annotation. - Fix orphan reference in exception creation that leaks memory until the garbage collector runs. ### Changed - Improve serialization performance marginally by using the fastcall/vectorcall calling convention on python3.7 and above. - Reduce build time. ## 3.0.0 - 2020-05-01 ### Added - `orjson.dumps()` serializes subclasses of `str`, `int`, `list`, and `dict`. ### Changed - `orjson.dumps()` serializes `dataclasses.dataclass` and `uuid.UUID` instances by default. The options `OPT_SERIALIZE_DATACLASS` and `OPT_SERIALIZE_UUID` can still be specified but have no effect. ## 2.6.8 - 2020-04-30 ### Changed - The source distribution vendors a forked dependency. ## 2.6.7 - 2020-04-30 ### Fixed - Fix integer overflows in debug builds. ### Changed - The source distribution sets the recommended RUSTFLAGS in `.cargo/config`. ## 2.6.6 - 2020-04-24 ### Fixed - Import `numpy` only on first use of `OPT_SERIALIZE_NUMPY` to reduce interpreter start time when not used. - Reduce build time by half. ## 2.6.5 - 2020-04-08 ### Fixed - Fix deserialization raising `JSONDecodeError` on some valid negative floats with large exponents. ## 2.6.4 - 2020-04-08 ### Changed - Improve deserialization performance of floats by about 40%. ## 2.6.3 - 2020-04-01 ### Changed - Serialize `enum.Enum` objects. - Minor performance improvements. ## 2.6.2 - 2020-03-27 ### Changed - Publish python3.9 `manylinux2014` wheel instead of `manylinux1` for `x86_64`. - Publish python3.9 `manylinux2014` wheel for `aarch64`. ### Fixed - Fix compilation failure on 32-bit. ## 2.6.1 - 2020-03-19 ### Changed - Serialization is 10-20% faster and uses about 50% less memory by writing directly to the returned `bytes` object. ## 2.6.0 - 2020-03-10 ### Added - `orjson.dumps()` pretty prints with an indentation of two spaces if `option=orjson.OPT_INDENT_2` is specified. ## 2.5.2 - 2020-03-07 ### Changed - Publish `manylinux2014` wheels for `aarch64`. - numpy support now includes `numpy.uint32` and `numpy.uint64`. ## 2.5.1 - 2020-02-24 ### Changed - `manylinux1` wheels for 3.6, 3.7, and 3.8 are now compliant with the spec by not depending on glibc 2.18. ## 2.5.0 - 2020-02-19 ### Added - `orjson.dumps()` serializes `dict` keys of type other than `str` if `option=orjson.OPT_NON_STR_KEYS` is specified. ## 2.4.0 - 2020-02-14 ### Added - `orjson.dumps()` serializes `numpy.ndarray` instances if `option=orjson.OPT_SERIALIZE_NUMPY` is specified. ### Fixed - Fix `dataclasses.dataclass` attributes that are `dict` to be effected by `orjson.OPT_SORT_KEYS`. ## 2.3.0 - 2020-02-12 ### Added - `orjson.dumps()` serializes `dict` instances sorted by keys, equivalent to `sort_keys` in other implementations, if `option=orjson.OPT_SORT_KEYS` is specified. ### Changed - `dataclasses.dataclass` instances without `__slots__` now serialize faster. ### Fixed - Fix documentation on `default`, in particular documenting the need to raise an exception if the type cannot be handled. ## 2.2.2 - 2020-02-10 ### Changed - Performance improvements to serializing a list containing elements of the same type. ## 2.2.1 - 2020-02-04 ### Fixed - `orjson.loads()` rejects floats that do not have a digit following the decimal, e.g., `-2.`, `2.e-3`. ### Changed - Build Linux, macOS, and Windows wheels on more recent distributions. ## 2.2.0 - 2020-01-22 ### Added - `orjson.dumps()` serializes `uuid.UUID` instances if `option=orjson.OPT_SERIALIZE_UUID` is specified. ### Changed - Minor performance improvements. - Publish Python 3.9 wheel for Linux. ## 2.1.4 - 2020-01-08 ### Fixed - Specify a text signature for `orjson.loads()`. ### Changed - Improve documentation. ## 2.1.3 - 2019-11-12 ### Changed - Publish Python 3.8 wheels for macOS and Windows. ## 2.1.2 - 2019-11-07 ### Changed - The recursion limit of `default` on `orjson.dumps()` has been increased from 5 to 254. ## 2.1.1 - 2019-10-29 ### Changed - Publish `manylinux1` wheels instead of `manylinux2010`. ## 2.1.0 - 2019-10-24 ### Added - `orjson.dumps()` serializes `dataclasses.dataclass` instances if `option=orjson.OPT_SERIALIZE_DATACLASS` is specified. - `orjson.dumps()` accepts `orjson.OPT_UTC_Z` to serialize UTC as "Z" instead of "+00:00". - `orjson.dumps()` accepts `orjson.OPT_OMIT_MICROSECONDS` to not serialize the `microseconds` attribute of `datetime.datetime` and `datetime.time` instances. - `orjson.loads()` accepts `bytearray`. ### Changed - Drop support for Python 3.5. - Publish `manylinux2010` wheels instead of `manylinux1`. ## 2.0.11 - 2019-10-01 ### Changed - Publish Python 3.8 wheel for Linux. ## 2.0.10 - 2019-09-25 ### Changed - Performance improvements and lower memory usage in deserialization by creating only one `str` object for repeated map keys. ## 2.0.9 - 2019-09-22 ### Changed - Minor performance improvements. ### Fixed - Fix inaccurate zero padding in serialization of microseconds on `datetime.time` objects. ## 2.0.8 - 2019-09-18 ### Fixed - Fix inaccurate zero padding in serialization of microseconds on `datetime.datetime` objects. ## 2.0.7 - 2019-08-29 ### Changed - Publish PEP 517 source distribution. ### Fixed - `orjson.dumps()` raises `JSONEncodeError` on circular references. ## 2.0.6 - 2019-05-11 ### Changed - Performance improvements. ## 2.0.5 - 2019-04-19 ### Fixed - Fix inaccuracy in deserializing some `float` values, e.g., 31.245270191439438 was parsed to 31.24527019143944. Serialization was unaffected. ## 2.0.4 - 2019-04-02 ### Changed - `orjson.dumps()` now serializes `datetime.datetime` objects without a `tzinfo` rather than raising `JSONEncodeError`. ## 2.0.3 - 2019-03-23 ### Changed - `orjson.loads()` uses SSE2 to validate `bytes` input. ## 2.0.2 - 2019-03-12 ### Changed - Support Python 3.5. ## 2.0.1 - 2019-02-05 ### Changed - Publish Windows wheel. ## 2.0.0 - 2019-01-28 ### Added - `orjson.dumps()` accepts a `default` callable to serialize arbitrary types. - `orjson.dumps()` accepts `datetime.datetime`, `datetime.date`, and `datetime.time`. Each is serialized to an RFC 3339 string. - `orjson.dumps(..., option=orjson.OPT_NAIVE_UTC)` allows serializing `datetime.datetime` objects that do not have a timezone set as UTC. - `orjson.dumps(..., option=orjson.OPT_STRICT_INTEGER)` available to raise an error on integer values outside the 53-bit range of all JSON implementations. ### Changed - `orjson.dumps()` no longer accepts `bytes`. ## 1.3.1 - 2019-01-03 ### Fixed - Handle invalid UTF-8 in str. ## 1.3.0 - 2019-01-02 ### Changed - Performance improvements of 15-25% on serialization, 10% on deserialization. ## 1.2.1 - 2018-12-31 ### Fixed - Fix memory leak in deserializing dict. ## 1.2.0 - 2018-12-16 ### Changed - Performance improvements. ## 1.1.0 - 2018-12-04 ### Changed - Performance improvements. ### Fixed - Dict key can only be str. ## 1.0.1 - 2018-11-26 ### Fixed - pyo3 bugfix update. ## 1.0.0 - 2018-11-23 ### Added - `orjson.dumps()` function. - `orjson.loads()` function. ijl-orjson-aa8c946/CONTRIBUTING.md000066400000000000000000000003001505336676500164630ustar00rootroot00000000000000orjson is stable. Contributions will be reviewed only if they are well documented, tested to the same standard as the rest of the library, not a breaking change, and important to other users. ijl-orjson-aa8c946/Cargo.lock000066400000000000000000000176221505336676500161560ustar00rootroot00000000000000# This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "associative-cache" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b993cd767a2bc7307dd87622311ca22c44329cc7a21366206bfa0896827b2bad" [[package]] name = "bytecount" version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" [[package]] name = "bytes" version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cc" version = "1.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e" dependencies = [ "shlex", ] [[package]] name = "cfg-if" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "crunchy" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "encoding_rs" version = "0.8.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" dependencies = [ "cfg-if", ] [[package]] name = "gimli" version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93563d740bc9ef04104f9ed6f86f1e3275c2cdafb95664e26584b9ca807a8ffe" [[package]] name = "half" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" dependencies = [ "cfg-if", "crunchy", ] [[package]] name = "itoa" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "itoap" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9028f49264629065d057f340a86acb84867925865f73bbf8d47b4d149a7e88b8" [[package]] name = "jiff" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49" dependencies = [ "jiff-static", "portable-atomic", "portable-atomic-util", ] [[package]] name = "jiff-static" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "libc" version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "memchr" version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "orjson" version = "3.11.3" dependencies = [ "associative-cache", "bytecount", "bytes", "cc", "encoding_rs", "half", "itoa", "itoap", "jiff", "once_cell", "pyo3-build-config", "pyo3-ffi", "ryu", "serde", "serde_json", "simdutf8", "smallvec", "unwinding", "uuid", "version_check", "xxhash-rust", ] [[package]] name = "portable-atomic" version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" [[package]] name = "portable-atomic-util" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" dependencies = [ "portable-atomic", ] [[package]] name = "proc-macro2" version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "beef09f85ae72cea1ef96ba6870c51e6382ebfa4f0e85b643459331f3daa5be0" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3-build-config" version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "458eb0c55e7ece017adeba38f2248ff3ac615e53660d7c71a238d7d2a01c7598" dependencies = [ "once_cell", "target-lexicon", ] [[package]] name = "pyo3-ffi" version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7114fe5457c61b276ab77c5055f206295b812608083644a5c5b2640c3102565c" dependencies = [ "libc", "pyo3-build-config", ] [[package]] name = "quote" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] [[package]] name = "ryu" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "serde" version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.142" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7" dependencies = [ "itoa", "memchr", "ryu", "serde", ] [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "simdutf8" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" [[package]] name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "syn" version = "2.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "target-lexicon" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" [[package]] name = "unicode-ident" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unwinding" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60612c845ef41699f39dc8c5391f252942c0a88b7d15da672eff0d14101bbd6d" dependencies = [ "gimli", ] [[package]] name = "uuid" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "xxhash-rust" version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3" ijl-orjson-aa8c946/Cargo.toml000066400000000000000000000051431505336676500161740ustar00rootroot00000000000000[package] name = "orjson" version = "3.11.3" authors = ["ijl "] edition = "2021" resolver = "2" rust-version = "1.85" license = "Apache-2.0 OR MIT" keywords = ["fast", "json", "dataclass", "dataclasses", "datetime", "rfc", "8259", "3339"] include = [ "Cargo.toml", "CHANGELOG.md", "include/yyjson", "LICENSE-APACHE", "LICENSE-MIT", "pyproject.toml", "README.md", "src", "test/*.py", "test/requirements.txt", ] [lib] name = "orjson" crate-type = ["cdylib"] [features] default = [] # Avoid bundling libgcc on musl. unwind = ["unwinding"] # Build yyjson as a backend and panic if it fails. The default is to attempt # to build and on failure fall back to another backend. yyjson = [] # Features detected by build.rs. Do not specify. avx512 = [] c_ulong_32 = [] generic_simd = [] inline_int = [] intrinsics = [] optimize = [] [dependencies] associative-cache = { version = "2", default-features = false } bytes = { version = "1", default-features = false } bytecount = { version = "^0.6.7", default-features = false, features = ["runtime-dispatch-simd"] } encoding_rs = { version = "0.8", default-features = false } half = { version = "2", default-features = false, features = ["std"] } itoa = { version = "1", default-features = false } itoap = { version = "1", default-features = false, features = ["std", "simd"] } jiff = { version = "^0.2", default-features = false } once_cell = { version = "1", default-features = false, features = ["alloc", "race"] } pyo3-ffi = { version = "0.25", default-features = false, features = ["extension-module"] } ryu = { version = "1", default-features = false } serde = { version = "1", default-features = false } serde_json = { version = "1", default-features = false, features = ["std", "float_roundtrip"] } simdutf8 = { version = "0.1", default-features = false, features = ["std", "public_imp", "aarch64_neon"] } smallvec = { version = "^1.11", default-features = false, features = ["union", "write"] } unwinding = { version = "=0.2.8", default-features = false, features = ["unwinder"], optional = true } uuid = { version = "1", default-features = false } xxhash-rust = { version = "^0.8", default-features = false, features = ["xxh3"] } [build-dependencies] cc = { version = "1" } pyo3-build-config = { version = "0.25" } version_check = { version = "0.9" } [profile.dev] codegen-units = 1 debug = 2 debug-assertions = true incremental = false lto = "off" opt-level = 3 overflow-checks = true [profile.release] codegen-units = 1 debug = false incremental = false lto = "thin" opt-level = 3 panic = "abort" [profile.release.build-override] opt-level = 0 ijl-orjson-aa8c946/LICENSE-APACHE000066400000000000000000000251371505336676500161750ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ijl-orjson-aa8c946/LICENSE-MIT000066400000000000000000000017771505336676500157110ustar00rootroot00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ijl-orjson-aa8c946/README.md000066400000000000000000001171151505336676500155260ustar00rootroot00000000000000# orjson orjson is a fast, correct JSON library for Python. It [benchmarks](https://github.com/ijl/orjson?tab=readme-ov-file#performance) as the fastest Python library for JSON and is more correct than the standard json library or other third-party libraries. It serializes [dataclass](https://github.com/ijl/orjson?tab=readme-ov-file#dataclass), [datetime](https://github.com/ijl/orjson?tab=readme-ov-file#datetime), [numpy](https://github.com/ijl/orjson?tab=readme-ov-file#numpy), and [UUID](https://github.com/ijl/orjson?tab=readme-ov-file#uuid) instances natively. [orjson.dumps()](https://github.com/ijl/orjson?tab=readme-ov-file#serialize) is something like 10x as fast as `json`, serializes common types and subtypes, has a `default` parameter for the caller to specify how to serialize arbitrary types, and has a number of flags controlling output. [orjson.loads()](https://github.com/ijl/orjson?tab=readme-ov-file#deserialize) is something like 2x as fast as `json`, and is strictly compliant with UTF-8 and RFC 8259 ("The JavaScript Object Notation (JSON) Data Interchange Format"). Reading from and writing to files, line-delimited JSON files, and so on is not provided by the library. orjson supports CPython 3.9, 3.10, 3.11, 3.12, 3.13, and 3.14. It distributes amd64/x86_64/x64, i686/x86, aarch64/arm64/armv8, arm7, ppc64le/POWER8, and s390x wheels for Linux, amd64 and aarch64 wheels for macOS, and amd64, i686, and aarch64 wheels for Windows. Wheels published to PyPI for amd64 run on x86-64-v1 (2003) or later, but will at runtime use AVX-512 if available for a significant performance benefit; aarch64 wheels run on ARMv8-A (2011) or later. orjson does not and will not support PyPy, embedded Python builds for Android/iOS, or PEP 554 subinterpreters. orjson may support PEP 703 free-threading when it is stable. Releases follow semantic versioning and serializing a new object type without an opt-in flag is considered a breaking change. orjson is licensed under both the Apache 2.0 and MIT licenses. The repository and issue tracker is [github.com/ijl/orjson](https://github.com/ijl/orjson), and patches may be submitted there. There is a [CHANGELOG](https://github.com/ijl/orjson/blob/master/CHANGELOG.md) available in the repository. 1. [Usage](https://github.com/ijl/orjson?tab=readme-ov-file#usage) 1. [Install](https://github.com/ijl/orjson?tab=readme-ov-file#install) 2. [Quickstart](https://github.com/ijl/orjson?tab=readme-ov-file#quickstart) 3. [Migrating](https://github.com/ijl/orjson?tab=readme-ov-file#migrating) 4. [Serialize](https://github.com/ijl/orjson?tab=readme-ov-file#serialize) 1. [default](https://github.com/ijl/orjson?tab=readme-ov-file#default) 2. [option](https://github.com/ijl/orjson?tab=readme-ov-file#option) 3. [Fragment](https://github.com/ijl/orjson?tab=readme-ov-file#fragment) 5. [Deserialize](https://github.com/ijl/orjson?tab=readme-ov-file#deserialize) 2. [Types](https://github.com/ijl/orjson?tab=readme-ov-file#types) 1. [dataclass](https://github.com/ijl/orjson?tab=readme-ov-file#dataclass) 2. [datetime](https://github.com/ijl/orjson?tab=readme-ov-file#datetime) 3. [enum](https://github.com/ijl/orjson?tab=readme-ov-file#enum) 4. [float](https://github.com/ijl/orjson?tab=readme-ov-file#float) 5. [int](https://github.com/ijl/orjson?tab=readme-ov-file#int) 6. [numpy](https://github.com/ijl/orjson?tab=readme-ov-file#numpy) 7. [str](https://github.com/ijl/orjson?tab=readme-ov-file#str) 8. [uuid](https://github.com/ijl/orjson?tab=readme-ov-file#uuid) 3. [Testing](https://github.com/ijl/orjson?tab=readme-ov-file#testing) 4. [Performance](https://github.com/ijl/orjson?tab=readme-ov-file#performance) 1. [Latency](https://github.com/ijl/orjson?tab=readme-ov-file#latency) 2. [Reproducing](https://github.com/ijl/orjson?tab=readme-ov-file#reproducing) 5. [Questions](https://github.com/ijl/orjson?tab=readme-ov-file#questions) 6. [Packaging](https://github.com/ijl/orjson?tab=readme-ov-file#packaging) 7. [License](https://github.com/ijl/orjson?tab=readme-ov-file#license) ## Usage ### Install To install a wheel from PyPI, install the `orjson` package. In `requirements.in` or `requirements.txt` format, specify: ```txt orjson >= 3.10,<4 ``` In `pyproject.toml` format, specify: ```toml orjson = "^3.10" ``` To build a wheel, see [packaging](https://github.com/ijl/orjson?tab=readme-ov-file#packaging). ### Quickstart This is an example of serializing, with options specified, and deserializing: ```python >>> import orjson, datetime, numpy >>> data = { "type": "job", "created_at": datetime.datetime(1970, 1, 1), "status": "🆗", "payload": numpy.array([[1, 2], [3, 4]]), } >>> orjson.dumps(data, option=orjson.OPT_NAIVE_UTC | orjson.OPT_SERIALIZE_NUMPY) b'{"type":"job","created_at":"1970-01-01T00:00:00+00:00","status":"\xf0\x9f\x86\x97","payload":[[1,2],[3,4]]}' >>> orjson.loads(_) {'type': 'job', 'created_at': '1970-01-01T00:00:00+00:00', 'status': '🆗', 'payload': [[1, 2], [3, 4]]} ``` ### Migrating orjson version 3 serializes more types than version 2. Subclasses of `str`, `int`, `dict`, and `list` are now serialized. This is faster and more similar to the standard library. It can be disabled with `orjson.OPT_PASSTHROUGH_SUBCLASS`.`dataclasses.dataclass` instances are now serialized by default and cannot be customized in a `default` function unless `option=orjson.OPT_PASSTHROUGH_DATACLASS` is specified. `uuid.UUID` instances are serialized by default. For any type that is now serialized, implementations in a `default` function and options enabling them can be removed but do not need to be. There was no change in deserialization. To migrate from the standard library, the largest difference is that `orjson.dumps` returns `bytes` and `json.dumps` returns a `str`. Users with `dict` objects using non-`str` keys should specify `option=orjson.OPT_NON_STR_KEYS`. `sort_keys` is replaced by `option=orjson.OPT_SORT_KEYS`. `indent` is replaced by `option=orjson.OPT_INDENT_2` and other levels of indentation are not supported. `ensure_ascii` is probably not relevant today and UTF-8 characters cannot be escaped to ASCII. ### Serialize ```python def dumps( __obj: Any, default: Optional[Callable[[Any], Any]] = ..., option: Optional[int] = ..., ) -> bytes: ... ``` `dumps()` serializes Python objects to JSON. It natively serializes `str`, `dict`, `list`, `tuple`, `int`, `float`, `bool`, `None`, `dataclasses.dataclass`, `typing.TypedDict`, `datetime.datetime`, `datetime.date`, `datetime.time`, `uuid.UUID`, `numpy.ndarray`, and `orjson.Fragment` instances. It supports arbitrary types through `default`. It serializes subclasses of `str`, `int`, `dict`, `list`, `dataclasses.dataclass`, and `enum.Enum`. It does not serialize subclasses of `tuple` to avoid serializing `namedtuple` objects as arrays. To avoid serializing subclasses, specify the option `orjson.OPT_PASSTHROUGH_SUBCLASS`. The output is a `bytes` object containing UTF-8. The global interpreter lock (GIL) is held for the duration of the call. It raises `JSONEncodeError` on an unsupported type. This exception message describes the invalid object with the error message `Type is not JSON serializable: ...`. To fix this, specify [default](https://github.com/ijl/orjson?tab=readme-ov-file#default). It raises `JSONEncodeError` on a `str` that contains invalid UTF-8. It raises `JSONEncodeError` on an integer that exceeds 64 bits by default or, with `OPT_STRICT_INTEGER`, 53 bits. It raises `JSONEncodeError` if a `dict` has a key of a type other than `str`, unless `OPT_NON_STR_KEYS` is specified. It raises `JSONEncodeError` if the output of `default` recurses to handling by `default` more than 254 levels deep. It raises `JSONEncodeError` on circular references. It raises `JSONEncodeError` if a `tzinfo` on a datetime object is unsupported. `JSONEncodeError` is a subclass of `TypeError`. This is for compatibility with the standard library. If the failure was caused by an exception in `default` then `JSONEncodeError` chains the original exception as `__cause__`. #### default To serialize a subclass or arbitrary types, specify `default` as a callable that returns a supported type. `default` may be a function, lambda, or callable class instance. To specify that a type was not handled by `default`, raise an exception such as `TypeError`. ```python >>> import orjson, decimal >>> def default(obj): if isinstance(obj, decimal.Decimal): return str(obj) raise TypeError >>> orjson.dumps(decimal.Decimal("0.0842389659712649442845")) JSONEncodeError: Type is not JSON serializable: decimal.Decimal >>> orjson.dumps(decimal.Decimal("0.0842389659712649442845"), default=default) b'"0.0842389659712649442845"' >>> orjson.dumps({1, 2}, default=default) orjson.JSONEncodeError: Type is not JSON serializable: set ``` The `default` callable may return an object that itself must be handled by `default` up to 254 times before an exception is raised. It is important that `default` raise an exception if a type cannot be handled. Python otherwise implicitly returns `None`, which appears to the caller like a legitimate value and is serialized: ```python >>> import orjson, json >>> def default(obj): if isinstance(obj, decimal.Decimal): return str(obj) >>> orjson.dumps({"set":{1, 2}}, default=default) b'{"set":null}' >>> json.dumps({"set":{1, 2}}, default=default) '{"set":null}' ``` #### option To modify how data is serialized, specify `option`. Each `option` is an integer constant in `orjson`. To specify multiple options, mask them together, e.g., `option=orjson.OPT_STRICT_INTEGER | orjson.OPT_NAIVE_UTC`. ##### OPT_APPEND_NEWLINE Append `\n` to the output. This is a convenience and optimization for the pattern of `dumps(...) + "\n"`. `bytes` objects are immutable and this pattern copies the original contents. ```python >>> import orjson >>> orjson.dumps([]) b"[]" >>> orjson.dumps([], option=orjson.OPT_APPEND_NEWLINE) b"[]\n" ``` ##### OPT_INDENT_2 Pretty-print output with an indent of two spaces. This is equivalent to `indent=2` in the standard library. Pretty printing is slower and the output larger. orjson is the fastest compared library at pretty printing and has much less of a slowdown to pretty print than the standard library does. This option is compatible with all other options. ```python >>> import orjson >>> orjson.dumps({"a": "b", "c": {"d": True}, "e": [1, 2]}) b'{"a":"b","c":{"d":true},"e":[1,2]}' >>> orjson.dumps( {"a": "b", "c": {"d": True}, "e": [1, 2]}, option=orjson.OPT_INDENT_2 ) b'{\n "a": "b",\n "c": {\n "d": true\n },\n "e": [\n 1,\n 2\n ]\n}' ``` If displayed, the indentation and linebreaks appear like this: ```json { "a": "b", "c": { "d": true }, "e": [ 1, 2 ] } ``` This measures serializing the github.json fixture as compact (52KiB) or pretty (64KiB): | Library | compact (ms) | pretty (ms) | vs. orjson | |-----------|----------------|---------------|--------------| | orjson | 0.01 | 0.02 | 1 | | json | 0.13 | 0.54 | 34 | This measures serializing the citm_catalog.json fixture, more of a worst case due to the amount of nesting and newlines, as compact (489KiB) or pretty (1.1MiB): | Library | compact (ms) | pretty (ms) | vs. orjson | |-----------|----------------|---------------|--------------| | orjson | 0.25 | 0.45 | 1 | | json | 3.01 | 24.42 | 54.4 | This can be reproduced using the `pyindent` script. ##### OPT_NAIVE_UTC Serialize `datetime.datetime` objects without a `tzinfo` as UTC. This has no effect on `datetime.datetime` objects that have `tzinfo` set. ```python >>> import orjson, datetime >>> orjson.dumps( datetime.datetime(1970, 1, 1, 0, 0, 0), ) b'"1970-01-01T00:00:00"' >>> orjson.dumps( datetime.datetime(1970, 1, 1, 0, 0, 0), option=orjson.OPT_NAIVE_UTC, ) b'"1970-01-01T00:00:00+00:00"' ``` ##### OPT_NON_STR_KEYS Serialize `dict` keys of type other than `str`. This allows `dict` keys to be one of `str`, `int`, `float`, `bool`, `None`, `datetime.datetime`, `datetime.date`, `datetime.time`, `enum.Enum`, and `uuid.UUID`. For comparison, the standard library serializes `str`, `int`, `float`, `bool` or `None` by default. orjson benchmarks as being faster at serializing non-`str` keys than other libraries. This option is slower for `str` keys than the default. ```python >>> import orjson, datetime, uuid >>> orjson.dumps( {uuid.UUID("7202d115-7ff3-4c81-a7c1-2a1f067b1ece"): [1, 2, 3]}, option=orjson.OPT_NON_STR_KEYS, ) b'{"7202d115-7ff3-4c81-a7c1-2a1f067b1ece":[1,2,3]}' >>> orjson.dumps( {datetime.datetime(1970, 1, 1, 0, 0, 0): [1, 2, 3]}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_NAIVE_UTC, ) b'{"1970-01-01T00:00:00+00:00":[1,2,3]}' ``` These types are generally serialized how they would be as values, e.g., `datetime.datetime` is still an RFC 3339 string and respects options affecting it. The exception is that `int` serialization does not respect `OPT_STRICT_INTEGER`. This option has the risk of creating duplicate keys. This is because non-`str` objects may serialize to the same `str` as an existing key, e.g., `{"1": true, 1: false}`. The last key to be inserted to the `dict` will be serialized last and a JSON deserializer will presumably take the last occurrence of a key (in the above, `false`). The first value will be lost. This option is compatible with `orjson.OPT_SORT_KEYS`. If sorting is used, note the sort is unstable and will be unpredictable for duplicate keys. ```python >>> import orjson, datetime >>> orjson.dumps( {"other": 1, datetime.date(1970, 1, 5): 2, datetime.date(1970, 1, 3): 3}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS ) b'{"1970-01-03":3,"1970-01-05":2,"other":1}' ``` This measures serializing 589KiB of JSON comprising a `list` of 100 `dict` in which each `dict` has both 365 randomly-sorted `int` keys representing epoch timestamps as well as one `str` key and the value for each key is a single integer. In "str keys", the keys were converted to `str` before serialization, and orjson still specifes `option=orjson.OPT_NON_STR_KEYS` (which is always somewhat slower). | Library | str keys (ms) | int keys (ms) | int keys sorted (ms) | |-----------|-----------------|-----------------|------------------------| | orjson | 0.5 | 0.93 | 2.08 | | json | 2.72 | 3.59 | | json is blank because it raises `TypeError` on attempting to sort before converting all keys to `str`. This can be reproduced using the `pynonstr` script. ##### OPT_OMIT_MICROSECONDS Do not serialize the `microsecond` field on `datetime.datetime` and `datetime.time` instances. ```python >>> import orjson, datetime >>> orjson.dumps( datetime.datetime(1970, 1, 1, 0, 0, 0, 1), ) b'"1970-01-01T00:00:00.000001"' >>> orjson.dumps( datetime.datetime(1970, 1, 1, 0, 0, 0, 1), option=orjson.OPT_OMIT_MICROSECONDS, ) b'"1970-01-01T00:00:00"' ``` ##### OPT_PASSTHROUGH_DATACLASS Passthrough `dataclasses.dataclass` instances to `default`. This allows customizing their output but is much slower. ```python >>> import orjson, dataclasses >>> @dataclasses.dataclass class User: id: str name: str password: str def default(obj): if isinstance(obj, User): return {"id": obj.id, "name": obj.name} raise TypeError >>> orjson.dumps(User("3b1", "asd", "zxc")) b'{"id":"3b1","name":"asd","password":"zxc"}' >>> orjson.dumps(User("3b1", "asd", "zxc"), option=orjson.OPT_PASSTHROUGH_DATACLASS) TypeError: Type is not JSON serializable: User >>> orjson.dumps( User("3b1", "asd", "zxc"), option=orjson.OPT_PASSTHROUGH_DATACLASS, default=default, ) b'{"id":"3b1","name":"asd"}' ``` ##### OPT_PASSTHROUGH_DATETIME Passthrough `datetime.datetime`, `datetime.date`, and `datetime.time` instances to `default`. This allows serializing datetimes to a custom format, e.g., HTTP dates: ```python >>> import orjson, datetime >>> def default(obj): if isinstance(obj, datetime.datetime): return obj.strftime("%a, %d %b %Y %H:%M:%S GMT") raise TypeError >>> orjson.dumps({"created_at": datetime.datetime(1970, 1, 1)}) b'{"created_at":"1970-01-01T00:00:00"}' >>> orjson.dumps({"created_at": datetime.datetime(1970, 1, 1)}, option=orjson.OPT_PASSTHROUGH_DATETIME) TypeError: Type is not JSON serializable: datetime.datetime >>> orjson.dumps( {"created_at": datetime.datetime(1970, 1, 1)}, option=orjson.OPT_PASSTHROUGH_DATETIME, default=default, ) b'{"created_at":"Thu, 01 Jan 1970 00:00:00 GMT"}' ``` This does not affect datetimes in `dict` keys if using OPT_NON_STR_KEYS. ##### OPT_PASSTHROUGH_SUBCLASS Passthrough subclasses of builtin types to `default`. ```python >>> import orjson >>> class Secret(str): pass def default(obj): if isinstance(obj, Secret): return "******" raise TypeError >>> orjson.dumps(Secret("zxc")) b'"zxc"' >>> orjson.dumps(Secret("zxc"), option=orjson.OPT_PASSTHROUGH_SUBCLASS) TypeError: Type is not JSON serializable: Secret >>> orjson.dumps(Secret("zxc"), option=orjson.OPT_PASSTHROUGH_SUBCLASS, default=default) b'"******"' ``` This does not affect serializing subclasses as `dict` keys if using OPT_NON_STR_KEYS. ##### OPT_SERIALIZE_DATACLASS This is deprecated and has no effect in version 3. In version 2 this was required to serialize `dataclasses.dataclass` instances. For more, see [dataclass](https://github.com/ijl/orjson?tab=readme-ov-file#dataclass). ##### OPT_SERIALIZE_NUMPY Serialize `numpy.ndarray` instances. For more, see [numpy](https://github.com/ijl/orjson?tab=readme-ov-file#numpy). ##### OPT_SERIALIZE_UUID This is deprecated and has no effect in version 3. In version 2 this was required to serialize `uuid.UUID` instances. For more, see [UUID](https://github.com/ijl/orjson?tab=readme-ov-file#UUID). ##### OPT_SORT_KEYS Serialize `dict` keys in sorted order. The default is to serialize in an unspecified order. This is equivalent to `sort_keys=True` in the standard library. This can be used to ensure the order is deterministic for hashing or tests. It has a substantial performance penalty and is not recommended in general. ```python >>> import orjson >>> orjson.dumps({"b": 1, "c": 2, "a": 3}) b'{"b":1,"c":2,"a":3}' >>> orjson.dumps({"b": 1, "c": 2, "a": 3}, option=orjson.OPT_SORT_KEYS) b'{"a":3,"b":1,"c":2}' ``` This measures serializing the twitter.json fixture unsorted and sorted: | Library | unsorted (ms) | sorted (ms) | vs. orjson | |-----------|-----------------|---------------|--------------| | orjson | 0.11 | 0.3 | 1 | | json | 1.36 | 1.93 | 6.4 | The benchmark can be reproduced using the `pysort` script. The sorting is not collation/locale-aware: ```python >>> import orjson >>> orjson.dumps({"a": 1, "ä": 2, "A": 3}, option=orjson.OPT_SORT_KEYS) b'{"A":3,"a":1,"\xc3\xa4":2}' ``` This is the same sorting behavior as the standard library. `dataclass` also serialize as maps but this has no effect on them. ##### OPT_STRICT_INTEGER Enforce 53-bit limit on integers. The limit is otherwise 64 bits, the same as the Python standard library. For more, see [int](https://github.com/ijl/orjson?tab=readme-ov-file#int). ##### OPT_UTC_Z Serialize a UTC timezone on `datetime.datetime` instances as `Z` instead of `+00:00`. ```python >>> import orjson, datetime, zoneinfo >>> orjson.dumps( datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=zoneinfo.ZoneInfo("UTC")), ) b'"1970-01-01T00:00:00+00:00"' >>> orjson.dumps( datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=zoneinfo.ZoneInfo("UTC")), option=orjson.OPT_UTC_Z ) b'"1970-01-01T00:00:00Z"' ``` #### Fragment `orjson.Fragment` includes already-serialized JSON in a document. This is an efficient way to include JSON blobs from a cache, JSONB field, or separately serialized object without first deserializing to Python objects via `loads()`. ```python >>> import orjson >>> orjson.dumps({"key": "zxc", "data": orjson.Fragment(b'{"a": "b", "c": 1}')}) b'{"key":"zxc","data":{"a": "b", "c": 1}}' ``` It does no reformatting: `orjson.OPT_INDENT_2` will not affect a compact blob nor will a pretty-printed JSON blob be rewritten as compact. The input must be `bytes` or `str` and given as a positional argument. This raises `orjson.JSONEncodeError` if a `str` is given and the input is not valid UTF-8. It otherwise does no validation and it is possible to write invalid JSON. This does not escape characters. The implementation is tested to not crash if given invalid strings or invalid JSON. ### Deserialize ```python def loads(__obj: Union[bytes, bytearray, memoryview, str]) -> Any: ... ``` `loads()` deserializes JSON to Python objects. It deserializes to `dict`, `list`, `int`, `float`, `str`, `bool`, and `None` objects. `bytes`, `bytearray`, `memoryview`, and `str` input are accepted. If the input exists as a `memoryview`, `bytearray`, or `bytes` object, it is recommended to pass these directly rather than creating an unnecessary `str` object. That is, `orjson.loads(b"{}")` instead of `orjson.loads(b"{}".decode("utf-8"))`. This has lower memory usage and lower latency. The input must be valid UTF-8. orjson maintains a cache of map keys for the duration of the process. This causes a net reduction in memory usage by avoiding duplicate strings. The keys must be at most 64 bytes to be cached and 2048 entries are stored. The global interpreter lock (GIL) is held for the duration of the call. It raises `JSONDecodeError` if given an invalid type or invalid JSON. This includes if the input contains `NaN`, `Infinity`, or `-Infinity`, which the standard library allows, but is not valid JSON. It raises `JSONDecodeError` if a combination of array or object recurses 1024 levels deep. It raises `JSONDecodeError` if unable to allocate a buffer large enough to parse the document. `JSONDecodeError` is a subclass of `json.JSONDecodeError` and `ValueError`. This is for compatibility with the standard library. ## Types ### dataclass orjson serializes instances of `dataclasses.dataclass` natively. It serializes instances 40-50x as fast as other libraries and avoids a severe slowdown seen in other libraries compared to serializing `dict`. It is supported to pass all variants of dataclasses, including dataclasses using `__slots__`, frozen dataclasses, those with optional or default attributes, and subclasses. There is a performance benefit to not using `__slots__`. | Library | dict (ms) | dataclass (ms) | vs. orjson | |-----------|-------------|------------------|--------------| | orjson | 0.43 | 0.95 | 1 | | json | 5.81 | 38.32 | 40 | This measures serializing 555KiB of JSON, orjson natively and other libraries using `default` to serialize the output of `dataclasses.asdict()`. This can be reproduced using the `pydataclass` script. Dataclasses are serialized as maps, with every attribute serialized and in the order given on class definition: ```python >>> import dataclasses, orjson, typing @dataclasses.dataclass class Member: id: int active: bool = dataclasses.field(default=False) @dataclasses.dataclass class Object: id: int name: str members: typing.List[Member] >>> orjson.dumps(Object(1, "a", [Member(1, True), Member(2)])) b'{"id":1,"name":"a","members":[{"id":1,"active":true},{"id":2,"active":false}]}' ``` ### datetime orjson serializes `datetime.datetime` objects to [RFC 3339](https://tools.ietf.org/html/rfc3339) format, e.g., "1970-01-01T00:00:00+00:00". This is a subset of ISO 8601 and is compatible with `isoformat()` in the standard library. ```python >>> import orjson, datetime, zoneinfo >>> orjson.dumps( datetime.datetime(2018, 12, 1, 2, 3, 4, 9, tzinfo=zoneinfo.ZoneInfo("Australia/Adelaide")) ) b'"2018-12-01T02:03:04.000009+10:30"' >>> orjson.dumps( datetime.datetime(2100, 9, 1, 21, 55, 2).replace(tzinfo=zoneinfo.ZoneInfo("UTC")) ) b'"2100-09-01T21:55:02+00:00"' >>> orjson.dumps( datetime.datetime(2100, 9, 1, 21, 55, 2) ) b'"2100-09-01T21:55:02"' ``` `datetime.datetime` supports instances with a `tzinfo` that is `None`, `datetime.timezone.utc`, a timezone instance from the python3.9+ `zoneinfo` module, or a timezone instance from the third-party `pendulum`, `pytz`, or `dateutil`/`arrow` libraries. It is fastest to use the standard library's `zoneinfo.ZoneInfo` for timezones. `datetime.time` objects must not have a `tzinfo`. ```python >>> import orjson, datetime >>> orjson.dumps(datetime.time(12, 0, 15, 290)) b'"12:00:15.000290"' ``` `datetime.date` objects will always serialize. ```python >>> import orjson, datetime >>> orjson.dumps(datetime.date(1900, 1, 2)) b'"1900-01-02"' ``` Errors with `tzinfo` result in `JSONEncodeError` being raised. To disable serialization of `datetime` objects specify the option `orjson.OPT_PASSTHROUGH_DATETIME`. To use "Z" suffix instead of "+00:00" to indicate UTC ("Zulu") time, use the option `orjson.OPT_UTC_Z`. To assume datetimes without timezone are UTC, use the option `orjson.OPT_NAIVE_UTC`. ### enum orjson serializes enums natively. Options apply to their values. ```python >>> import enum, datetime, orjson >>> class DatetimeEnum(enum.Enum): EPOCH = datetime.datetime(1970, 1, 1, 0, 0, 0) >>> orjson.dumps(DatetimeEnum.EPOCH) b'"1970-01-01T00:00:00"' >>> orjson.dumps(DatetimeEnum.EPOCH, option=orjson.OPT_NAIVE_UTC) b'"1970-01-01T00:00:00+00:00"' ``` Enums with members that are not supported types can be serialized using `default`: ```python >>> import enum, orjson >>> class Custom: def __init__(self, val): self.val = val def default(obj): if isinstance(obj, Custom): return obj.val raise TypeError class CustomEnum(enum.Enum): ONE = Custom(1) >>> orjson.dumps(CustomEnum.ONE, default=default) b'1' ``` ### float orjson serializes and deserializes double precision floats with no loss of precision and consistent rounding. `orjson.dumps()` serializes Nan, Infinity, and -Infinity, which are not compliant JSON, as `null`: ```python >>> import orjson, json >>> orjson.dumps([float("NaN"), float("Infinity"), float("-Infinity")]) b'[null,null,null]' >>> json.dumps([float("NaN"), float("Infinity"), float("-Infinity")]) '[NaN, Infinity, -Infinity]' ``` ### int orjson serializes and deserializes 64-bit integers by default. The range supported is a signed 64-bit integer's minimum (-9223372036854775807) to an unsigned 64-bit integer's maximum (18446744073709551615). This is widely compatible, but there are implementations that only support 53-bits for integers, e.g., web browsers. For those implementations, `dumps()` can be configured to raise a `JSONEncodeError` on values exceeding the 53-bit range. ```python >>> import orjson >>> orjson.dumps(9007199254740992) b'9007199254740992' >>> orjson.dumps(9007199254740992, option=orjson.OPT_STRICT_INTEGER) JSONEncodeError: Integer exceeds 53-bit range >>> orjson.dumps(-9007199254740992, option=orjson.OPT_STRICT_INTEGER) JSONEncodeError: Integer exceeds 53-bit range ``` ### numpy orjson natively serializes `numpy.ndarray` and individual `numpy.float64`, `numpy.float32`, `numpy.float16` (`numpy.half`), `numpy.int64`, `numpy.int32`, `numpy.int16`, `numpy.int8`, `numpy.uint64`, `numpy.uint32`, `numpy.uint16`, `numpy.uint8`, `numpy.uintp`, `numpy.intp`, `numpy.datetime64`, and `numpy.bool` instances. orjson is compatible with both numpy v1 and v2. orjson is faster than all compared libraries at serializing numpy instances. Serializing numpy data requires specifying `option=orjson.OPT_SERIALIZE_NUMPY`. ```python >>> import orjson, numpy >>> orjson.dumps( numpy.array([[1, 2, 3], [4, 5, 6]]), option=orjson.OPT_SERIALIZE_NUMPY, ) b'[[1,2,3],[4,5,6]]' ``` The array must be a contiguous C array (`C_CONTIGUOUS`) and one of the supported datatypes. Note a difference between serializing `numpy.float32` using `ndarray.tolist()` or `orjson.dumps(..., option=orjson.OPT_SERIALIZE_NUMPY)`: `tolist()` converts to a `double` before serializing and orjson's native path does not. This can result in different rounding. `numpy.datetime64` instances are serialized as RFC 3339 strings and datetime options affect them. ```python >>> import orjson, numpy >>> orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172"), option=orjson.OPT_SERIALIZE_NUMPY, ) b'"2021-01-01T00:00:00.172000"' >>> orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172"), option=( orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_OMIT_MICROSECONDS ), ) b'"2021-01-01T00:00:00+00:00"' ``` If an array is not a contiguous C array, contains an unsupported datatype, or contains a `numpy.datetime64` using an unsupported representation (e.g., picoseconds), orjson falls through to `default`. In `default`, `obj.tolist()` can be specified. If an array is not in the native endianness, e.g., an array of big-endian values on a little-endian system, `orjson.JSONEncodeError` is raised. If an array is malformed, `orjson.JSONEncodeError` is raised. This measures serializing 92MiB of JSON from an `numpy.ndarray` with dimensions of `(50000, 100)` and `numpy.float64` values: | Library | Latency (ms) | RSS diff (MiB) | vs. orjson | |-----------|----------------|------------------|--------------| | orjson | 105 | 105 | 1 | | json | 1,481 | 295 | 14.2 | This measures serializing 100MiB of JSON from an `numpy.ndarray` with dimensions of `(100000, 100)` and `numpy.int32` values: | Library | Latency (ms) | RSS diff (MiB) | vs. orjson | |-----------|----------------|------------------|--------------| | orjson | 68 | 119 | 1 | | json | 684 | 501 | 10.1 | This measures serializing 105MiB of JSON from an `numpy.ndarray` with dimensions of `(100000, 200)` and `numpy.bool` values: | Library | Latency (ms) | RSS diff (MiB) | vs. orjson | |-----------|----------------|------------------|--------------| | orjson | 50 | 125 | 1 | | json | 573 | 398 | 11.5 | In these benchmarks, orjson serializes natively and `json` serializes `ndarray.tolist()` via `default`. The RSS column measures peak memory usage during serialization. This can be reproduced using the `pynumpy` script. orjson does not have an installation or compilation dependency on numpy. The implementation is independent, reading `numpy.ndarray` using `PyArrayInterface`. ### str orjson is strict about UTF-8 conformance. This is stricter than the standard library's json module, which will serialize and deserialize UTF-16 surrogates, e.g., "\ud800", that are invalid UTF-8. If `orjson.dumps()` is given a `str` that does not contain valid UTF-8, `orjson.JSONEncodeError` is raised. If `loads()` receives invalid UTF-8, `orjson.JSONDecodeError` is raised. ```python >>> import orjson, json >>> orjson.dumps('\ud800') JSONEncodeError: str is not valid UTF-8: surrogates not allowed >>> json.dumps('\ud800') '"\\ud800"' >>> orjson.loads('"\\ud800"') JSONDecodeError: unexpected end of hex escape at line 1 column 8: line 1 column 1 (char 0) >>> json.loads('"\\ud800"') '\ud800' ``` To make a best effort at deserializing bad input, first decode `bytes` using the `replace` or `lossy` argument for `errors`: ```python >>> import orjson >>> orjson.loads(b'"\xed\xa0\x80"') JSONDecodeError: str is not valid UTF-8: surrogates not allowed >>> orjson.loads(b'"\xed\xa0\x80"'.decode("utf-8", "replace")) '���' ``` ### uuid orjson serializes `uuid.UUID` instances to [RFC 4122](https://tools.ietf.org/html/rfc4122) format, e.g., "f81d4fae-7dec-11d0-a765-00a0c91e6bf6". ``` python >>> import orjson, uuid >>> orjson.dumps(uuid.uuid5(uuid.NAMESPACE_DNS, "python.org")) b'"886313e1-3b8a-5372-9b90-0c9aee199e5d"' ``` ## Testing The library has comprehensive tests. There are tests against fixtures in the [JSONTestSuite](https://github.com/nst/JSONTestSuite) and [nativejson-benchmark](https://github.com/miloyip/nativejson-benchmark) repositories. It is tested to not crash against the [Big List of Naughty Strings](https://github.com/minimaxir/big-list-of-naughty-strings). It is tested to not leak memory. It is tested to not crash against and not accept invalid UTF-8. There are integration tests exercising the library's use in web servers (gunicorn using multiprocess/forked workers) and when multithreaded. It also uses some tests from the ultrajson library. orjson is the most correct of the compared libraries. This graph shows how each library handles a combined 342 JSON fixtures from the [JSONTestSuite](https://github.com/nst/JSONTestSuite) and [nativejson-benchmark](https://github.com/miloyip/nativejson-benchmark) tests: | Library | Invalid JSON documents not rejected | Valid JSON documents not deserialized | |------------|---------------------------------------|-----------------------------------------| | orjson | 0 | 0 | | json | 17 | 0 | This shows that all libraries deserialize valid JSON but only orjson correctly rejects the given invalid JSON fixtures. Errors are largely due to accepting invalid strings and numbers. The graph above can be reproduced using the `pycorrectness` script. ## Performance Serialization and deserialization performance of orjson is consistently better than the standard library's `json`. The graphs below illustrate a few commonly used documents. ### Latency ![Serialization](doc/serialization.png) ![Deserialization](doc/deserialization.png) #### twitter.json serialization | Library | Median latency (milliseconds) | Operations per second | Relative (latency) | |-----------|---------------------------------|-------------------------|----------------------| | orjson | 0.1 | 8453 | 1 | | json | 1.3 | 765 | 11.1 | #### twitter.json deserialization | Library | Median latency (milliseconds) | Operations per second | Relative (latency) | |-----------|---------------------------------|-------------------------|----------------------| | orjson | 0.5 | 1889 | 1 | | json | 2.2 | 453 | 4.2 | #### github.json serialization | Library | Median latency (milliseconds) | Operations per second | Relative (latency) | |-----------|---------------------------------|-------------------------|----------------------| | orjson | 0.01 | 103693 | 1 | | json | 0.13 | 7648 | 13.6 | #### github.json deserialization | Library | Median latency (milliseconds) | Operations per second | Relative (latency) | |-----------|---------------------------------|-------------------------|----------------------| | orjson | 0.04 | 23264 | 1 | | json | 0.1 | 10430 | 2.2 | #### citm_catalog.json serialization | Library | Median latency (milliseconds) | Operations per second | Relative (latency) | |-----------|---------------------------------|-------------------------|----------------------| | orjson | 0.3 | 3975 | 1 | | json | 3 | 338 | 11.8 | #### citm_catalog.json deserialization | Library | Median latency (milliseconds) | Operations per second | Relative (latency) | |-----------|---------------------------------|-------------------------|----------------------| | orjson | 1.3 | 781 | 1 | | json | 4 | 250 | 3.1 | #### canada.json serialization | Library | Median latency (milliseconds) | Operations per second | Relative (latency) | |-----------|---------------------------------|-------------------------|----------------------| | orjson | 2.5 | 399 | 1 | | json | 29.8 | 33 | 11.9 | #### canada.json deserialization | Library | Median latency (milliseconds) | Operations per second | Relative (latency) | |-----------|---------------------------------|-------------------------|----------------------| | orjson | 3 | 333 | 1 | | json | 18 | 55 | 6 | ### Reproducing The above was measured using Python 3.11.10 in a Fedora 42 container on an x86-64-v4 machine using the `orjson-3.10.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl` artifact on PyPI. The latency results can be reproduced using the `pybench` script. ## Questions ### Will it deserialize to dataclasses, UUIDs, decimals, etc or support object_hook? No. This requires a schema specifying what types are expected and how to handle errors etc. This is addressed by data validation libraries a level above this. ### Will it serialize to `str`? No. `bytes` is the correct type for a serialized blob. ### Will it support NDJSON or JSONL? No. [orjsonl](https://github.com/umarbutler/orjsonl) may be appropriate. ### Will it support JSON5 or RJSON? No, it supports RFC 8259. ### How do I depend on orjson in a Rust project? orjson is only shipped as a Python module. The project should depend on `orjson` in its own Python requirements and should obtain pointers to functions and objects using the normal `PyImport_*` APIs. ## Packaging To package orjson requires at least [Rust](https://www.rust-lang.org/) 1.85 and the [maturin](https://github.com/PyO3/maturin) build tool. The recommended build command is: ```sh maturin build --release --strip ``` It benefits from also having a C build environment to compile a faster deserialization backend. See this project's `manylinux_2_28` builds for an example using clang and LTO. The project's own CI tests against `nightly-2025-08-10` and stable 1.82. It is prudent to pin the nightly version because that channel can introduce breaking changes. There is a significant performance benefit to using nightly. orjson is tested on native hardware for amd64, aarch64, and i686 on Linux and for arm7, ppc64le, and s390x is cross-compiled and may be tested via emulation. It is tested for aarch64 on macOS and cross-compiles for amd64. For Windows it is tested on amd64, i686, and aarch64. There are no runtime dependencies other than libc. The source distribution on PyPI contains all dependencies' source and can be built without network access. The file can be downloaded from `https://files.pythonhosted.org/packages/source/o/orjson/orjson-${version}.tar.gz`. orjson's tests are included in the source distribution on PyPI. The tests require only `pytest`. There are optional packages such as `pytz` and `numpy` listed in `test/requirements.txt` and used in ~10% of tests. Not having these dependencies causes the tests needing them to skip. Tests can be run with `pytest -q test`. ## License orjson was written by ijl <>, copyright 2018 - 2025, available to you under either the Apache 2 license or MIT license at your choice. ijl-orjson-aa8c946/bench/000077500000000000000000000000001505336676500153205ustar00rootroot00000000000000ijl-orjson-aa8c946/bench/__init__.py000066400000000000000000000000001505336676500174170ustar00rootroot00000000000000ijl-orjson-aa8c946/bench/benchmark_dumps.py000066400000000000000000000011351505336676500210340ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) from json import loads as json_loads import pytest from .data import fixtures, libraries from .util import read_fixture_obj @pytest.mark.parametrize("library", libraries) @pytest.mark.parametrize("fixture", fixtures) def test_dumps(benchmark, fixture, library): dumper, loader = libraries[library] benchmark.group = f"{fixture} serialization" benchmark.extra_info["lib"] = library data = read_fixture_obj(f"{fixture}.xz") benchmark.extra_info["correct"] = json_loads(dumper(data)) == data # type: ignore benchmark(dumper, data) ijl-orjson-aa8c946/bench/benchmark_empty.py000066400000000000000000000007261505336676500210470ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) from json import loads as json_loads import pytest from .data import libraries @pytest.mark.parametrize("data", ["[]", "{}", '""']) @pytest.mark.parametrize("library", libraries) def test_empty(benchmark, data, library): dumper, loader = libraries[library] correct = json_loads(dumper(loader(data))) == json_loads(data) # type: ignore benchmark.extra_info["correct"] = correct benchmark(loader, data) ijl-orjson-aa8c946/bench/benchmark_loads.py000066400000000000000000000012011505336676500210000ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) from json import loads as json_loads import pytest from .data import fixtures, libraries from .util import read_fixture @pytest.mark.parametrize("fixture", fixtures) @pytest.mark.parametrize("library", libraries) def test_loads(benchmark, fixture, library): dumper, loader = libraries[library] benchmark.group = f"{fixture} deserialization" benchmark.extra_info["lib"] = library data = read_fixture(f"{fixture}.xz") correct = json_loads(dumper(loader(data))) == json_loads(data) # type: ignore benchmark.extra_info["correct"] = correct benchmark(loader, data) ijl-orjson-aa8c946/bench/data.py000066400000000000000000000007311505336676500166040ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) from json import dumps as _json_dumps from json import loads as json_loads from orjson import dumps as orjson_dumps from orjson import loads as orjson_loads def json_dumps(obj): return _json_dumps(obj).encode("utf-8") libraries = { "orjson": (orjson_dumps, orjson_loads), "json": (json_dumps, json_loads), } fixtures = [ "canada.json", "citm_catalog.json", "github.json", "twitter.json", ] ijl-orjson-aa8c946/bench/requirements.txt000066400000000000000000000002221505336676500206000ustar00rootroot00000000000000memory-profiler; python_version<"3.14" pandas; python_version<"3.14" pytest-benchmark pytest-random-order seaborn; python_version<"3.14" tabulate ijl-orjson-aa8c946/bench/run_default000077500000000000000000000006071505336676500175610ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import sys import os os.sched_setaffinity(os.getpid(), {0, 1}) from orjson import dumps, OPT_SERIALIZE_NUMPY class Custom: pass def default(_): return None n = int(sys.argv[1]) if len(sys.argv) >= 2 else 10000 obj = [[Custom()] * 1000] * 10 for _ in range(n): dumps(obj, default, OPT_SERIALIZE_NUMPY) ijl-orjson-aa8c946/bench/run_func000077500000000000000000000010321505336676500170610ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import sys import lzma import os import gc gc.disable() os.sched_setaffinity(os.getpid(), {0, 1}) from orjson import dumps, loads filename = sys.argv[1] n = int(sys.argv[3]) if len(sys.argv) >= 4 else 1000 with lzma.open(filename, "r") as fileh: file_bytes = fileh.read() if sys.argv[2] == "dumps": file_obj = loads(file_bytes) for _ in range(n): dumps(file_obj) elif sys.argv[2] == "loads": for _ in range(n): loads(file_bytes) ijl-orjson-aa8c946/bench/run_mem000077500000000000000000000013561505336676500167150ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import sys import lzma import gc import psutil filename = sys.argv[1] with lzma.open(filename, "r") as fileh: fixture = fileh.read() proc = psutil.Process() lib_name = sys.argv[2] if lib_name == "json": from json import dumps, loads elif lib_name == "orjson": from orjson import dumps, loads else: raise NotImplementedError gc.collect() mem_before = proc.memory_info().rss for _ in range(100): val = loads(fixture) mem_after = proc.memory_info().rss mem_diff = mem_after - mem_before from json import loads as json_loads correct = 1 if (json_loads(fixture) == json_loads(dumps(loads(fixture)))) else 0 print(f"{mem_before},{mem_diff},{correct}") ijl-orjson-aa8c946/bench/util.py000066400000000000000000000012041505336676500166440ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import lzma import os from functools import cache from pathlib import Path from typing import Any import orjson dirname = os.path.join(os.path.dirname(__file__), "../data") if hasattr(os, "sched_setaffinity"): os.sched_setaffinity(os.getpid(), {0, 1}) @cache def read_fixture(filename: str) -> bytes: path = Path(dirname, filename) if path.suffix == ".xz": contents = lzma.decompress(path.read_bytes()) else: contents = path.read_bytes() return contents @cache def read_fixture_obj(filename: str) -> Any: return orjson.loads(read_fixture(filename)) ijl-orjson-aa8c946/build.rs000066400000000000000000000062551505336676500157160ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use std::env; fn main() { println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=include/yyjson/*"); println!("cargo:rerun-if-env-changed=CC"); println!("cargo:rerun-if-env-changed=CFLAGS"); println!("cargo:rerun-if-env-changed=LDFLAGS"); println!("cargo:rerun-if-env-changed=ORJSON_DISABLE_YYJSON"); println!("cargo:rerun-if-env-changed=RUSTFLAGS"); println!("cargo:rustc-check-cfg=cfg(CPython)"); println!("cargo:rustc-check-cfg=cfg(GraalPy)"); println!("cargo:rustc-check-cfg=cfg(intrinsics)"); println!("cargo:rustc-check-cfg=cfg(optimize)"); println!("cargo:rustc-check-cfg=cfg(Py_3_10)"); println!("cargo:rustc-check-cfg=cfg(Py_3_11)"); println!("cargo:rustc-check-cfg=cfg(Py_3_12)"); println!("cargo:rustc-check-cfg=cfg(Py_3_13)"); println!("cargo:rustc-check-cfg=cfg(Py_3_14)"); println!("cargo:rustc-check-cfg=cfg(Py_3_15)"); println!("cargo:rustc-check-cfg=cfg(Py_3_9)"); println!("cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)"); println!("cargo:rustc-check-cfg=cfg(PyPy)"); let python_config = pyo3_build_config::get(); for cfg in python_config.build_script_outputs() { println!("{cfg}"); } if python_config.implementation == pyo3_build_config::PythonImplementation::CPython { println!("cargo:rustc-cfg=CPython"); } else { panic!("orjson only supports CPython") } #[allow(unused_variables)] let is_64_bit_python = matches!(python_config.pointer_width, Some(64)); #[cfg(all(target_arch = "x86_64", not(target_os = "macos")))] if version_check::is_min_version("1.89.0").unwrap_or(false) && is_64_bit_python { println!("cargo:rustc-cfg=feature=\"avx512\""); } if version_check::supports_feature("core_intrinsics").unwrap_or(false) { println!("cargo:rustc-cfg=feature=\"intrinsics\""); } if version_check::supports_feature("optimize_attribute").unwrap_or(false) { println!("cargo:rustc-cfg=feature=\"optimize\""); } #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] if is_64_bit_python { println!("cargo:rustc-cfg=feature=\"inline_int\""); } if env::var("ORJSON_DISABLE_YYJSON").is_ok() { if env::var("CARGO_FEATURE_YYJSON").is_ok() { panic!("ORJSON_DISABLE_YYJSON and --features=yyjson both enabled.") } } else { match cc::Build::new() .file("include/yyjson/yyjson.c") .include("include/yyjson") .define("YYJSON_DISABLE_NON_STANDARD", "1") .define("YYJSON_DISABLE_UTF8_VALIDATION", "1") .define("YYJSON_DISABLE_UTILS", "1") .define("YYJSON_DISABLE_WRITER", "1") .try_compile("yyjson") { Ok(_) => { println!("cargo:rustc-cfg=feature=\"yyjson\""); } Err(_) => { if env::var("CARGO_FEATURE_YYJSON").is_ok() { panic!( "yyjson was enabled but the build failed. To build with a different backend do not specify the feature." ) } } } } } ijl-orjson-aa8c946/ci/000077500000000000000000000000001505336676500146345ustar00rootroot00000000000000ijl-orjson-aa8c946/ci/config.toml000066400000000000000000000005661505336676500170050ustar00rootroot00000000000000[unstable] build-std = ["core", "std", "alloc", "proc_macro", "panic_abort"] build-std-features = ["panic_immediate_abort"] trim-paths = true [target.x86_64-apple-darwin] linker = "clang" rustflags = ["-C", "target-cpu=x86-64-v2", "-Z", "tune-cpu=generic"] [target.aarch64-apple-darwin] linker = "clang" rustflags = ["-C", "target-cpu=apple-m1", "-Z", "tune-cpu=generic"] ijl-orjson-aa8c946/ci/sdist.toml000066400000000000000000000001541505336676500166570ustar00rootroot00000000000000[source.crates-io] replace-with = "vendored-sources" [source.vendored-sources] directory = "include/cargo" ijl-orjson-aa8c946/data/000077500000000000000000000000001505336676500151525ustar00rootroot00000000000000ijl-orjson-aa8c946/data/blns.txt.xz000066400000000000000000000211141505336676500173100ustar00rootroot000000000000007zXZִF!Xo" ]F!}ZL_)&oxZAeӰ79G;i~B}ѭl=15ۣ@we4Sc[M ]VSnjf06Wx[x`L\3Xes96C]*FGwl4#oHjOW$ڌ̳ȐxR>R nq%̕B~g=XTxF|]'D]UJ@ۨ3h; ݛ@D{lVIv.+Hn`nxk^ve 5L~tZD%zE| >;ہ"' m _fz_ya*ҡ4LyɠA967x$ZRrz_RODI+Jrw=lW%e#Hr:N]iE|H%&UWV10G\whϭ>koO4 WkscRȷXCve <)6w;K?髐Y6V{wGkJ~oZRT9cBČJb"T$UlMup X6*lL΅Xgv1[$$*5{s3Am$^ }ElZ.i=2-i0b.-lwjf!e1_cԃgb,!v)ܒ痞qs!̓eA}uN?Q"NrlTbEj!ESLjٝy(ٍ]XrjVҵpϖc_Y|ʨ9FDeĺaY ̕Alpq>41sІ3/ɱ̵ŧBJNGl1 P16ǑзvpEt{3h v׃6VN΢p:Ud/i:g6-截K^ nt\9\0A<w$,zC#i KCKF::  ;A͡/~f|7-.兮5$rG-Ve$2Ur!tO4KUJC[&jp6;/ @QnP|Ԣ CӶ^sZbqzpwf)gYGZ H@!7Kָ3j j٠3Y= /|l gB~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Hu7.rwk 8 P|fIrG^zymI7doA  2Zϛk ЃJɩBٗktuVy;P+Z[*Dv liBzZbw p w|g S4_vwԭ^nÕ- D~Le"҄\d4Q[&v}}í\/Oy/.Vo Ҩz{"\v<3^;t)h2:qʼ]Ҁ^(VE3Ĥe&RsT5O_{ 7Yu5T|#h/\|Ξy(r ?,fg'~7 4r[kg]Kg=:X[U|>@J5I!$ dwx;YL!^"vAs!n/GgĤf!(|x-&ڬB4 j< Ffs\ }j8rX[:690PMs )89 BO0lmOēkvۂ!+nE/sBYoEnDogXRzǵx8O\66n!ҥ$qeC2ӄK@GWk%kϔ7Ug3qr~iT?*F!k6$y ؠm3xsGL{m Xd`Js1NEWD?[/fLMeB4$;iO Η'6B >7~`ۇ71ZrrA@.ȿ9?E K 93-)US=0>R#!laB躔rc^T!o>Ğ4x%0[^^ DI ڳ_`I]<;]yrB4p1=EvwhB֧\FI=qcjVlRޥpl^##-|>ळGALN3@ހ-GZct}ڜ{9?wNXO?Azэ=?N$Hb5EL ЙU[8>-laadLMF?}{$w^Mog7['jՋpe4 kp6 oaZ g@4wgYZijl-orjson-aa8c946/data/issue331_1.json.xz000066400000000000000000000011201505336676500202760ustar00rootroot000000000000007zXZִF!XK]=擮d d?@ 2%2hg1bb#*έKC?)m29O sqZ=l<0 aຉ`ѨOg/-Dx,颯.+O.fM*-U# _kWͧ;^<%M$wWl6?eWCJUD;pAJ|S6P iF/9_UEw\p6W6n/8čc&:?qn2t4!Vr|p=/t.R$@SW#z`! U3͝!骛S{5o7#| hx( |ӣU_;1ըCU'(^XMp*&HQN-Q<=k±[%u\mӔ`sSF YiCG"ypݓӱD^`"-bzX/<ڪn͹R,{hWk"HM:v5 +31+쯓?d3P XGtgYZijl-orjson-aa8c946/data/issue331_2.json.xz000066400000000000000000000011201505336676500202770ustar00rootroot000000000000007zXZִF!XL]=擮d d?@ 2%2hg1bb#*έKC?)m29O sqZ=l<0 aຉ`ѨOg/-Dx,颯.+O.fM*-U# _kWͧ;^<%M$wWl6?eWCJUD;pAJ|S6P iF/9_UEw\p6W6n/8čc&:?qn2t4!Vr|p=/t.R$@SW#z`! U3͝!骛S{5o7#| hx( |ӣU_;1ըCU'(^XMp*&HQN-Q<=k±[%u\mӔ`sSF YiCG"ypݓӱD^`"-bzX/<ڪn͹R,{hWk"HM:v5 +31+쯓K4!g| ѱgYZijl-orjson-aa8c946/data/jsonchecker/000077500000000000000000000000001505336676500174505ustar00rootroot00000000000000ijl-orjson-aa8c946/data/jsonchecker/fail01.json000066400000000000000000000000741505336676500214200ustar00rootroot00000000000000"A JSON payload should be an object or array, not a string."ijl-orjson-aa8c946/data/jsonchecker/fail02.json000066400000000000000000000000211505336676500214110ustar00rootroot00000000000000["Unclosed array"ijl-orjson-aa8c946/data/jsonchecker/fail03.json000066400000000000000000000000451505336676500214200ustar00rootroot00000000000000{unquoted_key: "keys must be quoted"}ijl-orjson-aa8c946/data/jsonchecker/fail04.json000066400000000000000000000000201505336676500214120ustar00rootroot00000000000000["extra comma",]ijl-orjson-aa8c946/data/jsonchecker/fail05.json000066400000000000000000000000301505336676500214140ustar00rootroot00000000000000["double extra comma",,]ijl-orjson-aa8c946/data/jsonchecker/fail06.json000066400000000000000000000000321505336676500214170ustar00rootroot00000000000000[ , "<-- missing value"]ijl-orjson-aa8c946/data/jsonchecker/fail07.json000066400000000000000000000000321505336676500214200ustar00rootroot00000000000000["Comma after the close"],ijl-orjson-aa8c946/data/jsonchecker/fail08.json000066400000000000000000000000201505336676500214160ustar00rootroot00000000000000["Extra close"]]ijl-orjson-aa8c946/data/jsonchecker/fail09.json000066400000000000000000000000261505336676500214250ustar00rootroot00000000000000{"Extra comma": true,}ijl-orjson-aa8c946/data/jsonchecker/fail10.json000066400000000000000000000000721505336676500214160ustar00rootroot00000000000000{"Extra value after close": true} "misplaced quoted value"ijl-orjson-aa8c946/data/jsonchecker/fail11.json000066400000000000000000000000351505336676500214160ustar00rootroot00000000000000{"Illegal expression": 1 + 2}ijl-orjson-aa8c946/data/jsonchecker/fail12.json000066400000000000000000000000371505336676500214210ustar00rootroot00000000000000{"Illegal invocation": alert()}ijl-orjson-aa8c946/data/jsonchecker/fail13.json000066400000000000000000000000531505336676500214200ustar00rootroot00000000000000{"Numbers cannot have leading zeroes": 013}ijl-orjson-aa8c946/data/jsonchecker/fail14.json000066400000000000000000000000371505336676500214230ustar00rootroot00000000000000{"Numbers cannot be hex": 0x14}ijl-orjson-aa8c946/data/jsonchecker/fail15.json000066400000000000000000000000421505336676500214200ustar00rootroot00000000000000["Illegal backslash escape: \x15"]ijl-orjson-aa8c946/data/jsonchecker/fail16.json000066400000000000000000000000101505336676500214140ustar00rootroot00000000000000[\naked]ijl-orjson-aa8c946/data/jsonchecker/fail17.json000066400000000000000000000000421505336676500214220ustar00rootroot00000000000000["Illegal backslash escape: \017"]ijl-orjson-aa8c946/data/jsonchecker/fail18.json000066400000000000000000000000621505336676500214250ustar00rootroot00000000000000[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]ijl-orjson-aa8c946/data/jsonchecker/fail19.json000066400000000000000000000000261505336676500214260ustar00rootroot00000000000000{"Missing colon" null}ijl-orjson-aa8c946/data/jsonchecker/fail20.json000066400000000000000000000000271505336676500214170ustar00rootroot00000000000000{"Double colon":: null}ijl-orjson-aa8c946/data/jsonchecker/fail21.json000066400000000000000000000000401505336676500214130ustar00rootroot00000000000000{"Comma instead of colon", null}ijl-orjson-aa8c946/data/jsonchecker/fail22.json000066400000000000000000000000411505336676500214150ustar00rootroot00000000000000["Colon instead of comma": false]ijl-orjson-aa8c946/data/jsonchecker/fail23.json000066400000000000000000000000241505336676500214170ustar00rootroot00000000000000["Bad value", truth]ijl-orjson-aa8c946/data/jsonchecker/fail24.json000066400000000000000000000000201505336676500214140ustar00rootroot00000000000000['single quote']ijl-orjson-aa8c946/data/jsonchecker/fail25.json000066400000000000000000000000351505336676500214230ustar00rootroot00000000000000[" tab character in string "]ijl-orjson-aa8c946/data/jsonchecker/fail26.json000066400000000000000000000000461505336676500214260ustar00rootroot00000000000000["tab\ character\ in\ string\ "]ijl-orjson-aa8c946/data/jsonchecker/fail27.json000066400000000000000000000000161505336676500214240ustar00rootroot00000000000000["line break"]ijl-orjson-aa8c946/data/jsonchecker/fail28.json000066400000000000000000000000171505336676500214260ustar00rootroot00000000000000["line\ break"]ijl-orjson-aa8c946/data/jsonchecker/fail29.json000066400000000000000000000000041505336676500214230ustar00rootroot00000000000000[0e]ijl-orjson-aa8c946/data/jsonchecker/fail30.json000066400000000000000000000000051505336676500214140ustar00rootroot00000000000000[0e+]ijl-orjson-aa8c946/data/jsonchecker/fail31.json000066400000000000000000000000071505336676500214170ustar00rootroot00000000000000[0e+-1]ijl-orjson-aa8c946/data/jsonchecker/fail32.json000066400000000000000000000000501505336676500214160ustar00rootroot00000000000000{"Comma instead if closing brace": true,ijl-orjson-aa8c946/data/jsonchecker/fail33.json000066400000000000000000000000141505336676500214170ustar00rootroot00000000000000["mismatch"}ijl-orjson-aa8c946/data/jsonchecker/pass01.json000066400000000000000000000026411505336676500214550ustar00rootroot00000000000000[ "JSON Test Pattern pass1", {"object with 1 member":["array with 1 element"]}, {}, [], -42, true, false, null, { "integer": 1234567890, "real": -9876.543210, "e": 0.123456789e-12, "E": 1.234567890E+34, "": 23456789012E66, "zero": 0, "one": 1, "space": " ", "quote": "\"", "backslash": "\\", "controls": "\b\f\n\r\t", "slash": "/ & \/", "alpha": "abcdefghijklmnopqrstuvwyz", "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", "digit": "0123456789", "0123456789": "digit", "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", "true": true, "false": false, "null": null, "array":[ ], "object":{ }, "address": "50 St. James Street", "url": "http://www.JSON.org/", "comment": "// /* */": " ", " s p a c e d " :[1,2 , 3 , 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", "quotes": "" \u0022 %22 0x22 034 "", "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" : "A key can be any string" }, 0.5 ,98.6 , 99.44 , 1066, 1e1, 0.1e1, 1e-1, 1e00,2e+00,2e-00 ,"rosebud"]ijl-orjson-aa8c946/data/jsonchecker/pass02.json000066400000000000000000000000641505336676500214530ustar00rootroot00000000000000[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]ijl-orjson-aa8c946/data/jsonchecker/pass03.json000066400000000000000000000002241505336676500214520ustar00rootroot00000000000000{ "JSON Test Pattern pass3": { "The outermost value": "must be an object or array.", "In this test": "It is an object." } } ijl-orjson-aa8c946/data/parsing/000077500000000000000000000000001505336676500166155ustar00rootroot00000000000000ijl-orjson-aa8c946/data/parsing/i_number_double_huge_neg_exp.json000066400000000000000000000000161505336676500253540ustar00rootroot00000000000000[123.456e-789]ijl-orjson-aa8c946/data/parsing/i_number_huge_exp.json000066400000000000000000000002111505336676500231660ustar00rootroot00000000000000[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]ijl-orjson-aa8c946/data/parsing/i_number_neg_int_huge_exp.json000066400000000000000000000000121505336676500246700ustar00rootroot00000000000000[-1e+9999]ijl-orjson-aa8c946/data/parsing/i_number_pos_double_huge_exp.json000066400000000000000000000000131505336676500254010ustar00rootroot00000000000000[1.5e+9999]ijl-orjson-aa8c946/data/parsing/i_number_real_neg_overflow.json000066400000000000000000000000201505336676500250570ustar00rootroot00000000000000[-123123e100000]ijl-orjson-aa8c946/data/parsing/i_number_real_pos_overflow.json000066400000000000000000000000171505336676500251150ustar00rootroot00000000000000[123123e100000]ijl-orjson-aa8c946/data/parsing/i_number_real_underflow.json000066400000000000000000000000171505336676500243760ustar00rootroot00000000000000[123e-10000000]ijl-orjson-aa8c946/data/parsing/i_number_too_big_neg_int.json000066400000000000000000000000411505336676500245100ustar00rootroot00000000000000[-123123123123123123123123123123]ijl-orjson-aa8c946/data/parsing/i_number_too_big_pos_int.json000066400000000000000000000000271505336676500245440ustar00rootroot00000000000000[100000000000000000000]ijl-orjson-aa8c946/data/parsing/i_number_very_big_negative_int.json000066400000000000000000000000631505336676500257310ustar00rootroot00000000000000[-237462374673276894279832749832423479823246327846]ijl-orjson-aa8c946/data/parsing/i_object_key_lone_2nd_surrogate.json000066400000000000000000000000141505336676500260040ustar00rootroot00000000000000{"\uDFAA":0}ijl-orjson-aa8c946/data/parsing/i_string_1st_surrogate_but_2nd_missing.json000066400000000000000000000000121505336676500273470ustar00rootroot00000000000000["\uDADA"]ijl-orjson-aa8c946/data/parsing/i_string_1st_valid_surrogate_2nd_invalid.json000066400000000000000000000000201505336676500276300ustar00rootroot00000000000000["\uD888\u1234"]ijl-orjson-aa8c946/data/parsing/i_string_UTF-16LE_with_BOM.json000066400000000000000000000000141505336676500242340ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_UTF-8_invalid_sequence.json000066400000000000000000000000121505336676500256000ustar00rootroot00000000000000["日ш"]ijl-orjson-aa8c946/data/parsing/i_string_UTF8_surrogate_U+D800.json000066400000000000000000000000071505336676500251170ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_incomplete_surrogate_and_escape_valid.json000066400000000000000000000000141505336676500311540ustar00rootroot00000000000000["\uD800\n"]ijl-orjson-aa8c946/data/parsing/i_string_incomplete_surrogate_pair.json000066400000000000000000000000131505336676500266450ustar00rootroot00000000000000["\uDd1ea"]ijl-orjson-aa8c946/data/parsing/i_string_incomplete_surrogates_escape_valid.json000066400000000000000000000000221505336676500305140ustar00rootroot00000000000000["\uD800\uD800\n"]ijl-orjson-aa8c946/data/parsing/i_string_invalid_lonely_surrogate.json000066400000000000000000000000121505336676500265020ustar00rootroot00000000000000["\ud800"]ijl-orjson-aa8c946/data/parsing/i_string_invalid_surrogate.json000066400000000000000000000000151505336676500251230ustar00rootroot00000000000000["\ud800abc"]ijl-orjson-aa8c946/data/parsing/i_string_invalid_utf-8.json000066400000000000000000000000051505336676500240520ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_inverted_surrogates_U+1D11E.json000066400000000000000000000000201505336676500264670ustar00rootroot00000000000000["\uDd1e\uD834"]ijl-orjson-aa8c946/data/parsing/i_string_iso_latin_1.json000066400000000000000000000000051505336676500236020ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_lone_second_surrogate.json000066400000000000000000000000121505336676500257620ustar00rootroot00000000000000["\uDFAA"]ijl-orjson-aa8c946/data/parsing/i_string_lone_utf8_continuation_byte.json000066400000000000000000000000051505336676500271210ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_not_in_unicode_range.json000066400000000000000000000000101505336676500255450ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_overlong_sequence_2_bytes.json000066400000000000000000000000061505336676500265540ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_overlong_sequence_6_bytes.json000066400000000000000000000000121505336676500265550ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_overlong_sequence_6_bytes_null.json000066400000000000000000000000121505336676500276070ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_truncated-utf-8.json000066400000000000000000000000061505336676500243340ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_utf16BE_no_BOM.json000066400000000000000000000000121505336676500237440ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_string_utf16LE_no_BOM.json000066400000000000000000000000121505336676500237560ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/i_structure_500_nested_arrays.json.xz000066400000000000000000000001201505336676500260200ustar00rootroot000000000000007zXZִF!X ]-JK ܢ/mOQޖ)4fgYZijl-orjson-aa8c946/data/parsing/i_structure_UTF-8_BOM_empty_object.json000066400000000000000000000000051505336676500261770ustar00rootroot00000000000000{}ijl-orjson-aa8c946/data/parsing/n_array_1_true_without_comma.json000066400000000000000000000000101505336676500253500ustar00rootroot00000000000000[1 true]ijl-orjson-aa8c946/data/parsing/n_array_a_invalid_utf8.json000066400000000000000000000000041505336676500241110ustar00rootroot00000000000000[a]ijl-orjson-aa8c946/data/parsing/n_array_colon_instead_of_comma.json000066400000000000000000000000071505336676500257010ustar00rootroot00000000000000["": 1]ijl-orjson-aa8c946/data/parsing/n_array_comma_after_close.json000066400000000000000000000000051505336676500246600ustar00rootroot00000000000000[""],ijl-orjson-aa8c946/data/parsing/n_array_comma_and_number.json000066400000000000000000000000041505336676500245030ustar00rootroot00000000000000[,1]ijl-orjson-aa8c946/data/parsing/n_array_double_comma.json000066400000000000000000000000061505336676500236450ustar00rootroot00000000000000[1,,2]ijl-orjson-aa8c946/data/parsing/n_array_double_extra_comma.json000066400000000000000000000000071505336676500250510ustar00rootroot00000000000000["x",,]ijl-orjson-aa8c946/data/parsing/n_array_extra_close.json000066400000000000000000000000061505336676500235270ustar00rootroot00000000000000["x"]]ijl-orjson-aa8c946/data/parsing/n_array_extra_comma.json000066400000000000000000000000051505336676500235150ustar00rootroot00000000000000["",]ijl-orjson-aa8c946/data/parsing/n_array_incomplete.json000066400000000000000000000000041505336676500233540ustar00rootroot00000000000000["x"ijl-orjson-aa8c946/data/parsing/n_array_incomplete_invalid_value.json000066400000000000000000000000021505336676500262540ustar00rootroot00000000000000[xijl-orjson-aa8c946/data/parsing/n_array_inner_array_no_comma.json000066400000000000000000000000061505336676500254000ustar00rootroot00000000000000[3[4]]ijl-orjson-aa8c946/data/parsing/n_array_invalid_utf8.json000066400000000000000000000000031505336676500236100ustar00rootroot00000000000000[]ijl-orjson-aa8c946/data/parsing/n_array_items_separated_by_semicolon.json000066400000000000000000000000051505336676500271310ustar00rootroot00000000000000[1:2]ijl-orjson-aa8c946/data/parsing/n_array_just_comma.json000066400000000000000000000000031505336676500233550ustar00rootroot00000000000000[,]ijl-orjson-aa8c946/data/parsing/n_array_just_minus.json000066400000000000000000000000031505336676500234140ustar00rootroot00000000000000[-]ijl-orjson-aa8c946/data/parsing/n_array_missing_value.json000066400000000000000000000000111505336676500240600ustar00rootroot00000000000000[ , ""]ijl-orjson-aa8c946/data/parsing/n_array_newlines_unclosed.json000066400000000000000000000000131505336676500247350ustar00rootroot00000000000000["a", 4 ,1,ijl-orjson-aa8c946/data/parsing/n_array_number_and_comma.json000066400000000000000000000000041505336676500245030ustar00rootroot00000000000000[1,]ijl-orjson-aa8c946/data/parsing/n_array_number_and_several_commas.json000066400000000000000000000000051505336676500264100ustar00rootroot00000000000000[1,,]ijl-orjson-aa8c946/data/parsing/n_array_spaces_vertical_tab_formfeed.json000066400000000000000000000000101505336676500270560ustar00rootroot00000000000000[" a"\f]ijl-orjson-aa8c946/data/parsing/n_array_star_inside.json000066400000000000000000000000031505336676500235200ustar00rootroot00000000000000[*]ijl-orjson-aa8c946/data/parsing/n_array_unclosed.json000066400000000000000000000000031505336676500230300ustar00rootroot00000000000000[""ijl-orjson-aa8c946/data/parsing/n_array_unclosed_trailing_comma.json000066400000000000000000000000031505336676500260750ustar00rootroot00000000000000[1,ijl-orjson-aa8c946/data/parsing/n_array_unclosed_with_new_lines.json000066400000000000000000000000101505336676500261240ustar00rootroot00000000000000[1, 1 ,1ijl-orjson-aa8c946/data/parsing/n_array_unclosed_with_object_inside.json000066400000000000000000000000031505336676500267440ustar00rootroot00000000000000[{}ijl-orjson-aa8c946/data/parsing/n_incomplete_false.json000066400000000000000000000000061505336676500233320ustar00rootroot00000000000000[fals]ijl-orjson-aa8c946/data/parsing/n_incomplete_null.json000066400000000000000000000000051505336676500232110ustar00rootroot00000000000000[nul]ijl-orjson-aa8c946/data/parsing/n_incomplete_true.json000066400000000000000000000000051505336676500232160ustar00rootroot00000000000000[tru]ijl-orjson-aa8c946/data/parsing/n_multidigit_number_then_00.json000066400000000000000000000000041505336676500250570ustar00rootroot00000000000000123ijl-orjson-aa8c946/data/parsing/n_number_++.json000066400000000000000000000000101505336676500215710ustar00rootroot00000000000000[++1234]ijl-orjson-aa8c946/data/parsing/n_number_+1.json000066400000000000000000000000041505336676500216020ustar00rootroot00000000000000[+1]ijl-orjson-aa8c946/data/parsing/n_number_+Inf.json000066400000000000000000000000061505336676500221600ustar00rootroot00000000000000[+Inf]ijl-orjson-aa8c946/data/parsing/n_number_-01.json000066400000000000000000000000051505336676500216650ustar00rootroot00000000000000[-01]ijl-orjson-aa8c946/data/parsing/n_number_-1.0..json000066400000000000000000000000071505336676500220230ustar00rootroot00000000000000[-1.0.]ijl-orjson-aa8c946/data/parsing/n_number_-2..json000066400000000000000000000000051505336676500216640ustar00rootroot00000000000000[-2.]ijl-orjson-aa8c946/data/parsing/n_number_-NaN.json000066400000000000000000000000061505336676500221220ustar00rootroot00000000000000[-NaN]ijl-orjson-aa8c946/data/parsing/n_number_.-1.json000066400000000000000000000000051505336676500216630ustar00rootroot00000000000000[.-1]ijl-orjson-aa8c946/data/parsing/n_number_.2e-3.json000066400000000000000000000000071505336676500221160ustar00rootroot00000000000000[.2e-3]ijl-orjson-aa8c946/data/parsing/n_number_0.1.2.json000066400000000000000000000000071505336676500220300ustar00rootroot00000000000000[0.1.2]ijl-orjson-aa8c946/data/parsing/n_number_0.3e+.json000066400000000000000000000000071505336676500221120ustar00rootroot00000000000000[0.3e+]ijl-orjson-aa8c946/data/parsing/n_number_0.3e.json000066400000000000000000000000061505336676500220360ustar00rootroot00000000000000[0.3e]ijl-orjson-aa8c946/data/parsing/n_number_0.e1.json000066400000000000000000000000061505336676500220340ustar00rootroot00000000000000[0.e1]ijl-orjson-aa8c946/data/parsing/n_number_0_capital_E+.json000066400000000000000000000000051505336676500235430ustar00rootroot00000000000000[0E+]ijl-orjson-aa8c946/data/parsing/n_number_0_capital_E.json000066400000000000000000000000041505336676500234670ustar00rootroot00000000000000[0E]ijl-orjson-aa8c946/data/parsing/n_number_0e+.json000066400000000000000000000000051505336676500217470ustar00rootroot00000000000000[0e+]ijl-orjson-aa8c946/data/parsing/n_number_0e.json000066400000000000000000000000041505336676500216730ustar00rootroot00000000000000[0e]ijl-orjson-aa8c946/data/parsing/n_number_1.0e+.json000066400000000000000000000000071505336676500221100ustar00rootroot00000000000000[1.0e+]ijl-orjson-aa8c946/data/parsing/n_number_1.0e-.json000066400000000000000000000000071505336676500221120ustar00rootroot00000000000000[1.0e-]ijl-orjson-aa8c946/data/parsing/n_number_1.0e.json000066400000000000000000000000061505336676500220340ustar00rootroot00000000000000[1.0e]ijl-orjson-aa8c946/data/parsing/n_number_1_000.json000066400000000000000000000000111505336676500221040ustar00rootroot00000000000000[1 000.0]ijl-orjson-aa8c946/data/parsing/n_number_1eE2.json000066400000000000000000000000061505336676500220650ustar00rootroot00000000000000[1eE2]ijl-orjson-aa8c946/data/parsing/n_number_2.e+3.json000066400000000000000000000000071505336676500221140ustar00rootroot00000000000000[2.e+3]ijl-orjson-aa8c946/data/parsing/n_number_2.e-3.json000066400000000000000000000000071505336676500221160ustar00rootroot00000000000000[2.e-3]ijl-orjson-aa8c946/data/parsing/n_number_2.e3.json000066400000000000000000000000061505336676500220400ustar00rootroot00000000000000[2.e3]ijl-orjson-aa8c946/data/parsing/n_number_9.e+.json000066400000000000000000000000061505336676500220370ustar00rootroot00000000000000[9.e+]ijl-orjson-aa8c946/data/parsing/n_number_Inf.json000066400000000000000000000000051505336676500221040ustar00rootroot00000000000000[Inf]ijl-orjson-aa8c946/data/parsing/n_number_NaN.json000066400000000000000000000000051505336676500220440ustar00rootroot00000000000000[NaN]ijl-orjson-aa8c946/data/parsing/n_number_U+FF11_fullwidth_digit_one.json000066400000000000000000000000051505336676500263300ustar00rootroot00000000000000[1]ijl-orjson-aa8c946/data/parsing/n_number_expression.json000066400000000000000000000000051505336676500235670ustar00rootroot00000000000000[1+2]ijl-orjson-aa8c946/data/parsing/n_number_hex_1_digit.json000066400000000000000000000000051505336676500235540ustar00rootroot00000000000000[0x1]ijl-orjson-aa8c946/data/parsing/n_number_hex_2_digits.json000066400000000000000000000000061505336676500237410ustar00rootroot00000000000000[0x42]ijl-orjson-aa8c946/data/parsing/n_number_infinity.json000066400000000000000000000000121505336676500232170ustar00rootroot00000000000000[Infinity]ijl-orjson-aa8c946/data/parsing/n_number_invalid+-.json000066400000000000000000000000071505336676500231500ustar00rootroot00000000000000[0e+-1]ijl-orjson-aa8c946/data/parsing/n_number_invalid-negative-real.json000066400000000000000000000000151505336676500255400ustar00rootroot00000000000000[-123.123foo]ijl-orjson-aa8c946/data/parsing/n_number_invalid-utf-8-in-bigger-int.json000066400000000000000000000000061505336676500264110ustar00rootroot00000000000000[123]ijl-orjson-aa8c946/data/parsing/n_number_invalid-utf-8-in-exponent.json000066400000000000000000000000061505336676500262220ustar00rootroot00000000000000[1e1]ijl-orjson-aa8c946/data/parsing/n_number_invalid-utf-8-in-int.json000066400000000000000000000000051505336676500251530ustar00rootroot00000000000000[0] ijl-orjson-aa8c946/data/parsing/n_number_minus_infinity.json000066400000000000000000000000131505336676500244330ustar00rootroot00000000000000[-Infinity]ijl-orjson-aa8c946/data/parsing/n_number_minus_sign_with_trailing_garbage.json000066400000000000000000000000061505336676500301400ustar00rootroot00000000000000[-foo]ijl-orjson-aa8c946/data/parsing/n_number_minus_space_1.json000066400000000000000000000000051505336676500241160ustar00rootroot00000000000000[- 1]ijl-orjson-aa8c946/data/parsing/n_number_neg_int_starting_with_zero.json000066400000000000000000000000061505336676500270210ustar00rootroot00000000000000[-012]ijl-orjson-aa8c946/data/parsing/n_number_neg_real_without_int_part.json000066400000000000000000000000071505336676500266310ustar00rootroot00000000000000[-.123]ijl-orjson-aa8c946/data/parsing/n_number_neg_with_garbage_at_end.json000066400000000000000000000000051505336676500261560ustar00rootroot00000000000000[-1x]ijl-orjson-aa8c946/data/parsing/n_number_real_garbage_after_e.json000066400000000000000000000000051505336676500254500ustar00rootroot00000000000000[1ea]ijl-orjson-aa8c946/data/parsing/n_number_real_with_invalid_utf8_after_e.json000066400000000000000000000000051505336676500275070ustar00rootroot00000000000000[1e]ijl-orjson-aa8c946/data/parsing/n_number_real_without_fractional_part.json000066400000000000000000000000041505336676500273250ustar00rootroot00000000000000[1.]ijl-orjson-aa8c946/data/parsing/n_number_starting_with_dot.json000066400000000000000000000000061505336676500251250ustar00rootroot00000000000000[.123]ijl-orjson-aa8c946/data/parsing/n_number_with_alpha.json000066400000000000000000000000101505336676500235040ustar00rootroot00000000000000[1.2a-3]ijl-orjson-aa8c946/data/parsing/n_number_with_alpha_char.json000066400000000000000000000000311505336676500245040ustar00rootroot00000000000000[1.8011670033376514H-308]ijl-orjson-aa8c946/data/parsing/n_number_with_leading_zero.json000066400000000000000000000000051505336676500250650ustar00rootroot00000000000000[012]ijl-orjson-aa8c946/data/parsing/n_object_bad_value.json000066400000000000000000000000141505336676500232700ustar00rootroot00000000000000["x", truth]ijl-orjson-aa8c946/data/parsing/n_object_bracket_key.json000066400000000000000000000000111505336676500236260ustar00rootroot00000000000000{[: "x"} ijl-orjson-aa8c946/data/parsing/n_object_comma_instead_of_colon.json000066400000000000000000000000131505336676500260260ustar00rootroot00000000000000{"x", null}ijl-orjson-aa8c946/data/parsing/n_object_double_colon.json000066400000000000000000000000121505336676500240100ustar00rootroot00000000000000{"x"::"b"}ijl-orjson-aa8c946/data/parsing/n_object_emoji.json000066400000000000000000000000121505336676500224470ustar00rootroot00000000000000{🇨🇭}ijl-orjson-aa8c946/data/parsing/n_object_garbage_at_end.json000066400000000000000000000000151505336676500242510ustar00rootroot00000000000000{"a":"a" 123}ijl-orjson-aa8c946/data/parsing/n_object_key_with_single_quotes.json000066400000000000000000000000161505336676500261340ustar00rootroot00000000000000{key: 'value'}ijl-orjson-aa8c946/data/parsing/n_object_lone_continuation_byte_in_key_and_trailing_comma.json000066400000000000000000000000121505336676500333430ustar00rootroot00000000000000{"":"0",}ijl-orjson-aa8c946/data/parsing/n_object_missing_colon.json000066400000000000000000000000071505336676500242130ustar00rootroot00000000000000{"a" b}ijl-orjson-aa8c946/data/parsing/n_object_missing_key.json000066400000000000000000000000061505336676500236700ustar00rootroot00000000000000{:"b"}ijl-orjson-aa8c946/data/parsing/n_object_missing_semicolon.json000066400000000000000000000000111505336676500250640ustar00rootroot00000000000000{"a" "b"}ijl-orjson-aa8c946/data/parsing/n_object_missing_value.json000066400000000000000000000000051505336676500242130ustar00rootroot00000000000000{"a":ijl-orjson-aa8c946/data/parsing/n_object_no-colon.json000066400000000000000000000000041505336676500230710ustar00rootroot00000000000000{"a"ijl-orjson-aa8c946/data/parsing/n_object_non_string_key.json000066400000000000000000000000051505336676500243760ustar00rootroot00000000000000{1:1}ijl-orjson-aa8c946/data/parsing/n_object_non_string_key_but_huge_number_instead.json000066400000000000000000000000151505336676500313400ustar00rootroot00000000000000{9999E9999:1}ijl-orjson-aa8c946/data/parsing/n_object_repeated_null_null.json000066400000000000000000000000251505336676500252250ustar00rootroot00000000000000{null:null,null:null}ijl-orjson-aa8c946/data/parsing/n_object_several_trailing_commas.json000066400000000000000000000000151505336676500262400ustar00rootroot00000000000000{"id":0,,,,,}ijl-orjson-aa8c946/data/parsing/n_object_single_quote.json000066400000000000000000000000071505336676500240460ustar00rootroot00000000000000{'a':0}ijl-orjson-aa8c946/data/parsing/n_object_trailing_comma.json000066400000000000000000000000111505336676500243300ustar00rootroot00000000000000{"id":0,}ijl-orjson-aa8c946/data/parsing/n_object_trailing_comment.json000066400000000000000000000000151505336676500247020ustar00rootroot00000000000000{"a":"b"}/**/ijl-orjson-aa8c946/data/parsing/n_object_trailing_comment_open.json000066400000000000000000000000161505336676500257240ustar00rootroot00000000000000{"a":"b"}/**//ijl-orjson-aa8c946/data/parsing/n_object_trailing_comment_slash_open.json000066400000000000000000000000131505336676500271130ustar00rootroot00000000000000{"a":"b"}//ijl-orjson-aa8c946/data/parsing/n_object_trailing_comment_slash_open_incomplete.json000066400000000000000000000000121505336676500313310ustar00rootroot00000000000000{"a":"b"}/ijl-orjson-aa8c946/data/parsing/n_object_two_commas_in_a_row.json000066400000000000000000000000221505336676500253720ustar00rootroot00000000000000{"a":"b",,"c":"d"}ijl-orjson-aa8c946/data/parsing/n_object_unquoted_key.json000066400000000000000000000000101505336676500240560ustar00rootroot00000000000000{a: "b"}ijl-orjson-aa8c946/data/parsing/n_object_unterminated-value.json000066400000000000000000000000071505336676500251610ustar00rootroot00000000000000{"a":"aijl-orjson-aa8c946/data/parsing/n_object_with_single_string.json000066400000000000000000000000261505336676500252530ustar00rootroot00000000000000{ "foo" : "bar", "a" }ijl-orjson-aa8c946/data/parsing/n_object_with_trailing_garbage.json000066400000000000000000000000121505336676500256600ustar00rootroot00000000000000{"a":"b"}#ijl-orjson-aa8c946/data/parsing/n_single_space.json000066400000000000000000000000011505336676500224500ustar00rootroot00000000000000 ijl-orjson-aa8c946/data/parsing/n_string_1_surrogate_then_escape.json000066400000000000000000000000131505336676500261760ustar00rootroot00000000000000["\uD800\"]ijl-orjson-aa8c946/data/parsing/n_string_1_surrogate_then_escape_u.json000066400000000000000000000000141505336676500265230ustar00rootroot00000000000000["\uD800\u"]ijl-orjson-aa8c946/data/parsing/n_string_1_surrogate_then_escape_u1.json000066400000000000000000000000151505336676500266050ustar00rootroot00000000000000["\uD800\u1"]ijl-orjson-aa8c946/data/parsing/n_string_1_surrogate_then_escape_u1x.json000066400000000000000000000000161505336676500267760ustar00rootroot00000000000000["\uD800\u1x"]ijl-orjson-aa8c946/data/parsing/n_string_accentuated_char_no_quotes.json000066400000000000000000000000041505336676500267560ustar00rootroot00000000000000[é]ijl-orjson-aa8c946/data/parsing/n_string_backslash_00.json000066400000000000000000000000061505336676500236410ustar00rootroot00000000000000["\"]ijl-orjson-aa8c946/data/parsing/n_string_escape_x.json000066400000000000000000000000101505336676500231710ustar00rootroot00000000000000["\x00"]ijl-orjson-aa8c946/data/parsing/n_string_escaped_backslash_bad.json000066400000000000000000000000071505336676500256350ustar00rootroot00000000000000["\\\"]ijl-orjson-aa8c946/data/parsing/n_string_escaped_ctrl_char_tab.json000066400000000000000000000000061505336676500256620ustar00rootroot00000000000000["\ "]ijl-orjson-aa8c946/data/parsing/n_string_escaped_emoji.json000066400000000000000000000000111505336676500241720ustar00rootroot00000000000000["\🌀"]ijl-orjson-aa8c946/data/parsing/n_string_incomplete_escape.json000066400000000000000000000000051505336676500250650ustar00rootroot00000000000000["\"]ijl-orjson-aa8c946/data/parsing/n_string_incomplete_escaped_character.json000066400000000000000000000000111505336676500272420ustar00rootroot00000000000000["\u00A"]ijl-orjson-aa8c946/data/parsing/n_string_incomplete_surrogate.json000066400000000000000000000000161505336676500256420ustar00rootroot00000000000000["\uD834\uDd"]ijl-orjson-aa8c946/data/parsing/n_string_incomplete_surrogate_escape_invalid.json000066400000000000000000000000221505336676500306650ustar00rootroot00000000000000["\uD800\uD800\x"]ijl-orjson-aa8c946/data/parsing/n_string_invalid-utf-8-in-escape.json000066400000000000000000000000071505336676500256410ustar00rootroot00000000000000["\u"]ijl-orjson-aa8c946/data/parsing/n_string_invalid_backslash_esc.json000066400000000000000000000000061505336676500257020ustar00rootroot00000000000000["\a"]ijl-orjson-aa8c946/data/parsing/n_string_invalid_unicode_escape.json000066400000000000000000000000121505336676500260600ustar00rootroot00000000000000["\uqqqq"]ijl-orjson-aa8c946/data/parsing/n_string_invalid_utf8_after_escape.json000066400000000000000000000000061505336676500265040ustar00rootroot00000000000000["\"]ijl-orjson-aa8c946/data/parsing/n_string_leading_uescaped_thinspace.json000066400000000000000000000000151505336676500267210ustar00rootroot00000000000000[\u0020"asd"]ijl-orjson-aa8c946/data/parsing/n_string_no_quotes_with_bad_escape.json000066400000000000000000000000041505336676500266020ustar00rootroot00000000000000[\n]ijl-orjson-aa8c946/data/parsing/n_string_single_doublequote.json000066400000000000000000000000011505336676500252730ustar00rootroot00000000000000"ijl-orjson-aa8c946/data/parsing/n_string_single_quote.json000066400000000000000000000000201505336676500241010ustar00rootroot00000000000000['single quote']ijl-orjson-aa8c946/data/parsing/n_string_single_string_no_double_quotes.json000066400000000000000000000000031505336676500277010ustar00rootroot00000000000000abcijl-orjson-aa8c946/data/parsing/n_string_start_escape_unclosed.json000066400000000000000000000000031505336676500257550ustar00rootroot00000000000000["\ijl-orjson-aa8c946/data/parsing/n_string_unescaped_crtl_char.json000066400000000000000000000000071505336676500254000ustar00rootroot00000000000000["aa"]ijl-orjson-aa8c946/data/parsing/n_string_unescaped_newline.json000066400000000000000000000000141505336676500250760ustar00rootroot00000000000000["new line"]ijl-orjson-aa8c946/data/parsing/n_string_unescaped_tab.json000066400000000000000000000000051505336676500242030ustar00rootroot00000000000000[" "]ijl-orjson-aa8c946/data/parsing/n_string_unicode_CapitalU.json000066400000000000000000000000101505336676500246120ustar00rootroot00000000000000"\UA66D"ijl-orjson-aa8c946/data/parsing/n_string_with_trailing_garbage.json000066400000000000000000000000031505336676500257200ustar00rootroot00000000000000""xijl-orjson-aa8c946/data/parsing/n_structure_100000_opening_arrays.json.xz000066400000000000000000000002241505336676500264230ustar00rootroot000000000000007zXZִF!XᆟS]-^?&UhpApLBiqf#M/ #SYuw jtId\Sֱl[CLonQgYZijl-orjson-aa8c946/data/parsing/n_structure_U+2060_word_joined.json000066400000000000000000000000051505336676500253120ustar00rootroot00000000000000[⁠]ijl-orjson-aa8c946/data/parsing/n_structure_UTF8_BOM_no_data.json000066400000000000000000000000031505336676500250460ustar00rootroot00000000000000ijl-orjson-aa8c946/data/parsing/n_structure_angle_bracket_..json000066400000000000000000000000031505336676500251340ustar00rootroot00000000000000<.>ijl-orjson-aa8c946/data/parsing/n_structure_angle_bracket_null.json000066400000000000000000000000101505336676500257470ustar00rootroot00000000000000[]ijl-orjson-aa8c946/data/parsing/n_structure_array_trailing_garbage.json000066400000000000000000000000041505336676500266160ustar00rootroot00000000000000[1]xijl-orjson-aa8c946/data/parsing/n_structure_array_with_extra_array_close.json000066400000000000000000000000041505336676500300760ustar00rootroot00000000000000[1]]ijl-orjson-aa8c946/data/parsing/n_structure_array_with_unclosed_string.json000066400000000000000000000000061505336676500275740ustar00rootroot00000000000000["asd]ijl-orjson-aa8c946/data/parsing/n_structure_ascii-unicode-identifier.json000066400000000000000000000000031505336676500267720ustar00rootroot00000000000000aåijl-orjson-aa8c946/data/parsing/n_structure_capitalized_True.json000066400000000000000000000000061505336676500254310ustar00rootroot00000000000000[True]ijl-orjson-aa8c946/data/parsing/n_structure_close_unopened_array.json000066400000000000000000000000021505336676500263350ustar00rootroot000000000000001]ijl-orjson-aa8c946/data/parsing/n_structure_comma_instead_of_closing_brace.json000066400000000000000000000000131505336676500303000ustar00rootroot00000000000000{"x": true,ijl-orjson-aa8c946/data/parsing/n_structure_double_array.json000066400000000000000000000000041505336676500246070ustar00rootroot00000000000000[][]ijl-orjson-aa8c946/data/parsing/n_structure_end_array.json000066400000000000000000000000011505336676500241000ustar00rootroot00000000000000]ijl-orjson-aa8c946/data/parsing/n_structure_incomplete_UTF8_BOM.json000066400000000000000000000000041505336676500256010ustar00rootroot00000000000000{}ijl-orjson-aa8c946/data/parsing/n_structure_lone-invalid-utf-8.json000066400000000000000000000000011505336676500254560ustar00rootroot00000000000000ijl-orjson-aa8c946/data/parsing/n_structure_lone-open-bracket.json000066400000000000000000000000011505336676500254410ustar00rootroot00000000000000[ijl-orjson-aa8c946/data/parsing/n_structure_no_data.json000066400000000000000000000000001505336676500235400ustar00rootroot00000000000000ijl-orjson-aa8c946/data/parsing/n_structure_null-byte-outside-string.json000066400000000000000000000000031505336676500270270ustar00rootroot00000000000000[]ijl-orjson-aa8c946/data/parsing/n_structure_number_with_trailing_garbage.json000066400000000000000000000000021505336676500300210ustar00rootroot000000000000002@ijl-orjson-aa8c946/data/parsing/n_structure_object_followed_by_closing_object.json000066400000000000000000000000031505336676500310350ustar00rootroot00000000000000{}}ijl-orjson-aa8c946/data/parsing/n_structure_object_unclosed_no_value.json000066400000000000000000000000041505336676500271710ustar00rootroot00000000000000{"":ijl-orjson-aa8c946/data/parsing/n_structure_object_with_comment.json000066400000000000000000000000241505336676500261640ustar00rootroot00000000000000{"a":/*comment*/"b"}ijl-orjson-aa8c946/data/parsing/n_structure_object_with_trailing_garbage.json000066400000000000000000000000171505336676500300050ustar00rootroot00000000000000{"a": true} "x"ijl-orjson-aa8c946/data/parsing/n_structure_open_array_apostrophe.json000066400000000000000000000000021505336676500265400ustar00rootroot00000000000000['ijl-orjson-aa8c946/data/parsing/n_structure_open_array_comma.json000066400000000000000000000000021505336676500254500ustar00rootroot00000000000000[,ijl-orjson-aa8c946/data/parsing/n_structure_open_array_object.json.xz000066400000000000000000000002601505336676500262700ustar00rootroot000000000000007zXZִF!XАp]-X:t{(5 DG 1CoF͑G〝Z9jlָ'uFʟ*]śWFf=O@O0t>ׇv}n=4%"qz_=WͱgYZijl-orjson-aa8c946/data/parsing/n_structure_open_array_open_object.json000066400000000000000000000000021505336676500266430ustar00rootroot00000000000000[{ijl-orjson-aa8c946/data/parsing/n_structure_open_array_open_string.json000066400000000000000000000000031505336676500267040ustar00rootroot00000000000000["aijl-orjson-aa8c946/data/parsing/n_structure_open_array_string.json000066400000000000000000000000041505336676500256640ustar00rootroot00000000000000["a"ijl-orjson-aa8c946/data/parsing/n_structure_open_object.json000066400000000000000000000000011505336676500244230ustar00rootroot00000000000000{ijl-orjson-aa8c946/data/parsing/n_structure_open_object_close_array.json000066400000000000000000000000021505336676500270070ustar00rootroot00000000000000{]ijl-orjson-aa8c946/data/parsing/n_structure_open_object_comma.json000066400000000000000000000000021505336676500256000ustar00rootroot00000000000000{,ijl-orjson-aa8c946/data/parsing/n_structure_open_object_open_array.json000066400000000000000000000000021505336676500266430ustar00rootroot00000000000000{[ijl-orjson-aa8c946/data/parsing/n_structure_open_object_open_string.json000066400000000000000000000000031505336676500270340ustar00rootroot00000000000000{"aijl-orjson-aa8c946/data/parsing/n_structure_open_object_string_with_apostrophes.json000066400000000000000000000000041505336676500314760ustar00rootroot00000000000000{'a'ijl-orjson-aa8c946/data/parsing/n_structure_open_open.json000066400000000000000000000000201505336676500241170ustar00rootroot00000000000000["\{["\{["\{["\{ijl-orjson-aa8c946/data/parsing/n_structure_single_eacute.json000066400000000000000000000000011505336676500247430ustar00rootroot00000000000000ijl-orjson-aa8c946/data/parsing/n_structure_single_star.json000066400000000000000000000000011505336676500244460ustar00rootroot00000000000000*ijl-orjson-aa8c946/data/parsing/n_structure_trailing_#.json000066400000000000000000000000141505336676500241530ustar00rootroot00000000000000{"a":"b"}#{}ijl-orjson-aa8c946/data/parsing/n_structure_uescaped_LF_before_string.json000066400000000000000000000000121505336676500272200ustar00rootroot00000000000000[\u000A""]ijl-orjson-aa8c946/data/parsing/n_structure_unclosed_array.json000066400000000000000000000000021505336676500251470ustar00rootroot00000000000000[1ijl-orjson-aa8c946/data/parsing/n_structure_unclosed_array_partial_null.json000066400000000000000000000000141505336676500277200ustar00rootroot00000000000000[ false, nulijl-orjson-aa8c946/data/parsing/n_structure_unclosed_array_unfinished_false.json000066400000000000000000000000141505336676500305400ustar00rootroot00000000000000[ true, falsijl-orjson-aa8c946/data/parsing/n_structure_unclosed_array_unfinished_true.json000066400000000000000000000000141505336676500304250ustar00rootroot00000000000000[ false, truijl-orjson-aa8c946/data/parsing/n_structure_unclosed_object.json000066400000000000000000000000141505336676500253020ustar00rootroot00000000000000{"asd":"asd"ijl-orjson-aa8c946/data/parsing/n_structure_unicode-identifier.json000066400000000000000000000000021505336676500257030ustar00rootroot00000000000000åijl-orjson-aa8c946/data/parsing/n_structure_whitespace_U+2060_word_joiner.json000066400000000000000000000000051505336676500275440ustar00rootroot00000000000000[⁠]ijl-orjson-aa8c946/data/parsing/n_structure_whitespace_formfeed.json000066400000000000000000000000031505336676500261410ustar00rootroot00000000000000[ ]ijl-orjson-aa8c946/data/parsing/y_array_arraysWithSpaces.json000066400000000000000000000000071505336676500245270ustar00rootroot00000000000000[[] ]ijl-orjson-aa8c946/data/parsing/y_array_empty-string.json000066400000000000000000000000041505336676500236720ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/y_array_empty.json000066400000000000000000000000021505336676500223640ustar00rootroot00000000000000[]ijl-orjson-aa8c946/data/parsing/y_array_ending_with_newline.json000066400000000000000000000000051505336676500252510ustar00rootroot00000000000000["a"]ijl-orjson-aa8c946/data/parsing/y_array_false.json000066400000000000000000000000071505336676500223250ustar00rootroot00000000000000[false]ijl-orjson-aa8c946/data/parsing/y_array_heterogeneous.json000066400000000000000000000000221505336676500241040ustar00rootroot00000000000000[null, 1, "1", {}]ijl-orjson-aa8c946/data/parsing/y_array_null.json000066400000000000000000000000061505336676500222040ustar00rootroot00000000000000[null]ijl-orjson-aa8c946/data/parsing/y_array_with_1_and_newline.json000066400000000000000000000000041505336676500247660ustar00rootroot00000000000000[1 ]ijl-orjson-aa8c946/data/parsing/y_array_with_leading_space.json000066400000000000000000000000041505336676500250410ustar00rootroot00000000000000 [1]ijl-orjson-aa8c946/data/parsing/y_array_with_several_null.json000066400000000000000000000000241505336676500247600ustar00rootroot00000000000000[1,null,null,null,2]ijl-orjson-aa8c946/data/parsing/y_array_with_trailing_space.json000066400000000000000000000000041505336676500252470ustar00rootroot00000000000000[2] ijl-orjson-aa8c946/data/parsing/y_number.json000066400000000000000000000000101505336676500213170ustar00rootroot00000000000000[123e65]ijl-orjson-aa8c946/data/parsing/y_number_0e+1.json000066400000000000000000000000061505336676500220440ustar00rootroot00000000000000[0e+1]ijl-orjson-aa8c946/data/parsing/y_number_0e1.json000066400000000000000000000000051505336676500217700ustar00rootroot00000000000000[0e1]ijl-orjson-aa8c946/data/parsing/y_number_after_space.json000066400000000000000000000000041505336676500236560ustar00rootroot00000000000000[ 4]ijl-orjson-aa8c946/data/parsing/y_number_double_close_to_zero.json000066400000000000000000000001241505336676500256050ustar00rootroot00000000000000[-0.000000000000000000000000000000000000000000000000000000000000000000000000000001] ijl-orjson-aa8c946/data/parsing/y_number_int_with_exp.json000066400000000000000000000000061505336676500241050ustar00rootroot00000000000000[20e1]ijl-orjson-aa8c946/data/parsing/y_number_minus_zero.json000066400000000000000000000000041505336676500235740ustar00rootroot00000000000000[-0]ijl-orjson-aa8c946/data/parsing/y_number_negative_int.json000066400000000000000000000000061505336676500240600ustar00rootroot00000000000000[-123]ijl-orjson-aa8c946/data/parsing/y_number_negative_one.json000066400000000000000000000000041505336676500240450ustar00rootroot00000000000000[-1]ijl-orjson-aa8c946/data/parsing/y_number_negative_zero.json000066400000000000000000000000041505336676500242430ustar00rootroot00000000000000[-0]ijl-orjson-aa8c946/data/parsing/y_number_real_capital_e.json000066400000000000000000000000061505336676500243300ustar00rootroot00000000000000[1E22]ijl-orjson-aa8c946/data/parsing/y_number_real_capital_e_neg_exp.json000066400000000000000000000000061505336676500260350ustar00rootroot00000000000000[1E-2]ijl-orjson-aa8c946/data/parsing/y_number_real_capital_e_pos_exp.json000066400000000000000000000000061505336676500260650ustar00rootroot00000000000000[1E+2]ijl-orjson-aa8c946/data/parsing/y_number_real_exponent.json000066400000000000000000000000101505336676500242420ustar00rootroot00000000000000[123e45]ijl-orjson-aa8c946/data/parsing/y_number_real_fraction_exponent.json000066400000000000000000000000141505336676500261330ustar00rootroot00000000000000[123.456e78]ijl-orjson-aa8c946/data/parsing/y_number_real_neg_exp.json000066400000000000000000000000061505336676500240340ustar00rootroot00000000000000[1e-2]ijl-orjson-aa8c946/data/parsing/y_number_real_pos_exponent.json000066400000000000000000000000061505336676500251300ustar00rootroot00000000000000[1e+2]ijl-orjson-aa8c946/data/parsing/y_number_simple_int.json000066400000000000000000000000051505336676500235460ustar00rootroot00000000000000[123]ijl-orjson-aa8c946/data/parsing/y_number_simple_real.json000066400000000000000000000000141505336676500236770ustar00rootroot00000000000000[123.456789]ijl-orjson-aa8c946/data/parsing/y_object.json000066400000000000000000000000321505336676500213010ustar00rootroot00000000000000{"asd":"sdf", "dfg":"fgh"}ijl-orjson-aa8c946/data/parsing/y_object_basic.json000066400000000000000000000000151505336676500224430ustar00rootroot00000000000000{"asd":"sdf"}ijl-orjson-aa8c946/data/parsing/y_object_duplicated_key.json000066400000000000000000000000211505336676500243450ustar00rootroot00000000000000{"a":"b","a":"c"}ijl-orjson-aa8c946/data/parsing/y_object_duplicated_key_and_value.json000066400000000000000000000000211505336676500263630ustar00rootroot00000000000000{"a":"b","a":"b"}ijl-orjson-aa8c946/data/parsing/y_object_empty.json000066400000000000000000000000021505336676500225140ustar00rootroot00000000000000{}ijl-orjson-aa8c946/data/parsing/y_object_empty_key.json000066400000000000000000000000061505336676500233700ustar00rootroot00000000000000{"":0}ijl-orjson-aa8c946/data/parsing/y_object_escaped_null_in_key.json000066400000000000000000000000241505336676500253560ustar00rootroot00000000000000{"foo\u0000bar": 42}ijl-orjson-aa8c946/data/parsing/y_object_extreme_numbers.json000066400000000000000000000000431505336676500245670ustar00rootroot00000000000000{ "min": -1.0e+28, "max": 1.0e+28 }ijl-orjson-aa8c946/data/parsing/y_object_long_strings.json000066400000000000000000000001541505336676500240760ustar00rootroot00000000000000{"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}ijl-orjson-aa8c946/data/parsing/y_object_simple.json000066400000000000000000000000101505336676500226460ustar00rootroot00000000000000{"a":[]}ijl-orjson-aa8c946/data/parsing/y_object_string_unicode.json000066400000000000000000000001561505336676500244040ustar00rootroot00000000000000{"title":"\u041f\u043e\u043b\u0442\u043e\u0440\u0430 \u0417\u0435\u043c\u043b\u0435\u043a\u043e\u043f\u0430" }ijl-orjson-aa8c946/data/parsing/y_object_with_newlines.json000066400000000000000000000000141505336676500242400ustar00rootroot00000000000000{ "a": "b" }ijl-orjson-aa8c946/data/parsing/y_string_1_2_3_bytes_UTF-8_sequences.json000066400000000000000000000000261505336676500263730ustar00rootroot00000000000000["\u0060\u012a\u12AB"]ijl-orjson-aa8c946/data/parsing/y_string_accepted_surrogate_pair.json000066400000000000000000000000201505336676500262740ustar00rootroot00000000000000["\uD801\udc37"]ijl-orjson-aa8c946/data/parsing/y_string_accepted_surrogate_pairs.json000066400000000000000000000000341505336676500264640ustar00rootroot00000000000000["\ud83d\ude39\ud83d\udc8d"]ijl-orjson-aa8c946/data/parsing/y_string_allowed_escapes.json000066400000000000000000000000241505336676500245540ustar00rootroot00000000000000["\"\\\/\b\f\n\r\t"]ijl-orjson-aa8c946/data/parsing/y_string_backslash_and_u_escaped_zero.json000066400000000000000000000000131505336676500272440ustar00rootroot00000000000000["\\u0000"]ijl-orjson-aa8c946/data/parsing/y_string_backslash_doublequotes.json000066400000000000000000000000061505336676500261500ustar00rootroot00000000000000["\""]ijl-orjson-aa8c946/data/parsing/y_string_comments.json000066400000000000000000000000211505336676500232440ustar00rootroot00000000000000["a/*b*/c/*d//e"]ijl-orjson-aa8c946/data/parsing/y_string_double_escape_a.json000066400000000000000000000000071505336676500245150ustar00rootroot00000000000000["\\a"]ijl-orjson-aa8c946/data/parsing/y_string_double_escape_n.json000066400000000000000000000000071505336676500245320ustar00rootroot00000000000000["\\n"]ijl-orjson-aa8c946/data/parsing/y_string_escaped_control_character.json000066400000000000000000000000121505336676500265770ustar00rootroot00000000000000["\u0012"]ijl-orjson-aa8c946/data/parsing/y_string_escaped_noncharacter.json000066400000000000000000000000121505336676500255520ustar00rootroot00000000000000["\uFFFF"]ijl-orjson-aa8c946/data/parsing/y_string_in_array.json000066400000000000000000000000071505336676500232270ustar00rootroot00000000000000["asd"]ijl-orjson-aa8c946/data/parsing/y_string_in_array_with_leading_space.json000066400000000000000000000000101505336676500271120ustar00rootroot00000000000000[ "asd"]ijl-orjson-aa8c946/data/parsing/y_string_last_surrogates_1_and_2.json000066400000000000000000000000201505336676500261220ustar00rootroot00000000000000["\uDBFF\uDFFF"]ijl-orjson-aa8c946/data/parsing/y_string_nbsp_uescaped.json000066400000000000000000000000211505336676500242320ustar00rootroot00000000000000["new\u00A0line"]ijl-orjson-aa8c946/data/parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json000066400000000000000000000000101505336676500261670ustar00rootroot00000000000000["􏿿"]ijl-orjson-aa8c946/data/parsing/y_string_nonCharacterInUTF-8_U+FFFF.json000066400000000000000000000000071505336676500260340ustar00rootroot00000000000000["￿"]ijl-orjson-aa8c946/data/parsing/y_string_null_escape.json000066400000000000000000000000121505336676500237110ustar00rootroot00000000000000["\u0000"]ijl-orjson-aa8c946/data/parsing/y_string_one-byte-utf-8.json000066400000000000000000000000121505336676500241020ustar00rootroot00000000000000["\u002c"]ijl-orjson-aa8c946/data/parsing/y_string_pi.json000066400000000000000000000000061505336676500220320ustar00rootroot00000000000000["π"]ijl-orjson-aa8c946/data/parsing/y_string_reservedCharacterInUTF-8_U+1BFFF.json000066400000000000000000000000101505336676500271300ustar00rootroot00000000000000["𛿿"]ijl-orjson-aa8c946/data/parsing/y_string_simple_ascii.json000066400000000000000000000000101505336676500240560ustar00rootroot00000000000000["asd "]ijl-orjson-aa8c946/data/parsing/y_string_space.json000066400000000000000000000000031505336676500225120ustar00rootroot00000000000000" "ijl-orjson-aa8c946/data/parsing/y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json000066400000000000000000000000201505336676500301100ustar00rootroot00000000000000["\uD834\uDd1e"]ijl-orjson-aa8c946/data/parsing/y_string_three-byte-utf-8.json000066400000000000000000000000121505336676500244300ustar00rootroot00000000000000["\u0821"]ijl-orjson-aa8c946/data/parsing/y_string_two-byte-utf-8.json000066400000000000000000000000121505336676500241320ustar00rootroot00000000000000["\u0123"]ijl-orjson-aa8c946/data/parsing/y_string_u+2028_line_sep.json000066400000000000000000000000071505336676500241340ustar00rootroot00000000000000["
"]ijl-orjson-aa8c946/data/parsing/y_string_u+2029_par_sep.json000066400000000000000000000000071505336676500237700ustar00rootroot00000000000000["
"]ijl-orjson-aa8c946/data/parsing/y_string_uEscape.json000066400000000000000000000000341505336676500230100ustar00rootroot00000000000000["\u0061\u30af\u30EA\u30b9"]ijl-orjson-aa8c946/data/parsing/y_string_uescaped_newline.json000066400000000000000000000000211505336676500247310ustar00rootroot00000000000000["new\u000Aline"]ijl-orjson-aa8c946/data/parsing/y_string_unescaped_char_delete.json000066400000000000000000000000051505336676500257070ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/parsing/y_string_unicode.json000066400000000000000000000000121505336676500230450ustar00rootroot00000000000000["\uA66D"]ijl-orjson-aa8c946/data/parsing/y_string_unicodeEscapedBackslash.json000066400000000000000000000000121505336676500261460ustar00rootroot00000000000000["\u005C"]ijl-orjson-aa8c946/data/parsing/y_string_unicode_2.json000066400000000000000000000000151505336676500232710ustar00rootroot00000000000000["⍂㈴⍂"]ijl-orjson-aa8c946/data/parsing/y_string_unicode_U+10FFFE_nonchar.json000066400000000000000000000000201505336676500257030ustar00rootroot00000000000000["\uDBFF\uDFFE"]ijl-orjson-aa8c946/data/parsing/y_string_unicode_U+1FFFE_nonchar.json000066400000000000000000000000201505336676500256230ustar00rootroot00000000000000["\uD83F\uDFFE"]ijl-orjson-aa8c946/data/parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json000066400000000000000000000000121505336676500264410ustar00rootroot00000000000000["\u200B"]ijl-orjson-aa8c946/data/parsing/y_string_unicode_U+2064_invisible_plus.json000066400000000000000000000000121505336676500270270ustar00rootroot00000000000000["\u2064"]ijl-orjson-aa8c946/data/parsing/y_string_unicode_U+FDD0_nonchar.json000066400000000000000000000000121505336676500255120ustar00rootroot00000000000000["\uFDD0"]ijl-orjson-aa8c946/data/parsing/y_string_unicode_U+FFFE_nonchar.json000066400000000000000000000000121505336676500255430ustar00rootroot00000000000000["\uFFFE"]ijl-orjson-aa8c946/data/parsing/y_string_unicode_escaped_double_quote.json000066400000000000000000000000121505336676500273000ustar00rootroot00000000000000["\u0022"]ijl-orjson-aa8c946/data/parsing/y_string_utf8.json000066400000000000000000000000131505336676500223060ustar00rootroot00000000000000["€𝄞"]ijl-orjson-aa8c946/data/parsing/y_string_with_del_character.json000066400000000000000000000000071505336676500252360ustar00rootroot00000000000000["aa"]ijl-orjson-aa8c946/data/parsing/y_structure_lonely_false.json000066400000000000000000000000051505336676500246270ustar00rootroot00000000000000falseijl-orjson-aa8c946/data/parsing/y_structure_lonely_int.json000066400000000000000000000000021505336676500243240ustar00rootroot0000000000000042ijl-orjson-aa8c946/data/parsing/y_structure_lonely_negative_real.json000066400000000000000000000000041505336676500263410ustar00rootroot00000000000000-0.1ijl-orjson-aa8c946/data/parsing/y_structure_lonely_null.json000066400000000000000000000000041505336676500245060ustar00rootroot00000000000000nullijl-orjson-aa8c946/data/parsing/y_structure_lonely_string.json000066400000000000000000000000051505336676500250430ustar00rootroot00000000000000"asd"ijl-orjson-aa8c946/data/parsing/y_structure_lonely_true.json000066400000000000000000000000041505336676500245130ustar00rootroot00000000000000trueijl-orjson-aa8c946/data/parsing/y_structure_string_empty.json000066400000000000000000000000021505336676500246740ustar00rootroot00000000000000""ijl-orjson-aa8c946/data/parsing/y_structure_trailing_newline.json000066400000000000000000000000061505336676500255060ustar00rootroot00000000000000["a"] ijl-orjson-aa8c946/data/parsing/y_structure_true_in_array.json000066400000000000000000000000061505336676500250170ustar00rootroot00000000000000[true]ijl-orjson-aa8c946/data/parsing/y_structure_whitespace_array.json000066400000000000000000000000041505336676500255040ustar00rootroot00000000000000 [] ijl-orjson-aa8c946/data/roundtrip/000077500000000000000000000000001505336676500172005ustar00rootroot00000000000000ijl-orjson-aa8c946/data/roundtrip/roundtrip01.json000066400000000000000000000000061505336676500222560ustar00rootroot00000000000000[null]ijl-orjson-aa8c946/data/roundtrip/roundtrip02.json000066400000000000000000000000061505336676500222570ustar00rootroot00000000000000[true]ijl-orjson-aa8c946/data/roundtrip/roundtrip03.json000066400000000000000000000000071505336676500222610ustar00rootroot00000000000000[false]ijl-orjson-aa8c946/data/roundtrip/roundtrip04.json000066400000000000000000000000031505336676500222560ustar00rootroot00000000000000[0]ijl-orjson-aa8c946/data/roundtrip/roundtrip05.json000066400000000000000000000000071505336676500222630ustar00rootroot00000000000000["foo"]ijl-orjson-aa8c946/data/roundtrip/roundtrip06.json000066400000000000000000000000021505336676500222570ustar00rootroot00000000000000[]ijl-orjson-aa8c946/data/roundtrip/roundtrip07.json000066400000000000000000000000021505336676500222600ustar00rootroot00000000000000{}ijl-orjson-aa8c946/data/roundtrip/roundtrip08.json000066400000000000000000000000051505336676500222640ustar00rootroot00000000000000[0,1]ijl-orjson-aa8c946/data/roundtrip/roundtrip09.json000066400000000000000000000000151505336676500222660ustar00rootroot00000000000000{"foo":"bar"}ijl-orjson-aa8c946/data/roundtrip/roundtrip10.json000066400000000000000000000000261505336676500222600ustar00rootroot00000000000000{"a":null,"foo":"bar"}ijl-orjson-aa8c946/data/roundtrip/roundtrip11.json000066400000000000000000000000041505336676500222550ustar00rootroot00000000000000[-1]ijl-orjson-aa8c946/data/roundtrip/roundtrip12.json000066400000000000000000000000151505336676500222600ustar00rootroot00000000000000[-2147483648]ijl-orjson-aa8c946/data/roundtrip/roundtrip13.json000066400000000000000000000000261505336676500222630ustar00rootroot00000000000000[-1234567890123456789]ijl-orjson-aa8c946/data/roundtrip/roundtrip14.json000066400000000000000000000000261505336676500222640ustar00rootroot00000000000000[-9223372036854775808]ijl-orjson-aa8c946/data/roundtrip/roundtrip15.json000066400000000000000000000000031505336676500222600ustar00rootroot00000000000000[1]ijl-orjson-aa8c946/data/roundtrip/roundtrip16.json000066400000000000000000000000141505336676500222630ustar00rootroot00000000000000[2147483647]ijl-orjson-aa8c946/data/roundtrip/roundtrip17.json000066400000000000000000000000141505336676500222640ustar00rootroot00000000000000[4294967295]ijl-orjson-aa8c946/data/roundtrip/roundtrip18.json000066400000000000000000000000251505336676500222670ustar00rootroot00000000000000[1234567890123456789]ijl-orjson-aa8c946/data/roundtrip/roundtrip19.json000066400000000000000000000000251505336676500222700ustar00rootroot00000000000000[9223372036854775807]ijl-orjson-aa8c946/data/roundtrip/roundtrip20.json000066400000000000000000000000051505336676500222560ustar00rootroot00000000000000[0.0]ijl-orjson-aa8c946/data/roundtrip/roundtrip21.json000066400000000000000000000000061505336676500222600ustar00rootroot00000000000000[-0.0]ijl-orjson-aa8c946/data/roundtrip/roundtrip22.json000066400000000000000000000000101505336676500222540ustar00rootroot00000000000000[1.2345]ijl-orjson-aa8c946/data/roundtrip/roundtrip23.json000066400000000000000000000000111505336676500222560ustar00rootroot00000000000000[-1.2345]ijl-orjson-aa8c946/data/roundtrip/roundtrip24.json000066400000000000000000000000101505336676500222560ustar00rootroot00000000000000[5e-324]ijl-orjson-aa8c946/data/roundtrip/roundtrip25.json000066400000000000000000000000301505336676500222610ustar00rootroot00000000000000[2.225073858507201e-308]ijl-orjson-aa8c946/data/roundtrip/roundtrip26.json000066400000000000000000000000311505336676500222630ustar00rootroot00000000000000[2.2250738585072014e-308]ijl-orjson-aa8c946/data/roundtrip/roundtrip27.json000066400000000000000000000000301505336676500222630ustar00rootroot00000000000000[1.7976931348623157e308]ijl-orjson-aa8c946/data/transform/000077500000000000000000000000001505336676500171655ustar00rootroot00000000000000ijl-orjson-aa8c946/data/transform/number_1.0.json000066400000000000000000000000051505336676500217210ustar00rootroot00000000000000[1.0]ijl-orjson-aa8c946/data/transform/number_1.000000000000000005.json000066400000000000000000000000261505336676500234110ustar00rootroot00000000000000[1.000000000000000005]ijl-orjson-aa8c946/data/transform/number_1000000000000000.json000066400000000000000000000000231505336676500231030ustar00rootroot00000000000000[1000000000000000] ijl-orjson-aa8c946/data/transform/number_10000000000000000999.json000066400000000000000000000000261505336676500234410ustar00rootroot00000000000000[10000000000000000999]ijl-orjson-aa8c946/data/transform/number_1e-999.json000066400000000000000000000000101505336676500222540ustar00rootroot00000000000000[1E-999]ijl-orjson-aa8c946/data/transform/number_1e6.json000066400000000000000000000000051505336676500220160ustar00rootroot00000000000000[1E6]ijl-orjson-aa8c946/data/transform/object_key_nfc_nfd.json000066400000000000000000000000301505336676500236440ustar00rootroot00000000000000{"é":"NFC","é":"NFD"}ijl-orjson-aa8c946/data/transform/object_key_nfd_nfc.json000066400000000000000000000000301505336676500236440ustar00rootroot00000000000000{"é":"NFD","é":"NFC"}ijl-orjson-aa8c946/data/transform/object_same_key_different_values.json000066400000000000000000000000151505336676500266040ustar00rootroot00000000000000{"a":1,"a":2}ijl-orjson-aa8c946/data/transform/object_same_key_same_value.json000066400000000000000000000000151505336676500254000ustar00rootroot00000000000000{"a":1,"a":1}ijl-orjson-aa8c946/data/transform/object_same_key_unclear_values.json000066400000000000000000000000201505336676500262630ustar00rootroot00000000000000{"a":0, "a":-0} ijl-orjson-aa8c946/data/transform/string_1_escaped_invalid_codepoint.json000066400000000000000000000000121505336676500270350ustar00rootroot00000000000000["\uD800"]ijl-orjson-aa8c946/data/transform/string_1_invalid_codepoint.json000066400000000000000000000000071505336676500253550ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/transform/string_2_escaped_invalid_codepoints.json000066400000000000000000000000201505336676500272200ustar00rootroot00000000000000["\uD800\uD800"]ijl-orjson-aa8c946/data/transform/string_2_invalid_codepoints.json000066400000000000000000000000121505336676500255350ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/transform/string_3_escaped_invalid_codepoints.json000066400000000000000000000000261505336676500272270ustar00rootroot00000000000000["\uD800\uD800\uD800"]ijl-orjson-aa8c946/data/transform/string_3_invalid_codepoints.json000066400000000000000000000000151505336676500255410ustar00rootroot00000000000000[""]ijl-orjson-aa8c946/data/transform/string_with_escaped_NULL.json000066400000000000000000000000141505336676500247320ustar00rootroot00000000000000["A\u0000B"]ijl-orjson-aa8c946/data/twitter.json.xz000066400000000000000000001037341505336676500202170ustar00rootroot000000000000007zXZִF!Xه]=1)x k u ;[wm[>|a88tB3\phF(~;Kf^sDBXB&* /G{_ڏ3ŵQZdLOPVrˣ~*N{eYWYNY RbQjm E+MG_`ӌ ϫ]hma`f֗,5t~5JMtH/voC>dH b1<'ӼG%@@GB^=X/ij_tig'!¯t\%1[(4]m sPv]Yݭ @ժr2"D8&sI_<_\àV)l{ǣq Sn` sU4ᨶwAZurFז-j c]Og`EB7'5Kz8ɏU-z_5?8+d{gR}75s@ta}拼 F̨ZP AꀾPu I&%$k$Ig]l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000000000000000001505336676500150065ustar00rootroot00000000000000ijl-orjson-aa8c946/doc/deserialization.png000066400000000000000000003240251505336676500207100ustar00rootroot00000000000000PNG  IHDR^9tEXtSoftwareMatplotlib version3.9.2, https://matplotlib.org/!N pHYs.#.#x?vIDATxye}_)PBRR*uH%Pr"JId1|̘sΜ33>߹w.l6 ppu 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `p&M 7A n0 `ncӦM_cӦMn Nt-oV/\/R=Z}j޼yuU&ɡ6nܨoV ?<<\-ZPNԥKEDDؽc_jڵ:sLM6z'Ծ}{8}:wl;%Iqqq/pBEGG[\Ui&=cٳu7믿jÆ ںuzڴiE5b-Zr]re6 m۶՜9szϱcǴb mڴI۶mSjjUVvOy6+-ZȦg?p@^xޮt1͘1CWeaaaj߾|I5ju o>}'ߕ+Wշo_y{{ҋ@a9T}ZlF^zytM2E_222 ?++K[lі-[4m4M4IճykZb]}iժUZj6lؠɓ'5vҤIZhrrr ?##C֭ӺuԶm[M8Q*TZJ#FP|||U~m6fǤi͚5ZfZl>)4p@ݻ׮qIII_/szwRl}4?^WvvvkҥZlwQF)44}fM2E}YϜ9~[ ,Ќ3YkʪUO^)--M#Fмyvttﯙ3gu=CZzM'$$vEq1WMo^7oV>}k׮"O?+WnjWջwo߿ߩ}]RRRZrx?i}K.i7oMf~GϮ{տo}'v޻wyi}o(o߮^xjRɤ-Z[oUŊkݺuڲe%x5l0֎Q߾} ^zjӦԩcyK166V;vի IJJ^x}7nm5Ԯ];ժUKaaaQjjuq:tH;wTff]xa/-5kVZf͚ QVV}vYưVtt EbŊv IW_}\IntMPtݻW{~[I&S$=zT[nUTTa\LL  *((sDŊՠA) PӦMUvmU^] TVVuamڴIG1;~^|E}Wmx#GW:5`>^G//~PXXCLm{1{z7Z@B 2224rHFzwԪU+1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CFF*W kkkZ#!*+˗/ׯV\Yu*bccqU )) &&&S7o^*{!..zzzm-i/_ƨQmmmq)œ'O/^ 99011аaCzKMMō7 իWBYy_wt355E5P~}>ȫ@"""8$$$@__氷G ##..055=\\\ڋ/pu 55&&&Y&QF@ymCK:&** ]tݽ{W?)all sssԮ]5XLܼyϟ?G\\޾}ʕ+nnnL\J\k\zHNNWƍEKJJBPP?D 6cuh?[333888]p5<~E*UРA4iҤL֭T8G"x?~ ''\24hziTll,kְ> 0Dpvv]p\?#pƍٳgceZ'ϟg}\^==zLDDDҼy`Z###ȱJO?7/6 .,:'ZBDD$\]x;JWDD)Q ȷlˉu yDTѰ]#"*DDD=\liiY9}H+VWWW2i8sIQ1<QE325""!$ ,;::Y]*zJsssrJʇ RsPr`9I-1<QE%ʢvH`""" >}[ >2QEpyt , ]͛OyfA FQ5$ gΜ='"":&,, GD*77ׯǛ7oЬY2QyW ""*i&dddɓ'p233_G~ʴDAzz:ك={NNNY&͑ׯ_͛ G`ٲe,v Ǒ۷oF ԭ[eV?""^:ӧػw/˗/#'''uKKKtUc#"*iǎChh(pUDFF ^ӧ""0Q!i&?5k,:Uto޼A``JcժUh׮]׋۽{:::X`A׉w^<}?n8TTOpBaf͚ccc$ _ɓKNDDDDDj1c0qIJ ֫S*Udܹ3N hb311ҥKѺu벮 )/TbѦ}}}L>,cZjaƍ*; @GG^:<<<0d8::u*^z[nz*^pDEE!&&Ɂ9*UxxxCW^YW>,,,mbذa|`DDDj+1zzz077Zn ///ږqJ,--Ѹqct AYW\u%9DGUV퟈,0LDDDDDDDDDDDDDTAuH3&""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" &""""""""""""" ʺDDDDDDQTTtҺ044,--amm [[[ԭ[5,--KDDDDDDDde] """""FJ(2 M4AϞ=ѿTVM#%"  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+S-KDDDDDD)ԍ7Defff 盕O 4ECYm|P4t^f͚2IDDDDDDZŋ2777d2Q͊B*))IT((62}挭\L/""""""bH+EFFٳN:)\JTC!*S<*UݻqUhXEUQZsVVVϞ=+t im۶!''GPf``>HNNNP/*XãG>vQNNN,xBChԨ,22eV'""""""`""""""-{p/ޥw (AYfQ١C:*LMM+({ ==]5m۶}oF4&MR]5P^=AYXX$a׮]v)]SNݻWQdS,$$D~ J{tETuVhk䩩eV""""""u0LDDDDD%N:+oE [Th"\EիWؾ};z?uwJ* N>s"--Mv'OСCG}YyꫯD FWx۷cƌA~pСr?|III:u*jBʕ[$&&ˏ>V'NҥKÙ3gгgO4jHLLÇ Hݻwoʕ+*8q">|(J}x{{N:hժׯJ*IIIHHHG03gpTT 000lcccM6Am&"""""*%sN}bE̢E?CP'OɓE ׯG%{R n*zݻ{fȑ8}4.^((; ݶe˖Xt)ƍhLUV7n~Ddddկ`„ Xn资)JvDDDDDDEc h"""""rN&iӦ6mN:e˖]]],ZsIV+vڅ6mHVGG3gĚ5k`kk+y{T!Zh///t޽իu7n(2uÆ ѱcGxzzN:*8z(|}}0dpww_|:*ۣ}8}48+W͛7Enggg6mڠ]vСutt0~x :ǎիW"##HDDDDD,W>={۷o#>>ׇlll cc;vjj*x]6իʕ+8/^7DVZh֬lll4^{.>}7o >>0559Q^=XXXuU; U```````````````mIENDB`ijl-orjson-aa8c946/doc/serialization.png000066400000000000000000003275021505336676500204020ustar00rootroot00000000000000PNG  IHDR^9tEXtSoftwareMatplotlib version3.9.2, https://matplotlib.org/!N pHYs.#.#x?vIDATxwtTg; J]@Q OEQl\E U 4AAi{5JBqe.IL2$3ZY{3'{l6 Py8c A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0`p"E A .\0.={TժU-_={tvKY:s挡ߪUj6Ϭ>k@ A `#Ϝ9:Ex9@2k,g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$*ST&Tcz UeʶA#}14Q9u5QfBrdddhNOO/ʔmKe{իWJ}H:&"""""*Ν;'*L&+K٬,-RRRDeR;[XXRQڜ*Uϋ&"""""*pIQyNokk+*{Ǐ) @ʕZWU*[%5'nYakk+@Sj!""""""&"""""*~ ʌ+]ETRz<<< x.өOV僱15j$(B|||Չa9s v-*ӧґxZѣG:7-(kڴ-*;pVք9eO<0dfffC6mDeǎ+NNNNՅH #O<_~)kjjI&ܮZjWƍq:ܹST֮];w ݻwk5*W2 kIZ]tmݺU4R 6&"""""*'?+BժUn'*[p!ru efff8pmUAYBBϟqRLy} IioܸjV5kL4jɓ'KN%Jq"""""0Qӧc„ J # Oacc#(~:.\Q=bbb0i$AfƍCCCAYPP.]*))y }e˖iXL2ْUL2E{'3f ))IG,΂K.q0+ 1 8q1tP <Txbknntm`` &Mxۆ`#&O\ի3g|/t/^mУGj޽;e3g222Tnw1 :4ԧq5k?\T?bԨQ|FILLĞ={0zh(s*ΗSV'"""""") 4Xtƍׯҿedd 99<533W_}4:zӧw^AѣGۣYfׯǏۢ}bŊ#GDXX(} < 6D۶mQF TT o޼Arr2߿?_cU1qD,YDPg8q={DF`nndStATo۷Gpp0ۇ/իWn֭[]vСC a:t(>˗/#22qqqHOOׯKDDDDDD*9۷o#11044-SSb;vzz:BCCD UիJ*8O>ŵkאdFhڴ)tZrwœ'O+$&&B.Y&ի++Ү*;`""""""""""""" sU U U U U U U U U U U U U U U UC4M9IENDB`ijl-orjson-aa8c946/include/000077500000000000000000000000001505336676500156645ustar00rootroot00000000000000ijl-orjson-aa8c946/include/yyjson-recursion-limit.patch000066400000000000000000000124351505336676500233700ustar00rootroot00000000000000diff --git a/include/yyjson/yyjson.c b/include/yyjson/yyjson.c index e76f538..4bac033 100644 --- a/include/yyjson/yyjson.c +++ b/include/yyjson/yyjson.c @@ -329,8 +329,9 @@ uint32_t yyjson_version(void) { #ifndef YYJSON_DISABLE_UTF8_VALIDATION #define YYJSON_DISABLE_UTF8_VALIDATION 0 #endif - - +#ifndef YYJSON_READER_CONTAINER_RECURSION_LIMIT +#define YYJSON_READER_CONTAINER_RECURSION_LIMIT 1024 +#endif /*============================================================================== * Macros @@ -5798,6 +5799,8 @@ fail_character: return_err(cur, UNEXPECTED_CHARACTER, "unexpected character"); fail_garbage: return_err(cur, UNEXPECTED_CONTENT, "unexpected content after document"); +fail_recursion: + return_err(cur, RECURSION_DEPTH, "array and object recursion depth exceeded"); #undef return_err } @@ -5854,7 +5857,8 @@ static_inline yyjson_doc *read_root_minify(u8 *hdr, yyjson_val *ctn_parent; /* parent of current container */ yyjson_doc *doc; /* the JSON document, equals to val_hdr */ const char *msg; /* error message */ - + + u32 container_depth = 0; /* limit on number of open array and map */ bool raw; /* read number as raw */ bool inv; /* allow invalid unicode */ u8 *raw_end; /* raw end for null-terminator */ @@ -5889,6 +5893,11 @@ static_inline yyjson_doc *read_root_minify(u8 *hdr, } arr_begin: + container_depth++; + if (unlikely(container_depth >= YYJSON_READER_CONTAINER_RECURSION_LIMIT)) { + goto fail_recursion; + } + /* save current container */ ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | (ctn->tag & YYJSON_TAG_MASK); @@ -5988,6 +5997,8 @@ arr_val_end: goto fail_character; arr_end: + container_depth--; + /* get parent container */ ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); @@ -6006,6 +6017,11 @@ arr_end: } obj_begin: + container_depth++; + if (unlikely(container_depth >= YYJSON_READER_CONTAINER_RECURSION_LIMIT)) { + goto fail_recursion; + } + /* push container */ ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | (ctn->tag & YYJSON_TAG_MASK); @@ -6134,6 +6150,8 @@ obj_val_end: goto fail_character; obj_end: + container_depth--; + /* pop container */ ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); /* point to the next value */ @@ -6185,6 +6203,8 @@ fail_character: return_err(cur, UNEXPECTED_CHARACTER, "unexpected character"); fail_garbage: return_err(cur, UNEXPECTED_CONTENT, "unexpected content after document"); +fail_recursion: + return_err(cur, RECURSION_DEPTH, "array and object recursion depth exceeded"); #undef val_incr #undef return_err @@ -6242,7 +6262,8 @@ static_inline yyjson_doc *read_root_pretty(u8 *hdr, yyjson_val *ctn_parent; /* parent of current container */ yyjson_doc *doc; /* the JSON document, equals to val_hdr */ const char *msg; /* error message */ - + + u32 container_depth = 0; /* limit on number of open array and map */ bool raw; /* read number as raw */ bool inv; /* allow invalid unicode */ u8 *raw_end; /* raw end for null-terminator */ @@ -6279,6 +6300,11 @@ static_inline yyjson_doc *read_root_pretty(u8 *hdr, } arr_begin: + container_depth++; + if (unlikely(container_depth >= YYJSON_READER_CONTAINER_RECURSION_LIMIT)) { + goto fail_recursion; + } + /* save current container */ ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | (ctn->tag & YYJSON_TAG_MASK); @@ -6395,6 +6421,8 @@ arr_val_end: goto fail_character; arr_end: + container_depth--; + /* get parent container */ ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); @@ -6414,6 +6442,11 @@ arr_end: } obj_begin: + container_depth++; + if (unlikely(container_depth >= YYJSON_READER_CONTAINER_RECURSION_LIMIT)) { + goto fail_recursion; + } + /* push container */ ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | (ctn->tag & YYJSON_TAG_MASK); @@ -6562,6 +6595,8 @@ obj_val_end: goto fail_character; obj_end: + container_depth--; + /* pop container */ ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); /* point to the next value */ @@ -6614,6 +6649,8 @@ fail_character: return_err(cur, UNEXPECTED_CHARACTER, "unexpected character"); fail_garbage: return_err(cur, UNEXPECTED_CONTENT, "unexpected content after document"); +fail_recursion: + return_err(cur, RECURSION_DEPTH, "array and object recursion depth exceeded"); #undef val_incr #undef return_err diff --git a/include/yyjson/yyjson.h b/include/yyjson/yyjson.h index c393408..bc688e0 100644 --- a/include/yyjson/yyjson.h +++ b/include/yyjson/yyjson.h @@ -831,6 +831,9 @@ static const yyjson_read_code YYJSON_READ_ERROR_FILE_OPEN = 12; /** Failed to read a file. */ static const yyjson_read_code YYJSON_READ_ERROR_FILE_READ = 13; +/** Document exceeded YYJSON_READER_CONTAINER_RECURSION_LIMIT. */ +static const yyjson_read_code YYJSON_READ_ERROR_RECURSION_DEPTH = 14; + /** Error information for JSON reader. */ typedef struct yyjson_read_err { /** Error code, see `yyjson_read_code` for all possible values. */ ijl-orjson-aa8c946/include/yyjson-reduce-unused.patch000066400000000000000000000700051505336676500230100ustar00rootroot00000000000000diff --git a/include/yyjson/yyjson.c b/include/yyjson/yyjson.c index fc80574..803c2f5 100644 --- a/include/yyjson/yyjson.c +++ b/include/yyjson/yyjson.c @@ -3846,14 +3846,6 @@ static_inline bool read_nan(bool sign, u8 **ptr, u8 **pre, yyjson_val *val) { return false; } -/** Read 'Inf', 'Infinity' or 'NaN' literal (ignoring case). */ -static_inline bool read_inf_or_nan(bool sign, u8 **ptr, u8 **pre, - yyjson_val *val) { - if (read_inf(sign, ptr, pre, val)) return true; - if (read_nan(sign, ptr, pre, val)) return true; - return false; -} - /** Read a JSON number as raw string. */ static_noinline bool read_number_raw(u8 **ptr, u8 **pre, @@ -3885,9 +3877,6 @@ static_noinline bool read_number_raw(u8 **ptr, /* read first digit, check leading zero */ if (unlikely(!digi_is_digit(*cur))) { - if (false) { - if (read_inf_or_nan(*hdr == '-', &cur, pre, val)) return_raw(); - } return_err(cur, "no digit after minus sign"); } @@ -3997,8 +3986,7 @@ static_inline bool is_truncated_str(u8 *cur, u8 *end, Returns true if the input is valid but truncated. */ static_noinline bool is_truncated_end(u8 *hdr, u8 *cur, u8 *end, - yyjson_read_code code, - yyjson_read_flag flg) { + yyjson_read_code code) { if (cur >= end) return true; if (code == YYJSON_READ_ERROR_LITERAL) { if (is_truncated_str(cur, end, "true", true) || @@ -4368,8 +4356,6 @@ static const f64 f64_pow10_table[] = { 3. This function (with inline attribute) may generate a lot of instructions. */ static_inline bool read_number(u8 **ptr, - u8 **pre, - yyjson_read_flag flg, yyjson_val *val, const char **msg) { @@ -4404,18 +4390,10 @@ static_inline bool read_number(u8 **ptr, } while (false) #define return_inf() do { \ - if (false) return_raw(); \ if (false) return_f64_bin(F64_RAW_INF); \ else return_err(hdr, "number is infinity when parsed as double"); \ } while (false) -#define return_raw() do { \ - if (*pre) **pre = '\0'; /* add null-terminator for previous raw string */ \ - val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ - val->uni.str = (const char *)hdr; \ - *pre = cur; *end = cur; return true; \ -} while (false) - u8 *sig_cut = NULL; /* significant part cutting position for long number */ u8 *sig_end = NULL; /* significant part ending position */ u8 *dot_pos = NULL; /* decimal point position */ @@ -4434,23 +4412,12 @@ static_inline bool read_number(u8 **ptr, u8 **end = ptr; bool sign; - /* read number as raw string if has `YYJSON_READ_NUMBER_AS_RAW` flag */ - if (unlikely(false)) { - return read_number_raw(ptr, pre, flg, val, msg); - } - sign = (*hdr == '-'); cur += sign; /* begin with a leading zero or non-digit */ if (unlikely(!digi_is_nonzero(*cur))) { /* 0 or non-digit char */ if (unlikely(*cur != '0')) { /* non-digit char */ - if (false) { - if (read_inf_or_nan(sign, &cur, pre, val)) { - *end = cur; - return true; - } - } return_err(cur, "no digit after minus sign"); } /* begin with 0 */ @@ -4504,7 +4471,6 @@ static_inline bool read_number(u8 **ptr, if (!digi_is_digit_or_fp(*cur)) { /* this number is an integer consisting of 19 digits */ if (sign && (sig > ((u64)1 << 63))) { /* overflow */ - if (false) return_raw(); return_f64(normalized_u64_to_f64(sig)); } return_i64(sig); @@ -4558,7 +4524,6 @@ digi_intg_more: cur++; /* convert to double if overflow */ if (sign) { - if (false) return_raw(); return_f64(normalized_u64_to_f64(sig)); } return_i64(sig); @@ -4585,9 +4550,6 @@ digi_frac_more: sig += (*cur >= '5'); /* round */ while (digi_is_digit(*++cur)); if (!dot_pos) { - if (!digi_is_fp(*cur) && false) { - return_raw(); /* it's a large integer */ - } dot_pos = cur; if (*cur == '.') { if (!digi_is_digit(*++cur)) { @@ -4980,8 +4942,6 @@ digi_finish: This function use libc's strtod() to read floating-point number. */ static_inline bool read_number(u8 **ptr, - u8 **pre, - yyjson_read_flag flg, yyjson_val *val, const char **msg) { @@ -5016,18 +4976,10 @@ static_inline bool read_number(u8 **ptr, } while (false) #define return_inf() do { \ - if (false) return_raw(); \ if (false) return_f64_bin(F64_RAW_INF); \ else return_err(hdr, "number is infinity when parsed as double"); \ } while (false) -#define return_raw() do { \ - if (*pre) **pre = '\0'; /* add null-terminator for previous raw string */ \ - val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ - val->uni.str = (const char *)hdr; \ - *pre = cur; *end = cur; return true; \ -} while (false) - u64 sig, num; u8 *hdr = *ptr; u8 *cur = *ptr; @@ -5047,12 +4999,6 @@ static_inline bool read_number(u8 **ptr, /* read first digit, check leading zero */ if (unlikely(!digi_is_digit(*cur))) { - if (false) { - if (read_inf_or_nan(sign, &cur, pre, val)) { - *end = cur; - return true; - } - } return_err(cur, "no digit after minus sign"); } if (*cur == '0') { @@ -5102,9 +5048,6 @@ intg_end: read_double: /* this number should be read as double */ while (digi_is_digit(*cur)) cur++; - if (!digi_is_fp(*cur) && false) { - return_raw(); /* it's a large integer */ - } if (*cur == '.') { /* skip fraction part */ dot = cur; @@ -5186,7 +5129,6 @@ read_double: */ static_inline bool read_string(u8 **ptr, u8 *lst, - bool inv, yyjson_val *val, const char **msg) { /* @@ -5421,10 +5363,6 @@ skip_utf8: uni = byte_load_4(src); } #endif - if (false) { - if (!inv) return_err(src, "invalid UTF-8 encoding in string"); - ++src; - } goto skip_ascii; } @@ -5486,13 +5424,10 @@ copy_escape: } else if (likely(*src == '"')) { val->tag = ((u64)(dst - cur) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = (const char *)cur; - *dst = '\0'; *end = src + 1; return true; } else { - if (!inv) return_err(src, "unexpected control character in string"); - if (src >= lst) return_err(src, "unclosed string"); - *dst++ = *src++; + return_err(src, "unexpected control character in string"); } copy_ascii: @@ -5664,10 +5599,6 @@ copy_utf8: uni = byte_load_4(src); } #endif - if (false) { - if (!inv) return_err(src, "invalid UTF-8 encoding in string"); - goto copy_ascii_stop_1; - } goto copy_ascii; } goto copy_escape; @@ -5694,11 +5625,10 @@ static_noinline yyjson_doc *read_root_single(u8 *hdr, u8 *cur, u8 *end, yyjson_alc alc, - yyjson_read_flag flg, yyjson_read_err *err) { #define return_err(_pos, _code, _msg) do { \ - if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code, flg)) { \ + if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code)) { \ err->pos = (usize)(end - hdr); \ err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ err->msg = "unexpected end of data"; \ @@ -5718,11 +5648,6 @@ static_noinline yyjson_doc *read_root_single(u8 *hdr, yyjson_doc *doc; /* the JSON document, equals to val_hdr */ const char *msg; /* error message */ - bool raw; /* read number as raw */ - bool inv; /* allow invalid unicode */ - u8 *raw_end; /* raw end for null-terminator */ - u8 **pre; /* previous raw end pointer */ - hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; alc_num = hdr_len + 1; /* single value */ @@ -5730,17 +5655,13 @@ static_noinline yyjson_doc *read_root_single(u8 *hdr, val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_num * sizeof(yyjson_val)); if (unlikely(!val_hdr)) goto fail_alloc; val = val_hdr + hdr_len; - raw = has_read_flag(NUMBER_AS_RAW) || false; - inv = has_read_flag(ALLOW_INVALID_UNICODE) != 0; - raw_end = NULL; - pre = raw ? &raw_end : NULL; if (char_is_number(*cur)) { - if (likely(read_number(&cur, pre, flg, val, &msg))) goto doc_end; + if (likely(read_number(&cur, val, &msg))) goto doc_end; goto fail_number; } if (*cur == '"') { - if (likely(read_string(&cur, end, inv, val, &msg))) goto doc_end; + if (likely(read_string(&cur, end, val, &msg))) goto doc_end; goto fail_string; } if (*cur == 't') { @@ -5754,13 +5675,10 @@ static_noinline yyjson_doc *read_root_single(u8 *hdr, if (*cur == 'n') { if (likely(read_null(&cur, val))) goto doc_end; if (false) { - if (read_nan(false, &cur, pre, val)) goto doc_end; + if (read_nan(false, &cur, 0, val)) goto doc_end; } goto fail_literal; } - if (false) { - if (read_inf_or_nan(false, &cur, pre, val)) goto doc_end; - } goto fail_character; doc_end: @@ -5776,13 +5694,12 @@ doc_end: if (unlikely(cur < end)) goto fail_garbage; } - if (false) **pre = '\0'; doc = (yyjson_doc *)val_hdr; doc->root = val_hdr + hdr_len; doc->alc = alc; doc->dat_read = (usize)(cur - hdr); doc->val_read = 1; - doc->str_pool = has_read_flag(INSITU) ? NULL : (char *)hdr; + doc->str_pool = (char *)hdr; return doc; fail_string: @@ -5810,11 +5727,10 @@ static_inline yyjson_doc *read_root_minify(u8 *hdr, u8 *cur, u8 *end, yyjson_alc alc, - yyjson_read_flag flg, yyjson_read_err *err) { #define return_err(_pos, _code, _msg) do { \ - if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code, flg)) { \ + if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code)) { \ err->pos = (usize)(end - hdr); \ err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ err->msg = "unexpected end of data"; \ @@ -5861,8 +5777,6 @@ static_inline yyjson_doc *read_root_minify(u8 *hdr, u32 container_depth = 0; /* limit on number of open array and map */ bool raw; /* read number as raw */ bool inv; /* allow invalid unicode */ - u8 *raw_end; /* raw end for null-terminator */ - u8 **pre; /* previous raw end pointer */ dat_len = has_read_flag(STOP_WHEN_DONE) ? 256 : (usize)(end - cur); hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); @@ -5877,11 +5791,7 @@ static_inline yyjson_doc *read_root_minify(u8 *hdr, val = val_hdr + hdr_len; ctn = val; ctn_len = 0; - raw = has_read_flag(NUMBER_AS_RAW) || false; - inv = has_read_flag(ALLOW_INVALID_UNICODE) != 0; - raw_end = NULL; - pre = raw ? &raw_end : NULL; - + if (*cur++ == '{') { ctn->tag = YYJSON_TYPE_OBJ; ctn->uni.ofs = 0; @@ -5923,13 +5833,13 @@ arr_val_begin: if (char_is_number(*cur)) { val_incr(); ctn_len++; - if (likely(read_number(&cur, pre, flg, val, &msg))) goto arr_val_end; + if (likely(read_number(&cur, val, &msg))) goto arr_val_end; goto fail_number; } if (*cur == '"') { val_incr(); ctn_len++; - if (likely(read_string(&cur, end, inv, val, &msg))) goto arr_val_end; + if (likely(read_string(&cur, end, val, &msg))) goto arr_val_end; goto fail_string; } if (*cur == 't') { @@ -5948,15 +5858,11 @@ arr_val_begin: val_incr(); ctn_len++; if (likely(read_null(&cur, val))) goto arr_val_end; - if (false) { - if (read_nan(false, &cur, pre, val)) goto arr_val_end; - } goto fail_literal; } if (*cur == ']') { cur++; if (likely(ctn_len == 0)) goto arr_end; - if (has_read_flag(ALLOW_TRAILING_COMMAS)) goto arr_end; while (*cur != ',') cur--; goto fail_trailing_comma; } @@ -5964,17 +5870,6 @@ arr_val_begin: while (char_is_space(*++cur)); goto arr_val_begin; } - if (false && - (*cur == 'i' || *cur == 'I' || *cur == 'N')) { - val_incr(); - ctn_len++; - if (read_inf_or_nan(false, &cur, pre, val)) goto arr_val_end; - goto fail_character; - } - if (false) { - if (skip_spaces_and_comments(&cur)) goto arr_val_begin; - if (byte_match_2(cur, "/*")) goto fail_comment; - } goto fail_character; arr_val_end: @@ -6036,13 +5931,12 @@ obj_key_begin: if (likely(*cur == '"')) { val_incr(); ctn_len++; - if (likely(read_string(&cur, end, inv, val, &msg))) goto obj_key_end; + if (likely(read_string(&cur, end, val, &msg))) goto obj_key_end; goto fail_string; } if (likely(*cur == '}')) { cur++; if (likely(ctn_len == 0)) goto obj_end; - if (has_read_flag(ALLOW_TRAILING_COMMAS)) goto obj_end; while (*cur != ',') cur--; goto fail_trailing_comma; } @@ -6075,13 +5969,13 @@ obj_val_begin: if (*cur == '"') { val++; ctn_len++; - if (likely(read_string(&cur, end, inv, val, &msg))) goto obj_val_end; + if (likely(read_string(&cur, end, val, &msg))) goto obj_val_end; goto fail_string; } if (char_is_number(*cur)) { val++; ctn_len++; - if (likely(read_number(&cur, pre, flg, val, &msg))) goto obj_val_end; + if (likely(read_number(&cur, val, &msg))) goto obj_val_end; goto fail_number; } if (*cur == '{') { @@ -6108,26 +6002,12 @@ obj_val_begin: val++; ctn_len++; if (likely(read_null(&cur, val))) goto obj_val_end; - if (false) { - if (read_nan(false, &cur, pre, val)) goto obj_val_end; - } goto fail_literal; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_val_begin; } - if (false && - (*cur == 'i' || *cur == 'I' || *cur == 'N')) { - val++; - ctn_len++; - if (read_inf_or_nan(false, &cur, pre, val)) goto obj_val_end; - goto fail_character; - } - if (false) { - if (skip_spaces_and_comments(&cur)) goto obj_val_begin; - if (byte_match_2(cur, "/*")) goto fail_comment; - } goto fail_character; obj_val_end: @@ -6178,7 +6058,6 @@ doc_end: if (unlikely(cur < end)) goto fail_garbage; } - if (false) **pre = '\0'; doc = (yyjson_doc *)val_hdr; doc->root = val_hdr + hdr_len; doc->alc = alc; @@ -6215,11 +6094,10 @@ static_inline yyjson_doc *read_root_pretty(u8 *hdr, u8 *cur, u8 *end, yyjson_alc alc, - yyjson_read_flag flg, yyjson_read_err *err) { #define return_err(_pos, _code, _msg) do { \ - if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code, flg)) { \ + if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code)) { \ err->pos = (usize)(end - hdr); \ err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ err->msg = "unexpected end of data"; \ @@ -6264,10 +6142,6 @@ static_inline yyjson_doc *read_root_pretty(u8 *hdr, const char *msg; /* error message */ u32 container_depth = 0; /* limit on number of open array and map */ - bool raw; /* read number as raw */ - bool inv; /* allow invalid unicode */ - u8 *raw_end; /* raw end for null-terminator */ - u8 **pre; /* previous raw end pointer */ dat_len = has_read_flag(STOP_WHEN_DONE) ? 256 : (usize)(end - cur); hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); @@ -6282,10 +6156,6 @@ static_inline yyjson_doc *read_root_pretty(u8 *hdr, val = val_hdr + hdr_len; ctn = val; ctn_len = 0; - raw = has_read_flag(NUMBER_AS_RAW) || false; - inv = has_read_flag(ALLOW_INVALID_UNICODE) != 0; - raw_end = NULL; - pre = raw ? &raw_end : NULL; if (*cur++ == '{') { ctn->tag = YYJSON_TYPE_OBJ; @@ -6343,13 +6213,13 @@ arr_val_begin: if (char_is_number(*cur)) { val_incr(); ctn_len++; - if (likely(read_number(&cur, pre, flg, val, &msg))) goto arr_val_end; + if (likely(read_number(&cur, val, &msg))) goto arr_val_end; goto fail_number; } if (*cur == '"') { val_incr(); ctn_len++; - if (likely(read_string(&cur, end, inv, val, &msg))) goto arr_val_end; + if (likely(read_string(&cur, end, val, &msg))) goto arr_val_end; goto fail_string; } if (*cur == 't') { @@ -6369,14 +6239,13 @@ arr_val_begin: ctn_len++; if (likely(read_null(&cur, val))) goto arr_val_end; if (false) { - if (read_nan(false, &cur, pre, val)) goto arr_val_end; + if (read_nan(false, &cur, 0, val)) goto arr_val_end; } goto fail_literal; } if (*cur == ']') { cur++; if (likely(ctn_len == 0)) goto arr_end; - if (has_read_flag(ALLOW_TRAILING_COMMAS)) goto arr_end; while (*cur != ',') cur--; goto fail_trailing_comma; } @@ -6384,17 +6253,6 @@ arr_val_begin: while (char_is_space(*++cur)); goto arr_val_begin; } - if (false && - (*cur == 'i' || *cur == 'I' || *cur == 'N')) { - val_incr(); - ctn_len++; - if (read_inf_or_nan(false, &cur, pre, val)) goto arr_val_end; - goto fail_character; - } - if (false) { - if (skip_spaces_and_comments(&cur)) goto arr_val_begin; - if (byte_match_2(cur, "/*")) goto fail_comment; - } goto fail_character; arr_val_end: @@ -6473,13 +6331,12 @@ obj_key_begin: if (likely(*cur == '"')) { val_incr(); ctn_len++; - if (likely(read_string(&cur, end, inv, val, &msg))) goto obj_key_end; + if (likely(read_string(&cur, end, val, &msg))) goto obj_key_end; goto fail_string; } if (likely(*cur == '}')) { cur++; if (likely(ctn_len == 0)) goto obj_end; - if (has_read_flag(ALLOW_TRAILING_COMMAS)) goto obj_end; while (*cur != ',') cur--; goto fail_trailing_comma; } @@ -6506,23 +6363,19 @@ obj_key_end: while (char_is_space(*++cur)); goto obj_key_end; } - if (false) { - if (skip_spaces_and_comments(&cur)) goto obj_key_end; - if (byte_match_2(cur, "/*")) goto fail_comment; - } goto fail_character; obj_val_begin: if (*cur == '"') { val++; ctn_len++; - if (likely(read_string(&cur, end, inv, val, &msg))) goto obj_val_end; + if (likely(read_string(&cur, end, val, &msg))) goto obj_val_end; goto fail_string; } if (char_is_number(*cur)) { val++; ctn_len++; - if (likely(read_number(&cur, pre, flg, val, &msg))) goto obj_val_end; + if (likely(read_number(&cur, val, &msg))) goto obj_val_end; goto fail_number; } if (*cur == '{') { @@ -6549,26 +6402,12 @@ obj_val_begin: val++; ctn_len++; if (likely(read_null(&cur, val))) goto obj_val_end; - if (false) { - if (read_nan(false, &cur, pre, val)) goto obj_val_end; - } goto fail_literal; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_val_begin; } - if (false && - (*cur == 'i' || *cur == 'I' || *cur == 'N')) { - val++; - ctn_len++; - if (read_inf_or_nan(false, &cur, pre, val)) goto obj_val_end; - goto fail_character; - } - if (false) { - if (skip_spaces_and_comments(&cur)) goto obj_val_begin; - if (byte_match_2(cur, "/*")) goto fail_comment; - } goto fail_character; obj_val_end: @@ -6588,10 +6427,6 @@ obj_val_end: while (char_is_space(*++cur)); goto obj_val_end; } - if (false) { - if (skip_spaces_and_comments(&cur)) goto obj_val_end; - if (byte_match_2(cur, "/*")) goto fail_comment; - } goto fail_character; obj_end: @@ -6624,7 +6459,6 @@ doc_end: if (unlikely(cur < end)) goto fail_garbage; } - if (false) **pre = '\0'; doc = (yyjson_doc *)val_hdr; doc->root = val_hdr + hdr_len; doc->alc = alc; @@ -6664,7 +6498,6 @@ fail_recursion: yyjson_doc *yyjson_read_opts(char *dat, usize len, - yyjson_read_flag flg, const yyjson_alc *alc_ptr, yyjson_read_err *err) { @@ -6675,56 +6508,26 @@ yyjson_doc *yyjson_read_opts(char *dat, if (!has_read_flag(INSITU) && hdr) alc.free(alc.ctx, (void *)hdr); \ return NULL; \ } while (false) - - yyjson_alc alc; yyjson_doc *doc; u8 *hdr = NULL, *end, *cur; - - /* validate input parameters */ if (!alc_ptr) { alc = YYJSON_DEFAULT_ALC; } else { alc = *alc_ptr; } - if (unlikely(!dat)) { - return_err(0, INVALID_PARAMETER, "input data is NULL"); - } - if (unlikely(!len)) { - return_err(0, INVALID_PARAMETER, "input length is 0"); - } - - /* add 4-byte zero padding for input data if necessary */ - if (has_read_flag(INSITU)) { - hdr = (u8 *)dat; - end = (u8 *)dat + len; - cur = (u8 *)dat; - } else { - if (unlikely(len >= USIZE_MAX - YYJSON_PADDING_SIZE)) { - return_err(0, MEMORY_ALLOCATION, "memory allocation failed"); - } - hdr = (u8 *)alc.malloc(alc.ctx, len + YYJSON_PADDING_SIZE); - if (unlikely(!hdr)) { - return_err(0, MEMORY_ALLOCATION, "memory allocation failed"); - } - end = hdr + len; - cur = hdr; - memcpy(hdr, dat, len); - memset(end, 0, YYJSON_PADDING_SIZE); - } + + hdr = (u8 *)alc.malloc(alc.ctx, len + YYJSON_PADDING_SIZE); + end = hdr + len; + cur = hdr; + memcpy(hdr, dat, len); + memset(end, 0, YYJSON_PADDING_SIZE); /* skip empty contents before json document */ if (unlikely(char_is_space_or_comment(*cur))) { - if (false) { - if (!skip_spaces_and_comments(&cur)) { - return_err(cur - hdr, INVALID_COMMENT, - "unclosed multiline comment"); - } - } else { - if (likely(char_is_space(*cur))) { - while (char_is_space(*++cur)); - } + if (likely(char_is_space(*cur))) { + while (char_is_space(*++cur)); } if (unlikely(cur >= end)) { return_err(0, EMPTY_CONTENT, "input data is empty"); @@ -6734,35 +6537,17 @@ yyjson_doc *yyjson_read_opts(char *dat, /* read json document */ if (likely(char_is_container(*cur))) { if (char_is_space(cur[1]) && char_is_space(cur[2])) { - doc = read_root_pretty(hdr, cur, end, alc, flg, err); + doc = read_root_pretty(hdr, cur, end, alc, err); } else { - doc = read_root_minify(hdr, cur, end, alc, flg, err); + doc = read_root_minify(hdr, cur, end, alc, err); } } else { - doc = read_root_single(hdr, cur, end, alc, flg, err); + doc = read_root_single(hdr, cur, end, alc, err); } /* check result */ - if (likely(doc)) { - memset(err, 0, sizeof(yyjson_read_err)); - } else { - /* RFC 8259: JSON text MUST be encoded using UTF-8 */ - if (err->pos == 0 && err->code != YYJSON_READ_ERROR_MEMORY_ALLOCATION) { - if ((hdr[0] == 0xEF && hdr[1] == 0xBB && hdr[2] == 0xBF)) { - err->msg = "byte order mark (BOM) is not supported"; - } else if (len >= 4 && - ((hdr[0] == 0x00 && hdr[1] == 0x00 && - hdr[2] == 0xFE && hdr[3] == 0xFF) || - (hdr[0] == 0xFF && hdr[1] == 0xFE && - hdr[2] == 0x00 && hdr[3] == 0x00))) { - err->msg = "UTF-32 encoding is not supported"; - } else if (len >= 2 && - ((hdr[0] == 0xFE && hdr[1] == 0xFF) || - (hdr[0] == 0xFF && hdr[1] == 0xFE))) { - err->msg = "UTF-16 encoding is not supported"; - } - } - if (!has_read_flag(INSITU)) alc.free(alc.ctx, (void *)hdr); + if (unlikely(!doc)) { + alc.free(alc.ctx, (void *)hdr); } return doc; @@ -6878,7 +6663,7 @@ yyjson_doc *yyjson_read_fp(FILE *file, /* read JSON */ memset((u8 *)buf + file_size, 0, YYJSON_PADDING_SIZE); flg |= YYJSON_READ_INSITU; - doc = yyjson_read_opts((char *)buf, (usize)file_size, flg, &alc, err); + doc = yyjson_read_opts((char *)buf, (usize)file_size, &alc, err); if (doc) { doc->str_pool = (char *)buf; return doc; @@ -6940,12 +6725,8 @@ const char *yyjson_read_number(const char *dat, hdr[dat_len] = 0; #endif - raw = false; - raw_end = NULL; - pre = raw ? &raw_end : NULL; - #if !YYJSON_HAS_IEEE_754 || YYJSON_DISABLE_FAST_FP_CONV - if (!read_number(&cur, pre, flg, val, &msg)) { + if (!read_number(&cur, val, &msg)) { if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr); return_err(cur, INVALID_NUMBER, msg); } @@ -6953,7 +6734,7 @@ const char *yyjson_read_number(const char *dat, if (yyjson_is_raw(val)) val->uni.str = dat; return dat + (cur - hdr); #else - if (!read_number(&cur, pre, flg, val, &msg)) { + if (!read_number(&cur, val, &msg)) { return_err(cur, INVALID_NUMBER, msg); } return (const char *)cur; diff --git a/include/yyjson/yyjson.h b/include/yyjson/yyjson.h index c2dcdd6..210449d 100644 --- a/include/yyjson/yyjson.h +++ b/include/yyjson/yyjson.h @@ -860,8 +860,6 @@ typedef struct yyjson_read_err { the `YYJSON_READ_INSITU` flag. @param len The length of JSON data in bytes. If this parameter is 0, the function will fail and return NULL. - @param flg The JSON read options. - Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON reader. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. @@ -871,7 +869,6 @@ typedef struct yyjson_read_err { */ yyjson_api yyjson_doc *yyjson_read_opts(char *dat, size_t len, - yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err); @@ -941,7 +938,7 @@ yyjson_api_inline yyjson_doc *yyjson_read(const char *dat, yyjson_read_flag flg) { flg &= ~YYJSON_READ_INSITU; /* const string cannot be modified */ return yyjson_read_opts((char *)(void *)(size_t)(const void *)dat, - len, flg, NULL, NULL); + len, NULL, NULL); } /** ijl-orjson-aa8c946/include/yyjson/000077500000000000000000000000001505336676500172175ustar00rootroot00000000000000ijl-orjson-aa8c946/include/yyjson/yyjson.c000066400000000000000000012417321505336676500207300ustar00rootroot00000000000000/*============================================================================== Copyright (c) 2020 YaoYuan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *============================================================================*/ #include "yyjson.h" #include /*============================================================================== * Warning Suppress *============================================================================*/ #if defined(__clang__) # pragma clang diagnostic ignored "-Wunused-function" # pragma clang diagnostic ignored "-Wunused-parameter" # pragma clang diagnostic ignored "-Wunused-label" # pragma clang diagnostic ignored "-Wunused-macros" # pragma clang diagnostic ignored "-Wunused-variable" #elif defined(__GNUC__) # pragma GCC diagnostic ignored "-Wunused-function" # pragma GCC diagnostic ignored "-Wunused-parameter" # pragma GCC diagnostic ignored "-Wunused-label" # pragma GCC diagnostic ignored "-Wunused-macros" # pragma GCC diagnostic ignored "-Wunused-variable" #elif defined(_MSC_VER) # pragma warning(disable:4100) /* unreferenced formal parameter */ # pragma warning(disable:4101) /* unreferenced variable */ # pragma warning(disable:4102) /* unreferenced label */ # pragma warning(disable:4127) /* conditional expression is constant */ # pragma warning(disable:4706) /* assignment within conditional expression */ #endif /*============================================================================== * Version *============================================================================*/ uint32_t yyjson_version(void) { return YYJSON_VERSION_HEX; } /*============================================================================== * Flags *============================================================================*/ /* msvc intrinsic */ #if YYJSON_MSC_VER >= 1400 # include # if defined(_M_AMD64) || defined(_M_ARM64) # define MSC_HAS_BIT_SCAN_64 1 # pragma intrinsic(_BitScanForward64) # pragma intrinsic(_BitScanReverse64) # else # define MSC_HAS_BIT_SCAN_64 0 # endif # if defined(_M_AMD64) || defined(_M_ARM64) || \ defined(_M_IX86) || defined(_M_ARM) # define MSC_HAS_BIT_SCAN 1 # pragma intrinsic(_BitScanForward) # pragma intrinsic(_BitScanReverse) # else # define MSC_HAS_BIT_SCAN 0 # endif # if defined(_M_AMD64) # define MSC_HAS_UMUL128 1 # pragma intrinsic(_umul128) # else # define MSC_HAS_UMUL128 0 # endif #else # define MSC_HAS_BIT_SCAN_64 0 # define MSC_HAS_BIT_SCAN 0 # define MSC_HAS_UMUL128 0 #endif /* gcc builtin */ #if yyjson_has_builtin(__builtin_clzll) || yyjson_gcc_available(3, 4, 0) # define GCC_HAS_CLZLL 1 #else # define GCC_HAS_CLZLL 0 #endif #if yyjson_has_builtin(__builtin_ctzll) || yyjson_gcc_available(3, 4, 0) # define GCC_HAS_CTZLL 1 #else # define GCC_HAS_CTZLL 0 #endif /* int128 type */ #if defined(__SIZEOF_INT128__) && (__SIZEOF_INT128__ == 16) && \ (defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)) # define YYJSON_HAS_INT128 1 #else # define YYJSON_HAS_INT128 0 #endif /* IEEE 754 floating-point binary representation */ #if defined(__STDC_IEC_559__) || defined(__STDC_IEC_60559_BFP__) # define YYJSON_HAS_IEEE_754 1 #elif (FLT_RADIX == 2) && (DBL_MANT_DIG == 53) && (DBL_DIG == 15) && \ (DBL_MIN_EXP == -1021) && (DBL_MAX_EXP == 1024) && \ (DBL_MIN_10_EXP == -307) && (DBL_MAX_10_EXP == 308) # define YYJSON_HAS_IEEE_754 1 #else # define YYJSON_HAS_IEEE_754 0 #endif /* Correct rounding in double number computations. On the x86 architecture, some compilers may use x87 FPU instructions for floating-point arithmetic. The x87 FPU loads all floating point number as 80-bit double-extended precision internally, then rounds the result to original precision, which may produce inaccurate results. For a more detailed explanation, see the paper: https://arxiv.org/abs/cs/0701192 Here are some examples of double precision calculation error: 2877.0 / 1e6 == 0.002877, but x87 returns 0.0028770000000000002 43683.0 * 1e21 == 4.3683e25, but x87 returns 4.3683000000000004e25 Here are some examples of compiler flags to generate x87 instructions on x86: clang -m32 -mno-sse gcc/icc -m32 -mfpmath=387 msvc /arch:SSE or /arch:IA32 If we are sure that there's no similar error described above, we can define the YYJSON_DOUBLE_MATH_CORRECT as 1 to enable the fast path calculation. This is not an accurate detection, it's just try to avoid the error at compile-time. An accurate detection can be done at run-time: bool is_double_math_correct(void) { volatile double r = 43683.0; r *= 1e21; return r == 4.3683e25; } See also: utils.h in https://github.com/google/double-conversion/ */ #if !defined(FLT_EVAL_METHOD) && defined(__FLT_EVAL_METHOD__) # define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ #endif #if defined(FLT_EVAL_METHOD) && FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1 # define YYJSON_DOUBLE_MATH_CORRECT 0 #elif defined(i386) || defined(__i386) || defined(__i386__) || \ defined(_X86_) || defined(__X86__) || defined(_M_IX86) || \ defined(__I86__) || defined(__IA32__) || defined(__THW_INTEL) # if (defined(_MSC_VER) && defined(_M_IX86_FP) && _M_IX86_FP == 2) || \ (defined(__SSE2_MATH__) && __SSE2_MATH__) # define YYJSON_DOUBLE_MATH_CORRECT 1 # else # define YYJSON_DOUBLE_MATH_CORRECT 0 # endif #elif defined(__mc68000__) || defined(__pnacl__) || defined(__native_client__) # define YYJSON_DOUBLE_MATH_CORRECT 0 #else # define YYJSON_DOUBLE_MATH_CORRECT 1 #endif /* endian */ #if yyjson_has_include() # include /* POSIX */ #endif #if yyjson_has_include() # include /* Linux */ #elif yyjson_has_include() # include /* BSD, Android */ #elif yyjson_has_include() # include /* BSD, Darwin */ #endif #define YYJSON_BIG_ENDIAN 4321 #define YYJSON_LITTLE_ENDIAN 1234 #if defined(BYTE_ORDER) && BYTE_ORDER # if defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN) # define YYJSON_ENDIAN YYJSON_BIG_ENDIAN # elif defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN) # define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN # endif #elif defined(__BYTE_ORDER) && __BYTE_ORDER # if defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) # define YYJSON_ENDIAN YYJSON_BIG_ENDIAN # elif defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) # define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN # endif #elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ # if defined(__ORDER_BIG_ENDIAN__) && \ (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) # define YYJSON_ENDIAN YYJSON_BIG_ENDIAN # elif defined(__ORDER_LITTLE_ENDIAN__) && \ (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) # define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN # endif #elif (defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__ == 1) || \ defined(__i386) || defined(__i386__) || \ defined(_X86_) || defined(__X86__) || \ defined(_M_IX86) || defined(__THW_INTEL__) || \ defined(__x86_64) || defined(__x86_64__) || \ defined(__amd64) || defined(__amd64__) || \ defined(_M_AMD64) || defined(_M_X64) || \ defined(_M_ARM) || defined(_M_ARM64) || \ defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \ defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \ defined(__EMSCRIPTEN__) || defined(__wasm__) || \ defined(__loongarch__) # define YYJSON_ENDIAN YYJSON_LITTLE_ENDIAN #elif (defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ == 1) || \ defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || \ defined(__or1k__) || defined(__OR1K__) # define YYJSON_ENDIAN YYJSON_BIG_ENDIAN #else # define YYJSON_ENDIAN 0 /* unknown endian, detect at run-time */ #endif /* This macro controls how yyjson handles unaligned memory accesses. By default, yyjson uses `memcpy()` for memory copying. This takes advantage of the compiler's automatic optimizations to generate unaligned memory access instructions when the target architecture supports it. However, for some older compilers or architectures where `memcpy()` isn't optimized well and may generate unnecessary function calls, consider defining this macro as 1. In such cases, yyjson switches to manual byte-by-byte access, potentially improving performance. An example of the generated assembly code on the ARM platform can be found here: https://godbolt.org/z/334jjhxPT As this flag has already been enabled for some common architectures in the following code, users typically don't need to manually specify it. If users are unsure about it, please review the generated assembly code or perform actual benchmark to make an informed decision. */ #ifndef YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS # if defined(__ia64) || defined(_IA64) || defined(__IA64__) || \ defined(__ia64__) || defined(_M_IA64) || defined(__itanium__) # define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* Itanium */ # elif (defined(__arm__) || defined(__arm64__) || defined(__aarch64__)) && \ (defined(__GNUC__) || defined(__clang__)) && \ (!defined(__ARM_FEATURE_UNALIGNED) || !__ARM_FEATURE_UNALIGNED) # define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* ARM */ # elif defined(__sparc) || defined(__sparc__) # define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* SPARC */ # elif defined(__mips) || defined(__mips__) || defined(__MIPS__) # define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* MIPS */ # elif defined(__m68k__) || defined(M68000) # define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 1 /* M68K */ # else # define YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS 0 # endif #endif /* Estimated initial ratio of the JSON data (data_size / value_count). For example: data: {"id":12345678,"name":"Harry"} data_size: 30 value_count: 5 ratio: 6 yyjson uses dynamic memory with a growth factor of 1.5 when reading and writing JSON, the ratios below are used to determine the initial memory size. A too large ratio will waste memory, and a too small ratio will cause multiple memory growths and degrade performance. Currently, these ratios are generated with some commonly used JSON datasets. */ #define YYJSON_READER_ESTIMATED_PRETTY_RATIO 16 #define YYJSON_READER_ESTIMATED_MINIFY_RATIO 6 #define YYJSON_WRITER_ESTIMATED_PRETTY_RATIO 32 #define YYJSON_WRITER_ESTIMATED_MINIFY_RATIO 18 /* The initial and maximum size of the memory pool's chunk in yyjson_mut_doc. */ #define YYJSON_MUT_DOC_STR_POOL_INIT_SIZE 0x100 #define YYJSON_MUT_DOC_STR_POOL_MAX_SIZE 0x10000000 #define YYJSON_MUT_DOC_VAL_POOL_INIT_SIZE (0x10 * sizeof(yyjson_mut_val)) #define YYJSON_MUT_DOC_VAL_POOL_MAX_SIZE (0x1000000 * sizeof(yyjson_mut_val)) /* The minimum size of the dynamic allocator's chunk. */ #define YYJSON_ALC_DYN_MIN_SIZE 0x1000 /* Default value for compile-time options. */ #ifndef YYJSON_DISABLE_READER #define YYJSON_DISABLE_READER 0 #endif #ifndef YYJSON_DISABLE_WRITER #define YYJSON_DISABLE_WRITER 0 #endif #ifndef YYJSON_DISABLE_UTILS #define YYJSON_DISABLE_UTILS 0 #endif #ifndef YYJSON_DISABLE_FAST_FP_CONV #define YYJSON_DISABLE_FAST_FP_CONV 0 #endif #ifndef YYJSON_DISABLE_NON_STANDARD #define YYJSON_DISABLE_NON_STANDARD 0 #endif #ifndef YYJSON_DISABLE_UTF8_VALIDATION #define YYJSON_DISABLE_UTF8_VALIDATION 0 #endif #ifndef YYJSON_READER_CONTAINER_RECURSION_LIMIT #define YYJSON_READER_CONTAINER_RECURSION_LIMIT 1024 #endif /*============================================================================== * Macros *============================================================================*/ /* Macros used for loop unrolling and other purpose. */ #define repeat2(x) { x x } #define repeat3(x) { x x x } #define repeat4(x) { x x x x } #define repeat8(x) { x x x x x x x x } #define repeat16(x) { x x x x x x x x x x x x x x x x } #define repeat2_incr(x) { x(0) x(1) } #define repeat4_incr(x) { x(0) x(1) x(2) x(3) } #define repeat8_incr(x) { x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) } #define repeat16_incr(x) { x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) \ x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) } #define repeat_in_1_18(x) { x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) \ x(9) x(10) x(11) x(12) x(13) x(14) x(15) x(16) \ x(17) x(18) } /* Macros used to provide branch prediction information for compiler. */ #undef likely #define likely(x) yyjson_likely(x) #undef unlikely #define unlikely(x) yyjson_unlikely(x) /* Macros used to provide inline information for compiler. */ #undef static_inline #define static_inline static yyjson_inline #undef static_noinline #define static_noinline static yyjson_noinline /* Macros for min and max. */ #undef yyjson_min #define yyjson_min(x, y) ((x) < (y) ? (x) : (y)) #undef yyjson_max #define yyjson_max(x, y) ((x) > (y) ? (x) : (y)) /* Used to write u64 literal for C89 which doesn't support "ULL" suffix. */ #undef U64 #define U64(hi, lo) ((((u64)hi##UL) << 32U) + lo##UL) /* Used to cast away (remove) const qualifier. */ #define constcast(type) (type)(void *)(size_t)(const void *) /* flag test */ #define has_read_flag(_flag) false #define has_write_flag(_flag) unlikely(write_flag_eq(flg, YYJSON_WRITE_##_flag)) static_inline bool read_flag_eq(yyjson_read_flag flg, yyjson_read_flag chk) { #if YYJSON_DISABLE_NON_STANDARD if (chk == YYJSON_READ_ALLOW_INF_AND_NAN || chk == YYJSON_READ_ALLOW_COMMENTS || chk == YYJSON_READ_ALLOW_TRAILING_COMMAS || chk == YYJSON_READ_ALLOW_INVALID_UNICODE) return false; /* this should be evaluated at compile-time */ #endif return (flg & chk) != 0; } static_inline bool write_flag_eq(yyjson_write_flag flg, yyjson_write_flag chk) { #if YYJSON_DISABLE_NON_STANDARD if (chk == YYJSON_WRITE_ALLOW_INF_AND_NAN || chk == YYJSON_WRITE_ALLOW_INVALID_UNICODE) return false; /* this should be evaluated at compile-time */ #endif return (flg & chk) != 0; } /*============================================================================== * Integer Constants *============================================================================*/ /* U64 constant values */ #undef U64_MAX #define U64_MAX U64(0xFFFFFFFF, 0xFFFFFFFF) #undef I64_MAX #define I64_MAX U64(0x7FFFFFFF, 0xFFFFFFFF) #undef USIZE_MAX #define USIZE_MAX ((usize)(~(usize)0)) /* Maximum number of digits for reading u32/u64/usize safety (not overflow). */ #undef U32_SAFE_DIG #define U32_SAFE_DIG 9 /* u32 max is 4294967295, 10 digits */ #undef U64_SAFE_DIG #define U64_SAFE_DIG 19 /* u64 max is 18446744073709551615, 20 digits */ #undef USIZE_SAFE_DIG #define USIZE_SAFE_DIG (sizeof(usize) == 8 ? U64_SAFE_DIG : U32_SAFE_DIG) /*============================================================================== * IEEE-754 Double Number Constants *============================================================================*/ /* Inf raw value (positive) */ #define F64_RAW_INF U64(0x7FF00000, 0x00000000) /* NaN raw value (quiet NaN, no payload, no sign) */ #if defined(__hppa__) || (defined(__mips__) && !defined(__mips_nan2008)) #define F64_RAW_NAN U64(0x7FF7FFFF, 0xFFFFFFFF) #else #define F64_RAW_NAN U64(0x7FF80000, 0x00000000) #endif /* double number bits */ #define F64_BITS 64 /* double number exponent part bits */ #define F64_EXP_BITS 11 /* double number significand part bits */ #define F64_SIG_BITS 52 /* double number significand part bits (with 1 hidden bit) */ #define F64_SIG_FULL_BITS 53 /* double number significand bit mask */ #define F64_SIG_MASK U64(0x000FFFFF, 0xFFFFFFFF) /* double number exponent bit mask */ #define F64_EXP_MASK U64(0x7FF00000, 0x00000000) /* double number exponent bias */ #define F64_EXP_BIAS 1023 /* double number significant digits count in decimal */ #define F64_DEC_DIG 17 /* max significant digits count in decimal when reading double number */ #define F64_MAX_DEC_DIG 768 /* maximum decimal power of double number (1.7976931348623157e308) */ #define F64_MAX_DEC_EXP 308 /* minimum decimal power of double number (4.9406564584124654e-324) */ #define F64_MIN_DEC_EXP (-324) /* maximum binary power of double number */ #define F64_MAX_BIN_EXP 1024 /* minimum binary power of double number */ #define F64_MIN_BIN_EXP (-1021) /*============================================================================== * Types *============================================================================*/ /** Type define for primitive types. */ typedef float f32; typedef double f64; typedef int8_t i8; typedef uint8_t u8; typedef int16_t i16; typedef uint16_t u16; typedef int32_t i32; typedef uint32_t u32; typedef int64_t i64; typedef uint64_t u64; typedef size_t usize; /** 128-bit integer, used by floating-point number reader and writer. */ #if YYJSON_HAS_INT128 __extension__ typedef __int128 i128; __extension__ typedef unsigned __int128 u128; #endif /** 16/32/64-bit vector */ typedef struct v16 { char c[2]; } v16; typedef struct v32 { char c[4]; } v32; typedef struct v64 { char c[8]; } v64; /** 16/32/64-bit vector union */ typedef union v16_uni { v16 v; u16 u; } v16_uni; typedef union v32_uni { v32 v; u32 u; } v32_uni; typedef union v64_uni { v64 v; u64 u; } v64_uni; /*============================================================================== * Load/Store Utils *============================================================================*/ #if YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS #define byte_move_idx(x) ((char *)dst)[x] = ((const char *)src)[x]; static_inline void byte_copy_2(void *dst, const void *src) { repeat2_incr(byte_move_idx) } static_inline void byte_copy_4(void *dst, const void *src) { repeat4_incr(byte_move_idx) } static_inline void byte_copy_8(void *dst, const void *src) { repeat8_incr(byte_move_idx) } static_inline void byte_copy_16(void *dst, const void *src) { repeat16_incr(byte_move_idx) } static_inline void byte_move_2(void *dst, const void *src) { repeat2_incr(byte_move_idx) } static_inline void byte_move_4(void *dst, const void *src) { repeat4_incr(byte_move_idx) } static_inline void byte_move_8(void *dst, const void *src) { repeat8_incr(byte_move_idx) } static_inline void byte_move_16(void *dst, const void *src) { repeat16_incr(byte_move_idx) } static_inline bool byte_match_2(void *buf, const char *pat) { return ((char *)buf)[0] == ((const char *)pat)[0] && ((char *)buf)[1] == ((const char *)pat)[1]; } static_inline bool byte_match_4(void *buf, const char *pat) { return ((char *)buf)[0] == ((const char *)pat)[0] && ((char *)buf)[1] == ((const char *)pat)[1] && ((char *)buf)[2] == ((const char *)pat)[2] && ((char *)buf)[3] == ((const char *)pat)[3]; } static_inline u16 byte_load_2(const void *src) { v16_uni uni; uni.v.c[0] = ((const char *)src)[0]; uni.v.c[1] = ((const char *)src)[1]; return uni.u; } static_inline u32 byte_load_3(const void *src) { v32_uni uni; uni.v.c[0] = ((const char *)src)[0]; uni.v.c[1] = ((const char *)src)[1]; uni.v.c[2] = ((const char *)src)[2]; uni.v.c[3] = 0; return uni.u; } static_inline u32 byte_load_4(const void *src) { v32_uni uni; uni.v.c[0] = ((const char *)src)[0]; uni.v.c[1] = ((const char *)src)[1]; uni.v.c[2] = ((const char *)src)[2]; uni.v.c[3] = ((const char *)src)[3]; return uni.u; } #undef byte_move_expr #else static_inline void byte_copy_2(void *dst, const void *src) { memcpy(dst, src, 2); } static_inline void byte_copy_4(void *dst, const void *src) { memcpy(dst, src, 4); } static_inline void byte_copy_8(void *dst, const void *src) { memcpy(dst, src, 8); } static_inline void byte_copy_16(void *dst, const void *src) { memcpy(dst, src, 16); } static_inline void byte_move_2(void *dst, const void *src) { u16 tmp; memcpy(&tmp, src, 2); memcpy(dst, &tmp, 2); } static_inline void byte_move_4(void *dst, const void *src) { u32 tmp; memcpy(&tmp, src, 4); memcpy(dst, &tmp, 4); } static_inline void byte_move_8(void *dst, const void *src) { u64 tmp; memcpy(&tmp, src, 8); memcpy(dst, &tmp, 8); } static_inline void byte_move_16(void *dst, const void *src) { char *pdst = (char *)dst; const char *psrc = (const char *)src; u64 tmp1, tmp2; memcpy(&tmp1, psrc, 8); memcpy(&tmp2, psrc + 8, 8); memcpy(pdst, &tmp1, 8); memcpy(pdst + 8, &tmp2, 8); } static_inline bool byte_match_2(void *buf, const char *pat) { v16_uni u1, u2; memcpy(&u1, buf, 2); memcpy(&u2, pat, 2); return u1.u == u2.u; } static_inline bool byte_match_4(void *buf, const char *pat) { v32_uni u1, u2; memcpy(&u1, buf, 4); memcpy(&u2, pat, 4); return u1.u == u2.u; } static_inline u16 byte_load_2(const void *src) { v16_uni uni; memcpy(&uni, src, 2); return uni.u; } static_inline u32 byte_load_3(const void *src) { v32_uni uni; memcpy(&uni, src, 2); uni.v.c[2] = ((const char *)src)[2]; uni.v.c[3] = 0; return uni.u; } static_inline u32 byte_load_4(const void *src) { v32_uni uni; memcpy(&uni, src, 4); return uni.u; } #endif /*============================================================================== * Number Utils * These functions are used to detect and convert NaN and Inf numbers. *============================================================================*/ /** Convert raw binary to double. */ static_inline f64 f64_from_raw(u64 u) { /* use memcpy to avoid violating the strict aliasing rule */ f64 f; memcpy(&f, &u, 8); return f; } /** Convert double to raw binary. */ static_inline u64 f64_to_raw(f64 f) { /* use memcpy to avoid violating the strict aliasing rule */ u64 u; memcpy(&u, &f, 8); return u; } /** Get raw 'infinity' with sign. */ static_inline u64 f64_raw_get_inf(bool sign) { #if YYJSON_HAS_IEEE_754 return F64_RAW_INF | ((u64)sign << 63); #elif defined(INFINITY) return f64_to_raw(sign ? -INFINITY : INFINITY); #else return f64_to_raw(sign ? -HUGE_VAL : HUGE_VAL); #endif } /** Get raw 'nan' with sign. */ static_inline u64 f64_raw_get_nan(bool sign) { #if YYJSON_HAS_IEEE_754 return F64_RAW_NAN | ((u64)sign << 63); #elif defined(NAN) return f64_to_raw(sign ? (f64)-NAN : (f64)NAN); #else return f64_to_raw((sign ? -0.0 : 0.0) / 0.0); #endif } /** Convert normalized u64 (highest bit is 1) to f64. Some compiler (such as Microsoft Visual C++ 6.0) do not support converting number from u64 to f64. This function will first convert u64 to i64 and then to f64, with `to nearest` rounding mode. */ static_inline f64 normalized_u64_to_f64(u64 val) { #if YYJSON_U64_TO_F64_NO_IMPL i64 sig = (i64)((val >> 1) | (val & 1)); return ((f64)sig) * (f64)2.0; #else return (f64)val; #endif } /*============================================================================== * Size Utils * These functions are used for memory allocation. *============================================================================*/ /** Returns whether the size is overflow after increment. */ static_inline bool size_add_is_overflow(usize size, usize add) { return size > (size + add); } /** Returns whether the size is power of 2 (size should not be 0). */ static_inline bool size_is_pow2(usize size) { return (size & (size - 1)) == 0; } /** Align size upwards (may overflow). */ static_inline usize size_align_up(usize size, usize align) { if (size_is_pow2(align)) { return (size + (align - 1)) & ~(align - 1); } else { return size + align - (size + align - 1) % align - 1; } } /** Align size downwards. */ static_inline usize size_align_down(usize size, usize align) { if (size_is_pow2(align)) { return size & ~(align - 1); } else { return size - (size % align); } } /** Align address upwards (may overflow). */ static_inline void *mem_align_up(void *mem, usize align) { usize size; memcpy(&size, &mem, sizeof(usize)); size = size_align_up(size, align); memcpy(&mem, &size, sizeof(usize)); return mem; } /*============================================================================== * Bits Utils * These functions are used by the floating-point number reader and writer. *============================================================================*/ /** Returns the number of leading 0-bits in value (input should not be 0). */ static_inline u32 u64_lz_bits(u64 v) { #if GCC_HAS_CLZLL return (u32)__builtin_clzll(v); #elif MSC_HAS_BIT_SCAN_64 unsigned long r; _BitScanReverse64(&r, v); return (u32)63 - (u32)r; #elif MSC_HAS_BIT_SCAN unsigned long hi, lo; bool hi_set = _BitScanReverse(&hi, (u32)(v >> 32)) != 0; _BitScanReverse(&lo, (u32)v); hi |= 32; return (u32)63 - (u32)(hi_set ? hi : lo); #else /* branchless, use de Bruijn sequences see: https://www.chessprogramming.org/BitScan */ const u8 table[64] = { 63, 16, 62, 7, 15, 36, 61, 3, 6, 14, 22, 26, 35, 47, 60, 2, 9, 5, 28, 11, 13, 21, 42, 19, 25, 31, 34, 40, 46, 52, 59, 1, 17, 8, 37, 4, 23, 27, 48, 10, 29, 12, 43, 20, 32, 41, 53, 18, 38, 24, 49, 30, 44, 33, 54, 39, 50, 45, 55, 51, 56, 57, 58, 0 }; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v |= v >> 32; return table[(v * U64(0x03F79D71, 0xB4CB0A89)) >> 58]; #endif } /** Returns the number of trailing 0-bits in value (input should not be 0). */ static_inline u32 u64_tz_bits(u64 v) { #if GCC_HAS_CTZLL return (u32)__builtin_ctzll(v); #elif MSC_HAS_BIT_SCAN_64 unsigned long r; _BitScanForward64(&r, v); return (u32)r; #elif MSC_HAS_BIT_SCAN unsigned long lo, hi; bool lo_set = _BitScanForward(&lo, (u32)(v)) != 0; _BitScanForward(&hi, (u32)(v >> 32)); hi += 32; return lo_set ? lo : hi; #else /* branchless, use de Bruijn sequences see: https://www.chessprogramming.org/BitScan */ const u8 table[64] = { 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 }; return table[((v & (~v + 1)) * U64(0x022FDD63, 0xCC95386D)) >> 58]; #endif } /*============================================================================== * 128-bit Integer Utils * These functions are used by the floating-point number reader and writer. *============================================================================*/ /** Multiplies two 64-bit unsigned integers (a * b), returns the 128-bit result as 'hi' and 'lo'. */ static_inline void u128_mul(u64 a, u64 b, u64 *hi, u64 *lo) { #if YYJSON_HAS_INT128 u128 m = (u128)a * b; *hi = (u64)(m >> 64); *lo = (u64)(m); #elif MSC_HAS_UMUL128 *lo = _umul128(a, b, hi); #else u32 a0 = (u32)(a), a1 = (u32)(a >> 32); u32 b0 = (u32)(b), b1 = (u32)(b >> 32); u64 p00 = (u64)a0 * b0, p01 = (u64)a0 * b1; u64 p10 = (u64)a1 * b0, p11 = (u64)a1 * b1; u64 m0 = p01 + (p00 >> 32); u32 m00 = (u32)(m0), m01 = (u32)(m0 >> 32); u64 m1 = p10 + m00; u32 m10 = (u32)(m1), m11 = (u32)(m1 >> 32); *hi = p11 + m01 + m11; *lo = ((u64)m10 << 32) | (u32)p00; #endif } /** Multiplies two 64-bit unsigned integers and add a value (a * b + c), returns the 128-bit result as 'hi' and 'lo'. */ static_inline void u128_mul_add(u64 a, u64 b, u64 c, u64 *hi, u64 *lo) { #if YYJSON_HAS_INT128 u128 m = (u128)a * b + c; *hi = (u64)(m >> 64); *lo = (u64)(m); #else u64 h, l, t; u128_mul(a, b, &h, &l); t = l + c; h += (u64)(((t < l) | (t < c))); *hi = h; *lo = t; #endif } /*============================================================================== * File Utils * These functions are used to read and write JSON files. *============================================================================*/ #define YYJSON_FOPEN_EXT #if !defined(_MSC_VER) && defined(__GLIBC__) && defined(__GLIBC_PREREQ) # if __GLIBC_PREREQ(2, 7) # undef YYJSON_FOPEN_EXT # define YYJSON_FOPEN_EXT "e" /* glibc extension to enable O_CLOEXEC */ # endif #endif static_inline FILE *fopen_safe(const char *path, const char *mode) { #if YYJSON_MSC_VER >= 1400 FILE *file = NULL; if (fopen_s(&file, path, mode) != 0) return NULL; return file; #else return fopen(path, mode); #endif } static_inline FILE *fopen_readonly(const char *path) { return fopen_safe(path, "rb" YYJSON_FOPEN_EXT); } static_inline FILE *fopen_writeonly(const char *path) { return fopen_safe(path, "wb" YYJSON_FOPEN_EXT); } static_inline usize fread_safe(void *buf, usize size, FILE *file) { #if YYJSON_MSC_VER >= 1400 return fread_s(buf, size, 1, size, file); #else return fread(buf, 1, size, file); #endif } /*============================================================================== * Default Memory Allocator * This is a simple libc memory allocator wrapper. *============================================================================*/ static void *default_malloc(void *ctx, usize size) { return malloc(size); } static void *default_realloc(void *ctx, void *ptr, usize old_size, usize size) { return realloc(ptr, size); } static void default_free(void *ctx, void *ptr) { free(ptr); } static const yyjson_alc YYJSON_DEFAULT_ALC = { default_malloc, default_realloc, default_free, NULL }; /*============================================================================== * Null Memory Allocator * * This allocator is just a placeholder to ensure that the internal * malloc/realloc/free function pointers are not null. *============================================================================*/ static void *null_malloc(void *ctx, usize size) { return NULL; } static void *null_realloc(void *ctx, void *ptr, usize old_size, usize size) { return NULL; } static void null_free(void *ctx, void *ptr) { return; } static const yyjson_alc YYJSON_NULL_ALC = { null_malloc, null_realloc, null_free, NULL }; /*============================================================================== * Pool Memory Allocator * * This allocator is initialized with a fixed-size buffer. * The buffer is split into multiple memory chunks for memory allocation. *============================================================================*/ /** memory chunk header */ typedef struct pool_chunk { usize size; /* chunk memory size, include chunk header */ struct pool_chunk *next; /* linked list, nullable */ /* char mem[]; flexible array member */ } pool_chunk; /** allocator ctx header */ typedef struct pool_ctx { usize size; /* total memory size, include ctx header */ pool_chunk *free_list; /* linked list, nullable */ /* pool_chunk chunks[]; flexible array member */ } pool_ctx; /** align up the input size to chunk size */ static_inline void pool_size_align(usize *size) { *size = size_align_up(*size, sizeof(pool_chunk)) + sizeof(pool_chunk); } static void *pool_malloc(void *ctx_ptr, usize size) { /* assert(size != 0) */ pool_ctx *ctx = (pool_ctx *)ctx_ptr; pool_chunk *next, *prev = NULL, *cur = ctx->free_list; if (unlikely(size >= ctx->size)) return NULL; pool_size_align(&size); while (cur) { if (cur->size < size) { /* not enough space, try next chunk */ prev = cur; cur = cur->next; continue; } if (cur->size >= size + sizeof(pool_chunk) * 2) { /* too much space, split this chunk */ next = (pool_chunk *)(void *)((u8 *)cur + size); next->size = cur->size - size; next->next = cur->next; cur->size = size; } else { /* just enough space, use whole chunk */ next = cur->next; } if (prev) prev->next = next; else ctx->free_list = next; return (void *)(cur + 1); } return NULL; } static void pool_free(void *ctx_ptr, void *ptr) { /* assert(ptr != NULL) */ pool_ctx *ctx = (pool_ctx *)ctx_ptr; pool_chunk *cur = ((pool_chunk *)ptr) - 1; pool_chunk *prev = NULL, *next = ctx->free_list; while (next && next < cur) { prev = next; next = next->next; } if (prev) prev->next = cur; else ctx->free_list = cur; cur->next = next; if (next && ((u8 *)cur + cur->size) == (u8 *)next) { /* merge cur to higher chunk */ cur->size += next->size; cur->next = next->next; } if (prev && ((u8 *)prev + prev->size) == (u8 *)cur) { /* merge cur to lower chunk */ prev->size += cur->size; prev->next = cur->next; } } static void *pool_realloc(void *ctx_ptr, void *ptr, usize old_size, usize size) { /* assert(ptr != NULL && size != 0 && old_size < size) */ pool_ctx *ctx = (pool_ctx *)ctx_ptr; pool_chunk *cur = ((pool_chunk *)ptr) - 1, *prev, *next, *tmp; /* check size */ if (unlikely(size >= ctx->size)) return NULL; pool_size_align(&old_size); pool_size_align(&size); if (unlikely(old_size == size)) return ptr; /* find next and prev chunk */ prev = NULL; next = ctx->free_list; while (next && next < cur) { prev = next; next = next->next; } if ((u8 *)cur + cur->size == (u8 *)next && cur->size + next->size >= size) { /* merge to higher chunk if they are contiguous */ usize free_size = cur->size + next->size - size; if (free_size > sizeof(pool_chunk) * 2) { tmp = (pool_chunk *)(void *)((u8 *)cur + size); if (prev) prev->next = tmp; else ctx->free_list = tmp; tmp->next = next->next; tmp->size = free_size; cur->size = size; } else { if (prev) prev->next = next->next; else ctx->free_list = next->next; cur->size += next->size; } return ptr; } else { /* fallback to malloc and memcpy */ void *new_ptr = pool_malloc(ctx_ptr, size - sizeof(pool_chunk)); if (new_ptr) { memcpy(new_ptr, ptr, cur->size - sizeof(pool_chunk)); pool_free(ctx_ptr, ptr); } return new_ptr; } } bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, usize size) { pool_chunk *chunk; pool_ctx *ctx; if (unlikely(!alc)) return false; *alc = YYJSON_NULL_ALC; if (size < sizeof(pool_ctx) * 4) return false; ctx = (pool_ctx *)mem_align_up(buf, sizeof(pool_ctx)); if (unlikely(!ctx)) return false; size -= (usize)((u8 *)ctx - (u8 *)buf); size = size_align_down(size, sizeof(pool_ctx)); chunk = (pool_chunk *)(ctx + 1); chunk->size = size - sizeof(pool_ctx); chunk->next = NULL; ctx->size = size; ctx->free_list = chunk; alc->malloc = pool_malloc; alc->realloc = pool_realloc; alc->free = pool_free; alc->ctx = (void *)ctx; return true; } /*============================================================================== * Dynamic Memory Allocator * * This allocator allocates memory on demand and does not immediately release * unused memory. Instead, it places the unused memory into a freelist for * potential reuse in the future. It is only when the entire allocator is * destroyed that all previously allocated memory is released at once. *============================================================================*/ /** memory chunk header */ typedef struct dyn_chunk { usize size; /* chunk size, include header */ struct dyn_chunk *next; /* char mem[]; flexible array member */ } dyn_chunk; /** allocator ctx header */ typedef struct { dyn_chunk free_list; /* dummy header, sorted from small to large */ dyn_chunk used_list; /* dummy header */ } dyn_ctx; /** align up the input size to chunk size */ static_inline bool dyn_size_align(usize *size) { usize alc_size = *size + sizeof(dyn_chunk); alc_size = size_align_up(alc_size, YYJSON_ALC_DYN_MIN_SIZE); if (unlikely(alc_size < *size)) return false; /* overflow */ *size = alc_size; return true; } /** remove a chunk from list (the chunk must already be in the list) */ static_inline void dyn_chunk_list_remove(dyn_chunk *list, dyn_chunk *chunk) { dyn_chunk *prev = list, *cur; for (cur = prev->next; cur; cur = cur->next) { if (cur == chunk) { prev->next = cur->next; cur->next = NULL; return; } prev = cur; } } /** add a chunk to list header (the chunk must not be in the list) */ static_inline void dyn_chunk_list_add(dyn_chunk *list, dyn_chunk *chunk) { chunk->next = list->next; list->next = chunk; } static void *dyn_malloc(void *ctx_ptr, usize size) { /* assert(size != 0) */ const yyjson_alc def = YYJSON_DEFAULT_ALC; dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; dyn_chunk *chunk, *prev, *next; if (unlikely(!dyn_size_align(&size))) return NULL; /* freelist is empty, create new chunk */ if (!ctx->free_list.next) { chunk = (dyn_chunk *)def.malloc(def.ctx, size); if (unlikely(!chunk)) return NULL; chunk->size = size; chunk->next = NULL; dyn_chunk_list_add(&ctx->used_list, chunk); return (void *)(chunk + 1); } /* find a large enough chunk, or resize the largest chunk */ prev = &ctx->free_list; while (true) { chunk = prev->next; if (chunk->size >= size) { /* enough size, reuse this chunk */ prev->next = chunk->next; dyn_chunk_list_add(&ctx->used_list, chunk); return (void *)(chunk + 1); } if (!chunk->next) { /* resize the largest chunk */ chunk = (dyn_chunk *)def.realloc(def.ctx, chunk, chunk->size, size); if (unlikely(!chunk)) return NULL; prev->next = NULL; chunk->size = size; dyn_chunk_list_add(&ctx->used_list, chunk); return (void *)(chunk + 1); } prev = chunk; } } static void *dyn_realloc(void *ctx_ptr, void *ptr, usize old_size, usize size) { /* assert(ptr != NULL && size != 0 && old_size < size) */ const yyjson_alc def = YYJSON_DEFAULT_ALC; dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; dyn_chunk *prev, *next, *new_chunk; dyn_chunk *chunk = (dyn_chunk *)ptr - 1; if (unlikely(!dyn_size_align(&size))) return NULL; if (chunk->size >= size) return ptr; dyn_chunk_list_remove(&ctx->used_list, chunk); new_chunk = (dyn_chunk *)def.realloc(def.ctx, chunk, chunk->size, size); if (likely(new_chunk)) { new_chunk->size = size; chunk = new_chunk; } dyn_chunk_list_add(&ctx->used_list, chunk); return new_chunk ? (void *)(new_chunk + 1) : NULL; } static void dyn_free(void *ctx_ptr, void *ptr) { /* assert(ptr != NULL) */ dyn_ctx *ctx = (dyn_ctx *)ctx_ptr; dyn_chunk *chunk = (dyn_chunk *)ptr - 1, *prev; dyn_chunk_list_remove(&ctx->used_list, chunk); for (prev = &ctx->free_list; prev; prev = prev->next) { if (!prev->next || prev->next->size >= chunk->size) { chunk->next = prev->next; prev->next = chunk; break; } } } yyjson_alc *yyjson_alc_dyn_new(void) { const yyjson_alc def = YYJSON_DEFAULT_ALC; usize hdr_len = sizeof(yyjson_alc) + sizeof(dyn_ctx); yyjson_alc *alc = (yyjson_alc *)def.malloc(def.ctx, hdr_len); dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1); if (unlikely(!alc)) return NULL; alc->malloc = dyn_malloc; alc->realloc = dyn_realloc; alc->free = dyn_free; alc->ctx = alc + 1; memset(ctx, 0, sizeof(*ctx)); return alc; } void yyjson_alc_dyn_free(yyjson_alc *alc) { const yyjson_alc def = YYJSON_DEFAULT_ALC; dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1); dyn_chunk *chunk, *next; if (unlikely(!alc)) return; for (chunk = ctx->free_list.next; chunk; chunk = next) { next = chunk->next; def.free(def.ctx, chunk); } for (chunk = ctx->used_list.next; chunk; chunk = next) { next = chunk->next; def.free(def.ctx, chunk); } def.free(def.ctx, alc); } /*============================================================================== * JSON document and value *============================================================================*/ static_inline void unsafe_yyjson_str_pool_release(yyjson_str_pool *pool, yyjson_alc *alc) { yyjson_str_chunk *chunk = pool->chunks, *next; while (chunk) { next = chunk->next; alc->free(alc->ctx, chunk); chunk = next; } } static_inline void unsafe_yyjson_val_pool_release(yyjson_val_pool *pool, yyjson_alc *alc) { yyjson_val_chunk *chunk = pool->chunks, *next; while (chunk) { next = chunk->next; alc->free(alc->ctx, chunk); chunk = next; } } bool unsafe_yyjson_str_pool_grow(yyjson_str_pool *pool, const yyjson_alc *alc, usize len) { yyjson_str_chunk *chunk; usize size, max_len; /* create a new chunk */ max_len = USIZE_MAX - sizeof(yyjson_str_chunk); if (unlikely(len > max_len)) return false; size = len + sizeof(yyjson_str_chunk); size = yyjson_max(pool->chunk_size, size); chunk = (yyjson_str_chunk *)alc->malloc(alc->ctx, size); if (unlikely(!chunk)) return false; /* insert the new chunk as the head of the linked list */ chunk->next = pool->chunks; chunk->chunk_size = size; pool->chunks = chunk; pool->cur = (char *)chunk + sizeof(yyjson_str_chunk); pool->end = (char *)chunk + size; /* the next chunk is twice the size of the current one */ size = yyjson_min(pool->chunk_size * 2, pool->chunk_size_max); if (size < pool->chunk_size) size = pool->chunk_size_max; /* overflow */ pool->chunk_size = size; return true; } bool unsafe_yyjson_val_pool_grow(yyjson_val_pool *pool, const yyjson_alc *alc, usize count) { yyjson_val_chunk *chunk; usize size, max_count; /* create a new chunk */ max_count = USIZE_MAX / sizeof(yyjson_mut_val) - 1; if (unlikely(count > max_count)) return false; size = (count + 1) * sizeof(yyjson_mut_val); size = yyjson_max(pool->chunk_size, size); chunk = (yyjson_val_chunk *)alc->malloc(alc->ctx, size); if (unlikely(!chunk)) return false; /* insert the new chunk as the head of the linked list */ chunk->next = pool->chunks; chunk->chunk_size = size; pool->chunks = chunk; pool->cur = (yyjson_mut_val *)(void *)((u8 *)chunk) + 1; pool->end = (yyjson_mut_val *)(void *)((u8 *)chunk + size); /* the next chunk is twice the size of the current one */ size = yyjson_min(pool->chunk_size * 2, pool->chunk_size_max); if (size < pool->chunk_size) size = pool->chunk_size_max; /* overflow */ pool->chunk_size = size; return true; } bool yyjson_mut_doc_set_str_pool_size(yyjson_mut_doc *doc, size_t len) { usize max_size = USIZE_MAX - sizeof(yyjson_str_chunk); if (!doc || !len || len > max_size) return false; doc->str_pool.chunk_size = len + sizeof(yyjson_str_chunk); return true; } bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, size_t count) { usize max_count = USIZE_MAX / sizeof(yyjson_mut_val) - 1; if (!doc || !count || count > max_count) return false; doc->val_pool.chunk_size = (count + 1) * sizeof(yyjson_mut_val); return true; } void yyjson_mut_doc_free(yyjson_mut_doc *doc) { if (doc) { yyjson_alc alc = doc->alc; memset(&doc->alc, 0, sizeof(alc)); unsafe_yyjson_str_pool_release(&doc->str_pool, &alc); unsafe_yyjson_val_pool_release(&doc->val_pool, &alc); alc.free(alc.ctx, doc); } } yyjson_mut_doc *yyjson_mut_doc_new(const yyjson_alc *alc) { yyjson_mut_doc *doc; if (!alc) alc = &YYJSON_DEFAULT_ALC; doc = (yyjson_mut_doc *)alc->malloc(alc->ctx, sizeof(yyjson_mut_doc)); if (!doc) return NULL; memset(doc, 0, sizeof(yyjson_mut_doc)); doc->alc = *alc; doc->str_pool.chunk_size = YYJSON_MUT_DOC_STR_POOL_INIT_SIZE; doc->str_pool.chunk_size_max = YYJSON_MUT_DOC_STR_POOL_MAX_SIZE; doc->val_pool.chunk_size = YYJSON_MUT_DOC_VAL_POOL_INIT_SIZE; doc->val_pool.chunk_size_max = YYJSON_MUT_DOC_VAL_POOL_MAX_SIZE; return doc; } yyjson_mut_doc *yyjson_doc_mut_copy(yyjson_doc *doc, const yyjson_alc *alc) { yyjson_mut_doc *m_doc; yyjson_mut_val *m_val; if (!doc || !doc->root) return NULL; m_doc = yyjson_mut_doc_new(alc); if (!m_doc) return NULL; m_val = yyjson_val_mut_copy(m_doc, doc->root); if (!m_val) { yyjson_mut_doc_free(m_doc); return NULL; } yyjson_mut_doc_set_root(m_doc, m_val); return m_doc; } yyjson_mut_doc *yyjson_mut_doc_mut_copy(yyjson_mut_doc *doc, const yyjson_alc *alc) { yyjson_mut_doc *m_doc; yyjson_mut_val *m_val; if (!doc) return NULL; if (!doc->root) return yyjson_mut_doc_new(alc); m_doc = yyjson_mut_doc_new(alc); if (!m_doc) return NULL; m_val = yyjson_mut_val_mut_copy(m_doc, doc->root); if (!m_val) { yyjson_mut_doc_free(m_doc); return NULL; } yyjson_mut_doc_set_root(m_doc, m_val); return m_doc; } yyjson_mut_val *yyjson_val_mut_copy(yyjson_mut_doc *m_doc, yyjson_val *i_vals) { /* The immutable object or array stores all sub-values in a contiguous memory, We copy them to another contiguous memory as mutable values, then reconnect the mutable values with the original relationship. */ usize i_vals_len; yyjson_mut_val *m_vals, *m_val; yyjson_val *i_val, *i_end; if (!m_doc || !i_vals) return NULL; i_end = unsafe_yyjson_get_next(i_vals); i_vals_len = (usize)(unsafe_yyjson_get_next(i_vals) - i_vals); m_vals = unsafe_yyjson_mut_val(m_doc, i_vals_len); if (!m_vals) return NULL; i_val = i_vals; m_val = m_vals; for (; i_val < i_end; i_val++, m_val++) { yyjson_type type = unsafe_yyjson_get_type(i_val); m_val->tag = i_val->tag; m_val->uni.u64 = i_val->uni.u64; if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { const char *str = i_val->uni.str; usize str_len = unsafe_yyjson_get_len(i_val); m_val->uni.str = unsafe_yyjson_mut_strncpy(m_doc, str, str_len); if (!m_val->uni.str) return NULL; } else if (type == YYJSON_TYPE_ARR) { usize len = unsafe_yyjson_get_len(i_val); if (len > 0) { yyjson_val *ii_val = i_val + 1, *ii_next; yyjson_mut_val *mm_val = m_val + 1, *mm_ctn = m_val, *mm_next; while (len-- > 1) { ii_next = unsafe_yyjson_get_next(ii_val); mm_next = mm_val + (ii_next - ii_val); mm_val->next = mm_next; ii_val = ii_next; mm_val = mm_next; } mm_val->next = mm_ctn + 1; mm_ctn->uni.ptr = mm_val; } } else if (type == YYJSON_TYPE_OBJ) { usize len = unsafe_yyjson_get_len(i_val); if (len > 0) { yyjson_val *ii_key = i_val + 1, *ii_nextkey; yyjson_mut_val *mm_key = m_val + 1, *mm_ctn = m_val; yyjson_mut_val *mm_nextkey; while (len-- > 1) { ii_nextkey = unsafe_yyjson_get_next(ii_key + 1); mm_nextkey = mm_key + (ii_nextkey - ii_key); mm_key->next = mm_key + 1; mm_key->next->next = mm_nextkey; ii_key = ii_nextkey; mm_key = mm_nextkey; } mm_key->next = mm_key + 1; mm_key->next->next = mm_ctn + 1; mm_ctn->uni.ptr = mm_key; } } } return m_vals; } static yyjson_mut_val *unsafe_yyjson_mut_val_mut_copy(yyjson_mut_doc *m_doc, yyjson_mut_val *m_vals) { /* The mutable object or array stores all sub-values in a circular linked list, so we can traverse them in the same loop. The traversal starts from the last item, continues with the first item in a list, and ends with the second to last item, which needs to be linked to the last item to close the circle. */ yyjson_mut_val *m_val = unsafe_yyjson_mut_val(m_doc, 1); if (unlikely(!m_val)) return NULL; m_val->tag = m_vals->tag; switch (unsafe_yyjson_get_type(m_vals)) { case YYJSON_TYPE_OBJ: case YYJSON_TYPE_ARR: if (unsafe_yyjson_get_len(m_vals) > 0) { yyjson_mut_val *last = (yyjson_mut_val *)m_vals->uni.ptr; yyjson_mut_val *next = last->next, *prev; prev = unsafe_yyjson_mut_val_mut_copy(m_doc, last); if (!prev) return NULL; m_val->uni.ptr = (void *)prev; while (next != last) { prev->next = unsafe_yyjson_mut_val_mut_copy(m_doc, next); if (!prev->next) return NULL; prev = prev->next; next = next->next; } prev->next = (yyjson_mut_val *)m_val->uni.ptr; } break; case YYJSON_TYPE_RAW: case YYJSON_TYPE_STR: { const char *str = m_vals->uni.str; usize str_len = unsafe_yyjson_get_len(m_vals); m_val->uni.str = unsafe_yyjson_mut_strncpy(m_doc, str, str_len); if (!m_val->uni.str) return NULL; break; } default: m_val->uni = m_vals->uni; break; } return m_val; } yyjson_mut_val *yyjson_mut_val_mut_copy(yyjson_mut_doc *doc, yyjson_mut_val *val) { if (doc && val) return unsafe_yyjson_mut_val_mut_copy(doc, val); return NULL; } /* Count the number of values and the total length of the strings. */ static void yyjson_mut_stat(yyjson_mut_val *val, usize *val_sum, usize *str_sum) { yyjson_type type = unsafe_yyjson_get_type(val); *val_sum += 1; if (type == YYJSON_TYPE_ARR || type == YYJSON_TYPE_OBJ) { yyjson_mut_val *child = (yyjson_mut_val *)val->uni.ptr; usize len = unsafe_yyjson_get_len(val), i; len <<= (u8)(type == YYJSON_TYPE_OBJ); *val_sum += len; for (i = 0; i < len; i++) { yyjson_type stype = unsafe_yyjson_get_type(child); if (stype == YYJSON_TYPE_STR || stype == YYJSON_TYPE_RAW) { *str_sum += unsafe_yyjson_get_len(child) + 1; } else if (stype == YYJSON_TYPE_ARR || stype == YYJSON_TYPE_OBJ) { yyjson_mut_stat(child, val_sum, str_sum); *val_sum -= 1; } child = child->next; } } else if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { *str_sum += unsafe_yyjson_get_len(val) + 1; } } /* Copy mutable values to immutable value pool. */ static usize yyjson_imut_copy(yyjson_val **val_ptr, char **buf_ptr, yyjson_mut_val *mval) { yyjson_val *val = *val_ptr; yyjson_type type = unsafe_yyjson_get_type(mval); if (type == YYJSON_TYPE_ARR || type == YYJSON_TYPE_OBJ) { yyjson_mut_val *child = (yyjson_mut_val *)mval->uni.ptr; usize len = unsafe_yyjson_get_len(mval), i; usize val_sum = 1; if (type == YYJSON_TYPE_OBJ) { if (len) child = child->next->next; len <<= 1; } else { if (len) child = child->next; } *val_ptr = val + 1; for (i = 0; i < len; i++) { val_sum += yyjson_imut_copy(val_ptr, buf_ptr, child); child = child->next; } val->tag = mval->tag; val->uni.ofs = val_sum * sizeof(yyjson_val); return val_sum; } else if (type == YYJSON_TYPE_STR || type == YYJSON_TYPE_RAW) { char *buf = *buf_ptr; usize len = unsafe_yyjson_get_len(mval); memcpy((void *)buf, (const void *)mval->uni.str, len); buf[len] = '\0'; val->tag = mval->tag; val->uni.str = buf; *val_ptr = val + 1; *buf_ptr = buf + len + 1; return 1; } else { val->tag = mval->tag; val->uni = mval->uni; *val_ptr = val + 1; return 1; } } yyjson_doc *yyjson_mut_doc_imut_copy(yyjson_mut_doc *mdoc, const yyjson_alc *alc) { if (!mdoc) return NULL; return yyjson_mut_val_imut_copy(mdoc->root, alc); } yyjson_doc *yyjson_mut_val_imut_copy(yyjson_mut_val *mval, const yyjson_alc *alc) { usize val_num = 0, str_sum = 0, hdr_size, buf_size; yyjson_doc *doc = NULL; yyjson_val *val_hdr = NULL; /* This value should be NULL here. Setting a non-null value suppresses warning from the clang analyzer. */ char *str_hdr = (char *)(void *)&str_sum; if (!mval) return NULL; if (!alc) alc = &YYJSON_DEFAULT_ALC; /* traverse the input value to get pool size */ yyjson_mut_stat(mval, &val_num, &str_sum); /* create doc and val pool */ hdr_size = size_align_up(sizeof(yyjson_doc), sizeof(yyjson_val)); buf_size = hdr_size + val_num * sizeof(yyjson_val); doc = (yyjson_doc *)alc->malloc(alc->ctx, buf_size); if (!doc) return NULL; memset(doc, 0, sizeof(yyjson_doc)); val_hdr = (yyjson_val *)(void *)((char *)(void *)doc + hdr_size); doc->root = val_hdr; doc->alc = *alc; /* create str pool */ if (str_sum > 0) { str_hdr = (char *)alc->malloc(alc->ctx, str_sum); doc->str_pool = str_hdr; if (!str_hdr) { alc->free(alc->ctx, (void *)doc); return NULL; } } /* copy vals and strs */ doc->val_read = yyjson_imut_copy(&val_hdr, &str_hdr, mval); doc->dat_read = str_sum + 1; return doc; } static_inline bool unsafe_yyjson_num_equals(void *lhs, void *rhs) { yyjson_val_uni *luni = &((yyjson_val *)lhs)->uni; yyjson_val_uni *runi = &((yyjson_val *)rhs)->uni; yyjson_subtype lt = unsafe_yyjson_get_subtype(lhs); yyjson_subtype rt = unsafe_yyjson_get_subtype(rhs); if (lt == rt) return luni->u64 == runi->u64; if (lt == YYJSON_SUBTYPE_SINT && rt == YYJSON_SUBTYPE_UINT) { return luni->i64 >= 0 && luni->u64 == runi->u64; } if (lt == YYJSON_SUBTYPE_UINT && rt == YYJSON_SUBTYPE_SINT) { return runi->i64 >= 0 && luni->u64 == runi->u64; } return false; } static_inline bool unsafe_yyjson_str_equals(void *lhs, void *rhs) { usize len = unsafe_yyjson_get_len(lhs); if (len != unsafe_yyjson_get_len(rhs)) return false; return !memcmp(unsafe_yyjson_get_str(lhs), unsafe_yyjson_get_str(rhs), len); } bool unsafe_yyjson_equals(yyjson_val *lhs, yyjson_val *rhs) { yyjson_type type = unsafe_yyjson_get_type(lhs); if (type != unsafe_yyjson_get_type(rhs)) return false; switch (type) { case YYJSON_TYPE_OBJ: { usize len = unsafe_yyjson_get_len(lhs); if (len != unsafe_yyjson_get_len(rhs)) return false; if (len > 0) { yyjson_obj_iter iter; yyjson_obj_iter_init(rhs, &iter); lhs = unsafe_yyjson_get_first(lhs); while (len-- > 0) { rhs = yyjson_obj_iter_getn(&iter, lhs->uni.str, unsafe_yyjson_get_len(lhs)); if (!rhs) return false; if (!unsafe_yyjson_equals(lhs + 1, rhs)) return false; lhs = unsafe_yyjson_get_next(lhs + 1); } } /* yyjson allows duplicate keys, so the check may be inaccurate */ return true; } case YYJSON_TYPE_ARR: { usize len = unsafe_yyjson_get_len(lhs); if (len != unsafe_yyjson_get_len(rhs)) return false; if (len > 0) { lhs = unsafe_yyjson_get_first(lhs); rhs = unsafe_yyjson_get_first(rhs); while (len-- > 0) { if (!unsafe_yyjson_equals(lhs, rhs)) return false; lhs = unsafe_yyjson_get_next(lhs); rhs = unsafe_yyjson_get_next(rhs); } } return true; } case YYJSON_TYPE_NUM: return unsafe_yyjson_num_equals(lhs, rhs); case YYJSON_TYPE_RAW: case YYJSON_TYPE_STR: return unsafe_yyjson_str_equals(lhs, rhs); case YYJSON_TYPE_NULL: case YYJSON_TYPE_BOOL: return lhs->tag == rhs->tag; default: return false; } } bool unsafe_yyjson_mut_equals(yyjson_mut_val *lhs, yyjson_mut_val *rhs) { yyjson_type type = unsafe_yyjson_get_type(lhs); if (type != unsafe_yyjson_get_type(rhs)) return false; switch (type) { case YYJSON_TYPE_OBJ: { usize len = unsafe_yyjson_get_len(lhs); if (len != unsafe_yyjson_get_len(rhs)) return false; if (len > 0) { yyjson_mut_obj_iter iter; yyjson_mut_obj_iter_init(rhs, &iter); lhs = (yyjson_mut_val *)lhs->uni.ptr; while (len-- > 0) { rhs = yyjson_mut_obj_iter_getn(&iter, lhs->uni.str, unsafe_yyjson_get_len(lhs)); if (!rhs) return false; if (!unsafe_yyjson_mut_equals(lhs->next, rhs)) return false; lhs = lhs->next->next; } } /* yyjson allows duplicate keys, so the check may be inaccurate */ return true; } case YYJSON_TYPE_ARR: { usize len = unsafe_yyjson_get_len(lhs); if (len != unsafe_yyjson_get_len(rhs)) return false; if (len > 0) { lhs = (yyjson_mut_val *)lhs->uni.ptr; rhs = (yyjson_mut_val *)rhs->uni.ptr; while (len-- > 0) { if (!unsafe_yyjson_mut_equals(lhs, rhs)) return false; lhs = lhs->next; rhs = rhs->next; } } return true; } case YYJSON_TYPE_NUM: return unsafe_yyjson_num_equals(lhs, rhs); case YYJSON_TYPE_RAW: case YYJSON_TYPE_STR: return unsafe_yyjson_str_equals(lhs, rhs); case YYJSON_TYPE_NULL: case YYJSON_TYPE_BOOL: return lhs->tag == rhs->tag; default: return false; } } #if !YYJSON_DISABLE_UTILS /*============================================================================== * JSON Pointer API (RFC 6901) *============================================================================*/ /** Get a token from JSON pointer string. @param ptr [in,out] in: string that points to current token prefix `/` out: string that points to next token prefix `/`, or string end @param end [in] end of the entire JSON Pointer string @param len [out] unescaped token length @param esc [out] number of escaped characters in this token @return head of the token, or NULL if syntax error */ static_inline const char *ptr_next_token(const char **ptr, const char *end, usize *len, usize *esc) { const char *hdr = *ptr + 1; const char *cur = hdr; /* skip unescaped characters */ while (cur < end && *cur != '/' && *cur != '~') cur++; if (likely(cur == end || *cur != '~')) { /* no escaped characters, return */ *ptr = cur; *len = (usize)(cur - hdr); *esc = 0; return hdr; } else { /* handle escaped characters */ usize esc_num = 0; while (cur < end && *cur != '/') { if (*cur++ == '~') { if (cur == end || (*cur != '0' && *cur != '1')) { *ptr = cur - 1; return NULL; } esc_num++; } } *ptr = cur; *len = (usize)(cur - hdr) - esc_num; *esc = esc_num; return hdr; } } /** Convert token string to index. @param cur [in] token head @param len [in] token length @param idx [out] the index number, or USIZE_MAX if token is '-' @return true if token is a valid array index */ static_inline bool ptr_token_to_idx(const char *cur, usize len, usize *idx) { const char *end = cur + len; usize num = 0, add; if (unlikely(len == 0 || len > USIZE_SAFE_DIG)) return false; if (*cur == '0') { if (unlikely(len > 1)) return false; *idx = 0; return true; } if (*cur == '-') { if (unlikely(len > 1)) return false; *idx = USIZE_MAX; return true; } for (; cur < end && (add = (usize)((u8)*cur - (u8)'0')) <= 9; cur++) { num = num * 10 + add; } if (unlikely(num == 0 || cur < end)) return false; *idx = num; return true; } /** Compare JSON key with token. @param key a string key (yyjson_val or yyjson_mut_val) @param token a JSON pointer token @param len unescaped token length @param esc number of escaped characters in this token @return true if `str` is equals to `token` */ static_inline bool ptr_token_eq(void *key, const char *token, usize len, usize esc) { yyjson_val *val = (yyjson_val *)key; if (unsafe_yyjson_get_len(val) != len) return false; if (likely(!esc)) { return memcmp(val->uni.str, token, len) == 0; } else { const char *str = val->uni.str; for (; len-- > 0; token++, str++) { if (*token == '~') { if (*str != (*++token == '0' ? '~' : '/')) return false; } else { if (*str != *token) return false; } } return true; } } /** Get a value from array by token. @param arr an array, should not be NULL or non-array type @param token a JSON pointer token @param len unescaped token length @param esc number of escaped characters in this token @return value at index, or NULL if token is not index or index is out of range */ static_inline yyjson_val *ptr_arr_get(yyjson_val *arr, const char *token, usize len, usize esc) { yyjson_val *val = unsafe_yyjson_get_first(arr); usize num = unsafe_yyjson_get_len(arr), idx = 0; if (unlikely(num == 0)) return NULL; if (unlikely(!ptr_token_to_idx(token, len, &idx))) return NULL; if (unlikely(idx >= num)) return NULL; if (unsafe_yyjson_arr_is_flat(arr)) { return val + idx; } else { while (idx-- > 0) val = unsafe_yyjson_get_next(val); return val; } } /** Get a value from object by token. @param obj [in] an object, should not be NULL or non-object type @param token [in] a JSON pointer token @param len [in] unescaped token length @param esc [in] number of escaped characters in this token @return value associated with the token, or NULL if no value */ static_inline yyjson_val *ptr_obj_get(yyjson_val *obj, const char *token, usize len, usize esc) { yyjson_val *key = unsafe_yyjson_get_first(obj); usize num = unsafe_yyjson_get_len(obj); if (unlikely(num == 0)) return NULL; for (; num > 0; num--, key = unsafe_yyjson_get_next(key + 1)) { if (ptr_token_eq(key, token, len, esc)) return key + 1; } return NULL; } /** Get a value from array by token. @param arr [in] an array, should not be NULL or non-array type @param token [in] a JSON pointer token @param len [in] unescaped token length @param esc [in] number of escaped characters in this token @param pre [out] previous (sibling) value of the returned value @param last [out] whether index is last @return value at index, or NULL if token is not index or index is out of range */ static_inline yyjson_mut_val *ptr_mut_arr_get(yyjson_mut_val *arr, const char *token, usize len, usize esc, yyjson_mut_val **pre, bool *last) { yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; /* last (tail) */ usize num = unsafe_yyjson_get_len(arr), idx; if (last) *last = false; if (false) *pre = NULL; if (unlikely(num == 0)) { if (last && len == 1 && (*token == '0' || *token == '-')) *last = true; return NULL; } if (unlikely(!ptr_token_to_idx(token, len, &idx))) return NULL; if (last) *last = (idx == num || idx == USIZE_MAX); if (unlikely(idx >= num)) return NULL; while (idx-- > 0) val = val->next; *pre = val; return val->next; } /** Get a value from object by token. @param obj [in] an object, should not be NULL or non-object type @param token [in] a JSON pointer token @param len [in] unescaped token length @param esc [in] number of escaped characters in this token @param pre [out] previous (sibling) key of the returned value's key @return value associated with the token, or NULL if no value */ static_inline yyjson_mut_val *ptr_mut_obj_get(yyjson_mut_val *obj, const char *token, usize len, usize esc, yyjson_mut_val **pre) { yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr, *key; usize num = unsafe_yyjson_get_len(obj); if (false) *pre = NULL; if (unlikely(num == 0)) return NULL; for (; num > 0; num--, pre_key = key) { key = pre_key->next->next; if (ptr_token_eq(key, token, len, esc)) { *pre = pre_key; return key->next; } } return NULL; } /** Create a string value with JSON pointer token. @param token [in] a JSON pointer token @param len [in] unescaped token length @param esc [in] number of escaped characters in this token @param doc [in] used for memory allocation when creating value @return new string value, or NULL if memory allocation failed */ static_inline yyjson_mut_val *ptr_new_key(const char *token, usize len, usize esc, yyjson_mut_doc *doc) { const char *src = token; if (likely(!esc)) { return yyjson_mut_strncpy(doc, src, len); } else { const char *end = src + len + esc; char *dst = unsafe_yyjson_mut_str_alc(doc, len + esc); char *str = dst; if (unlikely(!dst)) return NULL; for (; src < end; src++, dst++) { if (*src != '~') *dst = *src; else *dst = (*++src == '0' ? '~' : '/'); } *dst = '\0'; return yyjson_mut_strn(doc, str, len); } } /* macros for yyjson_ptr */ #define return_err(_ret, _code, _pos, _msg) do { \ if (err) { \ err->code = YYJSON_PTR_ERR_##_code; \ err->msg = _msg; \ err->pos = (usize)(_pos); \ } \ return _ret; \ } while (false) #define return_err_resolve(_ret, _pos) \ return_err(_ret, RESOLVE, _pos, "JSON pointer cannot be resolved") #define return_err_syntax(_ret, _pos) \ return_err(_ret, SYNTAX, _pos, "invalid escaped character") #define return_err_alloc(_ret) \ return_err(_ret, MEMORY_ALLOCATION, 0, "failed to create value") yyjson_val *unsafe_yyjson_ptr_getx(yyjson_val *val, const char *ptr, size_t ptr_len, yyjson_ptr_err *err) { const char *hdr = ptr, *end = ptr + ptr_len, *token; usize len, esc; yyjson_type type; while (true) { token = ptr_next_token(&ptr, end, &len, &esc); if (unlikely(!token)) return_err_syntax(NULL, ptr - hdr); type = unsafe_yyjson_get_type(val); if (type == YYJSON_TYPE_OBJ) { val = ptr_obj_get(val, token, len, esc); } else if (type == YYJSON_TYPE_ARR) { val = ptr_arr_get(val, token, len, esc); } else { val = NULL; } if (!val) return_err_resolve(NULL, token - hdr); if (ptr == end) return val; } } yyjson_mut_val *unsafe_yyjson_mut_ptr_getx(yyjson_mut_val *val, const char *ptr, size_t ptr_len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { const char *hdr = ptr, *end = ptr + ptr_len, *token; usize len, esc; yyjson_mut_val *ctn, *pre = NULL; yyjson_type type; bool idx_is_last = false; while (true) { token = ptr_next_token(&ptr, end, &len, &esc); if (unlikely(!token)) return_err_syntax(NULL, ptr - hdr); ctn = val; type = unsafe_yyjson_get_type(val); if (type == YYJSON_TYPE_OBJ) { val = ptr_mut_obj_get(val, token, len, esc, &pre); } else if (type == YYJSON_TYPE_ARR) { val = ptr_mut_arr_get(val, token, len, esc, &pre, &idx_is_last); } else { val = NULL; } if (ctx && (ptr == end)) { if (type == YYJSON_TYPE_OBJ || (type == YYJSON_TYPE_ARR && (val || idx_is_last))) { ctx->ctn = ctn; ctx->pre = pre; } } if (!val) return_err_resolve(NULL, token - hdr); if (ptr == end) return val; } } bool unsafe_yyjson_mut_ptr_putx(yyjson_mut_val *val, const char *ptr, size_t ptr_len, yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent, bool insert_new, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { const char *hdr = ptr, *end = ptr + ptr_len, *token; usize token_len, esc, ctn_len; yyjson_mut_val *ctn, *key, *pre = NULL; yyjson_mut_val *sep_ctn = NULL, *sep_key = NULL, *sep_val = NULL; yyjson_type ctn_type; bool idx_is_last = false; /* skip exist parent nodes */ while (true) { token = ptr_next_token(&ptr, end, &token_len, &esc); if (unlikely(!token)) return_err_syntax(false, ptr - hdr); ctn = val; ctn_type = unsafe_yyjson_get_type(ctn); if (ctn_type == YYJSON_TYPE_OBJ) { val = ptr_mut_obj_get(ctn, token, token_len, esc, &pre); } else if (ctn_type == YYJSON_TYPE_ARR) { val = ptr_mut_arr_get(ctn, token, token_len, esc, &pre, &idx_is_last); } else return_err_resolve(false, token - hdr); if (!val) break; if (ptr == end) break; /* is last token */ } /* create parent nodes if not exist */ if (unlikely(ptr != end)) { /* not last token */ if (!create_parent) return_err_resolve(false, token - hdr); /* add value at last index if container is array */ if (ctn_type == YYJSON_TYPE_ARR) { if (!idx_is_last || !insert_new) { return_err_resolve(false, token - hdr); } val = yyjson_mut_obj(doc); if (!val) return_err_alloc(false); /* delay attaching until all operations are completed */ sep_ctn = ctn; sep_key = NULL; sep_val = val; /* move to next token */ ctn = val; val = NULL; ctn_type = YYJSON_TYPE_OBJ; token = ptr_next_token(&ptr, end, &token_len, &esc); if (unlikely(!token)) return_err_resolve(false, token - hdr); } /* container is object, create parent nodes */ while (ptr != end) { /* not last token */ key = ptr_new_key(token, token_len, esc, doc); if (!key) return_err_alloc(false); val = yyjson_mut_obj(doc); if (!val) return_err_alloc(false); /* delay attaching until all operations are completed */ if (!sep_ctn) { sep_ctn = ctn; sep_key = key; sep_val = val; } else { yyjson_mut_obj_add(ctn, key, val); } /* move to next token */ ctn = val; val = NULL; token = ptr_next_token(&ptr, end, &token_len, &esc); if (unlikely(!token)) return_err_syntax(false, ptr - hdr); } } /* JSON pointer is resolved, insert or replace target value */ ctn_len = unsafe_yyjson_get_len(ctn); if (ctn_type == YYJSON_TYPE_OBJ) { if (ctx) ctx->ctn = ctn; if (!val || insert_new) { /* insert new key-value pair */ key = ptr_new_key(token, token_len, esc, doc); if (unlikely(!key)) return_err_alloc(false); if (ctx) ctx->pre = ctn_len ? (yyjson_mut_val *)ctn->uni.ptr : key; unsafe_yyjson_mut_obj_add(ctn, key, new_val, ctn_len); } else { /* replace exist value */ key = pre->next->next; if (ctx) ctx->pre = pre; if (ctx) ctx->old = val; yyjson_mut_obj_put(ctn, key, new_val); } } else { /* array */ if (ctx && (val || idx_is_last)) ctx->ctn = ctn; if (insert_new) { /* append new value */ if (val) { pre->next = new_val; new_val->next = val; if (ctx) ctx->pre = pre; unsafe_yyjson_set_len(ctn, ctn_len + 1); } else if (idx_is_last) { if (ctx) ctx->pre = ctn_len ? (yyjson_mut_val *)ctn->uni.ptr : new_val; yyjson_mut_arr_append(ctn, new_val); } else { return_err_resolve(false, token - hdr); } } else { /* replace exist value */ if (!val) return_err_resolve(false, token - hdr); if (ctn_len > 1) { new_val->next = val->next; pre->next = new_val; if (ctn->uni.ptr == val) ctn->uni.ptr = new_val; } else { new_val->next = new_val; ctn->uni.ptr = new_val; pre = new_val; } if (ctx) ctx->pre = pre; if (ctx) ctx->old = val; } } /* all operations are completed, attach the new components to the target */ if (unlikely(sep_ctn)) { if (sep_key) yyjson_mut_obj_add(sep_ctn, sep_key, sep_val); else yyjson_mut_arr_append(sep_ctn, sep_val); } return true; } yyjson_mut_val *unsafe_yyjson_mut_ptr_replacex( yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_mut_val *cur_val; yyjson_ptr_ctx cur_ctx; memset(&cur_ctx, 0, sizeof(cur_ctx)); if (!ctx) ctx = &cur_ctx; cur_val = unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); if (!cur_val) return NULL; if (yyjson_mut_is_obj(ctx->ctn)) { yyjson_mut_val *key = ctx->pre->next->next; yyjson_mut_obj_put(ctx->ctn, key, new_val); } else { yyjson_ptr_ctx_replace(ctx, new_val); } ctx->old = cur_val; return cur_val; } yyjson_mut_val *unsafe_yyjson_mut_ptr_removex(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_mut_val *cur_val; yyjson_ptr_ctx cur_ctx; memset(&cur_ctx, 0, sizeof(cur_ctx)); if (!ctx) ctx = &cur_ctx; cur_val = unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); if (cur_val) { if (yyjson_mut_is_obj(ctx->ctn)) { yyjson_mut_val *key = ctx->pre->next->next; yyjson_mut_obj_put(ctx->ctn, key, NULL); } else { yyjson_ptr_ctx_remove(ctx); } ctx->pre = NULL; ctx->old = cur_val; } return cur_val; } /* macros for yyjson_ptr */ #undef return_err #undef return_err_resolve #undef return_err_syntax #undef return_err_alloc /*============================================================================== * JSON Patch API (RFC 6902) *============================================================================*/ /* JSON Patch operation */ typedef enum patch_op { PATCH_OP_ADD, /* path, value */ PATCH_OP_REMOVE, /* path */ PATCH_OP_REPLACE, /* path, value */ PATCH_OP_MOVE, /* from, path */ PATCH_OP_COPY, /* from, path */ PATCH_OP_TEST, /* path, value */ PATCH_OP_NONE /* invalid */ } patch_op; static patch_op patch_op_get(yyjson_val *op) { const char *str = op->uni.str; switch (unsafe_yyjson_get_len(op)) { case 3: if (!memcmp(str, "add", 3)) return PATCH_OP_ADD; return PATCH_OP_NONE; case 4: if (!memcmp(str, "move", 4)) return PATCH_OP_MOVE; if (!memcmp(str, "copy", 4)) return PATCH_OP_COPY; if (!memcmp(str, "test", 4)) return PATCH_OP_TEST; return PATCH_OP_NONE; case 6: if (!memcmp(str, "remove", 6)) return PATCH_OP_REMOVE; return PATCH_OP_NONE; case 7: if (!memcmp(str, "replace", 7)) return PATCH_OP_REPLACE; return PATCH_OP_NONE; default: return PATCH_OP_NONE; } } /* macros for yyjson_patch */ #define return_err(_code, _msg) do { \ if (err->ptr.code == YYJSON_PTR_ERR_MEMORY_ALLOCATION) { \ err->code = YYJSON_PATCH_ERROR_MEMORY_ALLOCATION; \ err->msg = _msg; \ memset(&err->ptr, 0, sizeof(yyjson_ptr_err)); \ } else { \ err->code = YYJSON_PATCH_ERROR_##_code; \ err->msg = _msg; \ err->idx = iter.idx ? iter.idx - 1 : 0; \ } \ return NULL; \ } while (false) #define return_err_copy() \ return_err(MEMORY_ALLOCATION, "failed to copy value") #define return_err_key(_key) \ return_err(MISSING_KEY, "missing key " _key) #define return_err_val(_key) \ return_err(INVALID_MEMBER, "invalid member " _key) #define ptr_get(_ptr) yyjson_mut_ptr_getx( \ root, _ptr->uni.str, _ptr##_len, NULL, &err->ptr) #define ptr_add(_ptr, _val) yyjson_mut_ptr_addx( \ root, _ptr->uni.str, _ptr##_len, _val, doc, false, NULL, &err->ptr) #define ptr_remove(_ptr) yyjson_mut_ptr_removex( \ root, _ptr->uni.str, _ptr##_len, NULL, &err->ptr) #define ptr_replace(_ptr, _val)yyjson_mut_ptr_replacex( \ root, _ptr->uni.str, _ptr##_len, _val, NULL, &err->ptr) yyjson_mut_val *yyjson_patch(yyjson_mut_doc *doc, yyjson_val *orig, yyjson_val *patch, yyjson_patch_err *err) { yyjson_mut_val *root; yyjson_val *obj; yyjson_arr_iter iter; yyjson_patch_err err_tmp; if (!err) err = &err_tmp; memset(err, 0, sizeof(*err)); memset(&iter, 0, sizeof(iter)); if (unlikely(!doc || !orig || !patch)) { return_err(INVALID_PARAMETER, "input parameter is NULL"); } if (unlikely(!yyjson_is_arr(patch))) { return_err(INVALID_PARAMETER, "input patch is not array"); } root = yyjson_val_mut_copy(doc, orig); if (unlikely(!root)) return_err_copy(); /* iterate through the patch array */ yyjson_arr_iter_init(patch, &iter); while ((obj = yyjson_arr_iter_next(&iter))) { patch_op op_enum; yyjson_val *op, *path, *from = NULL, *value; yyjson_mut_val *val = NULL, *test; usize path_len, from_len = 0; if (unlikely(!unsafe_yyjson_is_obj(obj))) { return_err(INVALID_OPERATION, "JSON patch operation is not object"); } /* get required member: op */ op = yyjson_obj_get(obj, "op"); if (unlikely(!op)) return_err_key("`op`"); if (unlikely(!yyjson_is_str(op))) return_err_val("`op`"); op_enum = patch_op_get(op); /* get required member: path */ path = yyjson_obj_get(obj, "path"); if (unlikely(!path)) return_err_key("`path`"); if (unlikely(!yyjson_is_str(path))) return_err_val("`path`"); path_len = unsafe_yyjson_get_len(path); /* get required member: value, from */ switch ((int)op_enum) { case PATCH_OP_ADD: case PATCH_OP_REPLACE: case PATCH_OP_TEST: value = yyjson_obj_get(obj, "value"); if (unlikely(!value)) return_err_key("`value`"); val = yyjson_val_mut_copy(doc, value); if (unlikely(!val)) return_err_copy(); break; case PATCH_OP_MOVE: case PATCH_OP_COPY: from = yyjson_obj_get(obj, "from"); if (unlikely(!from)) return_err_key("`from`"); if (unlikely(!yyjson_is_str(from))) return_err_val("`from`"); from_len = unsafe_yyjson_get_len(from); break; default: break; } /* perform an operation */ switch ((int)op_enum) { case PATCH_OP_ADD: /* add(path, val) */ if (unlikely(path_len == 0)) { root = val; break; } if (unlikely(!ptr_add(path, val))) { return_err(POINTER, "failed to add `path`"); } break; case PATCH_OP_REMOVE: /* remove(path) */ if (unlikely(!ptr_remove(path))) { return_err(POINTER, "failed to remove `path`"); } break; case PATCH_OP_REPLACE: /* replace(path, val) */ if (unlikely(path_len == 0)) { root = val; break; } if (unlikely(!ptr_replace(path, val))) { return_err(POINTER, "failed to replace `path`"); } break; case PATCH_OP_MOVE: /* val = remove(from), add(path, val) */ if (unlikely(from_len == 0 && path_len == 0)) break; val = ptr_remove(from); if (unlikely(!val)) { return_err(POINTER, "failed to remove `from`"); } if (unlikely(path_len == 0)) { root = val; break; } if (unlikely(!ptr_add(path, val))) { return_err(POINTER, "failed to add `path`"); } break; case PATCH_OP_COPY: /* val = get(from).copy, add(path, val) */ val = ptr_get(from); if (unlikely(!val)) { return_err(POINTER, "failed to get `from`"); } if (unlikely(path_len == 0)) { root = val; break; } val = yyjson_mut_val_mut_copy(doc, val); if (unlikely(!val)) return_err_copy(); if (unlikely(!ptr_add(path, val))) { return_err(POINTER, "failed to add `path`"); } break; case PATCH_OP_TEST: /* test = get(path), test.eq(val) */ test = ptr_get(path); if (unlikely(!test)) { return_err(POINTER, "failed to get `path`"); } if (unlikely(!yyjson_mut_equals(val, test))) { return_err(EQUAL, "failed to test equal"); } break; default: return_err(INVALID_MEMBER, "unsupported `op`"); } } return root; } yyjson_mut_val *yyjson_mut_patch(yyjson_mut_doc *doc, yyjson_mut_val *orig, yyjson_mut_val *patch, yyjson_patch_err *err) { yyjson_mut_val *root, *obj; yyjson_mut_arr_iter iter; yyjson_patch_err err_tmp; if (!err) err = &err_tmp; memset(err, 0, sizeof(*err)); memset(&iter, 0, sizeof(iter)); if (unlikely(!doc || !orig || !patch)) { return_err(INVALID_PARAMETER, "input parameter is NULL"); } if (unlikely(!yyjson_mut_is_arr(patch))) { return_err(INVALID_PARAMETER, "input patch is not array"); } root = yyjson_mut_val_mut_copy(doc, orig); if (unlikely(!root)) return_err_copy(); /* iterate through the patch array */ yyjson_mut_arr_iter_init(patch, &iter); while ((obj = yyjson_mut_arr_iter_next(&iter))) { patch_op op_enum; yyjson_mut_val *op, *path, *from = NULL, *value; yyjson_mut_val *val = NULL, *test; usize path_len, from_len = 0; if (!unsafe_yyjson_is_obj(obj)) { return_err(INVALID_OPERATION, "JSON patch operation is not object"); } /* get required member: op */ op = yyjson_mut_obj_get(obj, "op"); if (unlikely(!op)) return_err_key("`op`"); if (unlikely(!yyjson_mut_is_str(op))) return_err_val("`op`"); op_enum = patch_op_get((yyjson_val *)(void *)op); /* get required member: path */ path = yyjson_mut_obj_get(obj, "path"); if (unlikely(!path)) return_err_key("`path`"); if (unlikely(!yyjson_mut_is_str(path))) return_err_val("`path`"); path_len = unsafe_yyjson_get_len(path); /* get required member: value, from */ switch ((int)op_enum) { case PATCH_OP_ADD: case PATCH_OP_REPLACE: case PATCH_OP_TEST: value = yyjson_mut_obj_get(obj, "value"); if (unlikely(!value)) return_err_key("`value`"); val = yyjson_mut_val_mut_copy(doc, value); if (unlikely(!val)) return_err_copy(); break; case PATCH_OP_MOVE: case PATCH_OP_COPY: from = yyjson_mut_obj_get(obj, "from"); if (unlikely(!from)) return_err_key("`from`"); if (unlikely(!yyjson_mut_is_str(from))) { return_err_val("`from`"); } from_len = unsafe_yyjson_get_len(from); break; default: break; } /* perform an operation */ switch ((int)op_enum) { case PATCH_OP_ADD: /* add(path, val) */ if (unlikely(path_len == 0)) { root = val; break; } if (unlikely(!ptr_add(path, val))) { return_err(POINTER, "failed to add `path`"); } break; case PATCH_OP_REMOVE: /* remove(path) */ if (unlikely(!ptr_remove(path))) { return_err(POINTER, "failed to remove `path`"); } break; case PATCH_OP_REPLACE: /* replace(path, val) */ if (unlikely(path_len == 0)) { root = val; break; } if (unlikely(!ptr_replace(path, val))) { return_err(POINTER, "failed to replace `path`"); } break; case PATCH_OP_MOVE: /* val = remove(from), add(path, val) */ if (unlikely(from_len == 0 && path_len == 0)) break; val = ptr_remove(from); if (unlikely(!val)) { return_err(POINTER, "failed to remove `from`"); } if (unlikely(path_len == 0)) { root = val; break; } if (unlikely(!ptr_add(path, val))) { return_err(POINTER, "failed to add `path`"); } break; case PATCH_OP_COPY: /* val = get(from).copy, add(path, val) */ val = ptr_get(from); if (unlikely(!val)) { return_err(POINTER, "failed to get `from`"); } if (unlikely(path_len == 0)) { root = val; break; } val = yyjson_mut_val_mut_copy(doc, val); if (unlikely(!val)) return_err_copy(); if (unlikely(!ptr_add(path, val))) { return_err(POINTER, "failed to add `path`"); } break; case PATCH_OP_TEST: /* test = get(path), test.eq(val) */ test = ptr_get(path); if (unlikely(!test)) { return_err(POINTER, "failed to get `path`"); } if (unlikely(!yyjson_mut_equals(val, test))) { return_err(EQUAL, "failed to test equal"); } break; default: return_err(INVALID_MEMBER, "unsupported `op`"); } } return root; } /* macros for yyjson_patch */ #undef return_err #undef return_err_copy #undef return_err_key #undef return_err_val #undef ptr_get #undef ptr_add #undef ptr_remove #undef ptr_replace /*============================================================================== * JSON Merge-Patch API (RFC 7386) *============================================================================*/ yyjson_mut_val *yyjson_merge_patch(yyjson_mut_doc *doc, yyjson_val *orig, yyjson_val *patch) { usize idx, max; yyjson_val *key, *orig_val, *patch_val, local_orig; yyjson_mut_val *builder, *mut_key, *mut_val, *merged_val; if (unlikely(!yyjson_is_obj(patch))) { return yyjson_val_mut_copy(doc, patch); } builder = yyjson_mut_obj(doc); if (unlikely(!builder)) return NULL; memset(&local_orig, 0, sizeof(local_orig)); if (!yyjson_is_obj(orig)) { orig = &local_orig; orig->tag = builder->tag; orig->uni = builder->uni; } /* If orig is contributing, copy any items not modified by the patch */ if (orig != &local_orig) { yyjson_obj_foreach(orig, idx, max, key, orig_val) { patch_val = yyjson_obj_getn(patch, unsafe_yyjson_get_str(key), unsafe_yyjson_get_len(key)); if (!patch_val) { mut_key = yyjson_val_mut_copy(doc, key); mut_val = yyjson_val_mut_copy(doc, orig_val); if (!yyjson_mut_obj_add(builder, mut_key, mut_val)) return NULL; } } } /* Merge items modified by the patch. */ yyjson_obj_foreach(patch, idx, max, key, patch_val) { /* null indicates the field is removed. */ if (unsafe_yyjson_is_null(patch_val)) { continue; } mut_key = yyjson_val_mut_copy(doc, key); orig_val = yyjson_obj_getn(orig, unsafe_yyjson_get_str(key), unsafe_yyjson_get_len(key)); merged_val = yyjson_merge_patch(doc, orig_val, patch_val); if (!yyjson_mut_obj_add(builder, mut_key, merged_val)) return NULL; } return builder; } yyjson_mut_val *yyjson_mut_merge_patch(yyjson_mut_doc *doc, yyjson_mut_val *orig, yyjson_mut_val *patch) { usize idx, max; yyjson_mut_val *key, *orig_val, *patch_val, local_orig; yyjson_mut_val *builder, *mut_key, *mut_val, *merged_val; if (unlikely(!yyjson_mut_is_obj(patch))) { return yyjson_mut_val_mut_copy(doc, patch); } builder = yyjson_mut_obj(doc); if (unlikely(!builder)) return NULL; memset(&local_orig, 0, sizeof(local_orig)); if (!yyjson_mut_is_obj(orig)) { orig = &local_orig; orig->tag = builder->tag; orig->uni = builder->uni; } /* If orig is contributing, copy any items not modified by the patch */ if (orig != &local_orig) { yyjson_mut_obj_foreach(orig, idx, max, key, orig_val) { patch_val = yyjson_mut_obj_getn(patch, unsafe_yyjson_get_str(key), unsafe_yyjson_get_len(key)); if (!patch_val) { mut_key = yyjson_mut_val_mut_copy(doc, key); mut_val = yyjson_mut_val_mut_copy(doc, orig_val); if (!yyjson_mut_obj_add(builder, mut_key, mut_val)) return NULL; } } } /* Merge items modified by the patch. */ yyjson_mut_obj_foreach(patch, idx, max, key, patch_val) { /* null indicates the field is removed. */ if (unsafe_yyjson_is_null(patch_val)) { continue; } mut_key = yyjson_mut_val_mut_copy(doc, key); orig_val = yyjson_mut_obj_getn(orig, unsafe_yyjson_get_str(key), unsafe_yyjson_get_len(key)); merged_val = yyjson_mut_merge_patch(doc, orig_val, patch_val); if (!yyjson_mut_obj_add(builder, mut_key, merged_val)) return NULL; } return builder; } #endif /* YYJSON_DISABLE_UTILS */ /*============================================================================== * Power10 Lookup Table * These data are used by the floating-point number reader and writer. *============================================================================*/ #if (!YYJSON_DISABLE_READER || !YYJSON_DISABLE_WRITER) && \ (!YYJSON_DISABLE_FAST_FP_CONV) /** Minimum decimal exponent in pow10_sig_table. */ #define POW10_SIG_TABLE_MIN_EXP -343 /** Maximum decimal exponent in pow10_sig_table. */ #define POW10_SIG_TABLE_MAX_EXP 324 /** Minimum exact decimal exponent in pow10_sig_table */ #define POW10_SIG_TABLE_MIN_EXACT_EXP 0 /** Maximum exact decimal exponent in pow10_sig_table */ #define POW10_SIG_TABLE_MAX_EXACT_EXP 55 /** Normalized significant 128 bits of pow10, no rounded up (size: 10.4KB). This lookup table is used by both the double number reader and writer. (generate with misc/make_tables.c) */ static const u64 pow10_sig_table[] = { U64(0xBF29DCAB, 0xA82FDEAE), U64(0x7432EE87, 0x3880FC33), /* ~= 10^-343 */ U64(0xEEF453D6, 0x923BD65A), U64(0x113FAA29, 0x06A13B3F), /* ~= 10^-342 */ U64(0x9558B466, 0x1B6565F8), U64(0x4AC7CA59, 0xA424C507), /* ~= 10^-341 */ U64(0xBAAEE17F, 0xA23EBF76), U64(0x5D79BCF0, 0x0D2DF649), /* ~= 10^-340 */ U64(0xE95A99DF, 0x8ACE6F53), U64(0xF4D82C2C, 0x107973DC), /* ~= 10^-339 */ U64(0x91D8A02B, 0xB6C10594), U64(0x79071B9B, 0x8A4BE869), /* ~= 10^-338 */ U64(0xB64EC836, 0xA47146F9), U64(0x9748E282, 0x6CDEE284), /* ~= 10^-337 */ U64(0xE3E27A44, 0x4D8D98B7), U64(0xFD1B1B23, 0x08169B25), /* ~= 10^-336 */ U64(0x8E6D8C6A, 0xB0787F72), U64(0xFE30F0F5, 0xE50E20F7), /* ~= 10^-335 */ U64(0xB208EF85, 0x5C969F4F), U64(0xBDBD2D33, 0x5E51A935), /* ~= 10^-334 */ U64(0xDE8B2B66, 0xB3BC4723), U64(0xAD2C7880, 0x35E61382), /* ~= 10^-333 */ U64(0x8B16FB20, 0x3055AC76), U64(0x4C3BCB50, 0x21AFCC31), /* ~= 10^-332 */ U64(0xADDCB9E8, 0x3C6B1793), U64(0xDF4ABE24, 0x2A1BBF3D), /* ~= 10^-331 */ U64(0xD953E862, 0x4B85DD78), U64(0xD71D6DAD, 0x34A2AF0D), /* ~= 10^-330 */ U64(0x87D4713D, 0x6F33AA6B), U64(0x8672648C, 0x40E5AD68), /* ~= 10^-329 */ U64(0xA9C98D8C, 0xCB009506), U64(0x680EFDAF, 0x511F18C2), /* ~= 10^-328 */ U64(0xD43BF0EF, 0xFDC0BA48), U64(0x0212BD1B, 0x2566DEF2), /* ~= 10^-327 */ U64(0x84A57695, 0xFE98746D), U64(0x014BB630, 0xF7604B57), /* ~= 10^-326 */ U64(0xA5CED43B, 0x7E3E9188), U64(0x419EA3BD, 0x35385E2D), /* ~= 10^-325 */ U64(0xCF42894A, 0x5DCE35EA), U64(0x52064CAC, 0x828675B9), /* ~= 10^-324 */ U64(0x818995CE, 0x7AA0E1B2), U64(0x7343EFEB, 0xD1940993), /* ~= 10^-323 */ U64(0xA1EBFB42, 0x19491A1F), U64(0x1014EBE6, 0xC5F90BF8), /* ~= 10^-322 */ U64(0xCA66FA12, 0x9F9B60A6), U64(0xD41A26E0, 0x77774EF6), /* ~= 10^-321 */ U64(0xFD00B897, 0x478238D0), U64(0x8920B098, 0x955522B4), /* ~= 10^-320 */ U64(0x9E20735E, 0x8CB16382), U64(0x55B46E5F, 0x5D5535B0), /* ~= 10^-319 */ U64(0xC5A89036, 0x2FDDBC62), U64(0xEB2189F7, 0x34AA831D), /* ~= 10^-318 */ U64(0xF712B443, 0xBBD52B7B), U64(0xA5E9EC75, 0x01D523E4), /* ~= 10^-317 */ U64(0x9A6BB0AA, 0x55653B2D), U64(0x47B233C9, 0x2125366E), /* ~= 10^-316 */ U64(0xC1069CD4, 0xEABE89F8), U64(0x999EC0BB, 0x696E840A), /* ~= 10^-315 */ U64(0xF148440A, 0x256E2C76), U64(0xC00670EA, 0x43CA250D), /* ~= 10^-314 */ U64(0x96CD2A86, 0x5764DBCA), U64(0x38040692, 0x6A5E5728), /* ~= 10^-313 */ U64(0xBC807527, 0xED3E12BC), U64(0xC6050837, 0x04F5ECF2), /* ~= 10^-312 */ U64(0xEBA09271, 0xE88D976B), U64(0xF7864A44, 0xC633682E), /* ~= 10^-311 */ U64(0x93445B87, 0x31587EA3), U64(0x7AB3EE6A, 0xFBE0211D), /* ~= 10^-310 */ U64(0xB8157268, 0xFDAE9E4C), U64(0x5960EA05, 0xBAD82964), /* ~= 10^-309 */ U64(0xE61ACF03, 0x3D1A45DF), U64(0x6FB92487, 0x298E33BD), /* ~= 10^-308 */ U64(0x8FD0C162, 0x06306BAB), U64(0xA5D3B6D4, 0x79F8E056), /* ~= 10^-307 */ U64(0xB3C4F1BA, 0x87BC8696), U64(0x8F48A489, 0x9877186C), /* ~= 10^-306 */ U64(0xE0B62E29, 0x29ABA83C), U64(0x331ACDAB, 0xFE94DE87), /* ~= 10^-305 */ U64(0x8C71DCD9, 0xBA0B4925), U64(0x9FF0C08B, 0x7F1D0B14), /* ~= 10^-304 */ U64(0xAF8E5410, 0x288E1B6F), U64(0x07ECF0AE, 0x5EE44DD9), /* ~= 10^-303 */ U64(0xDB71E914, 0x32B1A24A), U64(0xC9E82CD9, 0xF69D6150), /* ~= 10^-302 */ U64(0x892731AC, 0x9FAF056E), U64(0xBE311C08, 0x3A225CD2), /* ~= 10^-301 */ U64(0xAB70FE17, 0xC79AC6CA), U64(0x6DBD630A, 0x48AAF406), /* ~= 10^-300 */ U64(0xD64D3D9D, 0xB981787D), U64(0x092CBBCC, 0xDAD5B108), /* ~= 10^-299 */ U64(0x85F04682, 0x93F0EB4E), U64(0x25BBF560, 0x08C58EA5), /* ~= 10^-298 */ U64(0xA76C5823, 0x38ED2621), U64(0xAF2AF2B8, 0x0AF6F24E), /* ~= 10^-297 */ U64(0xD1476E2C, 0x07286FAA), U64(0x1AF5AF66, 0x0DB4AEE1), /* ~= 10^-296 */ U64(0x82CCA4DB, 0x847945CA), U64(0x50D98D9F, 0xC890ED4D), /* ~= 10^-295 */ U64(0xA37FCE12, 0x6597973C), U64(0xE50FF107, 0xBAB528A0), /* ~= 10^-294 */ U64(0xCC5FC196, 0xFEFD7D0C), U64(0x1E53ED49, 0xA96272C8), /* ~= 10^-293 */ U64(0xFF77B1FC, 0xBEBCDC4F), U64(0x25E8E89C, 0x13BB0F7A), /* ~= 10^-292 */ U64(0x9FAACF3D, 0xF73609B1), U64(0x77B19161, 0x8C54E9AC), /* ~= 10^-291 */ U64(0xC795830D, 0x75038C1D), U64(0xD59DF5B9, 0xEF6A2417), /* ~= 10^-290 */ U64(0xF97AE3D0, 0xD2446F25), U64(0x4B057328, 0x6B44AD1D), /* ~= 10^-289 */ U64(0x9BECCE62, 0x836AC577), U64(0x4EE367F9, 0x430AEC32), /* ~= 10^-288 */ U64(0xC2E801FB, 0x244576D5), U64(0x229C41F7, 0x93CDA73F), /* ~= 10^-287 */ U64(0xF3A20279, 0xED56D48A), U64(0x6B435275, 0x78C1110F), /* ~= 10^-286 */ U64(0x9845418C, 0x345644D6), U64(0x830A1389, 0x6B78AAA9), /* ~= 10^-285 */ U64(0xBE5691EF, 0x416BD60C), U64(0x23CC986B, 0xC656D553), /* ~= 10^-284 */ U64(0xEDEC366B, 0x11C6CB8F), U64(0x2CBFBE86, 0xB7EC8AA8), /* ~= 10^-283 */ U64(0x94B3A202, 0xEB1C3F39), U64(0x7BF7D714, 0x32F3D6A9), /* ~= 10^-282 */ U64(0xB9E08A83, 0xA5E34F07), U64(0xDAF5CCD9, 0x3FB0CC53), /* ~= 10^-281 */ U64(0xE858AD24, 0x8F5C22C9), U64(0xD1B3400F, 0x8F9CFF68), /* ~= 10^-280 */ U64(0x91376C36, 0xD99995BE), U64(0x23100809, 0xB9C21FA1), /* ~= 10^-279 */ U64(0xB5854744, 0x8FFFFB2D), U64(0xABD40A0C, 0x2832A78A), /* ~= 10^-278 */ U64(0xE2E69915, 0xB3FFF9F9), U64(0x16C90C8F, 0x323F516C), /* ~= 10^-277 */ U64(0x8DD01FAD, 0x907FFC3B), U64(0xAE3DA7D9, 0x7F6792E3), /* ~= 10^-276 */ U64(0xB1442798, 0xF49FFB4A), U64(0x99CD11CF, 0xDF41779C), /* ~= 10^-275 */ U64(0xDD95317F, 0x31C7FA1D), U64(0x40405643, 0xD711D583), /* ~= 10^-274 */ U64(0x8A7D3EEF, 0x7F1CFC52), U64(0x482835EA, 0x666B2572), /* ~= 10^-273 */ U64(0xAD1C8EAB, 0x5EE43B66), U64(0xDA324365, 0x0005EECF), /* ~= 10^-272 */ U64(0xD863B256, 0x369D4A40), U64(0x90BED43E, 0x40076A82), /* ~= 10^-271 */ U64(0x873E4F75, 0xE2224E68), U64(0x5A7744A6, 0xE804A291), /* ~= 10^-270 */ U64(0xA90DE353, 0x5AAAE202), U64(0x711515D0, 0xA205CB36), /* ~= 10^-269 */ U64(0xD3515C28, 0x31559A83), U64(0x0D5A5B44, 0xCA873E03), /* ~= 10^-268 */ U64(0x8412D999, 0x1ED58091), U64(0xE858790A, 0xFE9486C2), /* ~= 10^-267 */ U64(0xA5178FFF, 0x668AE0B6), U64(0x626E974D, 0xBE39A872), /* ~= 10^-266 */ U64(0xCE5D73FF, 0x402D98E3), U64(0xFB0A3D21, 0x2DC8128F), /* ~= 10^-265 */ U64(0x80FA687F, 0x881C7F8E), U64(0x7CE66634, 0xBC9D0B99), /* ~= 10^-264 */ U64(0xA139029F, 0x6A239F72), U64(0x1C1FFFC1, 0xEBC44E80), /* ~= 10^-263 */ U64(0xC9874347, 0x44AC874E), U64(0xA327FFB2, 0x66B56220), /* ~= 10^-262 */ U64(0xFBE91419, 0x15D7A922), U64(0x4BF1FF9F, 0x0062BAA8), /* ~= 10^-261 */ U64(0x9D71AC8F, 0xADA6C9B5), U64(0x6F773FC3, 0x603DB4A9), /* ~= 10^-260 */ U64(0xC4CE17B3, 0x99107C22), U64(0xCB550FB4, 0x384D21D3), /* ~= 10^-259 */ U64(0xF6019DA0, 0x7F549B2B), U64(0x7E2A53A1, 0x46606A48), /* ~= 10^-258 */ U64(0x99C10284, 0x4F94E0FB), U64(0x2EDA7444, 0xCBFC426D), /* ~= 10^-257 */ U64(0xC0314325, 0x637A1939), U64(0xFA911155, 0xFEFB5308), /* ~= 10^-256 */ U64(0xF03D93EE, 0xBC589F88), U64(0x793555AB, 0x7EBA27CA), /* ~= 10^-255 */ U64(0x96267C75, 0x35B763B5), U64(0x4BC1558B, 0x2F3458DE), /* ~= 10^-254 */ U64(0xBBB01B92, 0x83253CA2), U64(0x9EB1AAED, 0xFB016F16), /* ~= 10^-253 */ U64(0xEA9C2277, 0x23EE8BCB), U64(0x465E15A9, 0x79C1CADC), /* ~= 10^-252 */ U64(0x92A1958A, 0x7675175F), U64(0x0BFACD89, 0xEC191EC9), /* ~= 10^-251 */ U64(0xB749FAED, 0x14125D36), U64(0xCEF980EC, 0x671F667B), /* ~= 10^-250 */ U64(0xE51C79A8, 0x5916F484), U64(0x82B7E127, 0x80E7401A), /* ~= 10^-249 */ U64(0x8F31CC09, 0x37AE58D2), U64(0xD1B2ECB8, 0xB0908810), /* ~= 10^-248 */ U64(0xB2FE3F0B, 0x8599EF07), U64(0x861FA7E6, 0xDCB4AA15), /* ~= 10^-247 */ U64(0xDFBDCECE, 0x67006AC9), U64(0x67A791E0, 0x93E1D49A), /* ~= 10^-246 */ U64(0x8BD6A141, 0x006042BD), U64(0xE0C8BB2C, 0x5C6D24E0), /* ~= 10^-245 */ U64(0xAECC4991, 0x4078536D), U64(0x58FAE9F7, 0x73886E18), /* ~= 10^-244 */ U64(0xDA7F5BF5, 0x90966848), U64(0xAF39A475, 0x506A899E), /* ~= 10^-243 */ U64(0x888F9979, 0x7A5E012D), U64(0x6D8406C9, 0x52429603), /* ~= 10^-242 */ U64(0xAAB37FD7, 0xD8F58178), U64(0xC8E5087B, 0xA6D33B83), /* ~= 10^-241 */ U64(0xD5605FCD, 0xCF32E1D6), U64(0xFB1E4A9A, 0x90880A64), /* ~= 10^-240 */ U64(0x855C3BE0, 0xA17FCD26), U64(0x5CF2EEA0, 0x9A55067F), /* ~= 10^-239 */ U64(0xA6B34AD8, 0xC9DFC06F), U64(0xF42FAA48, 0xC0EA481E), /* ~= 10^-238 */ U64(0xD0601D8E, 0xFC57B08B), U64(0xF13B94DA, 0xF124DA26), /* ~= 10^-237 */ U64(0x823C1279, 0x5DB6CE57), U64(0x76C53D08, 0xD6B70858), /* ~= 10^-236 */ U64(0xA2CB1717, 0xB52481ED), U64(0x54768C4B, 0x0C64CA6E), /* ~= 10^-235 */ U64(0xCB7DDCDD, 0xA26DA268), U64(0xA9942F5D, 0xCF7DFD09), /* ~= 10^-234 */ U64(0xFE5D5415, 0x0B090B02), U64(0xD3F93B35, 0x435D7C4C), /* ~= 10^-233 */ U64(0x9EFA548D, 0x26E5A6E1), U64(0xC47BC501, 0x4A1A6DAF), /* ~= 10^-232 */ U64(0xC6B8E9B0, 0x709F109A), U64(0x359AB641, 0x9CA1091B), /* ~= 10^-231 */ U64(0xF867241C, 0x8CC6D4C0), U64(0xC30163D2, 0x03C94B62), /* ~= 10^-230 */ U64(0x9B407691, 0xD7FC44F8), U64(0x79E0DE63, 0x425DCF1D), /* ~= 10^-229 */ U64(0xC2109436, 0x4DFB5636), U64(0x985915FC, 0x12F542E4), /* ~= 10^-228 */ U64(0xF294B943, 0xE17A2BC4), U64(0x3E6F5B7B, 0x17B2939D), /* ~= 10^-227 */ U64(0x979CF3CA, 0x6CEC5B5A), U64(0xA705992C, 0xEECF9C42), /* ~= 10^-226 */ U64(0xBD8430BD, 0x08277231), U64(0x50C6FF78, 0x2A838353), /* ~= 10^-225 */ U64(0xECE53CEC, 0x4A314EBD), U64(0xA4F8BF56, 0x35246428), /* ~= 10^-224 */ U64(0x940F4613, 0xAE5ED136), U64(0x871B7795, 0xE136BE99), /* ~= 10^-223 */ U64(0xB9131798, 0x99F68584), U64(0x28E2557B, 0x59846E3F), /* ~= 10^-222 */ U64(0xE757DD7E, 0xC07426E5), U64(0x331AEADA, 0x2FE589CF), /* ~= 10^-221 */ U64(0x9096EA6F, 0x3848984F), U64(0x3FF0D2C8, 0x5DEF7621), /* ~= 10^-220 */ U64(0xB4BCA50B, 0x065ABE63), U64(0x0FED077A, 0x756B53A9), /* ~= 10^-219 */ U64(0xE1EBCE4D, 0xC7F16DFB), U64(0xD3E84959, 0x12C62894), /* ~= 10^-218 */ U64(0x8D3360F0, 0x9CF6E4BD), U64(0x64712DD7, 0xABBBD95C), /* ~= 10^-217 */ U64(0xB080392C, 0xC4349DEC), U64(0xBD8D794D, 0x96AACFB3), /* ~= 10^-216 */ U64(0xDCA04777, 0xF541C567), U64(0xECF0D7A0, 0xFC5583A0), /* ~= 10^-215 */ U64(0x89E42CAA, 0xF9491B60), U64(0xF41686C4, 0x9DB57244), /* ~= 10^-214 */ U64(0xAC5D37D5, 0xB79B6239), U64(0x311C2875, 0xC522CED5), /* ~= 10^-213 */ U64(0xD77485CB, 0x25823AC7), U64(0x7D633293, 0x366B828B), /* ~= 10^-212 */ U64(0x86A8D39E, 0xF77164BC), U64(0xAE5DFF9C, 0x02033197), /* ~= 10^-211 */ U64(0xA8530886, 0xB54DBDEB), U64(0xD9F57F83, 0x0283FDFC), /* ~= 10^-210 */ U64(0xD267CAA8, 0x62A12D66), U64(0xD072DF63, 0xC324FD7B), /* ~= 10^-209 */ U64(0x8380DEA9, 0x3DA4BC60), U64(0x4247CB9E, 0x59F71E6D), /* ~= 10^-208 */ U64(0xA4611653, 0x8D0DEB78), U64(0x52D9BE85, 0xF074E608), /* ~= 10^-207 */ U64(0xCD795BE8, 0x70516656), U64(0x67902E27, 0x6C921F8B), /* ~= 10^-206 */ U64(0x806BD971, 0x4632DFF6), U64(0x00BA1CD8, 0xA3DB53B6), /* ~= 10^-205 */ U64(0xA086CFCD, 0x97BF97F3), U64(0x80E8A40E, 0xCCD228A4), /* ~= 10^-204 */ U64(0xC8A883C0, 0xFDAF7DF0), U64(0x6122CD12, 0x8006B2CD), /* ~= 10^-203 */ U64(0xFAD2A4B1, 0x3D1B5D6C), U64(0x796B8057, 0x20085F81), /* ~= 10^-202 */ U64(0x9CC3A6EE, 0xC6311A63), U64(0xCBE33036, 0x74053BB0), /* ~= 10^-201 */ U64(0xC3F490AA, 0x77BD60FC), U64(0xBEDBFC44, 0x11068A9C), /* ~= 10^-200 */ U64(0xF4F1B4D5, 0x15ACB93B), U64(0xEE92FB55, 0x15482D44), /* ~= 10^-199 */ U64(0x99171105, 0x2D8BF3C5), U64(0x751BDD15, 0x2D4D1C4A), /* ~= 10^-198 */ U64(0xBF5CD546, 0x78EEF0B6), U64(0xD262D45A, 0x78A0635D), /* ~= 10^-197 */ U64(0xEF340A98, 0x172AACE4), U64(0x86FB8971, 0x16C87C34), /* ~= 10^-196 */ U64(0x9580869F, 0x0E7AAC0E), U64(0xD45D35E6, 0xAE3D4DA0), /* ~= 10^-195 */ U64(0xBAE0A846, 0xD2195712), U64(0x89748360, 0x59CCA109), /* ~= 10^-194 */ U64(0xE998D258, 0x869FACD7), U64(0x2BD1A438, 0x703FC94B), /* ~= 10^-193 */ U64(0x91FF8377, 0x5423CC06), U64(0x7B6306A3, 0x4627DDCF), /* ~= 10^-192 */ U64(0xB67F6455, 0x292CBF08), U64(0x1A3BC84C, 0x17B1D542), /* ~= 10^-191 */ U64(0xE41F3D6A, 0x7377EECA), U64(0x20CABA5F, 0x1D9E4A93), /* ~= 10^-190 */ U64(0x8E938662, 0x882AF53E), U64(0x547EB47B, 0x7282EE9C), /* ~= 10^-189 */ U64(0xB23867FB, 0x2A35B28D), U64(0xE99E619A, 0x4F23AA43), /* ~= 10^-188 */ U64(0xDEC681F9, 0xF4C31F31), U64(0x6405FA00, 0xE2EC94D4), /* ~= 10^-187 */ U64(0x8B3C113C, 0x38F9F37E), U64(0xDE83BC40, 0x8DD3DD04), /* ~= 10^-186 */ U64(0xAE0B158B, 0x4738705E), U64(0x9624AB50, 0xB148D445), /* ~= 10^-185 */ U64(0xD98DDAEE, 0x19068C76), U64(0x3BADD624, 0xDD9B0957), /* ~= 10^-184 */ U64(0x87F8A8D4, 0xCFA417C9), U64(0xE54CA5D7, 0x0A80E5D6), /* ~= 10^-183 */ U64(0xA9F6D30A, 0x038D1DBC), U64(0x5E9FCF4C, 0xCD211F4C), /* ~= 10^-182 */ U64(0xD47487CC, 0x8470652B), U64(0x7647C320, 0x0069671F), /* ~= 10^-181 */ U64(0x84C8D4DF, 0xD2C63F3B), U64(0x29ECD9F4, 0x0041E073), /* ~= 10^-180 */ U64(0xA5FB0A17, 0xC777CF09), U64(0xF4681071, 0x00525890), /* ~= 10^-179 */ U64(0xCF79CC9D, 0xB955C2CC), U64(0x7182148D, 0x4066EEB4), /* ~= 10^-178 */ U64(0x81AC1FE2, 0x93D599BF), U64(0xC6F14CD8, 0x48405530), /* ~= 10^-177 */ U64(0xA21727DB, 0x38CB002F), U64(0xB8ADA00E, 0x5A506A7C), /* ~= 10^-176 */ U64(0xCA9CF1D2, 0x06FDC03B), U64(0xA6D90811, 0xF0E4851C), /* ~= 10^-175 */ U64(0xFD442E46, 0x88BD304A), U64(0x908F4A16, 0x6D1DA663), /* ~= 10^-174 */ U64(0x9E4A9CEC, 0x15763E2E), U64(0x9A598E4E, 0x043287FE), /* ~= 10^-173 */ U64(0xC5DD4427, 0x1AD3CDBA), U64(0x40EFF1E1, 0x853F29FD), /* ~= 10^-172 */ U64(0xF7549530, 0xE188C128), U64(0xD12BEE59, 0xE68EF47C), /* ~= 10^-171 */ U64(0x9A94DD3E, 0x8CF578B9), U64(0x82BB74F8, 0x301958CE), /* ~= 10^-170 */ U64(0xC13A148E, 0x3032D6E7), U64(0xE36A5236, 0x3C1FAF01), /* ~= 10^-169 */ U64(0xF18899B1, 0xBC3F8CA1), U64(0xDC44E6C3, 0xCB279AC1), /* ~= 10^-168 */ U64(0x96F5600F, 0x15A7B7E5), U64(0x29AB103A, 0x5EF8C0B9), /* ~= 10^-167 */ U64(0xBCB2B812, 0xDB11A5DE), U64(0x7415D448, 0xF6B6F0E7), /* ~= 10^-166 */ U64(0xEBDF6617, 0x91D60F56), U64(0x111B495B, 0x3464AD21), /* ~= 10^-165 */ U64(0x936B9FCE, 0xBB25C995), U64(0xCAB10DD9, 0x00BEEC34), /* ~= 10^-164 */ U64(0xB84687C2, 0x69EF3BFB), U64(0x3D5D514F, 0x40EEA742), /* ~= 10^-163 */ U64(0xE65829B3, 0x046B0AFA), U64(0x0CB4A5A3, 0x112A5112), /* ~= 10^-162 */ U64(0x8FF71A0F, 0xE2C2E6DC), U64(0x47F0E785, 0xEABA72AB), /* ~= 10^-161 */ U64(0xB3F4E093, 0xDB73A093), U64(0x59ED2167, 0x65690F56), /* ~= 10^-160 */ U64(0xE0F218B8, 0xD25088B8), U64(0x306869C1, 0x3EC3532C), /* ~= 10^-159 */ U64(0x8C974F73, 0x83725573), U64(0x1E414218, 0xC73A13FB), /* ~= 10^-158 */ U64(0xAFBD2350, 0x644EEACF), U64(0xE5D1929E, 0xF90898FA), /* ~= 10^-157 */ U64(0xDBAC6C24, 0x7D62A583), U64(0xDF45F746, 0xB74ABF39), /* ~= 10^-156 */ U64(0x894BC396, 0xCE5DA772), U64(0x6B8BBA8C, 0x328EB783), /* ~= 10^-155 */ U64(0xAB9EB47C, 0x81F5114F), U64(0x066EA92F, 0x3F326564), /* ~= 10^-154 */ U64(0xD686619B, 0xA27255A2), U64(0xC80A537B, 0x0EFEFEBD), /* ~= 10^-153 */ U64(0x8613FD01, 0x45877585), U64(0xBD06742C, 0xE95F5F36), /* ~= 10^-152 */ U64(0xA798FC41, 0x96E952E7), U64(0x2C481138, 0x23B73704), /* ~= 10^-151 */ U64(0xD17F3B51, 0xFCA3A7A0), U64(0xF75A1586, 0x2CA504C5), /* ~= 10^-150 */ U64(0x82EF8513, 0x3DE648C4), U64(0x9A984D73, 0xDBE722FB), /* ~= 10^-149 */ U64(0xA3AB6658, 0x0D5FDAF5), U64(0xC13E60D0, 0xD2E0EBBA), /* ~= 10^-148 */ U64(0xCC963FEE, 0x10B7D1B3), U64(0x318DF905, 0x079926A8), /* ~= 10^-147 */ U64(0xFFBBCFE9, 0x94E5C61F), U64(0xFDF17746, 0x497F7052), /* ~= 10^-146 */ U64(0x9FD561F1, 0xFD0F9BD3), U64(0xFEB6EA8B, 0xEDEFA633), /* ~= 10^-145 */ U64(0xC7CABA6E, 0x7C5382C8), U64(0xFE64A52E, 0xE96B8FC0), /* ~= 10^-144 */ U64(0xF9BD690A, 0x1B68637B), U64(0x3DFDCE7A, 0xA3C673B0), /* ~= 10^-143 */ U64(0x9C1661A6, 0x51213E2D), U64(0x06BEA10C, 0xA65C084E), /* ~= 10^-142 */ U64(0xC31BFA0F, 0xE5698DB8), U64(0x486E494F, 0xCFF30A62), /* ~= 10^-141 */ U64(0xF3E2F893, 0xDEC3F126), U64(0x5A89DBA3, 0xC3EFCCFA), /* ~= 10^-140 */ U64(0x986DDB5C, 0x6B3A76B7), U64(0xF8962946, 0x5A75E01C), /* ~= 10^-139 */ U64(0xBE895233, 0x86091465), U64(0xF6BBB397, 0xF1135823), /* ~= 10^-138 */ U64(0xEE2BA6C0, 0x678B597F), U64(0x746AA07D, 0xED582E2C), /* ~= 10^-137 */ U64(0x94DB4838, 0x40B717EF), U64(0xA8C2A44E, 0xB4571CDC), /* ~= 10^-136 */ U64(0xBA121A46, 0x50E4DDEB), U64(0x92F34D62, 0x616CE413), /* ~= 10^-135 */ U64(0xE896A0D7, 0xE51E1566), U64(0x77B020BA, 0xF9C81D17), /* ~= 10^-134 */ U64(0x915E2486, 0xEF32CD60), U64(0x0ACE1474, 0xDC1D122E), /* ~= 10^-133 */ U64(0xB5B5ADA8, 0xAAFF80B8), U64(0x0D819992, 0x132456BA), /* ~= 10^-132 */ U64(0xE3231912, 0xD5BF60E6), U64(0x10E1FFF6, 0x97ED6C69), /* ~= 10^-131 */ U64(0x8DF5EFAB, 0xC5979C8F), U64(0xCA8D3FFA, 0x1EF463C1), /* ~= 10^-130 */ U64(0xB1736B96, 0xB6FD83B3), U64(0xBD308FF8, 0xA6B17CB2), /* ~= 10^-129 */ U64(0xDDD0467C, 0x64BCE4A0), U64(0xAC7CB3F6, 0xD05DDBDE), /* ~= 10^-128 */ U64(0x8AA22C0D, 0xBEF60EE4), U64(0x6BCDF07A, 0x423AA96B), /* ~= 10^-127 */ U64(0xAD4AB711, 0x2EB3929D), U64(0x86C16C98, 0xD2C953C6), /* ~= 10^-126 */ U64(0xD89D64D5, 0x7A607744), U64(0xE871C7BF, 0x077BA8B7), /* ~= 10^-125 */ U64(0x87625F05, 0x6C7C4A8B), U64(0x11471CD7, 0x64AD4972), /* ~= 10^-124 */ U64(0xA93AF6C6, 0xC79B5D2D), U64(0xD598E40D, 0x3DD89BCF), /* ~= 10^-123 */ U64(0xD389B478, 0x79823479), U64(0x4AFF1D10, 0x8D4EC2C3), /* ~= 10^-122 */ U64(0x843610CB, 0x4BF160CB), U64(0xCEDF722A, 0x585139BA), /* ~= 10^-121 */ U64(0xA54394FE, 0x1EEDB8FE), U64(0xC2974EB4, 0xEE658828), /* ~= 10^-120 */ U64(0xCE947A3D, 0xA6A9273E), U64(0x733D2262, 0x29FEEA32), /* ~= 10^-119 */ U64(0x811CCC66, 0x8829B887), U64(0x0806357D, 0x5A3F525F), /* ~= 10^-118 */ U64(0xA163FF80, 0x2A3426A8), U64(0xCA07C2DC, 0xB0CF26F7), /* ~= 10^-117 */ U64(0xC9BCFF60, 0x34C13052), U64(0xFC89B393, 0xDD02F0B5), /* ~= 10^-116 */ U64(0xFC2C3F38, 0x41F17C67), U64(0xBBAC2078, 0xD443ACE2), /* ~= 10^-115 */ U64(0x9D9BA783, 0x2936EDC0), U64(0xD54B944B, 0x84AA4C0D), /* ~= 10^-114 */ U64(0xC5029163, 0xF384A931), U64(0x0A9E795E, 0x65D4DF11), /* ~= 10^-113 */ U64(0xF64335BC, 0xF065D37D), U64(0x4D4617B5, 0xFF4A16D5), /* ~= 10^-112 */ U64(0x99EA0196, 0x163FA42E), U64(0x504BCED1, 0xBF8E4E45), /* ~= 10^-111 */ U64(0xC06481FB, 0x9BCF8D39), U64(0xE45EC286, 0x2F71E1D6), /* ~= 10^-110 */ U64(0xF07DA27A, 0x82C37088), U64(0x5D767327, 0xBB4E5A4C), /* ~= 10^-109 */ U64(0x964E858C, 0x91BA2655), U64(0x3A6A07F8, 0xD510F86F), /* ~= 10^-108 */ U64(0xBBE226EF, 0xB628AFEA), U64(0x890489F7, 0x0A55368B), /* ~= 10^-107 */ U64(0xEADAB0AB, 0xA3B2DBE5), U64(0x2B45AC74, 0xCCEA842E), /* ~= 10^-106 */ U64(0x92C8AE6B, 0x464FC96F), U64(0x3B0B8BC9, 0x0012929D), /* ~= 10^-105 */ U64(0xB77ADA06, 0x17E3BBCB), U64(0x09CE6EBB, 0x40173744), /* ~= 10^-104 */ U64(0xE5599087, 0x9DDCAABD), U64(0xCC420A6A, 0x101D0515), /* ~= 10^-103 */ U64(0x8F57FA54, 0xC2A9EAB6), U64(0x9FA94682, 0x4A12232D), /* ~= 10^-102 */ U64(0xB32DF8E9, 0xF3546564), U64(0x47939822, 0xDC96ABF9), /* ~= 10^-101 */ U64(0xDFF97724, 0x70297EBD), U64(0x59787E2B, 0x93BC56F7), /* ~= 10^-100 */ U64(0x8BFBEA76, 0xC619EF36), U64(0x57EB4EDB, 0x3C55B65A), /* ~= 10^-99 */ U64(0xAEFAE514, 0x77A06B03), U64(0xEDE62292, 0x0B6B23F1), /* ~= 10^-98 */ U64(0xDAB99E59, 0x958885C4), U64(0xE95FAB36, 0x8E45ECED), /* ~= 10^-97 */ U64(0x88B402F7, 0xFD75539B), U64(0x11DBCB02, 0x18EBB414), /* ~= 10^-96 */ U64(0xAAE103B5, 0xFCD2A881), U64(0xD652BDC2, 0x9F26A119), /* ~= 10^-95 */ U64(0xD59944A3, 0x7C0752A2), U64(0x4BE76D33, 0x46F0495F), /* ~= 10^-94 */ U64(0x857FCAE6, 0x2D8493A5), U64(0x6F70A440, 0x0C562DDB), /* ~= 10^-93 */ U64(0xA6DFBD9F, 0xB8E5B88E), U64(0xCB4CCD50, 0x0F6BB952), /* ~= 10^-92 */ U64(0xD097AD07, 0xA71F26B2), U64(0x7E2000A4, 0x1346A7A7), /* ~= 10^-91 */ U64(0x825ECC24, 0xC873782F), U64(0x8ED40066, 0x8C0C28C8), /* ~= 10^-90 */ U64(0xA2F67F2D, 0xFA90563B), U64(0x72890080, 0x2F0F32FA), /* ~= 10^-89 */ U64(0xCBB41EF9, 0x79346BCA), U64(0x4F2B40A0, 0x3AD2FFB9), /* ~= 10^-88 */ U64(0xFEA126B7, 0xD78186BC), U64(0xE2F610C8, 0x4987BFA8), /* ~= 10^-87 */ U64(0x9F24B832, 0xE6B0F436), U64(0x0DD9CA7D, 0x2DF4D7C9), /* ~= 10^-86 */ U64(0xC6EDE63F, 0xA05D3143), U64(0x91503D1C, 0x79720DBB), /* ~= 10^-85 */ U64(0xF8A95FCF, 0x88747D94), U64(0x75A44C63, 0x97CE912A), /* ~= 10^-84 */ U64(0x9B69DBE1, 0xB548CE7C), U64(0xC986AFBE, 0x3EE11ABA), /* ~= 10^-83 */ U64(0xC24452DA, 0x229B021B), U64(0xFBE85BAD, 0xCE996168), /* ~= 10^-82 */ U64(0xF2D56790, 0xAB41C2A2), U64(0xFAE27299, 0x423FB9C3), /* ~= 10^-81 */ U64(0x97C560BA, 0x6B0919A5), U64(0xDCCD879F, 0xC967D41A), /* ~= 10^-80 */ U64(0xBDB6B8E9, 0x05CB600F), U64(0x5400E987, 0xBBC1C920), /* ~= 10^-79 */ U64(0xED246723, 0x473E3813), U64(0x290123E9, 0xAAB23B68), /* ~= 10^-78 */ U64(0x9436C076, 0x0C86E30B), U64(0xF9A0B672, 0x0AAF6521), /* ~= 10^-77 */ U64(0xB9447093, 0x8FA89BCE), U64(0xF808E40E, 0x8D5B3E69), /* ~= 10^-76 */ U64(0xE7958CB8, 0x7392C2C2), U64(0xB60B1D12, 0x30B20E04), /* ~= 10^-75 */ U64(0x90BD77F3, 0x483BB9B9), U64(0xB1C6F22B, 0x5E6F48C2), /* ~= 10^-74 */ U64(0xB4ECD5F0, 0x1A4AA828), U64(0x1E38AEB6, 0x360B1AF3), /* ~= 10^-73 */ U64(0xE2280B6C, 0x20DD5232), U64(0x25C6DA63, 0xC38DE1B0), /* ~= 10^-72 */ U64(0x8D590723, 0x948A535F), U64(0x579C487E, 0x5A38AD0E), /* ~= 10^-71 */ U64(0xB0AF48EC, 0x79ACE837), U64(0x2D835A9D, 0xF0C6D851), /* ~= 10^-70 */ U64(0xDCDB1B27, 0x98182244), U64(0xF8E43145, 0x6CF88E65), /* ~= 10^-69 */ U64(0x8A08F0F8, 0xBF0F156B), U64(0x1B8E9ECB, 0x641B58FF), /* ~= 10^-68 */ U64(0xAC8B2D36, 0xEED2DAC5), U64(0xE272467E, 0x3D222F3F), /* ~= 10^-67 */ U64(0xD7ADF884, 0xAA879177), U64(0x5B0ED81D, 0xCC6ABB0F), /* ~= 10^-66 */ U64(0x86CCBB52, 0xEA94BAEA), U64(0x98E94712, 0x9FC2B4E9), /* ~= 10^-65 */ U64(0xA87FEA27, 0xA539E9A5), U64(0x3F2398D7, 0x47B36224), /* ~= 10^-64 */ U64(0xD29FE4B1, 0x8E88640E), U64(0x8EEC7F0D, 0x19A03AAD), /* ~= 10^-63 */ U64(0x83A3EEEE, 0xF9153E89), U64(0x1953CF68, 0x300424AC), /* ~= 10^-62 */ U64(0xA48CEAAA, 0xB75A8E2B), U64(0x5FA8C342, 0x3C052DD7), /* ~= 10^-61 */ U64(0xCDB02555, 0x653131B6), U64(0x3792F412, 0xCB06794D), /* ~= 10^-60 */ U64(0x808E1755, 0x5F3EBF11), U64(0xE2BBD88B, 0xBEE40BD0), /* ~= 10^-59 */ U64(0xA0B19D2A, 0xB70E6ED6), U64(0x5B6ACEAE, 0xAE9D0EC4), /* ~= 10^-58 */ U64(0xC8DE0475, 0x64D20A8B), U64(0xF245825A, 0x5A445275), /* ~= 10^-57 */ U64(0xFB158592, 0xBE068D2E), U64(0xEED6E2F0, 0xF0D56712), /* ~= 10^-56 */ U64(0x9CED737B, 0xB6C4183D), U64(0x55464DD6, 0x9685606B), /* ~= 10^-55 */ U64(0xC428D05A, 0xA4751E4C), U64(0xAA97E14C, 0x3C26B886), /* ~= 10^-54 */ U64(0xF5330471, 0x4D9265DF), U64(0xD53DD99F, 0x4B3066A8), /* ~= 10^-53 */ U64(0x993FE2C6, 0xD07B7FAB), U64(0xE546A803, 0x8EFE4029), /* ~= 10^-52 */ U64(0xBF8FDB78, 0x849A5F96), U64(0xDE985204, 0x72BDD033), /* ~= 10^-51 */ U64(0xEF73D256, 0xA5C0F77C), U64(0x963E6685, 0x8F6D4440), /* ~= 10^-50 */ U64(0x95A86376, 0x27989AAD), U64(0xDDE70013, 0x79A44AA8), /* ~= 10^-49 */ U64(0xBB127C53, 0xB17EC159), U64(0x5560C018, 0x580D5D52), /* ~= 10^-48 */ U64(0xE9D71B68, 0x9DDE71AF), U64(0xAAB8F01E, 0x6E10B4A6), /* ~= 10^-47 */ U64(0x92267121, 0x62AB070D), U64(0xCAB39613, 0x04CA70E8), /* ~= 10^-46 */ U64(0xB6B00D69, 0xBB55C8D1), U64(0x3D607B97, 0xC5FD0D22), /* ~= 10^-45 */ U64(0xE45C10C4, 0x2A2B3B05), U64(0x8CB89A7D, 0xB77C506A), /* ~= 10^-44 */ U64(0x8EB98A7A, 0x9A5B04E3), U64(0x77F3608E, 0x92ADB242), /* ~= 10^-43 */ U64(0xB267ED19, 0x40F1C61C), U64(0x55F038B2, 0x37591ED3), /* ~= 10^-42 */ U64(0xDF01E85F, 0x912E37A3), U64(0x6B6C46DE, 0xC52F6688), /* ~= 10^-41 */ U64(0x8B61313B, 0xBABCE2C6), U64(0x2323AC4B, 0x3B3DA015), /* ~= 10^-40 */ U64(0xAE397D8A, 0xA96C1B77), U64(0xABEC975E, 0x0A0D081A), /* ~= 10^-39 */ U64(0xD9C7DCED, 0x53C72255), U64(0x96E7BD35, 0x8C904A21), /* ~= 10^-38 */ U64(0x881CEA14, 0x545C7575), U64(0x7E50D641, 0x77DA2E54), /* ~= 10^-37 */ U64(0xAA242499, 0x697392D2), U64(0xDDE50BD1, 0xD5D0B9E9), /* ~= 10^-36 */ U64(0xD4AD2DBF, 0xC3D07787), U64(0x955E4EC6, 0x4B44E864), /* ~= 10^-35 */ U64(0x84EC3C97, 0xDA624AB4), U64(0xBD5AF13B, 0xEF0B113E), /* ~= 10^-34 */ U64(0xA6274BBD, 0xD0FADD61), U64(0xECB1AD8A, 0xEACDD58E), /* ~= 10^-33 */ U64(0xCFB11EAD, 0x453994BA), U64(0x67DE18ED, 0xA5814AF2), /* ~= 10^-32 */ U64(0x81CEB32C, 0x4B43FCF4), U64(0x80EACF94, 0x8770CED7), /* ~= 10^-31 */ U64(0xA2425FF7, 0x5E14FC31), U64(0xA1258379, 0xA94D028D), /* ~= 10^-30 */ U64(0xCAD2F7F5, 0x359A3B3E), U64(0x096EE458, 0x13A04330), /* ~= 10^-29 */ U64(0xFD87B5F2, 0x8300CA0D), U64(0x8BCA9D6E, 0x188853FC), /* ~= 10^-28 */ U64(0x9E74D1B7, 0x91E07E48), U64(0x775EA264, 0xCF55347D), /* ~= 10^-27 */ U64(0xC6120625, 0x76589DDA), U64(0x95364AFE, 0x032A819D), /* ~= 10^-26 */ U64(0xF79687AE, 0xD3EEC551), U64(0x3A83DDBD, 0x83F52204), /* ~= 10^-25 */ U64(0x9ABE14CD, 0x44753B52), U64(0xC4926A96, 0x72793542), /* ~= 10^-24 */ U64(0xC16D9A00, 0x95928A27), U64(0x75B7053C, 0x0F178293), /* ~= 10^-23 */ U64(0xF1C90080, 0xBAF72CB1), U64(0x5324C68B, 0x12DD6338), /* ~= 10^-22 */ U64(0x971DA050, 0x74DA7BEE), U64(0xD3F6FC16, 0xEBCA5E03), /* ~= 10^-21 */ U64(0xBCE50864, 0x92111AEA), U64(0x88F4BB1C, 0xA6BCF584), /* ~= 10^-20 */ U64(0xEC1E4A7D, 0xB69561A5), U64(0x2B31E9E3, 0xD06C32E5), /* ~= 10^-19 */ U64(0x9392EE8E, 0x921D5D07), U64(0x3AFF322E, 0x62439FCF), /* ~= 10^-18 */ U64(0xB877AA32, 0x36A4B449), U64(0x09BEFEB9, 0xFAD487C2), /* ~= 10^-17 */ U64(0xE69594BE, 0xC44DE15B), U64(0x4C2EBE68, 0x7989A9B3), /* ~= 10^-16 */ U64(0x901D7CF7, 0x3AB0ACD9), U64(0x0F9D3701, 0x4BF60A10), /* ~= 10^-15 */ U64(0xB424DC35, 0x095CD80F), U64(0x538484C1, 0x9EF38C94), /* ~= 10^-14 */ U64(0xE12E1342, 0x4BB40E13), U64(0x2865A5F2, 0x06B06FB9), /* ~= 10^-13 */ U64(0x8CBCCC09, 0x6F5088CB), U64(0xF93F87B7, 0x442E45D3), /* ~= 10^-12 */ U64(0xAFEBFF0B, 0xCB24AAFE), U64(0xF78F69A5, 0x1539D748), /* ~= 10^-11 */ U64(0xDBE6FECE, 0xBDEDD5BE), U64(0xB573440E, 0x5A884D1B), /* ~= 10^-10 */ U64(0x89705F41, 0x36B4A597), U64(0x31680A88, 0xF8953030), /* ~= 10^-9 */ U64(0xABCC7711, 0x8461CEFC), U64(0xFDC20D2B, 0x36BA7C3D), /* ~= 10^-8 */ U64(0xD6BF94D5, 0xE57A42BC), U64(0x3D329076, 0x04691B4C), /* ~= 10^-7 */ U64(0x8637BD05, 0xAF6C69B5), U64(0xA63F9A49, 0xC2C1B10F), /* ~= 10^-6 */ U64(0xA7C5AC47, 0x1B478423), U64(0x0FCF80DC, 0x33721D53), /* ~= 10^-5 */ U64(0xD1B71758, 0xE219652B), U64(0xD3C36113, 0x404EA4A8), /* ~= 10^-4 */ U64(0x83126E97, 0x8D4FDF3B), U64(0x645A1CAC, 0x083126E9), /* ~= 10^-3 */ U64(0xA3D70A3D, 0x70A3D70A), U64(0x3D70A3D7, 0x0A3D70A3), /* ~= 10^-2 */ U64(0xCCCCCCCC, 0xCCCCCCCC), U64(0xCCCCCCCC, 0xCCCCCCCC), /* ~= 10^-1 */ U64(0x80000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^0 */ U64(0xA0000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^1 */ U64(0xC8000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^2 */ U64(0xFA000000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^3 */ U64(0x9C400000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^4 */ U64(0xC3500000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^5 */ U64(0xF4240000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^6 */ U64(0x98968000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^7 */ U64(0xBEBC2000, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^8 */ U64(0xEE6B2800, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^9 */ U64(0x9502F900, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^10 */ U64(0xBA43B740, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^11 */ U64(0xE8D4A510, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^12 */ U64(0x9184E72A, 0x00000000), U64(0x00000000, 0x00000000), /* == 10^13 */ U64(0xB5E620F4, 0x80000000), U64(0x00000000, 0x00000000), /* == 10^14 */ U64(0xE35FA931, 0xA0000000), U64(0x00000000, 0x00000000), /* == 10^15 */ U64(0x8E1BC9BF, 0x04000000), U64(0x00000000, 0x00000000), /* == 10^16 */ U64(0xB1A2BC2E, 0xC5000000), U64(0x00000000, 0x00000000), /* == 10^17 */ U64(0xDE0B6B3A, 0x76400000), U64(0x00000000, 0x00000000), /* == 10^18 */ U64(0x8AC72304, 0x89E80000), U64(0x00000000, 0x00000000), /* == 10^19 */ U64(0xAD78EBC5, 0xAC620000), U64(0x00000000, 0x00000000), /* == 10^20 */ U64(0xD8D726B7, 0x177A8000), U64(0x00000000, 0x00000000), /* == 10^21 */ U64(0x87867832, 0x6EAC9000), U64(0x00000000, 0x00000000), /* == 10^22 */ U64(0xA968163F, 0x0A57B400), U64(0x00000000, 0x00000000), /* == 10^23 */ U64(0xD3C21BCE, 0xCCEDA100), U64(0x00000000, 0x00000000), /* == 10^24 */ U64(0x84595161, 0x401484A0), U64(0x00000000, 0x00000000), /* == 10^25 */ U64(0xA56FA5B9, 0x9019A5C8), U64(0x00000000, 0x00000000), /* == 10^26 */ U64(0xCECB8F27, 0xF4200F3A), U64(0x00000000, 0x00000000), /* == 10^27 */ U64(0x813F3978, 0xF8940984), U64(0x40000000, 0x00000000), /* == 10^28 */ U64(0xA18F07D7, 0x36B90BE5), U64(0x50000000, 0x00000000), /* == 10^29 */ U64(0xC9F2C9CD, 0x04674EDE), U64(0xA4000000, 0x00000000), /* == 10^30 */ U64(0xFC6F7C40, 0x45812296), U64(0x4D000000, 0x00000000), /* == 10^31 */ U64(0x9DC5ADA8, 0x2B70B59D), U64(0xF0200000, 0x00000000), /* == 10^32 */ U64(0xC5371912, 0x364CE305), U64(0x6C280000, 0x00000000), /* == 10^33 */ U64(0xF684DF56, 0xC3E01BC6), U64(0xC7320000, 0x00000000), /* == 10^34 */ U64(0x9A130B96, 0x3A6C115C), U64(0x3C7F4000, 0x00000000), /* == 10^35 */ U64(0xC097CE7B, 0xC90715B3), U64(0x4B9F1000, 0x00000000), /* == 10^36 */ U64(0xF0BDC21A, 0xBB48DB20), U64(0x1E86D400, 0x00000000), /* == 10^37 */ U64(0x96769950, 0xB50D88F4), U64(0x13144480, 0x00000000), /* == 10^38 */ U64(0xBC143FA4, 0xE250EB31), U64(0x17D955A0, 0x00000000), /* == 10^39 */ U64(0xEB194F8E, 0x1AE525FD), U64(0x5DCFAB08, 0x00000000), /* == 10^40 */ U64(0x92EFD1B8, 0xD0CF37BE), U64(0x5AA1CAE5, 0x00000000), /* == 10^41 */ U64(0xB7ABC627, 0x050305AD), U64(0xF14A3D9E, 0x40000000), /* == 10^42 */ U64(0xE596B7B0, 0xC643C719), U64(0x6D9CCD05, 0xD0000000), /* == 10^43 */ U64(0x8F7E32CE, 0x7BEA5C6F), U64(0xE4820023, 0xA2000000), /* == 10^44 */ U64(0xB35DBF82, 0x1AE4F38B), U64(0xDDA2802C, 0x8A800000), /* == 10^45 */ U64(0xE0352F62, 0xA19E306E), U64(0xD50B2037, 0xAD200000), /* == 10^46 */ U64(0x8C213D9D, 0xA502DE45), U64(0x4526F422, 0xCC340000), /* == 10^47 */ U64(0xAF298D05, 0x0E4395D6), U64(0x9670B12B, 0x7F410000), /* == 10^48 */ U64(0xDAF3F046, 0x51D47B4C), U64(0x3C0CDD76, 0x5F114000), /* == 10^49 */ U64(0x88D8762B, 0xF324CD0F), U64(0xA5880A69, 0xFB6AC800), /* == 10^50 */ U64(0xAB0E93B6, 0xEFEE0053), U64(0x8EEA0D04, 0x7A457A00), /* == 10^51 */ U64(0xD5D238A4, 0xABE98068), U64(0x72A49045, 0x98D6D880), /* == 10^52 */ U64(0x85A36366, 0xEB71F041), U64(0x47A6DA2B, 0x7F864750), /* == 10^53 */ U64(0xA70C3C40, 0xA64E6C51), U64(0x999090B6, 0x5F67D924), /* == 10^54 */ U64(0xD0CF4B50, 0xCFE20765), U64(0xFFF4B4E3, 0xF741CF6D), /* == 10^55 */ U64(0x82818F12, 0x81ED449F), U64(0xBFF8F10E, 0x7A8921A4), /* ~= 10^56 */ U64(0xA321F2D7, 0x226895C7), U64(0xAFF72D52, 0x192B6A0D), /* ~= 10^57 */ U64(0xCBEA6F8C, 0xEB02BB39), U64(0x9BF4F8A6, 0x9F764490), /* ~= 10^58 */ U64(0xFEE50B70, 0x25C36A08), U64(0x02F236D0, 0x4753D5B4), /* ~= 10^59 */ U64(0x9F4F2726, 0x179A2245), U64(0x01D76242, 0x2C946590), /* ~= 10^60 */ U64(0xC722F0EF, 0x9D80AAD6), U64(0x424D3AD2, 0xB7B97EF5), /* ~= 10^61 */ U64(0xF8EBAD2B, 0x84E0D58B), U64(0xD2E08987, 0x65A7DEB2), /* ~= 10^62 */ U64(0x9B934C3B, 0x330C8577), U64(0x63CC55F4, 0x9F88EB2F), /* ~= 10^63 */ U64(0xC2781F49, 0xFFCFA6D5), U64(0x3CBF6B71, 0xC76B25FB), /* ~= 10^64 */ U64(0xF316271C, 0x7FC3908A), U64(0x8BEF464E, 0x3945EF7A), /* ~= 10^65 */ U64(0x97EDD871, 0xCFDA3A56), U64(0x97758BF0, 0xE3CBB5AC), /* ~= 10^66 */ U64(0xBDE94E8E, 0x43D0C8EC), U64(0x3D52EEED, 0x1CBEA317), /* ~= 10^67 */ U64(0xED63A231, 0xD4C4FB27), U64(0x4CA7AAA8, 0x63EE4BDD), /* ~= 10^68 */ U64(0x945E455F, 0x24FB1CF8), U64(0x8FE8CAA9, 0x3E74EF6A), /* ~= 10^69 */ U64(0xB975D6B6, 0xEE39E436), U64(0xB3E2FD53, 0x8E122B44), /* ~= 10^70 */ U64(0xE7D34C64, 0xA9C85D44), U64(0x60DBBCA8, 0x7196B616), /* ~= 10^71 */ U64(0x90E40FBE, 0xEA1D3A4A), U64(0xBC8955E9, 0x46FE31CD), /* ~= 10^72 */ U64(0xB51D13AE, 0xA4A488DD), U64(0x6BABAB63, 0x98BDBE41), /* ~= 10^73 */ U64(0xE264589A, 0x4DCDAB14), U64(0xC696963C, 0x7EED2DD1), /* ~= 10^74 */ U64(0x8D7EB760, 0x70A08AEC), U64(0xFC1E1DE5, 0xCF543CA2), /* ~= 10^75 */ U64(0xB0DE6538, 0x8CC8ADA8), U64(0x3B25A55F, 0x43294BCB), /* ~= 10^76 */ U64(0xDD15FE86, 0xAFFAD912), U64(0x49EF0EB7, 0x13F39EBE), /* ~= 10^77 */ U64(0x8A2DBF14, 0x2DFCC7AB), U64(0x6E356932, 0x6C784337), /* ~= 10^78 */ U64(0xACB92ED9, 0x397BF996), U64(0x49C2C37F, 0x07965404), /* ~= 10^79 */ U64(0xD7E77A8F, 0x87DAF7FB), U64(0xDC33745E, 0xC97BE906), /* ~= 10^80 */ U64(0x86F0AC99, 0xB4E8DAFD), U64(0x69A028BB, 0x3DED71A3), /* ~= 10^81 */ U64(0xA8ACD7C0, 0x222311BC), U64(0xC40832EA, 0x0D68CE0C), /* ~= 10^82 */ U64(0xD2D80DB0, 0x2AABD62B), U64(0xF50A3FA4, 0x90C30190), /* ~= 10^83 */ U64(0x83C7088E, 0x1AAB65DB), U64(0x792667C6, 0xDA79E0FA), /* ~= 10^84 */ U64(0xA4B8CAB1, 0xA1563F52), U64(0x577001B8, 0x91185938), /* ~= 10^85 */ U64(0xCDE6FD5E, 0x09ABCF26), U64(0xED4C0226, 0xB55E6F86), /* ~= 10^86 */ U64(0x80B05E5A, 0xC60B6178), U64(0x544F8158, 0x315B05B4), /* ~= 10^87 */ U64(0xA0DC75F1, 0x778E39D6), U64(0x696361AE, 0x3DB1C721), /* ~= 10^88 */ U64(0xC913936D, 0xD571C84C), U64(0x03BC3A19, 0xCD1E38E9), /* ~= 10^89 */ U64(0xFB587849, 0x4ACE3A5F), U64(0x04AB48A0, 0x4065C723), /* ~= 10^90 */ U64(0x9D174B2D, 0xCEC0E47B), U64(0x62EB0D64, 0x283F9C76), /* ~= 10^91 */ U64(0xC45D1DF9, 0x42711D9A), U64(0x3BA5D0BD, 0x324F8394), /* ~= 10^92 */ U64(0xF5746577, 0x930D6500), U64(0xCA8F44EC, 0x7EE36479), /* ~= 10^93 */ U64(0x9968BF6A, 0xBBE85F20), U64(0x7E998B13, 0xCF4E1ECB), /* ~= 10^94 */ U64(0xBFC2EF45, 0x6AE276E8), U64(0x9E3FEDD8, 0xC321A67E), /* ~= 10^95 */ U64(0xEFB3AB16, 0xC59B14A2), U64(0xC5CFE94E, 0xF3EA101E), /* ~= 10^96 */ U64(0x95D04AEE, 0x3B80ECE5), U64(0xBBA1F1D1, 0x58724A12), /* ~= 10^97 */ U64(0xBB445DA9, 0xCA61281F), U64(0x2A8A6E45, 0xAE8EDC97), /* ~= 10^98 */ U64(0xEA157514, 0x3CF97226), U64(0xF52D09D7, 0x1A3293BD), /* ~= 10^99 */ U64(0x924D692C, 0xA61BE758), U64(0x593C2626, 0x705F9C56), /* ~= 10^100 */ U64(0xB6E0C377, 0xCFA2E12E), U64(0x6F8B2FB0, 0x0C77836C), /* ~= 10^101 */ U64(0xE498F455, 0xC38B997A), U64(0x0B6DFB9C, 0x0F956447), /* ~= 10^102 */ U64(0x8EDF98B5, 0x9A373FEC), U64(0x4724BD41, 0x89BD5EAC), /* ~= 10^103 */ U64(0xB2977EE3, 0x00C50FE7), U64(0x58EDEC91, 0xEC2CB657), /* ~= 10^104 */ U64(0xDF3D5E9B, 0xC0F653E1), U64(0x2F2967B6, 0x6737E3ED), /* ~= 10^105 */ U64(0x8B865B21, 0x5899F46C), U64(0xBD79E0D2, 0x0082EE74), /* ~= 10^106 */ U64(0xAE67F1E9, 0xAEC07187), U64(0xECD85906, 0x80A3AA11), /* ~= 10^107 */ U64(0xDA01EE64, 0x1A708DE9), U64(0xE80E6F48, 0x20CC9495), /* ~= 10^108 */ U64(0x884134FE, 0x908658B2), U64(0x3109058D, 0x147FDCDD), /* ~= 10^109 */ U64(0xAA51823E, 0x34A7EEDE), U64(0xBD4B46F0, 0x599FD415), /* ~= 10^110 */ U64(0xD4E5E2CD, 0xC1D1EA96), U64(0x6C9E18AC, 0x7007C91A), /* ~= 10^111 */ U64(0x850FADC0, 0x9923329E), U64(0x03E2CF6B, 0xC604DDB0), /* ~= 10^112 */ U64(0xA6539930, 0xBF6BFF45), U64(0x84DB8346, 0xB786151C), /* ~= 10^113 */ U64(0xCFE87F7C, 0xEF46FF16), U64(0xE6126418, 0x65679A63), /* ~= 10^114 */ U64(0x81F14FAE, 0x158C5F6E), U64(0x4FCB7E8F, 0x3F60C07E), /* ~= 10^115 */ U64(0xA26DA399, 0x9AEF7749), U64(0xE3BE5E33, 0x0F38F09D), /* ~= 10^116 */ U64(0xCB090C80, 0x01AB551C), U64(0x5CADF5BF, 0xD3072CC5), /* ~= 10^117 */ U64(0xFDCB4FA0, 0x02162A63), U64(0x73D9732F, 0xC7C8F7F6), /* ~= 10^118 */ U64(0x9E9F11C4, 0x014DDA7E), U64(0x2867E7FD, 0xDCDD9AFA), /* ~= 10^119 */ U64(0xC646D635, 0x01A1511D), U64(0xB281E1FD, 0x541501B8), /* ~= 10^120 */ U64(0xF7D88BC2, 0x4209A565), U64(0x1F225A7C, 0xA91A4226), /* ~= 10^121 */ U64(0x9AE75759, 0x6946075F), U64(0x3375788D, 0xE9B06958), /* ~= 10^122 */ U64(0xC1A12D2F, 0xC3978937), U64(0x0052D6B1, 0x641C83AE), /* ~= 10^123 */ U64(0xF209787B, 0xB47D6B84), U64(0xC0678C5D, 0xBD23A49A), /* ~= 10^124 */ U64(0x9745EB4D, 0x50CE6332), U64(0xF840B7BA, 0x963646E0), /* ~= 10^125 */ U64(0xBD176620, 0xA501FBFF), U64(0xB650E5A9, 0x3BC3D898), /* ~= 10^126 */ U64(0xEC5D3FA8, 0xCE427AFF), U64(0xA3E51F13, 0x8AB4CEBE), /* ~= 10^127 */ U64(0x93BA47C9, 0x80E98CDF), U64(0xC66F336C, 0x36B10137), /* ~= 10^128 */ U64(0xB8A8D9BB, 0xE123F017), U64(0xB80B0047, 0x445D4184), /* ~= 10^129 */ U64(0xE6D3102A, 0xD96CEC1D), U64(0xA60DC059, 0x157491E5), /* ~= 10^130 */ U64(0x9043EA1A, 0xC7E41392), U64(0x87C89837, 0xAD68DB2F), /* ~= 10^131 */ U64(0xB454E4A1, 0x79DD1877), U64(0x29BABE45, 0x98C311FB), /* ~= 10^132 */ U64(0xE16A1DC9, 0xD8545E94), U64(0xF4296DD6, 0xFEF3D67A), /* ~= 10^133 */ U64(0x8CE2529E, 0x2734BB1D), U64(0x1899E4A6, 0x5F58660C), /* ~= 10^134 */ U64(0xB01AE745, 0xB101E9E4), U64(0x5EC05DCF, 0xF72E7F8F), /* ~= 10^135 */ U64(0xDC21A117, 0x1D42645D), U64(0x76707543, 0xF4FA1F73), /* ~= 10^136 */ U64(0x899504AE, 0x72497EBA), U64(0x6A06494A, 0x791C53A8), /* ~= 10^137 */ U64(0xABFA45DA, 0x0EDBDE69), U64(0x0487DB9D, 0x17636892), /* ~= 10^138 */ U64(0xD6F8D750, 0x9292D603), U64(0x45A9D284, 0x5D3C42B6), /* ~= 10^139 */ U64(0x865B8692, 0x5B9BC5C2), U64(0x0B8A2392, 0xBA45A9B2), /* ~= 10^140 */ U64(0xA7F26836, 0xF282B732), U64(0x8E6CAC77, 0x68D7141E), /* ~= 10^141 */ U64(0xD1EF0244, 0xAF2364FF), U64(0x3207D795, 0x430CD926), /* ~= 10^142 */ U64(0x8335616A, 0xED761F1F), U64(0x7F44E6BD, 0x49E807B8), /* ~= 10^143 */ U64(0xA402B9C5, 0xA8D3A6E7), U64(0x5F16206C, 0x9C6209A6), /* ~= 10^144 */ U64(0xCD036837, 0x130890A1), U64(0x36DBA887, 0xC37A8C0F), /* ~= 10^145 */ U64(0x80222122, 0x6BE55A64), U64(0xC2494954, 0xDA2C9789), /* ~= 10^146 */ U64(0xA02AA96B, 0x06DEB0FD), U64(0xF2DB9BAA, 0x10B7BD6C), /* ~= 10^147 */ U64(0xC83553C5, 0xC8965D3D), U64(0x6F928294, 0x94E5ACC7), /* ~= 10^148 */ U64(0xFA42A8B7, 0x3ABBF48C), U64(0xCB772339, 0xBA1F17F9), /* ~= 10^149 */ U64(0x9C69A972, 0x84B578D7), U64(0xFF2A7604, 0x14536EFB), /* ~= 10^150 */ U64(0xC38413CF, 0x25E2D70D), U64(0xFEF51385, 0x19684ABA), /* ~= 10^151 */ U64(0xF46518C2, 0xEF5B8CD1), U64(0x7EB25866, 0x5FC25D69), /* ~= 10^152 */ U64(0x98BF2F79, 0xD5993802), U64(0xEF2F773F, 0xFBD97A61), /* ~= 10^153 */ U64(0xBEEEFB58, 0x4AFF8603), U64(0xAAFB550F, 0xFACFD8FA), /* ~= 10^154 */ U64(0xEEAABA2E, 0x5DBF6784), U64(0x95BA2A53, 0xF983CF38), /* ~= 10^155 */ U64(0x952AB45C, 0xFA97A0B2), U64(0xDD945A74, 0x7BF26183), /* ~= 10^156 */ U64(0xBA756174, 0x393D88DF), U64(0x94F97111, 0x9AEEF9E4), /* ~= 10^157 */ U64(0xE912B9D1, 0x478CEB17), U64(0x7A37CD56, 0x01AAB85D), /* ~= 10^158 */ U64(0x91ABB422, 0xCCB812EE), U64(0xAC62E055, 0xC10AB33A), /* ~= 10^159 */ U64(0xB616A12B, 0x7FE617AA), U64(0x577B986B, 0x314D6009), /* ~= 10^160 */ U64(0xE39C4976, 0x5FDF9D94), U64(0xED5A7E85, 0xFDA0B80B), /* ~= 10^161 */ U64(0x8E41ADE9, 0xFBEBC27D), U64(0x14588F13, 0xBE847307), /* ~= 10^162 */ U64(0xB1D21964, 0x7AE6B31C), U64(0x596EB2D8, 0xAE258FC8), /* ~= 10^163 */ U64(0xDE469FBD, 0x99A05FE3), U64(0x6FCA5F8E, 0xD9AEF3BB), /* ~= 10^164 */ U64(0x8AEC23D6, 0x80043BEE), U64(0x25DE7BB9, 0x480D5854), /* ~= 10^165 */ U64(0xADA72CCC, 0x20054AE9), U64(0xAF561AA7, 0x9A10AE6A), /* ~= 10^166 */ U64(0xD910F7FF, 0x28069DA4), U64(0x1B2BA151, 0x8094DA04), /* ~= 10^167 */ U64(0x87AA9AFF, 0x79042286), U64(0x90FB44D2, 0xF05D0842), /* ~= 10^168 */ U64(0xA99541BF, 0x57452B28), U64(0x353A1607, 0xAC744A53), /* ~= 10^169 */ U64(0xD3FA922F, 0x2D1675F2), U64(0x42889B89, 0x97915CE8), /* ~= 10^170 */ U64(0x847C9B5D, 0x7C2E09B7), U64(0x69956135, 0xFEBADA11), /* ~= 10^171 */ U64(0xA59BC234, 0xDB398C25), U64(0x43FAB983, 0x7E699095), /* ~= 10^172 */ U64(0xCF02B2C2, 0x1207EF2E), U64(0x94F967E4, 0x5E03F4BB), /* ~= 10^173 */ U64(0x8161AFB9, 0x4B44F57D), U64(0x1D1BE0EE, 0xBAC278F5), /* ~= 10^174 */ U64(0xA1BA1BA7, 0x9E1632DC), U64(0x6462D92A, 0x69731732), /* ~= 10^175 */ U64(0xCA28A291, 0x859BBF93), U64(0x7D7B8F75, 0x03CFDCFE), /* ~= 10^176 */ U64(0xFCB2CB35, 0xE702AF78), U64(0x5CDA7352, 0x44C3D43E), /* ~= 10^177 */ U64(0x9DEFBF01, 0xB061ADAB), U64(0x3A088813, 0x6AFA64A7), /* ~= 10^178 */ U64(0xC56BAEC2, 0x1C7A1916), U64(0x088AAA18, 0x45B8FDD0), /* ~= 10^179 */ U64(0xF6C69A72, 0xA3989F5B), U64(0x8AAD549E, 0x57273D45), /* ~= 10^180 */ U64(0x9A3C2087, 0xA63F6399), U64(0x36AC54E2, 0xF678864B), /* ~= 10^181 */ U64(0xC0CB28A9, 0x8FCF3C7F), U64(0x84576A1B, 0xB416A7DD), /* ~= 10^182 */ U64(0xF0FDF2D3, 0xF3C30B9F), U64(0x656D44A2, 0xA11C51D5), /* ~= 10^183 */ U64(0x969EB7C4, 0x7859E743), U64(0x9F644AE5, 0xA4B1B325), /* ~= 10^184 */ U64(0xBC4665B5, 0x96706114), U64(0x873D5D9F, 0x0DDE1FEE), /* ~= 10^185 */ U64(0xEB57FF22, 0xFC0C7959), U64(0xA90CB506, 0xD155A7EA), /* ~= 10^186 */ U64(0x9316FF75, 0xDD87CBD8), U64(0x09A7F124, 0x42D588F2), /* ~= 10^187 */ U64(0xB7DCBF53, 0x54E9BECE), U64(0x0C11ED6D, 0x538AEB2F), /* ~= 10^188 */ U64(0xE5D3EF28, 0x2A242E81), U64(0x8F1668C8, 0xA86DA5FA), /* ~= 10^189 */ U64(0x8FA47579, 0x1A569D10), U64(0xF96E017D, 0x694487BC), /* ~= 10^190 */ U64(0xB38D92D7, 0x60EC4455), U64(0x37C981DC, 0xC395A9AC), /* ~= 10^191 */ U64(0xE070F78D, 0x3927556A), U64(0x85BBE253, 0xF47B1417), /* ~= 10^192 */ U64(0x8C469AB8, 0x43B89562), U64(0x93956D74, 0x78CCEC8E), /* ~= 10^193 */ U64(0xAF584166, 0x54A6BABB), U64(0x387AC8D1, 0x970027B2), /* ~= 10^194 */ U64(0xDB2E51BF, 0xE9D0696A), U64(0x06997B05, 0xFCC0319E), /* ~= 10^195 */ U64(0x88FCF317, 0xF22241E2), U64(0x441FECE3, 0xBDF81F03), /* ~= 10^196 */ U64(0xAB3C2FDD, 0xEEAAD25A), U64(0xD527E81C, 0xAD7626C3), /* ~= 10^197 */ U64(0xD60B3BD5, 0x6A5586F1), U64(0x8A71E223, 0xD8D3B074), /* ~= 10^198 */ U64(0x85C70565, 0x62757456), U64(0xF6872D56, 0x67844E49), /* ~= 10^199 */ U64(0xA738C6BE, 0xBB12D16C), U64(0xB428F8AC, 0x016561DB), /* ~= 10^200 */ U64(0xD106F86E, 0x69D785C7), U64(0xE13336D7, 0x01BEBA52), /* ~= 10^201 */ U64(0x82A45B45, 0x0226B39C), U64(0xECC00246, 0x61173473), /* ~= 10^202 */ U64(0xA34D7216, 0x42B06084), U64(0x27F002D7, 0xF95D0190), /* ~= 10^203 */ U64(0xCC20CE9B, 0xD35C78A5), U64(0x31EC038D, 0xF7B441F4), /* ~= 10^204 */ U64(0xFF290242, 0xC83396CE), U64(0x7E670471, 0x75A15271), /* ~= 10^205 */ U64(0x9F79A169, 0xBD203E41), U64(0x0F0062C6, 0xE984D386), /* ~= 10^206 */ U64(0xC75809C4, 0x2C684DD1), U64(0x52C07B78, 0xA3E60868), /* ~= 10^207 */ U64(0xF92E0C35, 0x37826145), U64(0xA7709A56, 0xCCDF8A82), /* ~= 10^208 */ U64(0x9BBCC7A1, 0x42B17CCB), U64(0x88A66076, 0x400BB691), /* ~= 10^209 */ U64(0xC2ABF989, 0x935DDBFE), U64(0x6ACFF893, 0xD00EA435), /* ~= 10^210 */ U64(0xF356F7EB, 0xF83552FE), U64(0x0583F6B8, 0xC4124D43), /* ~= 10^211 */ U64(0x98165AF3, 0x7B2153DE), U64(0xC3727A33, 0x7A8B704A), /* ~= 10^212 */ U64(0xBE1BF1B0, 0x59E9A8D6), U64(0x744F18C0, 0x592E4C5C), /* ~= 10^213 */ U64(0xEDA2EE1C, 0x7064130C), U64(0x1162DEF0, 0x6F79DF73), /* ~= 10^214 */ U64(0x9485D4D1, 0xC63E8BE7), U64(0x8ADDCB56, 0x45AC2BA8), /* ~= 10^215 */ U64(0xB9A74A06, 0x37CE2EE1), U64(0x6D953E2B, 0xD7173692), /* ~= 10^216 */ U64(0xE8111C87, 0xC5C1BA99), U64(0xC8FA8DB6, 0xCCDD0437), /* ~= 10^217 */ U64(0x910AB1D4, 0xDB9914A0), U64(0x1D9C9892, 0x400A22A2), /* ~= 10^218 */ U64(0xB54D5E4A, 0x127F59C8), U64(0x2503BEB6, 0xD00CAB4B), /* ~= 10^219 */ U64(0xE2A0B5DC, 0x971F303A), U64(0x2E44AE64, 0x840FD61D), /* ~= 10^220 */ U64(0x8DA471A9, 0xDE737E24), U64(0x5CEAECFE, 0xD289E5D2), /* ~= 10^221 */ U64(0xB10D8E14, 0x56105DAD), U64(0x7425A83E, 0x872C5F47), /* ~= 10^222 */ U64(0xDD50F199, 0x6B947518), U64(0xD12F124E, 0x28F77719), /* ~= 10^223 */ U64(0x8A5296FF, 0xE33CC92F), U64(0x82BD6B70, 0xD99AAA6F), /* ~= 10^224 */ U64(0xACE73CBF, 0xDC0BFB7B), U64(0x636CC64D, 0x1001550B), /* ~= 10^225 */ U64(0xD8210BEF, 0xD30EFA5A), U64(0x3C47F7E0, 0x5401AA4E), /* ~= 10^226 */ U64(0x8714A775, 0xE3E95C78), U64(0x65ACFAEC, 0x34810A71), /* ~= 10^227 */ U64(0xA8D9D153, 0x5CE3B396), U64(0x7F1839A7, 0x41A14D0D), /* ~= 10^228 */ U64(0xD31045A8, 0x341CA07C), U64(0x1EDE4811, 0x1209A050), /* ~= 10^229 */ U64(0x83EA2B89, 0x2091E44D), U64(0x934AED0A, 0xAB460432), /* ~= 10^230 */ U64(0xA4E4B66B, 0x68B65D60), U64(0xF81DA84D, 0x5617853F), /* ~= 10^231 */ U64(0xCE1DE406, 0x42E3F4B9), U64(0x36251260, 0xAB9D668E), /* ~= 10^232 */ U64(0x80D2AE83, 0xE9CE78F3), U64(0xC1D72B7C, 0x6B426019), /* ~= 10^233 */ U64(0xA1075A24, 0xE4421730), U64(0xB24CF65B, 0x8612F81F), /* ~= 10^234 */ U64(0xC94930AE, 0x1D529CFC), U64(0xDEE033F2, 0x6797B627), /* ~= 10^235 */ U64(0xFB9B7CD9, 0xA4A7443C), U64(0x169840EF, 0x017DA3B1), /* ~= 10^236 */ U64(0x9D412E08, 0x06E88AA5), U64(0x8E1F2895, 0x60EE864E), /* ~= 10^237 */ U64(0xC491798A, 0x08A2AD4E), U64(0xF1A6F2BA, 0xB92A27E2), /* ~= 10^238 */ U64(0xF5B5D7EC, 0x8ACB58A2), U64(0xAE10AF69, 0x6774B1DB), /* ~= 10^239 */ U64(0x9991A6F3, 0xD6BF1765), U64(0xACCA6DA1, 0xE0A8EF29), /* ~= 10^240 */ U64(0xBFF610B0, 0xCC6EDD3F), U64(0x17FD090A, 0x58D32AF3), /* ~= 10^241 */ U64(0xEFF394DC, 0xFF8A948E), U64(0xDDFC4B4C, 0xEF07F5B0), /* ~= 10^242 */ U64(0x95F83D0A, 0x1FB69CD9), U64(0x4ABDAF10, 0x1564F98E), /* ~= 10^243 */ U64(0xBB764C4C, 0xA7A4440F), U64(0x9D6D1AD4, 0x1ABE37F1), /* ~= 10^244 */ U64(0xEA53DF5F, 0xD18D5513), U64(0x84C86189, 0x216DC5ED), /* ~= 10^245 */ U64(0x92746B9B, 0xE2F8552C), U64(0x32FD3CF5, 0xB4E49BB4), /* ~= 10^246 */ U64(0xB7118682, 0xDBB66A77), U64(0x3FBC8C33, 0x221DC2A1), /* ~= 10^247 */ U64(0xE4D5E823, 0x92A40515), U64(0x0FABAF3F, 0xEAA5334A), /* ~= 10^248 */ U64(0x8F05B116, 0x3BA6832D), U64(0x29CB4D87, 0xF2A7400E), /* ~= 10^249 */ U64(0xB2C71D5B, 0xCA9023F8), U64(0x743E20E9, 0xEF511012), /* ~= 10^250 */ U64(0xDF78E4B2, 0xBD342CF6), U64(0x914DA924, 0x6B255416), /* ~= 10^251 */ U64(0x8BAB8EEF, 0xB6409C1A), U64(0x1AD089B6, 0xC2F7548E), /* ~= 10^252 */ U64(0xAE9672AB, 0xA3D0C320), U64(0xA184AC24, 0x73B529B1), /* ~= 10^253 */ U64(0xDA3C0F56, 0x8CC4F3E8), U64(0xC9E5D72D, 0x90A2741E), /* ~= 10^254 */ U64(0x88658996, 0x17FB1871), U64(0x7E2FA67C, 0x7A658892), /* ~= 10^255 */ U64(0xAA7EEBFB, 0x9DF9DE8D), U64(0xDDBB901B, 0x98FEEAB7), /* ~= 10^256 */ U64(0xD51EA6FA, 0x85785631), U64(0x552A7422, 0x7F3EA565), /* ~= 10^257 */ U64(0x8533285C, 0x936B35DE), U64(0xD53A8895, 0x8F87275F), /* ~= 10^258 */ U64(0xA67FF273, 0xB8460356), U64(0x8A892ABA, 0xF368F137), /* ~= 10^259 */ U64(0xD01FEF10, 0xA657842C), U64(0x2D2B7569, 0xB0432D85), /* ~= 10^260 */ U64(0x8213F56A, 0x67F6B29B), U64(0x9C3B2962, 0x0E29FC73), /* ~= 10^261 */ U64(0xA298F2C5, 0x01F45F42), U64(0x8349F3BA, 0x91B47B8F), /* ~= 10^262 */ U64(0xCB3F2F76, 0x42717713), U64(0x241C70A9, 0x36219A73), /* ~= 10^263 */ U64(0xFE0EFB53, 0xD30DD4D7), U64(0xED238CD3, 0x83AA0110), /* ~= 10^264 */ U64(0x9EC95D14, 0x63E8A506), U64(0xF4363804, 0x324A40AA), /* ~= 10^265 */ U64(0xC67BB459, 0x7CE2CE48), U64(0xB143C605, 0x3EDCD0D5), /* ~= 10^266 */ U64(0xF81AA16F, 0xDC1B81DA), U64(0xDD94B786, 0x8E94050A), /* ~= 10^267 */ U64(0x9B10A4E5, 0xE9913128), U64(0xCA7CF2B4, 0x191C8326), /* ~= 10^268 */ U64(0xC1D4CE1F, 0x63F57D72), U64(0xFD1C2F61, 0x1F63A3F0), /* ~= 10^269 */ U64(0xF24A01A7, 0x3CF2DCCF), U64(0xBC633B39, 0x673C8CEC), /* ~= 10^270 */ U64(0x976E4108, 0x8617CA01), U64(0xD5BE0503, 0xE085D813), /* ~= 10^271 */ U64(0xBD49D14A, 0xA79DBC82), U64(0x4B2D8644, 0xD8A74E18), /* ~= 10^272 */ U64(0xEC9C459D, 0x51852BA2), U64(0xDDF8E7D6, 0x0ED1219E), /* ~= 10^273 */ U64(0x93E1AB82, 0x52F33B45), U64(0xCABB90E5, 0xC942B503), /* ~= 10^274 */ U64(0xB8DA1662, 0xE7B00A17), U64(0x3D6A751F, 0x3B936243), /* ~= 10^275 */ U64(0xE7109BFB, 0xA19C0C9D), U64(0x0CC51267, 0x0A783AD4), /* ~= 10^276 */ U64(0x906A617D, 0x450187E2), U64(0x27FB2B80, 0x668B24C5), /* ~= 10^277 */ U64(0xB484F9DC, 0x9641E9DA), U64(0xB1F9F660, 0x802DEDF6), /* ~= 10^278 */ U64(0xE1A63853, 0xBBD26451), U64(0x5E7873F8, 0xA0396973), /* ~= 10^279 */ U64(0x8D07E334, 0x55637EB2), U64(0xDB0B487B, 0x6423E1E8), /* ~= 10^280 */ U64(0xB049DC01, 0x6ABC5E5F), U64(0x91CE1A9A, 0x3D2CDA62), /* ~= 10^281 */ U64(0xDC5C5301, 0xC56B75F7), U64(0x7641A140, 0xCC7810FB), /* ~= 10^282 */ U64(0x89B9B3E1, 0x1B6329BA), U64(0xA9E904C8, 0x7FCB0A9D), /* ~= 10^283 */ U64(0xAC2820D9, 0x623BF429), U64(0x546345FA, 0x9FBDCD44), /* ~= 10^284 */ U64(0xD732290F, 0xBACAF133), U64(0xA97C1779, 0x47AD4095), /* ~= 10^285 */ U64(0x867F59A9, 0xD4BED6C0), U64(0x49ED8EAB, 0xCCCC485D), /* ~= 10^286 */ U64(0xA81F3014, 0x49EE8C70), U64(0x5C68F256, 0xBFFF5A74), /* ~= 10^287 */ U64(0xD226FC19, 0x5C6A2F8C), U64(0x73832EEC, 0x6FFF3111), /* ~= 10^288 */ U64(0x83585D8F, 0xD9C25DB7), U64(0xC831FD53, 0xC5FF7EAB), /* ~= 10^289 */ U64(0xA42E74F3, 0xD032F525), U64(0xBA3E7CA8, 0xB77F5E55), /* ~= 10^290 */ U64(0xCD3A1230, 0xC43FB26F), U64(0x28CE1BD2, 0xE55F35EB), /* ~= 10^291 */ U64(0x80444B5E, 0x7AA7CF85), U64(0x7980D163, 0xCF5B81B3), /* ~= 10^292 */ U64(0xA0555E36, 0x1951C366), U64(0xD7E105BC, 0xC332621F), /* ~= 10^293 */ U64(0xC86AB5C3, 0x9FA63440), U64(0x8DD9472B, 0xF3FEFAA7), /* ~= 10^294 */ U64(0xFA856334, 0x878FC150), U64(0xB14F98F6, 0xF0FEB951), /* ~= 10^295 */ U64(0x9C935E00, 0xD4B9D8D2), U64(0x6ED1BF9A, 0x569F33D3), /* ~= 10^296 */ U64(0xC3B83581, 0x09E84F07), U64(0x0A862F80, 0xEC4700C8), /* ~= 10^297 */ U64(0xF4A642E1, 0x4C6262C8), U64(0xCD27BB61, 0x2758C0FA), /* ~= 10^298 */ U64(0x98E7E9CC, 0xCFBD7DBD), U64(0x8038D51C, 0xB897789C), /* ~= 10^299 */ U64(0xBF21E440, 0x03ACDD2C), U64(0xE0470A63, 0xE6BD56C3), /* ~= 10^300 */ U64(0xEEEA5D50, 0x04981478), U64(0x1858CCFC, 0xE06CAC74), /* ~= 10^301 */ U64(0x95527A52, 0x02DF0CCB), U64(0x0F37801E, 0x0C43EBC8), /* ~= 10^302 */ U64(0xBAA718E6, 0x8396CFFD), U64(0xD3056025, 0x8F54E6BA), /* ~= 10^303 */ U64(0xE950DF20, 0x247C83FD), U64(0x47C6B82E, 0xF32A2069), /* ~= 10^304 */ U64(0x91D28B74, 0x16CDD27E), U64(0x4CDC331D, 0x57FA5441), /* ~= 10^305 */ U64(0xB6472E51, 0x1C81471D), U64(0xE0133FE4, 0xADF8E952), /* ~= 10^306 */ U64(0xE3D8F9E5, 0x63A198E5), U64(0x58180FDD, 0xD97723A6), /* ~= 10^307 */ U64(0x8E679C2F, 0x5E44FF8F), U64(0x570F09EA, 0xA7EA7648), /* ~= 10^308 */ U64(0xB201833B, 0x35D63F73), U64(0x2CD2CC65, 0x51E513DA), /* ~= 10^309 */ U64(0xDE81E40A, 0x034BCF4F), U64(0xF8077F7E, 0xA65E58D1), /* ~= 10^310 */ U64(0x8B112E86, 0x420F6191), U64(0xFB04AFAF, 0x27FAF782), /* ~= 10^311 */ U64(0xADD57A27, 0xD29339F6), U64(0x79C5DB9A, 0xF1F9B563), /* ~= 10^312 */ U64(0xD94AD8B1, 0xC7380874), U64(0x18375281, 0xAE7822BC), /* ~= 10^313 */ U64(0x87CEC76F, 0x1C830548), U64(0x8F229391, 0x0D0B15B5), /* ~= 10^314 */ U64(0xA9C2794A, 0xE3A3C69A), U64(0xB2EB3875, 0x504DDB22), /* ~= 10^315 */ U64(0xD433179D, 0x9C8CB841), U64(0x5FA60692, 0xA46151EB), /* ~= 10^316 */ U64(0x849FEEC2, 0x81D7F328), U64(0xDBC7C41B, 0xA6BCD333), /* ~= 10^317 */ U64(0xA5C7EA73, 0x224DEFF3), U64(0x12B9B522, 0x906C0800), /* ~= 10^318 */ U64(0xCF39E50F, 0xEAE16BEF), U64(0xD768226B, 0x34870A00), /* ~= 10^319 */ U64(0x81842F29, 0xF2CCE375), U64(0xE6A11583, 0x00D46640), /* ~= 10^320 */ U64(0xA1E53AF4, 0x6F801C53), U64(0x60495AE3, 0xC1097FD0), /* ~= 10^321 */ U64(0xCA5E89B1, 0x8B602368), U64(0x385BB19C, 0xB14BDFC4), /* ~= 10^322 */ U64(0xFCF62C1D, 0xEE382C42), U64(0x46729E03, 0xDD9ED7B5), /* ~= 10^323 */ U64(0x9E19DB92, 0xB4E31BA9), U64(0x6C07A2C2, 0x6A8346D1) /* ~= 10^324 */ }; /** Get the cached pow10 value from pow10_sig_table. @param exp10 The exponent of pow(10, e). This value must in range POW10_SIG_TABLE_MIN_EXP to POW10_SIG_TABLE_MAX_EXP. @param hi The highest 64 bits of pow(10, e). @param lo The lower 64 bits after `hi`. */ static_inline void pow10_table_get_sig(i32 exp10, u64 *hi, u64 *lo) { i32 idx = exp10 - (POW10_SIG_TABLE_MIN_EXP); *hi = pow10_sig_table[idx * 2]; *lo = pow10_sig_table[idx * 2 + 1]; } /** Get the exponent (base 2) for highest 64 bits significand in pow10_sig_table. */ static_inline void pow10_table_get_exp(i32 exp10, i32 *exp2) { /* e2 = floor(log2(pow(10, e))) - 64 + 1 */ /* = floor(e * log2(10) - 63) */ *exp2 = (exp10 * 217706 - 4128768) >> 16; } #endif /*============================================================================== * JSON Character Matcher *============================================================================*/ /** Character type */ typedef u8 char_type; /** Whitespace character: ' ', '\\t', '\\n', '\\r'. */ static const char_type CHAR_TYPE_SPACE = 1 << 0; /** Number character: '-', [0-9]. */ static const char_type CHAR_TYPE_NUMBER = 1 << 1; /** JSON Escaped character: '"', '\', [0x00-0x1F]. */ static const char_type CHAR_TYPE_ESC_ASCII = 1 << 2; /** Non-ASCII character: [0x80-0xFF]. */ static const char_type CHAR_TYPE_NON_ASCII = 1 << 3; /** JSON container character: '{', '['. */ static const char_type CHAR_TYPE_CONTAINER = 1 << 4; /** Comment character: '/'. */ static const char_type CHAR_TYPE_COMMENT = 1 << 5; /** Line end character: '\\n', '\\r', '\0'. */ static const char_type CHAR_TYPE_LINE_END = 1 << 6; /** Hexadecimal numeric character: [0-9a-fA-F]. */ static const char_type CHAR_TYPE_HEX = 1 << 7; /** Character type table (generate with misc/make_tables.c) */ static const char_type char_table[256] = { 0x44, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x45, 0x04, 0x04, 0x45, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x20, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }; /** Match a character with specified type. */ static_inline bool char_is_type(u8 c, char_type type) { return (char_table[c] & type) != 0; } /** Match a whitespace: ' ', '\\t', '\\n', '\\r'. */ static_inline bool char_is_space(u8 c) { return char_is_type(c, (char_type)CHAR_TYPE_SPACE); } /** Match a whitespace or comment: ' ', '\\t', '\\n', '\\r', '/'. */ static_inline bool char_is_space_or_comment(u8 c) { return char_is_type(c, (char_type)(CHAR_TYPE_SPACE | CHAR_TYPE_COMMENT)); } /** Match a JSON number: '-', [0-9]. */ static_inline bool char_is_number(u8 c) { return char_is_type(c, (char_type)CHAR_TYPE_NUMBER); } /** Match a JSON container: '{', '['. */ static_inline bool char_is_container(u8 c) { return char_is_type(c, (char_type)CHAR_TYPE_CONTAINER); } /** Match a stop character in ASCII string: '"', '\', [0x00-0x1F,0x80-0xFF]. */ static_inline bool char_is_ascii_stop(u8 c) { return char_is_type(c, (char_type)(CHAR_TYPE_ESC_ASCII | CHAR_TYPE_NON_ASCII)); } /** Match a line end character: '\\n', '\\r', '\0'. */ static_inline bool char_is_line_end(u8 c) { return char_is_type(c, (char_type)CHAR_TYPE_LINE_END); } /** Match a hexadecimal numeric character: [0-9a-fA-F]. */ static_inline bool char_is_hex(u8 c) { return char_is_type(c, (char_type)CHAR_TYPE_HEX); } /*============================================================================== * Digit Character Matcher *============================================================================*/ /** Digit type */ typedef u8 digi_type; /** Digit: '0'. */ static const digi_type DIGI_TYPE_ZERO = 1 << 0; /** Digit: [1-9]. */ static const digi_type DIGI_TYPE_NONZERO = 1 << 1; /** Plus sign (positive): '+'. */ static const digi_type DIGI_TYPE_POS = 1 << 2; /** Minus sign (negative): '-'. */ static const digi_type DIGI_TYPE_NEG = 1 << 3; /** Decimal point: '.' */ static const digi_type DIGI_TYPE_DOT = 1 << 4; /** Exponent sign: 'e, 'E'. */ static const digi_type DIGI_TYPE_EXP = 1 << 5; /** Digit type table (generate with misc/make_tables.c) */ static const digi_type digi_table[256] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x10, 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /** Match a character with specified type. */ static_inline bool digi_is_type(u8 d, digi_type type) { return (digi_table[d] & type) != 0; } /** Match a sign: '+', '-' */ static_inline bool digi_is_sign(u8 d) { return digi_is_type(d, (digi_type)(DIGI_TYPE_POS | DIGI_TYPE_NEG)); } /** Match a none zero digit: [1-9] */ static_inline bool digi_is_nonzero(u8 d) { return digi_is_type(d, (digi_type)DIGI_TYPE_NONZERO); } /** Match a digit: [0-9] */ static_inline bool digi_is_digit(u8 d) { return digi_is_type(d, (digi_type)(DIGI_TYPE_ZERO | DIGI_TYPE_NONZERO)); } /** Match an exponent sign: 'e', 'E'. */ static_inline bool digi_is_exp(u8 d) { return digi_is_type(d, (digi_type)DIGI_TYPE_EXP); } /** Match a floating point indicator: '.', 'e', 'E'. */ static_inline bool digi_is_fp(u8 d) { return digi_is_type(d, (digi_type)(DIGI_TYPE_DOT | DIGI_TYPE_EXP)); } /** Match a digit or floating point indicator: [0-9], '.', 'e', 'E'. */ static_inline bool digi_is_digit_or_fp(u8 d) { return digi_is_type(d, (digi_type)(DIGI_TYPE_ZERO | DIGI_TYPE_NONZERO | DIGI_TYPE_DOT | DIGI_TYPE_EXP)); } #if !YYJSON_DISABLE_READER /*============================================================================== * Hex Character Reader * This function is used by JSON reader to read escaped characters. *============================================================================*/ /** This table is used to convert 4 hex character sequence to a number. A valid hex character [0-9A-Fa-f] will mapped to it's raw number [0x00, 0x0F], an invalid hex character will mapped to [0xF0]. (generate with misc/make_tables.c) */ static const u8 hex_conv_table[256] = { 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0,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0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0 }; /** Scans an escaped character sequence as a UTF-16 code unit (branchless). e.g. "\\u005C" should pass "005C" as `cur`. This requires the string has 4-byte zero padding. */ static_inline bool read_hex_u16(const u8 *cur, u16 *val) { u16 c0, c1, c2, c3, t0, t1; c0 = hex_conv_table[cur[0]]; c1 = hex_conv_table[cur[1]]; c2 = hex_conv_table[cur[2]]; c3 = hex_conv_table[cur[3]]; t0 = (u16)((c0 << 8) | c2); t1 = (u16)((c1 << 8) | c3); *val = (u16)((t0 << 4) | t1); return ((t0 | t1) & (u16)0xF0F0) == 0; } /*============================================================================== * JSON Reader Utils * These functions are used by JSON reader to read literals and comments. *============================================================================*/ /** Read 'true' literal, '*cur' should be 't'. */ static_inline bool read_true(u8 **ptr, yyjson_val *val) { u8 *cur = *ptr; u8 **end = ptr; if (likely(byte_match_4(cur, "true"))) { val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE; *end = cur + 4; return true; } return false; } /** Read 'false' literal, '*cur' should be 'f'. */ static_inline bool read_false(u8 **ptr, yyjson_val *val) { u8 *cur = *ptr; u8 **end = ptr; if (likely(byte_match_4(cur + 1, "alse"))) { val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE; *end = cur + 5; return true; } return false; } /** Read 'null' literal, '*cur' should be 'n'. */ static_inline bool read_null(u8 **ptr, yyjson_val *val) { u8 *cur = *ptr; u8 **end = ptr; if (likely(byte_match_4(cur, "null"))) { val->tag = YYJSON_TYPE_NULL; *end = cur + 4; return true; } return false; } /** Read 'Inf' or 'Infinity' literal (ignoring case). */ static_inline bool read_inf(bool sign, u8 **ptr, u8 **pre, yyjson_val *val) { u8 *hdr = *ptr - sign; u8 *cur = *ptr; u8 **end = ptr; if ((cur[0] == 'I' || cur[0] == 'i') && (cur[1] == 'N' || cur[1] == 'n') && (cur[2] == 'F' || cur[2] == 'f')) { if ((cur[3] == 'I' || cur[3] == 'i') && (cur[4] == 'N' || cur[4] == 'n') && (cur[5] == 'I' || cur[5] == 'i') && (cur[6] == 'T' || cur[6] == 't') && (cur[7] == 'Y' || cur[7] == 'y')) { cur += 8; } else { cur += 3; } *end = cur; if (false) { /* add null-terminator for previous raw string */ if (*pre) **pre = '\0'; *pre = cur; val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; val->uni.str = (const char *)hdr; } else { val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; val->uni.u64 = f64_raw_get_inf(sign); } return true; } return false; } /** Read 'NaN' literal (ignoring case). */ static_inline bool read_nan(bool sign, u8 **ptr, u8 **pre, yyjson_val *val) { u8 *hdr = *ptr - sign; u8 *cur = *ptr; u8 **end = ptr; if ((cur[0] == 'N' || cur[0] == 'n') && (cur[1] == 'A' || cur[1] == 'a') && (cur[2] == 'N' || cur[2] == 'n')) { cur += 3; *end = cur; if (false) { /* add null-terminator for previous raw string */ if (*pre) **pre = '\0'; *pre = cur; val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; val->uni.str = (const char *)hdr; } else { val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; val->uni.u64 = f64_raw_get_nan(sign); } return true; } return false; } /** Read a JSON number as raw string. */ static_noinline bool read_number_raw(u8 **ptr, u8 **pre, yyjson_read_flag flg, yyjson_val *val, const char **msg) { #define return_err(_pos, _msg) do { \ *msg = _msg; \ *end = _pos; \ return false; \ } while (false) #define return_raw() do { \ val->tag = ((u64)(cur - hdr) << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; \ val->uni.str = (const char *)hdr; \ *pre = cur; *end = cur; return true; \ } while (false) u8 *hdr = *ptr; u8 *cur = *ptr; u8 **end = ptr; /* add null-terminator for previous raw string */ if (*pre) **pre = '\0'; /* skip sign */ cur += (*cur == '-'); /* read first digit, check leading zero */ if (unlikely(!digi_is_digit(*cur))) { return_err(cur, "no digit after minus sign"); } /* read integral part */ if (*cur == '0') { cur++; if (unlikely(digi_is_digit(*cur))) { return_err(cur - 1, "number with leading zero is not allowed"); } if (!digi_is_fp(*cur)) return_raw(); } else { while (digi_is_digit(*cur)) cur++; if (!digi_is_fp(*cur)) return_raw(); } /* read fraction part */ if (*cur == '.') { cur++; if (!digi_is_digit(*cur++)) { return_err(cur, "no digit after decimal point"); } while (digi_is_digit(*cur)) cur++; } /* read exponent part */ if (digi_is_exp(*cur)) { cur += 1 + digi_is_sign(cur[1]); if (!digi_is_digit(*cur++)) { return_err(cur, "no digit after exponent sign"); } while (digi_is_digit(*cur)) cur++; } return_raw(); #undef return_err #undef return_raw } /** Skips spaces and comments as many as possible. It will return false in these cases: 1. No character is skipped. The 'end' pointer is set as input cursor. 2. A multiline comment is not closed. The 'end' pointer is set as the head of this comment block. */ static_noinline bool skip_spaces_and_comments(u8 **ptr) { u8 *hdr = *ptr; u8 *cur = *ptr; u8 **end = ptr; while (true) { if (byte_match_2(cur, "/*")) { hdr = cur; cur += 2; while (true) { if (byte_match_2(cur, "*/")) { cur += 2; break; } if (*cur == 0) { *end = hdr; return false; } cur++; } continue; } if (byte_match_2(cur, "//")) { cur += 2; while (!char_is_line_end(*cur)) cur++; continue; } if (char_is_space(*cur)) { cur += 1; while (char_is_space(*cur)) cur++; continue; } break; } *end = cur; return hdr != cur; } /** Check truncated string. Returns true if `cur` match `str` but is truncated. */ static_inline bool is_truncated_str(u8 *cur, u8 *end, const char *str, bool case_sensitive) { usize len = strlen(str); if (cur + len <= end || end <= cur) return false; if (case_sensitive) { return memcmp(cur, str, (usize)(end - cur)) == 0; } for (; cur < end; cur++, str++) { if ((*cur != (u8)*str) && (*cur != (u8)*str - 'a' + 'A')) { return false; } } return true; } /** Check truncated JSON on parsing errors. Returns true if the input is valid but truncated. */ static_noinline bool is_truncated_end(u8 *hdr, u8 *cur, u8 *end, yyjson_read_code code) { if (cur >= end) return true; if (code == YYJSON_READ_ERROR_LITERAL) { if (is_truncated_str(cur, end, "true", true) || is_truncated_str(cur, end, "false", true) || is_truncated_str(cur, end, "null", true)) { return true; } } if (code == YYJSON_READ_ERROR_UNEXPECTED_CHARACTER || code == YYJSON_READ_ERROR_INVALID_NUMBER || code == YYJSON_READ_ERROR_LITERAL) { if (false) { if (*cur == '-') cur++; if (is_truncated_str(cur, end, "infinity", false) || is_truncated_str(cur, end, "nan", false)) { return true; } } } if (code == YYJSON_READ_ERROR_UNEXPECTED_CONTENT) { if (false) { if (hdr + 3 <= cur && is_truncated_str(cur - 3, end, "infinity", false)) { return true; /* e.g. infin would be read as inf + in */ } } } if (code == YYJSON_READ_ERROR_INVALID_STRING) { usize len = (usize)(end - cur); /* unicode escape sequence */ if (*cur == '\\') { if (len == 1) return true; if (len <= 5) { if (*++cur != 'u') return false; for (++cur; cur < end; cur++) { if (!char_is_hex(*cur)) return false; } return true; } return false; } /* 2 to 4 bytes UTF-8, see `read_string()` for details. */ if (*cur & 0x80) { u8 c0 = cur[0], c1 = cur[1], c2 = cur[2]; if (len == 1) { /* 2 bytes UTF-8, truncated */ if ((c0 & 0xE0) == 0xC0 && (c0 & 0x1E) != 0x00) return true; /* 3 bytes UTF-8, truncated */ if ((c0 & 0xF0) == 0xE0) return true; /* 4 bytes UTF-8, truncated */ if ((c0 & 0xF8) == 0xF0 && (c0 & 0x07) <= 0x04) return true; } if (len == 2) { /* 3 bytes UTF-8, truncated */ if ((c0 & 0xF0) == 0xE0 && (c1 & 0xC0) == 0x80) { u8 pat = (u8)(((c0 & 0x0F) << 1) | ((c1 & 0x20) >> 5)); return 0x01 <= pat && pat != 0x1B; } /* 4 bytes UTF-8, truncated */ if ((c0 & 0xF8) == 0xF0 && (c1 & 0xC0) == 0x80) { u8 pat = (u8)(((c0 & 0x07) << 2) | ((c1 & 0x30) >> 4)); return 0x01 <= pat && pat <= 0x10; } } if (len == 3) { /* 4 bytes UTF-8, truncated */ if ((c0 & 0xF8) == 0xF0 && (c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80) { u8 pat = (u8)(((c0 & 0x07) << 2) | ((c1 & 0x30) >> 4)); return 0x01 <= pat && pat <= 0x10; } } } } return false; } #if YYJSON_HAS_IEEE_754 && !YYJSON_DISABLE_FAST_FP_CONV /* FP_READER */ /*============================================================================== * BigInt For Floating Point Number Reader * * The bigint algorithm is used by floating-point number reader to get correctly * rounded result for numbers with lots of digits. This part of code is rarely * used for common numbers. *============================================================================*/ /** Maximum exponent of exact pow10 */ #define U64_POW10_MAX_EXP 19 /** Table: [ 10^0, ..., 10^19 ] (generate with misc/make_tables.c) */ static const u64 u64_pow10_table[U64_POW10_MAX_EXP + 1] = { U64(0x00000000, 0x00000001), U64(0x00000000, 0x0000000A), U64(0x00000000, 0x00000064), U64(0x00000000, 0x000003E8), U64(0x00000000, 0x00002710), U64(0x00000000, 0x000186A0), U64(0x00000000, 0x000F4240), U64(0x00000000, 0x00989680), U64(0x00000000, 0x05F5E100), U64(0x00000000, 0x3B9ACA00), U64(0x00000002, 0x540BE400), U64(0x00000017, 0x4876E800), U64(0x000000E8, 0xD4A51000), U64(0x00000918, 0x4E72A000), U64(0x00005AF3, 0x107A4000), U64(0x00038D7E, 0xA4C68000), U64(0x002386F2, 0x6FC10000), U64(0x01634578, 0x5D8A0000), U64(0x0DE0B6B3, 0xA7640000), U64(0x8AC72304, 0x89E80000) }; /** Maximum numbers of chunks used by a bigint (58 is enough here). */ #define BIGINT_MAX_CHUNKS 64 /** Unsigned arbitrarily large integer */ typedef struct bigint { u32 used; /* used chunks count, should not be 0 */ u64 bits[BIGINT_MAX_CHUNKS]; /* chunks */ } bigint; /** Evaluate 'big += val'. @param big A big number (can be 0). @param val An unsigned integer (can be 0). */ static_inline void bigint_add_u64(bigint *big, u64 val) { u32 idx, max; u64 num = big->bits[0]; u64 add = num + val; big->bits[0] = add; if (likely((add >= num) || (add >= val))) return; for ((void)(idx = 1), max = big->used; idx < max; idx++) { if (likely(big->bits[idx] != U64_MAX)) { big->bits[idx] += 1; return; } big->bits[idx] = 0; } big->bits[big->used++] = 1; } /** Evaluate 'big *= val'. @param big A big number (can be 0). @param val An unsigned integer (cannot be 0). */ static_inline void bigint_mul_u64(bigint *big, u64 val) { u32 idx = 0, max = big->used; u64 hi, lo, carry = 0; for (; idx < max; idx++) { if (big->bits[idx]) break; } for (; idx < max; idx++) { u128_mul_add(big->bits[idx], val, carry, &hi, &lo); big->bits[idx] = lo; carry = hi; } if (carry) big->bits[big->used++] = carry; } /** Evaluate 'big *= 2^exp'. @param big A big number (can be 0). @param exp An exponent integer (can be 0). */ static_inline void bigint_mul_pow2(bigint *big, u32 exp) { u32 shft = exp % 64; u32 move = exp / 64; u32 idx = big->used; if (unlikely(shft == 0)) { for (; idx > 0; idx--) { big->bits[idx + move - 1] = big->bits[idx - 1]; } big->used += move; while (move) big->bits[--move] = 0; } else { big->bits[idx] = 0; for (; idx > 0; idx--) { u64 num = big->bits[idx] << shft; num |= big->bits[idx - 1] >> (64 - shft); big->bits[idx + move] = num; } big->bits[move] = big->bits[0] << shft; big->used += move + (big->bits[big->used + move] > 0); while (move) big->bits[--move] = 0; } } /** Evaluate 'big *= 10^exp'. @param big A big number (can be 0). @param exp An exponent integer (cannot be 0). */ static_inline void bigint_mul_pow10(bigint *big, i32 exp) { for (; exp >= U64_POW10_MAX_EXP; exp -= U64_POW10_MAX_EXP) { bigint_mul_u64(big, u64_pow10_table[U64_POW10_MAX_EXP]); } if (exp) { bigint_mul_u64(big, u64_pow10_table[exp]); } } /** Compare two bigint. @return -1 if 'a < b', +1 if 'a > b', 0 if 'a == b'. */ static_inline i32 bigint_cmp(bigint *a, bigint *b) { u32 idx = a->used; if (a->used < b->used) return -1; if (a->used > b->used) return +1; while (idx-- > 0) { u64 av = a->bits[idx]; u64 bv = b->bits[idx]; if (av < bv) return -1; if (av > bv) return +1; } return 0; } /** Evaluate 'big = val'. @param big A big number (can be 0). @param val An unsigned integer (can be 0). */ static_inline void bigint_set_u64(bigint *big, u64 val) { big->used = 1; big->bits[0] = val; } /** Set a bigint with floating point number string. */ static_noinline void bigint_set_buf(bigint *big, u64 sig, i32 *exp, u8 *sig_cut, u8 *sig_end, u8 *dot_pos) { if (unlikely(!sig_cut)) { /* no digit cut, set significant part only */ bigint_set_u64(big, sig); return; } else { /* some digits were cut, read them from 'sig_cut' to 'sig_end' */ u8 *hdr = sig_cut; u8 *cur = hdr; u32 len = 0; u64 val = 0; bool dig_big_cut = false; bool has_dot = (hdr < dot_pos) & (dot_pos < sig_end); u32 dig_len_total = U64_SAFE_DIG + (u32)(sig_end - hdr) - has_dot; sig -= (*sig_cut >= '5'); /* sig was rounded before */ if (dig_len_total > F64_MAX_DEC_DIG) { dig_big_cut = true; sig_end -= dig_len_total - (F64_MAX_DEC_DIG + 1); sig_end -= (dot_pos + 1 == sig_end); dig_len_total = (F64_MAX_DEC_DIG + 1); } *exp -= (i32)dig_len_total - U64_SAFE_DIG; big->used = 1; big->bits[0] = sig; while (cur < sig_end) { if (likely(cur != dot_pos)) { val = val * 10 + (u8)(*cur++ - '0'); len++; if (unlikely(cur == sig_end && dig_big_cut)) { /* The last digit must be non-zero, */ /* set it to '1' for correct rounding. */ val = val - (val % 10) + 1; } if (len == U64_SAFE_DIG || cur == sig_end) { bigint_mul_pow10(big, (i32)len); bigint_add_u64(big, val); val = 0; len = 0; } } else { cur++; } } } } /*============================================================================== * Diy Floating Point *============================================================================*/ /** "Do It Yourself Floating Point" struct. */ typedef struct diy_fp { u64 sig; /* significand */ i32 exp; /* exponent, base 2 */ i32 pad; /* padding, useless */ } diy_fp; /** Get cached rounded diy_fp with pow(10, e) The input value must in range [POW10_SIG_TABLE_MIN_EXP, POW10_SIG_TABLE_MAX_EXP]. */ static_inline diy_fp diy_fp_get_cached_pow10(i32 exp10) { diy_fp fp; u64 sig_ext; pow10_table_get_sig(exp10, &fp.sig, &sig_ext); pow10_table_get_exp(exp10, &fp.exp); fp.sig += (sig_ext >> 63); return fp; } /** Returns fp * fp2. */ static_inline diy_fp diy_fp_mul(diy_fp fp, diy_fp fp2) { u64 hi, lo; u128_mul(fp.sig, fp2.sig, &hi, &lo); fp.sig = hi + (lo >> 63); fp.exp += fp2.exp + 64; return fp; } /** Convert diy_fp to IEEE-754 raw value. */ static_inline u64 diy_fp_to_ieee_raw(diy_fp fp) { u64 sig = fp.sig; i32 exp = fp.exp; u32 lz_bits; if (unlikely(fp.sig == 0)) return 0; lz_bits = u64_lz_bits(sig); sig <<= lz_bits; sig >>= F64_BITS - F64_SIG_FULL_BITS; exp -= (i32)lz_bits; exp += F64_BITS - F64_SIG_FULL_BITS; exp += F64_SIG_BITS; if (unlikely(exp >= F64_MAX_BIN_EXP)) { /* overflow */ return F64_RAW_INF; } else if (likely(exp >= F64_MIN_BIN_EXP - 1)) { /* normal */ exp += F64_EXP_BIAS; return ((u64)exp << F64_SIG_BITS) | (sig & F64_SIG_MASK); } else if (likely(exp >= F64_MIN_BIN_EXP - F64_SIG_FULL_BITS)) { /* subnormal */ return sig >> (F64_MIN_BIN_EXP - exp - 1); } else { /* underflow */ return 0; } } /*============================================================================== * JSON Number Reader (IEEE-754) *============================================================================*/ /** Maximum exact pow10 exponent for double value. */ #define F64_POW10_EXP_MAX_EXACT 22 /** Cached pow10 table. */ static const f64 f64_pow10_table[] = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22 }; /** Read a JSON number. 1. This function assume that the floating-point number is in IEEE-754 format. 2. This function support uint64/int64/double number. If an integer number cannot fit in uint64/int64, it will returns as a double number. If a double number is infinite, the return value is based on flag. 3. This function (with inline attribute) may generate a lot of instructions. */ static_inline bool read_number(u8 **ptr, yyjson_val *val, const char **msg) { #define return_err(_pos, _msg) do { \ *msg = _msg; \ *end = _pos; \ return false; \ } while (false) #define return_0() do { \ val->tag = YYJSON_TYPE_NUM | (u8)((u8)sign << 3); \ val->uni.u64 = 0; \ *end = cur; return true; \ } while (false) #define return_i64(_v) do { \ val->tag = YYJSON_TYPE_NUM | (u8)((u8)sign << 3); \ val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \ *end = cur; return true; \ } while (false) #define return_f64(_v) do { \ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ val->uni.f64 = sign ? -(f64)(_v) : (f64)(_v); \ *end = cur; return true; \ } while (false) #define return_f64_bin(_v) do { \ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ val->uni.u64 = ((u64)sign << 63) | (u64)(_v); \ *end = cur; return true; \ } while (false) #define return_inf() do { \ if (false) return_f64_bin(F64_RAW_INF); \ else return_err(hdr, "number is infinity when parsed as double"); \ } while (false) u8 *sig_cut = NULL; /* significant part cutting position for long number */ u8 *sig_end = NULL; /* significant part ending position */ u8 *dot_pos = NULL; /* decimal point position */ u64 sig = 0; /* significant part of the number */ i32 exp = 0; /* exponent part of the number */ bool exp_sign; /* temporary exponent sign from literal part */ i64 exp_sig = 0; /* temporary exponent number from significant part */ i64 exp_lit = 0; /* temporary exponent number from exponent literal part */ u64 num; /* temporary number for reading */ u8 *tmp; /* temporary cursor for reading */ u8 *hdr = *ptr; u8 *cur = *ptr; u8 **end = ptr; bool sign; sign = (*hdr == '-'); cur += sign; /* begin with a leading zero or non-digit */ if (unlikely(!digi_is_nonzero(*cur))) { /* 0 or non-digit char */ if (unlikely(*cur != '0')) { /* non-digit char */ return_err(cur, "no digit after minus sign"); } /* begin with 0 */ if (likely(!digi_is_digit_or_fp(*++cur))) return_0(); if (likely(*cur == '.')) { dot_pos = cur++; if (unlikely(!digi_is_digit(*cur))) { return_err(cur, "no digit after decimal point"); } while (unlikely(*cur == '0')) cur++; if (likely(digi_is_digit(*cur))) { /* first non-zero digit after decimal point */ sig = (u64)(*cur - '0'); /* read first digit */ cur--; goto digi_frac_1; /* continue read fraction part */ } } if (unlikely(digi_is_digit(*cur))) { return_err(cur - 1, "number with leading zero is not allowed"); } if (unlikely(digi_is_exp(*cur))) { /* 0 with any exponent is still 0 */ cur += (usize)1 + digi_is_sign(cur[1]); if (unlikely(!digi_is_digit(*cur))) { return_err(cur, "no digit after exponent sign"); } while (digi_is_digit(*++cur)); } return_f64_bin(0); } /* begin with non-zero digit */ sig = (u64)(*cur - '0'); /* Read integral part, same as the following code. for (int i = 1; i <= 18; i++) { num = cur[i] - '0'; if (num <= 9) sig = num + sig * 10; else goto digi_sepr_i; } */ #define expr_intg(i) \ if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \ else { goto digi_sepr_##i; } repeat_in_1_18(expr_intg) #undef expr_intg cur += 19; /* skip continuous 19 digits */ if (!digi_is_digit_or_fp(*cur)) { /* this number is an integer consisting of 19 digits */ if (sign && (sig > ((u64)1 << 63))) { /* overflow */ return_f64(normalized_u64_to_f64(sig)); } return_i64(sig); } goto digi_intg_more; /* read more digits in integral part */ /* process first non-digit character */ #define expr_sepr(i) \ digi_sepr_##i: \ if (likely(!digi_is_fp(cur[i]))) { cur += i; return_i64(sig); } \ dot_pos = cur + i; \ if (likely(cur[i] == '.')) goto digi_frac_##i; \ cur += i; sig_end = cur; goto digi_exp_more; repeat_in_1_18(expr_sepr) #undef expr_sepr /* read fraction part */ #define expr_frac(i) \ digi_frac_##i: \ if (likely((num = (u64)(cur[i + 1] - (u8)'0')) <= 9)) \ sig = num + sig * 10; \ else { goto digi_stop_##i; } repeat_in_1_18(expr_frac) #undef expr_frac cur += 20; /* skip 19 digits and 1 decimal point */ if (!digi_is_digit(*cur)) goto digi_frac_end; /* fraction part end */ goto digi_frac_more; /* read more digits in fraction part */ /* significant part end */ #define expr_stop(i) \ digi_stop_##i: \ cur += i + 1; \ goto digi_frac_end; repeat_in_1_18(expr_stop) #undef expr_stop /* read more digits in integral part */ digi_intg_more: if (digi_is_digit(*cur)) { if (!digi_is_digit_or_fp(cur[1])) { /* this number is an integer consisting of 20 digits */ num = (u64)(*cur - '0'); if ((sig < (U64_MAX / 10)) || (sig == (U64_MAX / 10) && num <= (U64_MAX % 10))) { sig = num + sig * 10; cur++; /* convert to double if overflow */ if (sign) { return_f64(normalized_u64_to_f64(sig)); } return_i64(sig); } } } if (digi_is_exp(*cur)) { dot_pos = cur; goto digi_exp_more; } if (*cur == '.') { dot_pos = cur++; if (!digi_is_digit(*cur)) { return_err(cur, "no digit after decimal point"); } } /* read more digits in fraction part */ digi_frac_more: sig_cut = cur; /* too large to fit in u64, excess digits need to be cut */ sig += (*cur >= '5'); /* round */ while (digi_is_digit(*++cur)); if (!dot_pos) { dot_pos = cur; if (*cur == '.') { if (!digi_is_digit(*++cur)) { return_err(cur, "no digit after decimal point"); } while (digi_is_digit(*cur)) cur++; } } exp_sig = (i64)(dot_pos - sig_cut); exp_sig += (dot_pos < sig_cut); /* ignore trailing zeros */ tmp = cur - 1; while (*tmp == '0' || *tmp == '.') tmp--; if (tmp < sig_cut) { sig_cut = NULL; } else { sig_end = cur; } if (digi_is_exp(*cur)) goto digi_exp_more; goto digi_exp_finish; /* fraction part end */ digi_frac_end: if (unlikely(dot_pos + 1 == cur)) { return_err(cur, "no digit after decimal point"); } sig_end = cur; exp_sig = -(i64)((u64)(cur - dot_pos) - 1); if (likely(!digi_is_exp(*cur))) { if (unlikely(exp_sig < F64_MIN_DEC_EXP - 19)) { return_f64_bin(0); /* underflow */ } exp = (i32)exp_sig; goto digi_finish; } else { goto digi_exp_more; } /* read exponent part */ digi_exp_more: exp_sign = (*++cur == '-'); cur += digi_is_sign(*cur); if (unlikely(!digi_is_digit(*cur))) { return_err(cur, "no digit after exponent sign"); } while (*cur == '0') cur++; /* read exponent literal */ tmp = cur; while (digi_is_digit(*cur)) { exp_lit = (i64)((u8)(*cur++ - '0') + (u64)exp_lit * 10); } if (unlikely(cur - tmp >= U64_SAFE_DIG)) { if (exp_sign) { return_f64_bin(0); /* underflow */ } else { return_inf(); /* overflow */ } } exp_sig += exp_sign ? -exp_lit : exp_lit; /* validate exponent value */ digi_exp_finish: if (unlikely(exp_sig < F64_MIN_DEC_EXP - 19)) { return_f64_bin(0); /* underflow */ } if (unlikely(exp_sig > F64_MAX_DEC_EXP)) { return_inf(); /* overflow */ } exp = (i32)exp_sig; /* all digit read finished */ digi_finish: /* Fast path 1: 1. The floating-point number calculation should be accurate, see the comments of macro `YYJSON_DOUBLE_MATH_CORRECT`. 2. Correct rounding should be performed (fegetround() == FE_TONEAREST). 3. The input of floating point number calculation does not lose precision, which means: 64 - leading_zero(input) - trailing_zero(input) < 53. We don't check all available inputs here, because that would make the code more complicated, and not friendly to branch predictor. */ #if YYJSON_DOUBLE_MATH_CORRECT if (sig < ((u64)1 << 53) && exp >= -F64_POW10_EXP_MAX_EXACT && exp <= +F64_POW10_EXP_MAX_EXACT) { f64 dbl = (f64)sig; if (exp < 0) { dbl /= f64_pow10_table[-exp]; } else { dbl *= f64_pow10_table[+exp]; } return_f64(dbl); } #endif /* Fast path 2: To keep it simple, we only accept normal number here, let the slow path to handle subnormal and infinity number. */ if (likely(!sig_cut && exp > -F64_MAX_DEC_EXP + 1 && exp < +F64_MAX_DEC_EXP - 20)) { /* The result value is exactly equal to (sig * 10^exp), the exponent part (10^exp) can be converted to (sig2 * 2^exp2). The sig2 can be an infinite length number, only the highest 128 bits is cached in the pow10_sig_table. Now we have these bits: sig1 (normalized 64bit) : aaaaaaaa sig2 (higher 64bit) : bbbbbbbb sig2_ext (lower 64bit) : cccccccc sig2_cut (extra unknown bits) : dddddddddddd.... And the calculation process is: ---------------------------------------- aaaaaaaa * bbbbbbbbccccccccdddddddddddd.... ---------------------------------------- abababababababab + acacacacacacacac + adadadadadadadadadad.... ---------------------------------------- [hi____][lo____] + [hi2___][lo2___] + [unknown___________....] ---------------------------------------- The addition with carry may affect higher bits, but if there is a 0 in higher bits, the bits higher than 0 will not be affected. `lo2` + `unknown` may get a carry bit and may affect `hi2`, the max value of `hi2` is 0xFFFFFFFFFFFFFFFE, so `hi2` will not overflow. `lo` + `hi2` may also get a carry bit and may affect `hi`, but only the highest significant 53 bits of `hi` is needed. If there is a 0 in the lower bits of `hi`, then all the following bits can be dropped. To convert the result to IEEE-754 double number, we need to perform correct rounding: 1. if bit 54 is 0, round down, 2. if bit 54 is 1 and any bit beyond bit 54 is 1, round up, 3. if bit 54 is 1 and all bits beyond bit 54 are 0, round to even, as the extra bits is unknown, this case will not be handled here. */ u64 raw; u64 sig1, sig2, sig2_ext, hi, lo, hi2, lo2, add, bits; i32 exp2; u32 lz; bool exact = false, carry, round_up; /* convert (10^exp) to (sig2 * 2^exp2) */ pow10_table_get_sig(exp, &sig2, &sig2_ext); pow10_table_get_exp(exp, &exp2); /* normalize and multiply */ lz = u64_lz_bits(sig); sig1 = sig << lz; exp2 -= (i32)lz; u128_mul(sig1, sig2, &hi, &lo); /* The `hi` is in range [0x4000000000000000, 0xFFFFFFFFFFFFFFFE], To get normalized value, `hi` should be shifted to the left by 0 or 1. The highest significant 53 bits is used by IEEE-754 double number, and the bit 54 is used to detect rounding direction. The lowest (64 - 54 - 1) bits is used to check whether it contains 0. */ bits = hi & (((u64)1 << (64 - 54 - 1)) - 1); if (bits - 1 < (((u64)1 << (64 - 54 - 1)) - 2)) { /* (bits != 0 && bits != 0x1FF) => (bits - 1 < 0x1FF - 1) The `bits` is not zero, so we don't need to check `round to even` case. The `bits` contains bit `0`, so we can drop the extra bits after `0`. */ exact = true; } else { /* (bits == 0 || bits == 0x1FF) The `bits` is filled with all `0` or all `1`, so we need to check lower bits with another 64-bit multiplication. */ u128_mul(sig1, sig2_ext, &hi2, &lo2); add = lo + hi2; if (add + 1 > (u64)1) { /* (add != 0 && add != U64_MAX) => (add + 1 > 1) The `add` is not zero, so we don't need to check `round to even` case. The `add` contains bit `0`, so we can drop the extra bits after `0`. The `hi` cannot be U64_MAX, so it will not overflow. */ carry = add < lo || add < hi2; hi += carry; exact = true; } } if (exact) { /* normalize */ lz = hi < ((u64)1 << 63); hi <<= lz; exp2 -= (i32)lz; exp2 += 64; /* test the bit 54 and get rounding direction */ round_up = (hi & ((u64)1 << (64 - 54))) > (u64)0; hi += (round_up ? ((u64)1 << (64 - 54)) : (u64)0); /* test overflow */ if (hi < ((u64)1 << (64 - 54))) { hi = ((u64)1 << 63); exp2 += 1; } /* This is a normal number, convert it to IEEE-754 format. */ hi >>= F64_BITS - F64_SIG_FULL_BITS; exp2 += F64_BITS - F64_SIG_FULL_BITS + F64_SIG_BITS; exp2 += F64_EXP_BIAS; raw = ((u64)exp2 << F64_SIG_BITS) | (hi & F64_SIG_MASK); return_f64_bin(raw); } } /* Slow path: read double number exactly with diyfp. 1. Use cached diyfp to get an approximation value. 2. Use bigcomp to check the approximation value if needed. This algorithm refers to google's double-conversion project: https://github.com/google/double-conversion */ { const i32 ERR_ULP_LOG = 3; const i32 ERR_ULP = 1 << ERR_ULP_LOG; const i32 ERR_CACHED_POW = ERR_ULP / 2; const i32 ERR_MUL_FIXED = ERR_ULP / 2; const i32 DIY_SIG_BITS = 64; const i32 EXP_BIAS = F64_EXP_BIAS + F64_SIG_BITS; const i32 EXP_SUBNORMAL = -EXP_BIAS + 1; u64 fp_err; u32 bits; i32 order_of_magnitude; i32 effective_significand_size; i32 precision_digits_count; u64 precision_bits; u64 half_way; u64 raw; diy_fp fp, fp_upper; bigint big_full, big_comp; i32 cmp; fp.sig = sig; fp.exp = 0; fp_err = sig_cut ? (u64)(ERR_ULP / 2) : (u64)0; /* normalize */ bits = u64_lz_bits(fp.sig); fp.sig <<= bits; fp.exp -= (i32)bits; fp_err <<= bits; /* multiply and add error */ fp = diy_fp_mul(fp, diy_fp_get_cached_pow10(exp)); fp_err += (u64)ERR_CACHED_POW + (fp_err != 0) + (u64)ERR_MUL_FIXED; /* normalize */ bits = u64_lz_bits(fp.sig); fp.sig <<= bits; fp.exp -= (i32)bits; fp_err <<= bits; /* effective significand */ order_of_magnitude = DIY_SIG_BITS + fp.exp; if (likely(order_of_magnitude >= EXP_SUBNORMAL + F64_SIG_FULL_BITS)) { effective_significand_size = F64_SIG_FULL_BITS; } else if (order_of_magnitude <= EXP_SUBNORMAL) { effective_significand_size = 0; } else { effective_significand_size = order_of_magnitude - EXP_SUBNORMAL; } /* precision digits count */ precision_digits_count = DIY_SIG_BITS - effective_significand_size; if (unlikely(precision_digits_count + ERR_ULP_LOG >= DIY_SIG_BITS)) { i32 shr = (precision_digits_count + ERR_ULP_LOG) - DIY_SIG_BITS + 1; fp.sig >>= shr; fp.exp += shr; fp_err = (fp_err >> shr) + 1 + (u32)ERR_ULP; precision_digits_count -= shr; } /* half way */ precision_bits = fp.sig & (((u64)1 << precision_digits_count) - 1); precision_bits *= (u32)ERR_ULP; half_way = (u64)1 << (precision_digits_count - 1); half_way *= (u32)ERR_ULP; /* rounding */ fp.sig >>= precision_digits_count; fp.sig += (precision_bits >= half_way + fp_err); fp.exp += precision_digits_count; /* get IEEE double raw value */ raw = diy_fp_to_ieee_raw(fp); if (unlikely(raw == F64_RAW_INF)) return_inf(); if (likely(precision_bits <= half_way - fp_err || precision_bits >= half_way + fp_err)) { return_f64_bin(raw); /* number is accurate */ } /* now the number is the correct value, or the next lower value */ /* upper boundary */ if (raw & F64_EXP_MASK) { fp_upper.sig = (raw & F64_SIG_MASK) + ((u64)1 << F64_SIG_BITS); fp_upper.exp = (i32)((raw & F64_EXP_MASK) >> F64_SIG_BITS); } else { fp_upper.sig = (raw & F64_SIG_MASK); fp_upper.exp = 1; } fp_upper.exp -= F64_EXP_BIAS + F64_SIG_BITS; fp_upper.sig <<= 1; fp_upper.exp -= 1; fp_upper.sig += 1; /* add half ulp */ /* compare with bigint */ bigint_set_buf(&big_full, sig, &exp, sig_cut, sig_end, dot_pos); bigint_set_u64(&big_comp, fp_upper.sig); if (exp >= 0) { bigint_mul_pow10(&big_full, +exp); } else { bigint_mul_pow10(&big_comp, -exp); } if (fp_upper.exp > 0) { bigint_mul_pow2(&big_comp, (u32)+fp_upper.exp); } else { bigint_mul_pow2(&big_full, (u32)-fp_upper.exp); } cmp = bigint_cmp(&big_full, &big_comp); if (likely(cmp != 0)) { /* round down or round up */ raw += (cmp > 0); } else { /* falls midway, round to even */ raw += (raw & 1); } if (unlikely(raw == F64_RAW_INF)) return_inf(); return_f64_bin(raw); } #undef return_err #undef return_inf #undef return_0 #undef return_i64 #undef return_f64 #undef return_f64_bin #undef return_raw } #else /* FP_READER */ /** Read a JSON number. This is a fallback function if the custom number reader is disabled. This function use libc's strtod() to read floating-point number. */ static_inline bool read_number(u8 **ptr, yyjson_val *val, const char **msg) { #define return_err(_pos, _msg) do { \ *msg = _msg; \ *end = _pos; \ return false; \ } while (false) #define return_0() do { \ val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); \ val->uni.u64 = 0; \ *end = cur; return true; \ } while (false) #define return_i64(_v) do { \ val->tag = YYJSON_TYPE_NUM | (u64)((u8)sign << 3); \ val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \ *end = cur; return true; \ } while (false) #define return_f64(_v) do { \ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ val->uni.f64 = sign ? -(f64)(_v) : (f64)(_v); \ *end = cur; return true; \ } while (false) #define return_f64_bin(_v) do { \ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; \ val->uni.u64 = ((u64)sign << 63) | (u64)(_v); \ *end = cur; return true; \ } while (false) #define return_inf() do { \ if (false) return_f64_bin(F64_RAW_INF); \ else return_err(hdr, "number is infinity when parsed as double"); \ } while (false) u64 sig, num; u8 *hdr = *ptr; u8 *cur = *ptr; u8 **end = ptr; u8 *dot = NULL; u8 *f64_end = NULL; bool sign; /* read number as raw string if has `YYJSON_READ_NUMBER_AS_RAW` flag */ if (unlikely(false)) { return read_number_raw(ptr, pre, flg, val, msg); } sign = (*hdr == '-'); cur += sign; sig = (u8)(*cur - '0'); /* read first digit, check leading zero */ if (unlikely(!digi_is_digit(*cur))) { return_err(cur, "no digit after minus sign"); } if (*cur == '0') { cur++; if (unlikely(digi_is_digit(*cur))) { return_err(cur - 1, "number with leading zero is not allowed"); } if (!digi_is_fp(*cur)) return_0(); goto read_double; } /* read continuous digits, up to 19 characters */ #define expr_intg(i) \ if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \ else { cur += i; goto intg_end; } repeat_in_1_18(expr_intg) #undef expr_intg /* here are 19 continuous digits, skip them */ cur += 19; if (digi_is_digit(cur[0]) && !digi_is_digit_or_fp(cur[1])) { /* this number is an integer consisting of 20 digits */ num = (u8)(*cur - '0'); if ((sig < (U64_MAX / 10)) || (sig == (U64_MAX / 10) && num <= (U64_MAX % 10))) { sig = num + sig * 10; cur++; if (sign) { if (false) return_raw(); return_f64(normalized_u64_to_f64(sig)); } return_i64(sig); } } intg_end: /* continuous digits ended */ if (!digi_is_digit_or_fp(*cur)) { /* this number is an integer consisting of 1 to 19 digits */ if (sign && (sig > ((u64)1 << 63))) { if (false) return_raw(); return_f64(normalized_u64_to_f64(sig)); } return_i64(sig); } read_double: /* this number should be read as double */ while (digi_is_digit(*cur)) cur++; if (*cur == '.') { /* skip fraction part */ dot = cur; cur++; if (!digi_is_digit(*cur)) { return_err(cur, "no digit after decimal point"); } cur++; while (digi_is_digit(*cur)) cur++; } if (digi_is_exp(*cur)) { /* skip exponent part */ cur += 1 + digi_is_sign(cur[1]); if (!digi_is_digit(*cur)) { return_err(cur, "no digit after exponent sign"); } cur++; while (digi_is_digit(*cur)) cur++; } /* libc's strtod() is used to parse the floating-point number. Note that the decimal point character used by strtod() is locale-dependent, and the rounding direction may affected by fesetround(). For currently known locales, (en, zh, ja, ko, am, he, hi) use '.' as the decimal point, while other locales use ',' as the decimal point. Here strtod() is called twice for different locales, but if another thread happens calls setlocale() between two strtod(), parsing may still fail. */ val->uni.f64 = strtod((const char *)hdr, (char **)&f64_end); if (unlikely(f64_end != cur)) { /* replace '.' with ',' for locale */ bool cut = (*cur == ','); if (cut) *cur = ' '; if (dot) *dot = ','; val->uni.f64 = strtod((const char *)hdr, (char **)&f64_end); /* restore ',' to '.' */ if (cut) *cur = ','; if (dot) *dot = '.'; if (unlikely(f64_end != cur)) { return_err(hdr, "strtod() failed to parse the number"); } } if (unlikely(val->uni.f64 >= HUGE_VAL || val->uni.f64 <= -HUGE_VAL)) { return_inf(); } val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; *end = cur; return true; #undef return_err #undef return_0 #undef return_i64 #undef return_f64 #undef return_f64_bin #undef return_inf #undef return_raw } #endif /* FP_READER */ /*============================================================================== * JSON String Reader *============================================================================*/ /** Read a JSON string. @param ptr The head pointer of string before '"' prefix (inout). @param lst JSON last position. @param inv Allow invalid unicode. @param val The string value to be written. @param msg The error message pointer. @return Whether success. */ static_inline bool read_string(u8 **ptr, u8 *lst, yyjson_val *val, const char **msg) { /* Each unicode code point is encoded as 1 to 4 bytes in UTF-8 encoding, we use 4-byte mask and pattern value to validate UTF-8 byte sequence, this requires the input data to have 4-byte zero padding. --------------------------------------------------- 1 byte unicode range [U+0000, U+007F] unicode min [.......0] unicode max [.1111111] bit pattern [0.......] --------------------------------------------------- 2 byte unicode range [U+0080, U+07FF] unicode min [......10 ..000000] unicode max [...11111 ..111111] bit require [...xxxx. ........] (1E 00) bit mask [xxx..... xx......] (E0 C0) bit pattern [110..... 10......] (C0 80) --------------------------------------------------- 3 byte unicode range [U+0800, U+FFFF] unicode min [........ ..100000 ..000000] unicode max [....1111 ..111111 ..111111] bit require [....xxxx ..x..... ........] (0F 20 00) bit mask [xxxx.... xx...... xx......] (F0 C0 C0) bit pattern [1110.... 10...... 10......] (E0 80 80) --------------------------------------------------- 3 byte invalid (reserved for surrogate halves) unicode range [U+D800, U+DFFF] unicode min [....1101 ..100000 ..000000] unicode max [....1101 ..111111 ..111111] bit mask [....xxxx ..x..... ........] (0F 20 00) bit pattern [....1101 ..1..... ........] (0D 20 00) --------------------------------------------------- 4 byte unicode range [U+10000, U+10FFFF] unicode min [........ ...10000 ..000000 ..000000] unicode max [.....100 ..001111 ..111111 ..111111] bit require [.....xxx ..xx.... ........ ........] (07 30 00 00) bit mask [xxxxx... xx...... xx...... xx......] (F8 C0 C0 C0) bit pattern [11110... 10...... 10...... 10......] (F0 80 80 80) --------------------------------------------------- */ #if YYJSON_ENDIAN == YYJSON_BIG_ENDIAN const u32 b1_mask = 0x80000000UL; const u32 b1_patt = 0x00000000UL; const u32 b2_mask = 0xE0C00000UL; const u32 b2_patt = 0xC0800000UL; const u32 b2_requ = 0x1E000000UL; const u32 b3_mask = 0xF0C0C000UL; const u32 b3_patt = 0xE0808000UL; const u32 b3_requ = 0x0F200000UL; const u32 b3_erro = 0x0D200000UL; const u32 b4_mask = 0xF8C0C0C0UL; const u32 b4_patt = 0xF0808080UL; const u32 b4_requ = 0x07300000UL; const u32 b4_err0 = 0x04000000UL; const u32 b4_err1 = 0x03300000UL; #elif YYJSON_ENDIAN == YYJSON_LITTLE_ENDIAN const u32 b1_mask = 0x00000080UL; const u32 b1_patt = 0x00000000UL; const u32 b2_mask = 0x0000C0E0UL; const u32 b2_patt = 0x000080C0UL; const u32 b2_requ = 0x0000001EUL; const u32 b3_mask = 0x00C0C0F0UL; const u32 b3_patt = 0x008080E0UL; const u32 b3_requ = 0x0000200FUL; const u32 b3_erro = 0x0000200DUL; const u32 b4_mask = 0xC0C0C0F8UL; const u32 b4_patt = 0x808080F0UL; const u32 b4_requ = 0x00003007UL; const u32 b4_err0 = 0x00000004UL; const u32 b4_err1 = 0x00003003UL; #else /* this should be evaluated at compile-time */ v32_uni b1_mask_uni = {{ 0x80, 0x00, 0x00, 0x00 }}; v32_uni b1_patt_uni = {{ 0x00, 0x00, 0x00, 0x00 }}; v32_uni b2_mask_uni = {{ 0xE0, 0xC0, 0x00, 0x00 }}; v32_uni b2_patt_uni = {{ 0xC0, 0x80, 0x00, 0x00 }}; v32_uni b2_requ_uni = {{ 0x1E, 0x00, 0x00, 0x00 }}; v32_uni b3_mask_uni = {{ 0xF0, 0xC0, 0xC0, 0x00 }}; v32_uni b3_patt_uni = {{ 0xE0, 0x80, 0x80, 0x00 }}; v32_uni b3_requ_uni = {{ 0x0F, 0x20, 0x00, 0x00 }}; v32_uni b3_erro_uni = {{ 0x0D, 0x20, 0x00, 0x00 }}; v32_uni b4_mask_uni = {{ 0xF8, 0xC0, 0xC0, 0xC0 }}; v32_uni b4_patt_uni = {{ 0xF0, 0x80, 0x80, 0x80 }}; v32_uni b4_requ_uni = {{ 0x07, 0x30, 0x00, 0x00 }}; v32_uni b4_err0_uni = {{ 0x04, 0x00, 0x00, 0x00 }}; v32_uni b4_err1_uni = {{ 0x03, 0x30, 0x00, 0x00 }}; u32 b1_mask = b1_mask_uni.u; u32 b1_patt = b1_patt_uni.u; u32 b2_mask = b2_mask_uni.u; u32 b2_patt = b2_patt_uni.u; u32 b2_requ = b2_requ_uni.u; u32 b3_mask = b3_mask_uni.u; u32 b3_patt = b3_patt_uni.u; u32 b3_requ = b3_requ_uni.u; u32 b3_erro = b3_erro_uni.u; u32 b4_mask = b4_mask_uni.u; u32 b4_patt = b4_patt_uni.u; u32 b4_requ = b4_requ_uni.u; u32 b4_err0 = b4_err0_uni.u; u32 b4_err1 = b4_err1_uni.u; #endif #define is_valid_seq_1(uni) ( \ ((uni & b1_mask) == b1_patt) \ ) #define is_valid_seq_2(uni) ( \ ((uni & b2_mask) == b2_patt) && \ ((uni & b2_requ)) \ ) #define is_valid_seq_3(uni) ( \ ((uni & b3_mask) == b3_patt) && \ ((tmp = (uni & b3_requ))) && \ ((tmp != b3_erro)) \ ) #define is_valid_seq_4(uni) ( \ ((uni & b4_mask) == b4_patt) && \ ((tmp = (uni & b4_requ))) && \ ((tmp & b4_err0) == 0 || (tmp & b4_err1) == 0) \ ) #define return_err(_end, _msg) do { \ *msg = _msg; \ *end = _end; \ return false; \ } while (false) u8 *cur = *ptr; u8 **end = ptr; u8 *src = ++cur, *dst; u16 hi, lo; u32 uni, tmp; skip_ascii: /* Most strings have no escaped characters, so we can jump them quickly. */ skip_ascii_begin: /* We want to make loop unrolling, as shown in the following code. Some compiler may not generate instructions as expected, so we rewrite it with explicit goto statements. We hope the compiler can generate instructions like this: https://godbolt.org/z/8vjsYq while (true) repeat16({ if (likely(!(char_is_ascii_stop(*src)))) src++; else break; }) */ #define expr_jump(i) \ if (likely(!char_is_ascii_stop(src[i]))) {} \ else goto skip_ascii_stop##i; #define expr_stop(i) \ skip_ascii_stop##i: \ src += i; \ goto skip_ascii_end; repeat16_incr(expr_jump) src += 16; goto skip_ascii_begin; repeat16_incr(expr_stop) #undef expr_jump #undef expr_stop skip_ascii_end: /* GCC may store src[i] in a register at each line of expr_jump(i) above. These instructions are useless and will degrade performance. This inline asm is a hint for gcc: "the memory has been modified, do not cache it". MSVC, Clang, ICC can generate expected instructions without this hint. */ #if YYJSON_IS_REAL_GCC __asm__ volatile("":"=m"(*src)); #endif if (likely(*src == '"')) { val->tag = ((u64)(src - cur) << YYJSON_TAG_BIT) | (u64)(YYJSON_TYPE_STR); val->uni.str = (const char *)cur; *src = '\0'; *end = src + 1; return true; } skip_utf8: if (*src & 0x80) { /* non-ASCII character */ /* Non-ASCII character appears here, which means that the text is likely to be written in non-English or emoticons. According to some common data set statistics, byte sequences of the same length may appear consecutively. We process the byte sequences of the same length in each loop, which is more friendly to branch prediction. */ #if YYJSON_DISABLE_UTF8_VALIDATION while (true) repeat8({ if (likely((*src & 0xF0) == 0xE0)) src += 3; else break; }) if (*src < 0x80) goto skip_ascii; while (true) repeat8({ if (likely((*src & 0xE0) == 0xC0)) src += 2; else break; }) while (true) repeat8({ if (likely((*src & 0xF8) == 0xF0)) src += 4; else break; }) #else uni = byte_load_4(src); while (is_valid_seq_3(uni)) { src += 3; uni = byte_load_4(src); } if (is_valid_seq_1(uni)) goto skip_ascii; while (is_valid_seq_2(uni)) { src += 2; uni = byte_load_4(src); } while (is_valid_seq_4(uni)) { src += 4; uni = byte_load_4(src); } #endif goto skip_ascii; } /* The escape character appears, we need to copy it. */ dst = src; copy_escape: if (likely(*src == '\\')) { switch (*++src) { case '"': *dst++ = '"'; src++; break; case '\\': *dst++ = '\\'; src++; break; case '/': *dst++ = '/'; src++; break; case 'b': *dst++ = '\b'; src++; break; case 'f': *dst++ = '\f'; src++; break; case 'n': *dst++ = '\n'; src++; break; case 'r': *dst++ = '\r'; src++; break; case 't': *dst++ = '\t'; src++; break; case 'u': if (unlikely(!read_hex_u16(++src, &hi))) { return_err(src - 2, "invalid escaped sequence in string"); } src += 4; if (likely((hi & 0xF800) != 0xD800)) { /* a BMP character */ if (hi >= 0x800) { *dst++ = (u8)(0xE0 | (hi >> 12)); *dst++ = (u8)(0x80 | ((hi >> 6) & 0x3F)); *dst++ = (u8)(0x80 | (hi & 0x3F)); } else if (hi >= 0x80) { *dst++ = (u8)(0xC0 | (hi >> 6)); *dst++ = (u8)(0x80 | (hi & 0x3F)); } else { *dst++ = (u8)hi; } } else { /* a non-BMP character, represented as a surrogate pair */ if (unlikely((hi & 0xFC00) != 0xD800)) { return_err(src - 6, "invalid high surrogate in string"); } if (unlikely(!byte_match_2(src, "\\u"))) { return_err(src, "no low surrogate in string"); } if (unlikely(!read_hex_u16(src + 2, &lo))) { return_err(src, "invalid escaped sequence in string"); } if (unlikely((lo & 0xFC00) != 0xDC00)) { return_err(src, "invalid low surrogate in string"); } uni = ((((u32)hi - 0xD800) << 10) | ((u32)lo - 0xDC00)) + 0x10000; *dst++ = (u8)(0xF0 | (uni >> 18)); *dst++ = (u8)(0x80 | ((uni >> 12) & 0x3F)); *dst++ = (u8)(0x80 | ((uni >> 6) & 0x3F)); *dst++ = (u8)(0x80 | (uni & 0x3F)); src += 6; } break; default: return_err(src, "invalid escaped character in string"); } } else if (likely(*src == '"')) { val->tag = ((u64)(dst - cur) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = (const char *)cur; *end = src + 1; return true; } else { return_err(src, "unexpected control character in string"); } copy_ascii: /* Copy continuous ASCII, loop unrolling, same as the following code: while (true) repeat16({ if (unlikely(char_is_ascii_stop(*src))) break; *dst++ = *src++; }) */ #if YYJSON_IS_REAL_GCC # define expr_jump(i) \ if (likely(!(char_is_ascii_stop(src[i])))) {} \ else { __asm__ volatile("":"=m"(src[i])); goto copy_ascii_stop_##i; } #else # define expr_jump(i) \ if (likely(!(char_is_ascii_stop(src[i])))) {} \ else { goto copy_ascii_stop_##i; } #endif repeat16_incr(expr_jump) #undef expr_jump byte_move_16(dst, src); src += 16; dst += 16; goto copy_ascii; /* The memory will be moved forward by at least 1 byte. So the `byte_move` can be one byte more than needed to reduce the number of instructions. */ copy_ascii_stop_0: goto copy_utf8; copy_ascii_stop_1: byte_move_2(dst, src); src += 1; dst += 1; goto copy_utf8; copy_ascii_stop_2: byte_move_2(dst, src); src += 2; dst += 2; goto copy_utf8; copy_ascii_stop_3: byte_move_4(dst, src); src += 3; dst += 3; goto copy_utf8; copy_ascii_stop_4: byte_move_4(dst, src); src += 4; dst += 4; goto copy_utf8; copy_ascii_stop_5: byte_move_4(dst, src); byte_move_2(dst + 4, src + 4); src += 5; dst += 5; goto copy_utf8; copy_ascii_stop_6: byte_move_4(dst, src); byte_move_2(dst + 4, src + 4); src += 6; dst += 6; goto copy_utf8; copy_ascii_stop_7: byte_move_8(dst, src); src += 7; dst += 7; goto copy_utf8; copy_ascii_stop_8: byte_move_8(dst, src); src += 8; dst += 8; goto copy_utf8; copy_ascii_stop_9: byte_move_8(dst, src); byte_move_2(dst + 8, src + 8); src += 9; dst += 9; goto copy_utf8; copy_ascii_stop_10: byte_move_8(dst, src); byte_move_2(dst + 8, src + 8); src += 10; dst += 10; goto copy_utf8; copy_ascii_stop_11: byte_move_8(dst, src); byte_move_4(dst + 8, src + 8); src += 11; dst += 11; goto copy_utf8; copy_ascii_stop_12: byte_move_8(dst, src); byte_move_4(dst + 8, src + 8); src += 12; dst += 12; goto copy_utf8; copy_ascii_stop_13: byte_move_8(dst, src); byte_move_4(dst + 8, src + 8); byte_move_2(dst + 12, src + 12); src += 13; dst += 13; goto copy_utf8; copy_ascii_stop_14: byte_move_8(dst, src); byte_move_4(dst + 8, src + 8); byte_move_2(dst + 12, src + 12); src += 14; dst += 14; goto copy_utf8; copy_ascii_stop_15: byte_move_16(dst, src); src += 15; dst += 15; goto copy_utf8; copy_utf8: if (*src & 0x80) { /* non-ASCII character */ uni = byte_load_4(src); #if YYJSON_DISABLE_UTF8_VALIDATION while (true) repeat4({ if ((uni & b3_mask) == b3_patt) { byte_copy_4(dst, &uni); dst += 3; src += 3; uni = byte_load_4(src); } else break; }) if ((uni & b1_mask) == b1_patt) goto copy_ascii; while (true) repeat4({ if ((uni & b2_mask) == b2_patt) { byte_copy_2(dst, &uni); dst += 2; src += 2; uni = byte_load_4(src); } else break; }) while (true) repeat4({ if ((uni & b4_mask) == b4_patt) { byte_copy_4(dst, &uni); dst += 4; src += 4; uni = byte_load_4(src); } else break; }) #else while (is_valid_seq_3(uni)) { byte_copy_4(dst, &uni); dst += 3; src += 3; uni = byte_load_4(src); } if (is_valid_seq_1(uni)) goto copy_ascii; while (is_valid_seq_2(uni)) { byte_copy_2(dst, &uni); dst += 2; src += 2; uni = byte_load_4(src); } while (is_valid_seq_4(uni)) { byte_copy_4(dst, &uni); dst += 4; src += 4; uni = byte_load_4(src); } #endif goto copy_ascii; } goto copy_escape; #undef return_err #undef is_valid_seq_1 #undef is_valid_seq_2 #undef is_valid_seq_3 #undef is_valid_seq_4 } /*============================================================================== * JSON Reader Implementation * * We use goto statements to build the finite state machine (FSM). * The FSM's state was held by program counter (PC) and the 'goto' make the * state transitions. *============================================================================*/ /** Read single value JSON document. */ static_noinline yyjson_doc *read_root_single(u8 *hdr, u8 *cur, u8 *end, yyjson_alc alc, yyjson_read_err *err) { #define return_err(_pos, _code, _msg) do { \ if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code)) { \ err->pos = (usize)(end - hdr); \ err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ err->msg = "unexpected end of data"; \ } else { \ err->pos = (usize)(_pos - hdr); \ err->code = YYJSON_READ_ERROR_##_code; \ err->msg = _msg; \ } \ if (val_hdr) alc.free(alc.ctx, (void *)val_hdr); \ return NULL; \ } while (false) usize hdr_len; /* value count used by doc */ usize alc_num; /* value count capacity */ yyjson_val *val_hdr; /* the head of allocated values */ yyjson_val *val; /* current value */ yyjson_doc *doc; /* the JSON document, equals to val_hdr */ const char *msg; /* error message */ hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; alc_num = hdr_len + 1; /* single value */ val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_num * sizeof(yyjson_val)); if (unlikely(!val_hdr)) goto fail_alloc; val = val_hdr + hdr_len; if (char_is_number(*cur)) { if (likely(read_number(&cur, val, &msg))) goto doc_end; goto fail_number; } if (*cur == '"') { if (likely(read_string(&cur, end, val, &msg))) goto doc_end; goto fail_string; } if (*cur == 't') { if (likely(read_true(&cur, val))) goto doc_end; goto fail_literal; } if (*cur == 'f') { if (likely(read_false(&cur, val))) goto doc_end; goto fail_literal; } if (*cur == 'n') { if (likely(read_null(&cur, val))) goto doc_end; if (false) { if (read_nan(false, &cur, 0, val)) goto doc_end; } goto fail_literal; } goto fail_character; doc_end: /* check invalid contents after json document */ if (unlikely(cur < end) && !has_read_flag(STOP_WHEN_DONE)) { if (false) { if (!skip_spaces_and_comments(&cur)) { if (byte_match_2(cur, "/*")) goto fail_comment; } } else { while (char_is_space(*cur)) cur++; } if (unlikely(cur < end)) goto fail_garbage; } doc = (yyjson_doc *)val_hdr; doc->root = val_hdr + hdr_len; doc->alc = alc; doc->dat_read = (usize)(cur - hdr); doc->val_read = 1; doc->str_pool = (char *)hdr; return doc; fail_string: return_err(cur, INVALID_STRING, msg); fail_number: return_err(cur, INVALID_NUMBER, msg); fail_alloc: return_err(cur, MEMORY_ALLOCATION, "memory allocation failed"); fail_literal: return_err(cur, LITERAL, "invalid literal"); fail_comment: return_err(cur, INVALID_COMMENT, "unclosed multiline comment"); fail_character: return_err(cur, UNEXPECTED_CHARACTER, "unexpected character"); fail_garbage: return_err(cur, UNEXPECTED_CONTENT, "unexpected content after document"); fail_recursion: return_err(cur, RECURSION_DEPTH, "array and object recursion depth exceeded"); #undef return_err } /** Read JSON document (accept all style, but optimized for minify). */ static_inline yyjson_doc *read_root_minify(u8 *hdr, u8 *cur, u8 *end, yyjson_alc alc, yyjson_read_err *err) { #define return_err(_pos, _code, _msg) do { \ if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code)) { \ err->pos = (usize)(end - hdr); \ err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ err->msg = "unexpected end of data"; \ } else { \ err->pos = (usize)(_pos - hdr); \ err->code = YYJSON_READ_ERROR_##_code; \ err->msg = _msg; \ } \ if (val_hdr) alc.free(alc.ctx, (void *)val_hdr); \ return NULL; \ } while (false) #define val_incr() do { \ val++; \ if (unlikely(val >= val_end)) { \ usize alc_old = alc_len; \ alc_len += alc_len / 2; \ if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \ val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \ alc_old * sizeof(yyjson_val), \ alc_len * sizeof(yyjson_val)); \ if ((!val_tmp)) goto fail_alloc; \ val = val_tmp + (usize)(val - val_hdr); \ ctn = val_tmp + (usize)(ctn - val_hdr); \ val_hdr = val_tmp; \ val_end = val_tmp + (alc_len - 2); \ } \ } while (false) usize dat_len; /* data length in bytes, hint for allocator */ usize hdr_len; /* value count used by yyjson_doc */ usize alc_len; /* value count allocated */ usize alc_max; /* maximum value count for allocator */ usize ctn_len; /* the number of elements in current container */ yyjson_val *val_hdr; /* the head of allocated values */ yyjson_val *val_end; /* the end of allocated values */ yyjson_val *val_tmp; /* temporary pointer for realloc */ yyjson_val *val; /* current JSON value */ yyjson_val *ctn; /* current container */ yyjson_val *ctn_parent; /* parent of current container */ yyjson_doc *doc; /* the JSON document, equals to val_hdr */ const char *msg; /* error message */ u32 container_depth = 0; /* limit on number of open array and map */ bool raw; /* read number as raw */ bool inv; /* allow invalid unicode */ dat_len = has_read_flag(STOP_WHEN_DONE) ? 256 : (usize)(end - cur); hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; alc_max = USIZE_MAX / sizeof(yyjson_val); alc_len = hdr_len + (dat_len / YYJSON_READER_ESTIMATED_MINIFY_RATIO) + 4; alc_len = yyjson_min(alc_len, alc_max); val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_len * sizeof(yyjson_val)); if (unlikely(!val_hdr)) goto fail_alloc; val_end = val_hdr + (alc_len - 2); /* padding for key-value pair reading */ val = val_hdr + hdr_len; ctn = val; ctn_len = 0; if (*cur++ == '{') { ctn->tag = YYJSON_TYPE_OBJ; ctn->uni.ofs = 0; goto obj_key_begin; } else { ctn->tag = YYJSON_TYPE_ARR; ctn->uni.ofs = 0; goto arr_val_begin; } arr_begin: container_depth++; if (unlikely(container_depth >= YYJSON_READER_CONTAINER_RECURSION_LIMIT)) { goto fail_recursion; } /* save current container */ ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | (ctn->tag & YYJSON_TAG_MASK); /* create a new array value, save parent container offset */ val_incr(); val->tag = YYJSON_TYPE_ARR; val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); /* push the new array value as current container */ ctn = val; ctn_len = 0; arr_val_begin: if (*cur == '{') { cur++; goto obj_begin; } if (*cur == '[') { cur++; goto arr_begin; } if (char_is_number(*cur)) { val_incr(); ctn_len++; if (likely(read_number(&cur, val, &msg))) goto arr_val_end; goto fail_number; } if (*cur == '"') { val_incr(); ctn_len++; if (likely(read_string(&cur, end, val, &msg))) goto arr_val_end; goto fail_string; } if (*cur == 't') { val_incr(); ctn_len++; if (likely(read_true(&cur, val))) goto arr_val_end; goto fail_literal; } if (*cur == 'f') { val_incr(); ctn_len++; if (likely(read_false(&cur, val))) goto arr_val_end; goto fail_literal; } if (*cur == 'n') { val_incr(); ctn_len++; if (likely(read_null(&cur, val))) goto arr_val_end; goto fail_literal; } if (*cur == ']') { cur++; if (likely(ctn_len == 0)) goto arr_end; while (*cur != ',') cur--; goto fail_trailing_comma; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto arr_val_begin; } goto fail_character; arr_val_end: if (*cur == ',') { cur++; goto arr_val_begin; } if (*cur == ']') { cur++; goto arr_end; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto arr_val_end; } if (false) { if (skip_spaces_and_comments(&cur)) goto arr_val_end; if (byte_match_2(cur, "/*")) goto fail_comment; } goto fail_character; arr_end: container_depth--; /* get parent container */ ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); /* save the next sibling value offset */ ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; if (unlikely(ctn == ctn_parent)) goto doc_end; /* pop parent as current container */ ctn = ctn_parent; ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { goto obj_val_end; } else { goto arr_val_end; } obj_begin: container_depth++; if (unlikely(container_depth >= YYJSON_READER_CONTAINER_RECURSION_LIMIT)) { goto fail_recursion; } /* push container */ ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | (ctn->tag & YYJSON_TAG_MASK); val_incr(); val->tag = YYJSON_TYPE_OBJ; /* offset to the parent */ val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); ctn = val; ctn_len = 0; obj_key_begin: if (likely(*cur == '"')) { val_incr(); ctn_len++; if (likely(read_string(&cur, end, val, &msg))) goto obj_key_end; goto fail_string; } if (likely(*cur == '}')) { cur++; if (likely(ctn_len == 0)) goto obj_end; while (*cur != ',') cur--; goto fail_trailing_comma; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_key_begin; } if (false) { if (skip_spaces_and_comments(&cur)) goto obj_key_begin; if (byte_match_2(cur, "/*")) goto fail_comment; } goto fail_character; obj_key_end: if (*cur == ':') { cur++; goto obj_val_begin; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_key_end; } if (false) { if (skip_spaces_and_comments(&cur)) goto obj_key_end; if (byte_match_2(cur, "/*")) goto fail_comment; } goto fail_character; obj_val_begin: if (*cur == '"') { val++; ctn_len++; if (likely(read_string(&cur, end, val, &msg))) goto obj_val_end; goto fail_string; } if (char_is_number(*cur)) { val++; ctn_len++; if (likely(read_number(&cur, val, &msg))) goto obj_val_end; goto fail_number; } if (*cur == '{') { cur++; goto obj_begin; } if (*cur == '[') { cur++; goto arr_begin; } if (*cur == 't') { val++; ctn_len++; if (likely(read_true(&cur, val))) goto obj_val_end; goto fail_literal; } if (*cur == 'f') { val++; ctn_len++; if (likely(read_false(&cur, val))) goto obj_val_end; goto fail_literal; } if (*cur == 'n') { val++; ctn_len++; if (likely(read_null(&cur, val))) goto obj_val_end; goto fail_literal; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_val_begin; } goto fail_character; obj_val_end: if (likely(*cur == ',')) { cur++; goto obj_key_begin; } if (likely(*cur == '}')) { cur++; goto obj_end; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_val_end; } if (false) { if (skip_spaces_and_comments(&cur)) goto obj_val_end; if (byte_match_2(cur, "/*")) goto fail_comment; } goto fail_character; obj_end: container_depth--; /* pop container */ ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); /* point to the next value */ ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ; if (unlikely(ctn == ctn_parent)) goto doc_end; ctn = ctn_parent; ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { goto obj_val_end; } else { goto arr_val_end; } doc_end: /* check invalid contents after json document */ if (unlikely(cur < end) && !has_read_flag(STOP_WHEN_DONE)) { if (false) { skip_spaces_and_comments(&cur); if (byte_match_2(cur, "/*")) goto fail_comment; } else { while (char_is_space(*cur)) cur++; } if (unlikely(cur < end)) goto fail_garbage; } doc = (yyjson_doc *)val_hdr; doc->root = val_hdr + hdr_len; doc->alc = alc; doc->dat_read = (usize)(cur - hdr); doc->val_read = (usize)((val - doc->root) + 1); doc->str_pool = has_read_flag(INSITU) ? NULL : (char *)hdr; return doc; fail_string: return_err(cur, INVALID_STRING, msg); fail_number: return_err(cur, INVALID_NUMBER, msg); fail_alloc: return_err(cur, MEMORY_ALLOCATION, "memory allocation failed"); fail_trailing_comma: return_err(cur, JSON_STRUCTURE, "trailing comma is not allowed"); fail_literal: return_err(cur, LITERAL, "invalid literal"); fail_comment: return_err(cur, INVALID_COMMENT, "unclosed multiline comment"); fail_character: return_err(cur, UNEXPECTED_CHARACTER, "unexpected character"); fail_garbage: return_err(cur, UNEXPECTED_CONTENT, "unexpected content after document"); fail_recursion: return_err(cur, RECURSION_DEPTH, "array and object recursion depth exceeded"); #undef val_incr #undef return_err } /** Read JSON document (accept all style, but optimized for pretty). */ static_inline yyjson_doc *read_root_pretty(u8 *hdr, u8 *cur, u8 *end, yyjson_alc alc, yyjson_read_err *err) { #define return_err(_pos, _code, _msg) do { \ if (is_truncated_end(hdr, _pos, end, YYJSON_READ_ERROR_##_code)) { \ err->pos = (usize)(end - hdr); \ err->code = YYJSON_READ_ERROR_UNEXPECTED_END; \ err->msg = "unexpected end of data"; \ } else { \ err->pos = (usize)(_pos - hdr); \ err->code = YYJSON_READ_ERROR_##_code; \ err->msg = _msg; \ } \ if (val_hdr) alc.free(alc.ctx, (void *)val_hdr); \ return NULL; \ } while (false) #define val_incr() do { \ val++; \ if (unlikely(val >= val_end)) { \ usize alc_old = alc_len; \ alc_len += alc_len / 2; \ if ((sizeof(usize) < 8) && (alc_len >= alc_max)) goto fail_alloc; \ val_tmp = (yyjson_val *)alc.realloc(alc.ctx, (void *)val_hdr, \ alc_old * sizeof(yyjson_val), \ alc_len * sizeof(yyjson_val)); \ if ((!val_tmp)) goto fail_alloc; \ val = val_tmp + (usize)(val - val_hdr); \ ctn = val_tmp + (usize)(ctn - val_hdr); \ val_hdr = val_tmp; \ val_end = val_tmp + (alc_len - 2); \ } \ } while (false) usize dat_len; /* data length in bytes, hint for allocator */ usize hdr_len; /* value count used by yyjson_doc */ usize alc_len; /* value count allocated */ usize alc_max; /* maximum value count for allocator */ usize ctn_len; /* the number of elements in current container */ yyjson_val *val_hdr; /* the head of allocated values */ yyjson_val *val_end; /* the end of allocated values */ yyjson_val *val_tmp; /* temporary pointer for realloc */ yyjson_val *val; /* current JSON value */ yyjson_val *ctn; /* current container */ yyjson_val *ctn_parent; /* parent of current container */ yyjson_doc *doc; /* the JSON document, equals to val_hdr */ const char *msg; /* error message */ u32 container_depth = 0; /* limit on number of open array and map */ dat_len = has_read_flag(STOP_WHEN_DONE) ? 256 : (usize)(end - cur); hdr_len = sizeof(yyjson_doc) / sizeof(yyjson_val); hdr_len += (sizeof(yyjson_doc) % sizeof(yyjson_val)) > 0; alc_max = USIZE_MAX / sizeof(yyjson_val); alc_len = hdr_len + (dat_len / YYJSON_READER_ESTIMATED_PRETTY_RATIO) + 4; alc_len = yyjson_min(alc_len, alc_max); val_hdr = (yyjson_val *)alc.malloc(alc.ctx, alc_len * sizeof(yyjson_val)); if (unlikely(!val_hdr)) goto fail_alloc; val_end = val_hdr + (alc_len - 2); /* padding for key-value pair reading */ val = val_hdr + hdr_len; ctn = val; ctn_len = 0; if (*cur++ == '{') { ctn->tag = YYJSON_TYPE_OBJ; ctn->uni.ofs = 0; if (*cur == '\n') cur++; goto obj_key_begin; } else { ctn->tag = YYJSON_TYPE_ARR; ctn->uni.ofs = 0; if (*cur == '\n') cur++; goto arr_val_begin; } arr_begin: container_depth++; if (unlikely(container_depth >= YYJSON_READER_CONTAINER_RECURSION_LIMIT)) { goto fail_recursion; } /* save current container */ ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | (ctn->tag & YYJSON_TAG_MASK); /* create a new array value, save parent container offset */ val_incr(); val->tag = YYJSON_TYPE_ARR; val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); /* push the new array value as current container */ ctn = val; ctn_len = 0; if (*cur == '\n') cur++; arr_val_begin: #if YYJSON_IS_REAL_GCC while (true) repeat16({ if (byte_match_2(cur, " ")) cur += 2; else break; }) #else while (true) repeat16({ if (likely(byte_match_2(cur, " "))) cur += 2; else break; }) #endif if (*cur == '{') { cur++; goto obj_begin; } if (*cur == '[') { cur++; goto arr_begin; } if (char_is_number(*cur)) { val_incr(); ctn_len++; if (likely(read_number(&cur, val, &msg))) goto arr_val_end; goto fail_number; } if (*cur == '"') { val_incr(); ctn_len++; if (likely(read_string(&cur, end, val, &msg))) goto arr_val_end; goto fail_string; } if (*cur == 't') { val_incr(); ctn_len++; if (likely(read_true(&cur, val))) goto arr_val_end; goto fail_literal; } if (*cur == 'f') { val_incr(); ctn_len++; if (likely(read_false(&cur, val))) goto arr_val_end; goto fail_literal; } if (*cur == 'n') { val_incr(); ctn_len++; if (likely(read_null(&cur, val))) goto arr_val_end; if (false) { if (read_nan(false, &cur, 0, val)) goto arr_val_end; } goto fail_literal; } if (*cur == ']') { cur++; if (likely(ctn_len == 0)) goto arr_end; while (*cur != ',') cur--; goto fail_trailing_comma; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto arr_val_begin; } goto fail_character; arr_val_end: if (byte_match_2(cur, ",\n")) { cur += 2; goto arr_val_begin; } if (*cur == ',') { cur++; goto arr_val_begin; } if (*cur == ']') { cur++; goto arr_end; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto arr_val_end; } if (false) { if (skip_spaces_and_comments(&cur)) goto arr_val_end; if (byte_match_2(cur, "/*")) goto fail_comment; } goto fail_character; arr_end: container_depth--; /* get parent container */ ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); /* save the next sibling value offset */ ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); ctn->tag = ((ctn_len) << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; if (unlikely(ctn == ctn_parent)) goto doc_end; /* pop parent as current container */ ctn = ctn_parent; ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); if (*cur == '\n') cur++; if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { goto obj_val_end; } else { goto arr_val_end; } obj_begin: container_depth++; if (unlikely(container_depth >= YYJSON_READER_CONTAINER_RECURSION_LIMIT)) { goto fail_recursion; } /* push container */ ctn->tag = (((u64)ctn_len + 1) << YYJSON_TAG_BIT) | (ctn->tag & YYJSON_TAG_MASK); val_incr(); val->tag = YYJSON_TYPE_OBJ; /* offset to the parent */ val->uni.ofs = (usize)((u8 *)val - (u8 *)ctn); ctn = val; ctn_len = 0; if (*cur == '\n') cur++; obj_key_begin: #if YYJSON_IS_REAL_GCC while (true) repeat16({ if (byte_match_2(cur, " ")) cur += 2; else break; }) #else while (true) repeat16({ if (likely(byte_match_2(cur, " "))) cur += 2; else break; }) #endif if (likely(*cur == '"')) { val_incr(); ctn_len++; if (likely(read_string(&cur, end, val, &msg))) goto obj_key_end; goto fail_string; } if (likely(*cur == '}')) { cur++; if (likely(ctn_len == 0)) goto obj_end; while (*cur != ',') cur--; goto fail_trailing_comma; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_key_begin; } if (false) { if (skip_spaces_and_comments(&cur)) goto obj_key_begin; if (byte_match_2(cur, "/*")) goto fail_comment; } goto fail_character; obj_key_end: if (byte_match_2(cur, ": ")) { cur += 2; goto obj_val_begin; } if (*cur == ':') { cur++; goto obj_val_begin; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_key_end; } goto fail_character; obj_val_begin: if (*cur == '"') { val++; ctn_len++; if (likely(read_string(&cur, end, val, &msg))) goto obj_val_end; goto fail_string; } if (char_is_number(*cur)) { val++; ctn_len++; if (likely(read_number(&cur, val, &msg))) goto obj_val_end; goto fail_number; } if (*cur == '{') { cur++; goto obj_begin; } if (*cur == '[') { cur++; goto arr_begin; } if (*cur == 't') { val++; ctn_len++; if (likely(read_true(&cur, val))) goto obj_val_end; goto fail_literal; } if (*cur == 'f') { val++; ctn_len++; if (likely(read_false(&cur, val))) goto obj_val_end; goto fail_literal; } if (*cur == 'n') { val++; ctn_len++; if (likely(read_null(&cur, val))) goto obj_val_end; goto fail_literal; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_val_begin; } goto fail_character; obj_val_end: if (byte_match_2(cur, ",\n")) { cur += 2; goto obj_key_begin; } if (likely(*cur == ',')) { cur++; goto obj_key_begin; } if (likely(*cur == '}')) { cur++; goto obj_end; } if (char_is_space(*cur)) { while (char_is_space(*++cur)); goto obj_val_end; } goto fail_character; obj_end: container_depth--; /* pop container */ ctn_parent = (yyjson_val *)(void *)((u8 *)ctn - ctn->uni.ofs); /* point to the next value */ ctn->uni.ofs = (usize)((u8 *)val - (u8 *)ctn) + sizeof(yyjson_val); ctn->tag = (ctn_len << (YYJSON_TAG_BIT - 1)) | YYJSON_TYPE_OBJ; if (unlikely(ctn == ctn_parent)) goto doc_end; ctn = ctn_parent; ctn_len = (usize)(ctn->tag >> YYJSON_TAG_BIT); if (*cur == '\n') cur++; if ((ctn->tag & YYJSON_TYPE_MASK) == YYJSON_TYPE_OBJ) { goto obj_val_end; } else { goto arr_val_end; } doc_end: /* check invalid contents after json document */ if (unlikely(cur < end) && !has_read_flag(STOP_WHEN_DONE)) { if (false) { skip_spaces_and_comments(&cur); if (byte_match_2(cur, "/*")) goto fail_comment; } else { while (char_is_space(*cur)) cur++; } if (unlikely(cur < end)) goto fail_garbage; } doc = (yyjson_doc *)val_hdr; doc->root = val_hdr + hdr_len; doc->alc = alc; doc->dat_read = (usize)(cur - hdr); doc->val_read = (usize)((val - val_hdr)) - hdr_len + 1; doc->str_pool = has_read_flag(INSITU) ? NULL : (char *)hdr; return doc; fail_string: return_err(cur, INVALID_STRING, msg); fail_number: return_err(cur, INVALID_NUMBER, msg); fail_alloc: return_err(cur, MEMORY_ALLOCATION, "memory allocation failed"); fail_trailing_comma: return_err(cur, JSON_STRUCTURE, "trailing comma is not allowed"); fail_literal: return_err(cur, LITERAL, "invalid literal"); fail_comment: return_err(cur, INVALID_COMMENT, "unclosed multiline comment"); fail_character: return_err(cur, UNEXPECTED_CHARACTER, "unexpected character"); fail_garbage: return_err(cur, UNEXPECTED_CONTENT, "unexpected content after document"); fail_recursion: return_err(cur, RECURSION_DEPTH, "array and object recursion depth exceeded"); #undef val_incr #undef return_err } /*============================================================================== * JSON Reader Entrance *============================================================================*/ yyjson_doc *yyjson_read_opts(char *dat, usize len, const yyjson_alc *alc_ptr, yyjson_read_err *err) { #define return_err(_pos, _code, _msg) do { \ err->pos = (usize)(_pos); \ err->msg = _msg; \ err->code = YYJSON_READ_ERROR_##_code; \ if (!has_read_flag(INSITU) && hdr) alc.free(alc.ctx, (void *)hdr); \ return NULL; \ } while (false) yyjson_alc alc; yyjson_doc *doc; u8 *hdr = NULL, *end, *cur; if (!alc_ptr) { alc = YYJSON_DEFAULT_ALC; } else { alc = *alc_ptr; } hdr = (u8 *)alc.malloc(alc.ctx, len + YYJSON_PADDING_SIZE); end = hdr + len; cur = hdr; memcpy(hdr, dat, len); memset(end, 0, YYJSON_PADDING_SIZE); /* skip empty contents before json document */ if (unlikely(char_is_space_or_comment(*cur))) { if (likely(char_is_space(*cur))) { while (char_is_space(*++cur)); } if (unlikely(cur >= end)) { return_err(0, EMPTY_CONTENT, "input data is empty"); } } /* read json document */ if (likely(char_is_container(*cur))) { if (char_is_space(cur[1]) && char_is_space(cur[2])) { doc = read_root_pretty(hdr, cur, end, alc, err); } else { doc = read_root_minify(hdr, cur, end, alc, err); } } else { doc = read_root_single(hdr, cur, end, alc, err); } /* check result */ if (unlikely(!doc)) { alc.free(alc.ctx, (void *)hdr); } return doc; #undef return_err } yyjson_doc *yyjson_read_file(const char *path, yyjson_read_flag flg, const yyjson_alc *alc_ptr, yyjson_read_err *err) { #define return_err(_code, _msg) do { \ err->pos = 0; \ err->msg = _msg; \ err->code = YYJSON_READ_ERROR_##_code; \ return NULL; \ } while (false) yyjson_doc *doc; FILE *file; if (unlikely(!path)) return_err(INVALID_PARAMETER, "input path is NULL"); file = fopen_readonly(path); if (unlikely(!file)) return_err(FILE_OPEN, "file opening failed"); doc = yyjson_read_fp(file, flg, alc_ptr, err); fclose(file); return doc; #undef return_err } yyjson_doc *yyjson_read_fp(FILE *file, yyjson_read_flag flg, const yyjson_alc *alc_ptr, yyjson_read_err *err) { #define return_err(_code, _msg) do { \ err->pos = 0; \ err->msg = _msg; \ err->code = YYJSON_READ_ERROR_##_code; \ if (buf) alc.free(alc.ctx, buf); \ return NULL; \ } while (false) yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; yyjson_doc *doc; long file_size = 0, file_pos; void *buf = NULL; usize buf_size = 0; /* validate input parameters */ if (unlikely(!file)) return_err(INVALID_PARAMETER, "input file is NULL"); /* get current position */ file_pos = ftell(file); if (file_pos != -1) { /* get total file size, may fail */ if (fseek(file, 0, SEEK_END) == 0) file_size = ftell(file); /* reset to original position, may fail */ if (fseek(file, file_pos, SEEK_SET) != 0) file_size = 0; /* get file size from current postion to end */ if (file_size > 0) file_size -= file_pos; } /* read file */ if (file_size > 0) { /* read the entire file in one call */ buf_size = (usize)file_size + YYJSON_PADDING_SIZE; buf = alc.malloc(alc.ctx, buf_size); if (buf == NULL) { return_err(MEMORY_ALLOCATION, "fail to alloc memory"); } if (fread_safe(buf, (usize)file_size, file) != (usize)file_size) { return_err(FILE_READ, "file reading failed"); } } else { /* failed to get file size, read it as a stream */ usize chunk_min = (usize)64; usize chunk_max = (usize)512 * 1024 * 1024; usize chunk_now = chunk_min; usize read_size; void *tmp; buf_size = YYJSON_PADDING_SIZE; while (true) { if (buf_size + chunk_now < buf_size) { /* overflow */ return_err(MEMORY_ALLOCATION, "fail to alloc memory"); } buf_size += chunk_now; if (!buf) { buf = alc.malloc(alc.ctx, buf_size); if (!buf) return_err(MEMORY_ALLOCATION, "fail to alloc memory"); } else { tmp = alc.realloc(alc.ctx, buf, buf_size - chunk_now, buf_size); if (!tmp) return_err(MEMORY_ALLOCATION, "fail to alloc memory"); buf = tmp; } tmp = ((u8 *)buf) + buf_size - YYJSON_PADDING_SIZE - chunk_now; read_size = fread_safe(tmp, chunk_now, file); file_size += (long)read_size; if (read_size != chunk_now) break; chunk_now *= 2; if (chunk_now > chunk_max) chunk_now = chunk_max; } } /* read JSON */ memset((u8 *)buf + file_size, 0, YYJSON_PADDING_SIZE); flg |= YYJSON_READ_INSITU; doc = yyjson_read_opts((char *)buf, (usize)file_size, &alc, err); if (doc) { doc->str_pool = (char *)buf; return doc; } else { alc.free(alc.ctx, buf); return NULL; } #undef return_err } const char *yyjson_read_number(const char *dat, yyjson_val *val, yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err) { #define return_err(_pos, _code, _msg) do { \ err->pos = _pos > hdr ? (usize)(_pos - hdr) : 0; \ err->msg = _msg; \ err->code = YYJSON_READ_ERROR_##_code; \ return NULL; \ } while (false) u8 *hdr = constcast(u8 *)dat, *cur = hdr; bool raw; /* read number as raw */ u8 *raw_end; /* raw end for null-terminator */ u8 **pre; /* previous raw end pointer */ const char *msg; #if !YYJSON_HAS_IEEE_754 || YYJSON_DISABLE_FAST_FP_CONV u8 buf[128]; usize dat_len; #endif if (unlikely(!dat)) { return_err(cur, INVALID_PARAMETER, "input data is NULL"); } if (unlikely(!val)) { return_err(cur, INVALID_PARAMETER, "output value is NULL"); } #if !YYJSON_HAS_IEEE_754 || YYJSON_DISABLE_FAST_FP_CONV if (!alc) alc = &YYJSON_DEFAULT_ALC; dat_len = strlen(dat); if (dat_len < sizeof(buf)) { memcpy(buf, dat, dat_len + 1); hdr = buf; cur = hdr; } else { hdr = (u8 *)alc->malloc(alc->ctx, dat_len + 1); cur = hdr; if (unlikely(!hdr)) { return_err(cur, MEMORY_ALLOCATION, "memory allocation failed"); } memcpy(hdr, dat, dat_len + 1); } hdr[dat_len] = 0; #endif #if !YYJSON_HAS_IEEE_754 || YYJSON_DISABLE_FAST_FP_CONV if (!read_number(&cur, val, &msg)) { if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr); return_err(cur, INVALID_NUMBER, msg); } if (dat_len >= sizeof(buf)) alc->free(alc->ctx, hdr); if (yyjson_is_raw(val)) val->uni.str = dat; return dat + (cur - hdr); #else if (!read_number(&cur, val, &msg)) { return_err(cur, INVALID_NUMBER, msg); } return (const char *)cur; #endif #undef return_err } #endif /* YYJSON_DISABLE_READER */ #if !YYJSON_DISABLE_WRITER /*============================================================================== * Integer Writer * * The maximum value of uint32_t is 4294967295 (10 digits), * these digits are named as 'aabbccddee' here. * * Although most compilers may convert the "division by constant value" into * "multiply and shift", manual conversion can still help some compilers * generate fewer and better instructions. * * Reference: * Division by Invariant Integers using Multiplication, 1994. * https://gmplib.org/~tege/divcnst-pldi94.pdf * Improved division by invariant integers, 2011. * https://gmplib.org/~tege/division-paper.pdf *============================================================================*/ /** Digit table from 00 to 99. */ yyjson_align(2) static const char digit_table[200] = { '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9' }; static_inline u8 *write_u32_len_8(u32 val, u8 *buf) { u32 aa, bb, cc, dd, aabb, ccdd; /* 8 digits: aabbccdd */ aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ ccdd = val - aabb * 10000; /* (val % 10000) */ aa = (aabb * 5243) >> 19; /* (aabb / 100) */ cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ bb = aabb - aa * 100; /* (aabb % 100) */ dd = ccdd - cc * 100; /* (ccdd % 100) */ byte_copy_2(buf + 0, digit_table + aa * 2); byte_copy_2(buf + 2, digit_table + bb * 2); byte_copy_2(buf + 4, digit_table + cc * 2); byte_copy_2(buf + 6, digit_table + dd * 2); return buf + 8; } static_inline u8 *write_u32_len_4(u32 val, u8 *buf) { u32 aa, bb; /* 4 digits: aabb */ aa = (val * 5243) >> 19; /* (val / 100) */ bb = val - aa * 100; /* (val % 100) */ byte_copy_2(buf + 0, digit_table + aa * 2); byte_copy_2(buf + 2, digit_table + bb * 2); return buf + 4; } static_inline u8 *write_u32_len_1_8(u32 val, u8 *buf) { u32 aa, bb, cc, dd, aabb, bbcc, ccdd, lz; if (val < 100) { /* 1-2 digits: aa */ lz = val < 10; /* leading zero: 0 or 1 */ byte_copy_2(buf + 0, digit_table + val * 2 + lz); buf -= lz; return buf + 2; } else if (val < 10000) { /* 3-4 digits: aabb */ aa = (val * 5243) >> 19; /* (val / 100) */ bb = val - aa * 100; /* (val % 100) */ lz = aa < 10; /* leading zero: 0 or 1 */ byte_copy_2(buf + 0, digit_table + aa * 2 + lz); buf -= lz; byte_copy_2(buf + 2, digit_table + bb * 2); return buf + 4; } else if (val < 1000000) { /* 5-6 digits: aabbcc */ aa = (u32)(((u64)val * 429497) >> 32); /* (val / 10000) */ bbcc = val - aa * 10000; /* (val % 10000) */ bb = (bbcc * 5243) >> 19; /* (bbcc / 100) */ cc = bbcc - bb * 100; /* (bbcc % 100) */ lz = aa < 10; /* leading zero: 0 or 1 */ byte_copy_2(buf + 0, digit_table + aa * 2 + lz); buf -= lz; byte_copy_2(buf + 2, digit_table + bb * 2); byte_copy_2(buf + 4, digit_table + cc * 2); return buf + 6; } else { /* 7-8 digits: aabbccdd */ aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ ccdd = val - aabb * 10000; /* (val % 10000) */ aa = (aabb * 5243) >> 19; /* (aabb / 100) */ cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ bb = aabb - aa * 100; /* (aabb % 100) */ dd = ccdd - cc * 100; /* (ccdd % 100) */ lz = aa < 10; /* leading zero: 0 or 1 */ byte_copy_2(buf + 0, digit_table + aa * 2 + lz); buf -= lz; byte_copy_2(buf + 2, digit_table + bb * 2); byte_copy_2(buf + 4, digit_table + cc * 2); byte_copy_2(buf + 6, digit_table + dd * 2); return buf + 8; } } static_inline u8 *write_u64_len_5_8(u32 val, u8 *buf) { u32 aa, bb, cc, dd, aabb, bbcc, ccdd, lz; if (val < 1000000) { /* 5-6 digits: aabbcc */ aa = (u32)(((u64)val * 429497) >> 32); /* (val / 10000) */ bbcc = val - aa * 10000; /* (val % 10000) */ bb = (bbcc * 5243) >> 19; /* (bbcc / 100) */ cc = bbcc - bb * 100; /* (bbcc % 100) */ lz = aa < 10; /* leading zero: 0 or 1 */ byte_copy_2(buf + 0, digit_table + aa * 2 + lz); buf -= lz; byte_copy_2(buf + 2, digit_table + bb * 2); byte_copy_2(buf + 4, digit_table + cc * 2); return buf + 6; } else { /* 7-8 digits: aabbccdd */ aabb = (u32)(((u64)val * 109951163) >> 40); /* (val / 10000) */ ccdd = val - aabb * 10000; /* (val % 10000) */ aa = (aabb * 5243) >> 19; /* (aabb / 100) */ cc = (ccdd * 5243) >> 19; /* (ccdd / 100) */ bb = aabb - aa * 100; /* (aabb % 100) */ dd = ccdd - cc * 100; /* (ccdd % 100) */ lz = aa < 10; /* leading zero: 0 or 1 */ byte_copy_2(buf + 0, digit_table + aa * 2 + lz); buf -= lz; byte_copy_2(buf + 2, digit_table + bb * 2); byte_copy_2(buf + 4, digit_table + cc * 2); byte_copy_2(buf + 6, digit_table + dd * 2); return buf + 8; } } static_inline u8 *write_u64(u64 val, u8 *buf) { u64 tmp, hgh; u32 mid, low; if (val < 100000000) { /* 1-8 digits */ buf = write_u32_len_1_8((u32)val, buf); return buf; } else if (val < (u64)100000000 * 100000000) { /* 9-16 digits */ hgh = val / 100000000; /* (val / 100000000) */ low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ buf = write_u32_len_1_8((u32)hgh, buf); buf = write_u32_len_8(low, buf); return buf; } else { /* 17-20 digits */ tmp = val / 100000000; /* (val / 100000000) */ low = (u32)(val - tmp * 100000000); /* (val % 100000000) */ hgh = (u32)(tmp / 10000); /* (tmp / 10000) */ mid = (u32)(tmp - hgh * 10000); /* (tmp % 10000) */ buf = write_u64_len_5_8((u32)hgh, buf); buf = write_u32_len_4(mid, buf); buf = write_u32_len_8(low, buf); return buf; } } /*============================================================================== * Number Writer *============================================================================*/ #if YYJSON_HAS_IEEE_754 && !YYJSON_DISABLE_FAST_FP_CONV /* FP_WRITER */ /** Trailing zero count table for number 0 to 99. (generate with misc/make_tables.c) */ static const u8 dec_trailing_zero_table[] = { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /** Write an unsigned integer with a length of 1 to 16. */ static_inline u8 *write_u64_len_1_to_16(u64 val, u8 *buf) { u64 hgh; u32 low; if (val < 100000000) { /* 1-8 digits */ buf = write_u32_len_1_8((u32)val, buf); return buf; } else { /* 9-16 digits */ hgh = val / 100000000; /* (val / 100000000) */ low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ buf = write_u32_len_1_8((u32)hgh, buf); buf = write_u32_len_8(low, buf); return buf; } } /** Write an unsigned integer with a length of 1 to 17. */ static_inline u8 *write_u64_len_1_to_17(u64 val, u8 *buf) { u64 hgh; u32 mid, low, one; if (val >= (u64)100000000 * 10000000) { /* len: 16 to 17 */ hgh = val / 100000000; /* (val / 100000000) */ low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ one = (u32)(hgh / 100000000); /* (hgh / 100000000) */ mid = (u32)(hgh - (u64)one * 100000000); /* (hgh % 100000000) */ *buf = (u8)((u8)one + (u8)'0'); buf += one > 0; buf = write_u32_len_8(mid, buf); buf = write_u32_len_8(low, buf); return buf; } else if (val >= (u64)100000000){ /* len: 9 to 15 */ hgh = val / 100000000; /* (val / 100000000) */ low = (u32)(val - hgh * 100000000); /* (val % 100000000) */ buf = write_u32_len_1_8((u32)hgh, buf); buf = write_u32_len_8(low, buf); return buf; } else { /* len: 1 to 8 */ buf = write_u32_len_1_8((u32)val, buf); return buf; } } /** Write an unsigned integer with a length of 15 to 17 with trailing zero trimmed. These digits are named as "aabbccddeeffgghhii" here. For example, input 1234567890123000, output "1234567890123". */ static_inline u8 *write_u64_len_15_to_17_trim(u8 *buf, u64 sig) { bool lz; /* leading zero */ u32 tz1, tz2, tz; /* trailing zero */ u32 abbccddee = (u32)(sig / 100000000); u32 ffgghhii = (u32)(sig - (u64)abbccddee * 100000000); u32 abbcc = abbccddee / 10000; /* (abbccddee / 10000) */ u32 ddee = abbccddee - abbcc * 10000; /* (abbccddee % 10000) */ u32 abb = (u32)(((u64)abbcc * 167773) >> 24); /* (abbcc / 100) */ u32 a = (abb * 41) >> 12; /* (abb / 100) */ u32 bb = abb - a * 100; /* (abb % 100) */ u32 cc = abbcc - abb * 100; /* (abbcc % 100) */ /* write abbcc */ buf[0] = (u8)(a + '0'); buf += a > 0; lz = bb < 10 && a == 0; byte_copy_2(buf + 0, digit_table + bb * 2 + lz); buf -= lz; byte_copy_2(buf + 2, digit_table + cc * 2); if (ffgghhii) { u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */ u32 ee = ddee - dd * 100; /* (ddee % 100) */ u32 ffgg = (u32)(((u64)ffgghhii * 109951163) >> 40); /* (val / 10000) */ u32 hhii = ffgghhii - ffgg * 10000; /* (val % 10000) */ u32 ff = (ffgg * 5243) >> 19; /* (aabb / 100) */ u32 gg = ffgg - ff * 100; /* (aabb % 100) */ byte_copy_2(buf + 4, digit_table + dd * 2); byte_copy_2(buf + 6, digit_table + ee * 2); byte_copy_2(buf + 8, digit_table + ff * 2); byte_copy_2(buf + 10, digit_table + gg * 2); if (hhii) { u32 hh = (hhii * 5243) >> 19; /* (ccdd / 100) */ u32 ii = hhii - hh * 100; /* (ccdd % 100) */ byte_copy_2(buf + 12, digit_table + hh * 2); byte_copy_2(buf + 14, digit_table + ii * 2); tz1 = dec_trailing_zero_table[hh]; tz2 = dec_trailing_zero_table[ii]; tz = ii ? tz2 : (tz1 + 2); buf += 16 - tz; return buf; } else { tz1 = dec_trailing_zero_table[ff]; tz2 = dec_trailing_zero_table[gg]; tz = gg ? tz2 : (tz1 + 2); buf += 12 - tz; return buf; } } else { if (ddee) { u32 dd = (ddee * 5243) >> 19; /* (ddee / 100) */ u32 ee = ddee - dd * 100; /* (ddee % 100) */ byte_copy_2(buf + 4, digit_table + dd * 2); byte_copy_2(buf + 6, digit_table + ee * 2); tz1 = dec_trailing_zero_table[dd]; tz2 = dec_trailing_zero_table[ee]; tz = ee ? tz2 : (tz1 + 2); buf += 8 - tz; return buf; } else { tz1 = dec_trailing_zero_table[bb]; tz2 = dec_trailing_zero_table[cc]; tz = cc ? tz2 : (tz1 + tz2); buf += 4 - tz; return buf; } } } /** Write a signed integer in the range -324 to 308. */ static_inline u8 *write_f64_exp(i32 exp, u8 *buf) { buf[0] = '-'; buf += exp < 0; exp = exp < 0 ? -exp : exp; if (exp < 100) { u32 lz = exp < 10; byte_copy_2(buf + 0, digit_table + (u32)exp * 2 + lz); return buf + 2 - lz; } else { u32 hi = ((u32)exp * 656) >> 16; /* exp / 100 */ u32 lo = (u32)exp - hi * 100; /* exp % 100 */ buf[0] = (u8)((u8)hi + (u8)'0'); byte_copy_2(buf + 1, digit_table + lo * 2); return buf + 3; } } /** Multiplies 128-bit integer and returns highest 64-bit rounded value. */ static_inline u64 round_to_odd(u64 hi, u64 lo, u64 cp) { u64 x_hi, x_lo, y_hi, y_lo; u128_mul(cp, lo, &x_hi, &x_lo); u128_mul_add(cp, hi, x_hi, &y_hi, &y_lo); return y_hi | (y_lo > 1); } /** Convert double number from binary to decimal. The output significand is shortest decimal but may have trailing zeros. This function use the Schubfach algorithm: Raffaello Giulietti, The Schubfach way to render doubles (5th version), 2022. https://drive.google.com/file/d/1gp5xv4CAa78SVgCeWfGqqI4FfYYYuNFb https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-November/083536.html https://github.com/openjdk/jdk/pull/3402 (Java implementation) https://github.com/abolz/Drachennest (C++ implementation) See also: Dragonbox: A New Floating-Point Binary-to-Decimal Conversion Algorithm, 2022. https://github.com/jk-jeon/dragonbox/blob/master/other_files/Dragonbox.pdf https://github.com/jk-jeon/dragonbox @param sig_raw The raw value of significand in IEEE 754 format. @param exp_raw The raw value of exponent in IEEE 754 format. @param sig_bin The decoded value of significand in binary. @param exp_bin The decoded value of exponent in binary. @param sig_dec The output value of significand in decimal. @param exp_dec The output value of exponent in decimal. @warning The input double number should not be 0, inf, nan. */ static_inline void f64_bin_to_dec(u64 sig_raw, u32 exp_raw, u64 sig_bin, i32 exp_bin, u64 *sig_dec, i32 *exp_dec) { bool is_even, regular_spacing, u_inside, w_inside, round_up; u64 s, sp, cb, cbl, cbr, vb, vbl, vbr, pow10hi, pow10lo, upper, lower, mid; i32 k, h, exp10; is_even = !(sig_bin & 1); regular_spacing = (sig_raw == 0 && exp_raw > 1); cbl = 4 * sig_bin - 2 + regular_spacing; cb = 4 * sig_bin; cbr = 4 * sig_bin + 2; /* exp_bin: [-1074, 971] */ /* k = regular_spacing ? floor(log10(pow(2, exp_bin))) */ /* : floor(log10(pow(2, exp_bin) * 3.0 / 4.0)) */ /* = regular_spacing ? floor(exp_bin * log10(2)) */ /* : floor(exp_bin * log10(2) + log10(3.0 / 4.0)) */ k = (i32)(exp_bin * 315653 - (regular_spacing ? 131237 : 0)) >> 20; /* k: [-324, 292] */ /* h = exp_bin + floor(log2(pow(10, e))) */ /* = exp_bin + floor(log2(10) * e) */ exp10 = -k; h = exp_bin + ((exp10 * 217707) >> 16) + 1; pow10_table_get_sig(exp10, &pow10hi, &pow10lo); pow10lo += (exp10 < POW10_SIG_TABLE_MIN_EXACT_EXP || exp10 > POW10_SIG_TABLE_MAX_EXACT_EXP); vbl = round_to_odd(pow10hi, pow10lo, cbl << h); vb = round_to_odd(pow10hi, pow10lo, cb << h); vbr = round_to_odd(pow10hi, pow10lo, cbr << h); lower = vbl + !is_even; upper = vbr - !is_even; s = vb / 4; if (s >= 10) { sp = s / 10; u_inside = (lower <= 40 * sp); w_inside = (upper >= 40 * sp + 40); if (u_inside != w_inside) { *sig_dec = sp + w_inside; *exp_dec = k + 1; return; } } u_inside = (lower <= 4 * s); w_inside = (upper >= 4 * s + 4); mid = 4 * s + 2; round_up = (vb > mid) || (vb == mid && (s & 1) != 0); *sig_dec = s + ((u_inside != w_inside) ? w_inside : round_up); *exp_dec = k; } /** Write a double number (requires 32 bytes buffer). We follows the ECMAScript specification to print floating point numbers, but with the following changes: 1. Keep the negative sign of 0.0 to preserve input information. 2. Keep decimal point to indicate the number is floating point. 3. Remove positive sign of exponent part. */ static_inline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) { u64 sig_bin, sig_dec, sig_raw; i32 exp_bin, exp_dec, sig_len, dot_pos, i, max; u32 exp_raw, hi, lo; u8 *hdr, *num_hdr, *num_end, *dot_end; bool sign; /* decode raw bytes from IEEE-754 double format. */ sign = (bool)(raw >> (F64_BITS - 1)); sig_raw = raw & F64_SIG_MASK; exp_raw = (u32)((raw & F64_EXP_MASK) >> F64_SIG_BITS); /* return inf and nan */ if (unlikely(exp_raw == ((u32)1 << F64_EXP_BITS) - 1)) { if (has_write_flag(INF_AND_NAN_AS_NULL)) { byte_copy_4(buf, "null"); return buf + 4; } else if (has_write_flag(ALLOW_INF_AND_NAN)) { if (sig_raw == 0) { buf[0] = '-'; buf += sign; byte_copy_8(buf, "Infinity"); buf += 8; return buf; } else { byte_copy_4(buf, "NaN"); return buf + 3; } } return NULL; } /* add sign for all finite double value, including 0.0 and inf */ buf[0] = '-'; buf += sign; hdr = buf; /* return zero */ if ((raw << 1) == 0) { byte_copy_4(buf, "0.0"); buf += 3; return buf; } if (likely(exp_raw != 0)) { /* normal number */ sig_bin = sig_raw | ((u64)1 << F64_SIG_BITS); exp_bin = (i32)exp_raw - F64_EXP_BIAS - F64_SIG_BITS; /* fast path for small integer number without fraction */ if (-F64_SIG_BITS <= exp_bin && exp_bin <= 0) { if (u64_tz_bits(sig_bin) >= (u32)-exp_bin) { /* number is integer in range 1 to 0x1FFFFFFFFFFFFF */ sig_dec = sig_bin >> -exp_bin; buf = write_u64_len_1_to_16(sig_dec, buf); byte_copy_2(buf, ".0"); buf += 2; return buf; } } /* binary to decimal */ f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); /* the sig length is 15 to 17 */ sig_len = 17; sig_len -= (sig_dec < (u64)100000000 * 100000000); sig_len -= (sig_dec < (u64)100000000 * 10000000); /* the decimal point position relative to the first digit */ dot_pos = sig_len + exp_dec; if (-6 < dot_pos && dot_pos <= 21) { /* no need to write exponent part */ if (dot_pos <= 0) { /* dot before first digit */ /* such as 0.1234, 0.000001234 */ num_hdr = hdr + (2 - dot_pos); num_end = write_u64_len_15_to_17_trim(num_hdr, sig_dec); hdr[0] = '0'; hdr[1] = '.'; hdr += 2; max = -dot_pos; for (i = 0; i < max; i++) hdr[i] = '0'; return num_end; } else { /* dot after first digit */ /* such as 1.234, 1234.0, 123400000000000000000.0 */ memset(hdr + 0, '0', 8); memset(hdr + 8, '0', 8); memset(hdr + 16, '0', 8); num_hdr = hdr + 1; num_end = write_u64_len_15_to_17_trim(num_hdr, sig_dec); for (i = 0; i < dot_pos; i++) hdr[i] = hdr[i + 1]; hdr[dot_pos] = '.'; dot_end = hdr + dot_pos + 2; return dot_end < num_end ? num_end : dot_end; } } else { /* write with scientific notation */ /* such as 1.234e56 */ u8 *end = write_u64_len_15_to_17_trim(buf + 1, sig_dec); end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e34 */ exp_dec += sig_len - 1; hdr[0] = hdr[1]; hdr[1] = '.'; end[0] = 'e'; buf = write_f64_exp(exp_dec, end + 1); return buf; } } else { /* subnormal number */ sig_bin = sig_raw; exp_bin = 1 - F64_EXP_BIAS - F64_SIG_BITS; /* binary to decimal */ f64_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec); /* write significand part */ buf = write_u64_len_1_to_17(sig_dec, buf + 1); hdr[0] = hdr[1]; hdr[1] = '.'; do { buf--; exp_dec++; } while (*buf == '0'); exp_dec += (i32)(buf - hdr - 2); buf += (*buf != '.'); buf[0] = 'e'; buf++; /* write exponent part */ buf[0] = '-'; buf++; exp_dec = -exp_dec; hi = ((u32)exp_dec * 656) >> 16; /* exp / 100 */ lo = (u32)exp_dec - hi * 100; /* exp % 100 */ buf[0] = (u8)((u8)hi + (u8)'0'); byte_copy_2(buf + 1, digit_table + lo * 2); buf += 3; return buf; } } #else /* FP_WRITER */ /** Write a double number (requires 32 bytes buffer). */ static_inline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) { /* For IEEE 754, `DBL_DECIMAL_DIG` is 17 for round-trip. For non-IEEE formats, 17 is used to avoid buffer overflow, round-trip is not guaranteed. */ #if defined(DBL_DECIMAL_DIG) && DBL_DECIMAL_DIG != 17 int dig = DBL_DECIMAL_DIG > 17 ? 17 : DBL_DECIMAL_DIG; #else int dig = 17; #endif /* The snprintf() function is locale-dependent. For currently known locales, (en, zh, ja, ko, am, he, hi) use '.' as the decimal point, while other locales use ',' as the decimal point. we need to replace ',' with '.' to avoid the locale setting. */ f64 val = f64_from_raw(raw); #if YYJSON_MSC_VER >= 1400 int len = sprintf_s((char *)buf, 32, "%.*g", dig, val); #elif defined(snprintf) || (YYJSON_STDC_VER >= 199901L) int len = snprintf((char *)buf, 32, "%.*g", dig, val); #else int len = sprintf((char *)buf, "%.*g", dig, val); #endif u8 *cur = buf; if (unlikely(len < 1)) return NULL; cur += (*cur == '-'); if (unlikely(!digi_is_digit(*cur))) { /* nan, inf, or bad output */ if (has_write_flag(INF_AND_NAN_AS_NULL)) { byte_copy_4(buf, "null"); return buf + 4; } else if (has_write_flag(ALLOW_INF_AND_NAN)) { if (*cur == 'i') { byte_copy_8(cur, "Infinity"); cur += 8; return cur; } else if (*cur == 'n') { byte_copy_4(buf, "NaN"); return buf + 3; } } return NULL; } else { /* finite number */ int i = 0; bool fp = false; for (; i < len; i++) { if (buf[i] == ',') buf[i] = '.'; if (digi_is_fp((u8)buf[i])) fp = true; } if (!fp) { buf[len++] = '.'; buf[len++] = '0'; } } return buf + len; } #endif /* FP_WRITER */ /** Write a JSON number (requires 32 bytes buffer). */ static_inline u8 *write_number(u8 *cur, yyjson_val *val, yyjson_write_flag flg) { if (val->tag & YYJSON_SUBTYPE_REAL) { u64 raw = val->uni.u64; return write_f64_raw(cur, raw, flg); } else { u64 pos = val->uni.u64; u64 neg = ~pos + 1; usize sgn = ((val->tag & YYJSON_SUBTYPE_SINT) > 0) & ((i64)pos < 0); *cur = '-'; return write_u64(sgn ? neg : pos, cur + sgn); } } /*============================================================================== * String Writer *============================================================================*/ /** Character encode type, if (type > CHAR_ENC_ERR_1) bytes = type / 2; */ typedef u8 char_enc_type; #define CHAR_ENC_CPY_1 0 /* 1-byte UTF-8, copy. */ #define CHAR_ENC_ERR_1 1 /* 1-byte UTF-8, error. */ #define CHAR_ENC_ESC_A 2 /* 1-byte ASCII, escaped as '\x'. */ #define CHAR_ENC_ESC_1 3 /* 1-byte UTF-8, escaped as '\uXXXX'. */ #define CHAR_ENC_CPY_2 4 /* 2-byte UTF-8, copy. */ #define CHAR_ENC_ESC_2 5 /* 2-byte UTF-8, escaped as '\uXXXX'. */ #define CHAR_ENC_CPY_3 6 /* 3-byte UTF-8, copy. */ #define CHAR_ENC_ESC_3 7 /* 3-byte UTF-8, escaped as '\uXXXX'. */ #define CHAR_ENC_CPY_4 8 /* 4-byte UTF-8, copy. */ #define CHAR_ENC_ESC_4 9 /* 4-byte UTF-8, escaped as '\uXXXX\uXXXX'. */ /** Character encode type table: don't escape unicode, don't escape '/'. (generate with misc/make_tables.c) */ static const char_enc_type enc_table_cpy[256] = { 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1 }; /** Character encode type table: escape unicode, escape '/'. (generate with misc/make_tables.c) */ static const char_enc_type enc_table_esc_slash[256] = { 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1 }; /** Escaped hex character table: ["00" "01" "02" ... "FD" "FE" "FF"]. (generate with misc/make_tables.c) */ yyjson_align(2) static const u8 esc_hex_char_table[512] = { '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '0', 'A', '0', 'B', '0', 'C', '0', 'D', '0', 'E', '0', 'F', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '1', 'A', '1', 'B', '1', 'C', '1', 'D', '1', 'E', '1', 'F', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', '2', 'A', '2', 'B', '2', 'C', '2', 'D', '2', 'E', '2', 'F', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', '3', 'A', '3', 'B', '3', 'C', '3', 'D', '3', 'E', '3', 'F', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '4', 'A', '4', 'B', '4', 'C', '4', 'D', '4', 'E', '4', 'F', '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', '5', 'A', '5', 'B', '5', 'C', '5', 'D', '5', 'E', '5', 'F', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', '6', 'A', '6', 'B', '6', 'C', '6', 'D', '6', 'E', '6', 'F', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '7', 'A', '7', 'B', '7', 'C', '7', 'D', '7', 'E', '7', 'F', '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', '8', 'A', '8', 'B', '8', 'C', '8', 'D', '8', 'E', '8', 'F', '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9', '9', 'A', '9', 'B', '9', 'C', '9', 'D', '9', 'E', '9', 'F', 'A', '0', 'A', '1', 'A', '2', 'A', '3', 'A', '4', 'A', '5', 'A', '6', 'A', '7', 'A', '8', 'A', '9', 'A', 'A', 'A', 'B', 'A', 'C', 'A', 'D', 'A', 'E', 'A', 'F', 'B', '0', 'B', '1', 'B', '2', 'B', '3', 'B', '4', 'B', '5', 'B', '6', 'B', '7', 'B', '8', 'B', '9', 'B', 'A', 'B', 'B', 'B', 'C', 'B', 'D', 'B', 'E', 'B', 'F', 'C', '0', 'C', '1', 'C', '2', 'C', '3', 'C', '4', 'C', '5', 'C', '6', 'C', '7', 'C', '8', 'C', '9', 'C', 'A', 'C', 'B', 'C', 'C', 'C', 'D', 'C', 'E', 'C', 'F', 'D', '0', 'D', '1', 'D', '2', 'D', '3', 'D', '4', 'D', '5', 'D', '6', 'D', '7', 'D', '8', 'D', '9', 'D', 'A', 'D', 'B', 'D', 'C', 'D', 'D', 'D', 'E', 'D', 'F', 'E', '0', 'E', '1', 'E', '2', 'E', '3', 'E', '4', 'E', '5', 'E', '6', 'E', '7', 'E', '8', 'E', '9', 'E', 'A', 'E', 'B', 'E', 'C', 'E', 'D', 'E', 'E', 'E', 'F', 'F', '0', 'F', '1', 'F', '2', 'F', '3', 'F', '4', 'F', '5', 'F', '6', 'F', '7', 'F', '8', 'F', '9', 'F', 'A', 'F', 'B', 'F', 'C', 'F', 'D', 'F', 'E', 'F', 'F' }; /** Escaped single character table. (generate with misc/make_tables.c) */ yyjson_align(2) static const u8 esc_single_char_table[512] = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\', 'b', '\\', 't', '\\', 'n', ' ', ' ', '\\', 'f', '\\', 'r', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\', '"', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\', '/', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\', '\\', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }; /** Returns the encode table with options. */ static_inline const char_enc_type *get_enc_table_with_flag( yyjson_read_flag flg) { if (has_write_flag(ESCAPE_UNICODE)) { if (has_write_flag(ESCAPE_SLASHES)) { return enc_table_esc_slash; } else { return enc_table_esc; } } else { if (has_write_flag(ESCAPE_SLASHES)) { return enc_table_cpy_slash; } else { return enc_table_cpy; } } } /** Write raw string. */ static_inline u8 *write_raw(u8 *cur, const u8 *raw, usize raw_len) { memcpy(cur, raw, raw_len); return cur + raw_len; } /** Write string no-escape. @param cur Buffer cursor. @param str A UTF-8 string, null-terminator is not required. @param str_len Length of string in bytes. @return The buffer cursor after string. */ static_inline u8 *write_string_noesc(u8 *cur, const u8 *str, usize str_len) { *cur++ = '"'; while (str_len >= 16) { byte_copy_16(cur, str); cur += 16; str += 16; str_len -= 16; } while (str_len >= 4) { byte_copy_4(cur, str); cur += 4; str += 4; str_len -= 4; } while (str_len) { *cur++ = *str++; str_len -= 1; } *cur++ = '"'; return cur; } /** Write UTF-8 string (requires len * 6 + 2 bytes buffer). @param cur Buffer cursor. @param esc Escape unicode. @param inv Allow invalid unicode. @param str A UTF-8 string, null-terminator is not required. @param str_len Length of string in bytes. @param enc_table Encode type table for character. @return The buffer cursor after string, or NULL on invalid unicode. */ static_inline u8 *write_string(u8 *cur, bool esc, bool inv, const u8 *str, usize str_len, const char_enc_type *enc_table) { /* UTF-8 character mask and pattern, see `read_string()` for details. */ #if YYJSON_ENDIAN == YYJSON_BIG_ENDIAN const u16 b2_mask = 0xE0C0UL; const u16 b2_patt = 0xC080UL; const u16 b2_requ = 0x1E00UL; const u32 b3_mask = 0xF0C0C000UL; const u32 b3_patt = 0xE0808000UL; const u32 b3_requ = 0x0F200000UL; const u32 b3_erro = 0x0D200000UL; const u32 b4_mask = 0xF8C0C0C0UL; const u32 b4_patt = 0xF0808080UL; const u32 b4_requ = 0x07300000UL; const u32 b4_err0 = 0x04000000UL; const u32 b4_err1 = 0x03300000UL; #elif YYJSON_ENDIAN == YYJSON_LITTLE_ENDIAN const u16 b2_mask = 0xC0E0UL; const u16 b2_patt = 0x80C0UL; const u16 b2_requ = 0x001EUL; const u32 b3_mask = 0x00C0C0F0UL; const u32 b3_patt = 0x008080E0UL; const u32 b3_requ = 0x0000200FUL; const u32 b3_erro = 0x0000200DUL; const u32 b4_mask = 0xC0C0C0F8UL; const u32 b4_patt = 0x808080F0UL; const u32 b4_requ = 0x00003007UL; const u32 b4_err0 = 0x00000004UL; const u32 b4_err1 = 0x00003003UL; #else /* this should be evaluated at compile-time */ v16_uni b2_mask_uni = {{ 0xE0, 0xC0 }}; v16_uni b2_patt_uni = {{ 0xC0, 0x80 }}; v16_uni b2_requ_uni = {{ 0x1E, 0x00 }}; v32_uni b3_mask_uni = {{ 0xF0, 0xC0, 0xC0, 0x00 }}; v32_uni b3_patt_uni = {{ 0xE0, 0x80, 0x80, 0x00 }}; v32_uni b3_requ_uni = {{ 0x0F, 0x20, 0x00, 0x00 }}; v32_uni b3_erro_uni = {{ 0x0D, 0x20, 0x00, 0x00 }}; v32_uni b4_mask_uni = {{ 0xF8, 0xC0, 0xC0, 0xC0 }}; v32_uni b4_patt_uni = {{ 0xF0, 0x80, 0x80, 0x80 }}; v32_uni b4_requ_uni = {{ 0x07, 0x30, 0x00, 0x00 }}; v32_uni b4_err0_uni = {{ 0x04, 0x00, 0x00, 0x00 }}; v32_uni b4_err1_uni = {{ 0x03, 0x30, 0x00, 0x00 }}; u16 b2_mask = b2_mask_uni.u; u16 b2_patt = b2_patt_uni.u; u16 b2_requ = b2_requ_uni.u; u32 b3_mask = b3_mask_uni.u; u32 b3_patt = b3_patt_uni.u; u32 b3_requ = b3_requ_uni.u; u32 b3_erro = b3_erro_uni.u; u32 b4_mask = b4_mask_uni.u; u32 b4_patt = b4_patt_uni.u; u32 b4_requ = b4_requ_uni.u; u32 b4_err0 = b4_err0_uni.u; u32 b4_err1 = b4_err1_uni.u; #endif #define is_valid_seq_2(uni) ( \ ((uni & b2_mask) == b2_patt) && \ ((uni & b2_requ)) \ ) #define is_valid_seq_3(uni) ( \ ((uni & b3_mask) == b3_patt) && \ ((tmp = (uni & b3_requ))) && \ ((tmp != b3_erro)) \ ) #define is_valid_seq_4(uni) ( \ ((uni & b4_mask) == b4_patt) && \ ((tmp = (uni & b4_requ))) && \ ((tmp & b4_err0) == 0 || (tmp & b4_err1) == 0) \ ) /* The replacement character U+FFFD, used to indicate invalid character. */ const v32 rep = {{ 'F', 'F', 'F', 'D' }}; const v32 pre = {{ '\\', 'u', '0', '0' }}; const u8 *src = str; const u8 *end = str + str_len; *cur++ = '"'; copy_ascii: /* Copy continuous ASCII, loop unrolling, same as the following code: while (end > src) ( if (unlikely(enc_table[*src])) break; *cur++ = *src++; ); */ #define expr_jump(i) \ if (unlikely(enc_table[src[i]])) goto stop_char_##i; #define expr_stop(i) \ stop_char_##i: \ memcpy(cur, src, i); \ cur += i; src += i; goto copy_utf8; while (end - src >= 16) { repeat16_incr(expr_jump) byte_copy_16(cur, src); cur += 16; src += 16; } while (end - src >= 4) { repeat4_incr(expr_jump) byte_copy_4(cur, src); cur += 4; src += 4; } while (end > src) { expr_jump(0) *cur++ = *src++; } *cur++ = '"'; return cur; repeat16_incr(expr_stop) #undef expr_jump #undef expr_stop copy_utf8: if (unlikely(src + 4 > end)) { if (end == src) goto copy_end; if (end - src < enc_table[*src] / 2) goto err_one; } switch (enc_table[*src]) { case CHAR_ENC_CPY_1: { *cur++ = *src++; goto copy_ascii; } case CHAR_ENC_CPY_2: { u16 v; #if YYJSON_DISABLE_UTF8_VALIDATION byte_copy_2(cur, src); #else v = byte_load_2(src); if (unlikely(!is_valid_seq_2(v))) goto err_cpy; byte_copy_2(cur, src); #endif cur += 2; src += 2; goto copy_utf8; } case CHAR_ENC_CPY_3: { u32 v, tmp; #if YYJSON_DISABLE_UTF8_VALIDATION if (likely(src + 4 <= end)) { byte_copy_4(cur, src); } else { byte_copy_2(cur, src); cur[2] = src[2]; } #else if (likely(src + 4 <= end)) { v = byte_load_4(src); if (unlikely(!is_valid_seq_3(v))) goto err_cpy; byte_copy_4(cur, src); } else { v = byte_load_3(src); if (unlikely(!is_valid_seq_3(v))) goto err_cpy; byte_copy_4(cur, &v); } #endif cur += 3; src += 3; goto copy_utf8; } case CHAR_ENC_CPY_4: { u32 v, tmp; #if YYJSON_DISABLE_UTF8_VALIDATION byte_copy_4(cur, src); #else v = byte_load_4(src); if (unlikely(!is_valid_seq_4(v))) goto err_cpy; byte_copy_4(cur, src); #endif cur += 4; src += 4; goto copy_utf8; } case CHAR_ENC_ESC_A: { byte_copy_2(cur, &esc_single_char_table[*src * 2]); cur += 2; src += 1; goto copy_utf8; } case CHAR_ENC_ESC_1: { byte_copy_4(cur + 0, &pre); byte_copy_2(cur + 4, &esc_hex_char_table[*src * 2]); cur += 6; src += 1; goto copy_utf8; } case CHAR_ENC_ESC_2: { u16 u, v; #if !YYJSON_DISABLE_UTF8_VALIDATION v = byte_load_2(src); if (unlikely(!is_valid_seq_2(v))) goto err_esc; #endif u = (u16)(((u16)(src[0] & 0x1F) << 6) | ((u16)(src[1] & 0x3F) << 0)); byte_copy_2(cur + 0, &pre); byte_copy_2(cur + 2, &esc_hex_char_table[(u >> 8) * 2]); byte_copy_2(cur + 4, &esc_hex_char_table[(u & 0xFF) * 2]); cur += 6; src += 2; goto copy_utf8; } case CHAR_ENC_ESC_3: { u16 u; u32 v, tmp; #if !YYJSON_DISABLE_UTF8_VALIDATION v = byte_load_3(src); if (unlikely(!is_valid_seq_3(v))) goto err_esc; #endif u = (u16)(((u16)(src[0] & 0x0F) << 12) | ((u16)(src[1] & 0x3F) << 6) | ((u16)(src[2] & 0x3F) << 0)); byte_copy_2(cur + 0, &pre); byte_copy_2(cur + 2, &esc_hex_char_table[(u >> 8) * 2]); byte_copy_2(cur + 4, &esc_hex_char_table[(u & 0xFF) * 2]); cur += 6; src += 3; goto copy_utf8; } case CHAR_ENC_ESC_4: { u32 hi, lo, u, v, tmp; #if !YYJSON_DISABLE_UTF8_VALIDATION v = byte_load_4(src); if (unlikely(!is_valid_seq_4(v))) goto err_esc; #endif u = ((u32)(src[0] & 0x07) << 18) | ((u32)(src[1] & 0x3F) << 12) | ((u32)(src[2] & 0x3F) << 6) | ((u32)(src[3] & 0x3F) << 0); u -= 0x10000; hi = (u >> 10) + 0xD800; lo = (u & 0x3FF) + 0xDC00; byte_copy_2(cur + 0, &pre); byte_copy_2(cur + 2, &esc_hex_char_table[(hi >> 8) * 2]); byte_copy_2(cur + 4, &esc_hex_char_table[(hi & 0xFF) * 2]); byte_copy_2(cur + 6, &pre); byte_copy_2(cur + 8, &esc_hex_char_table[(lo >> 8) * 2]); byte_copy_2(cur + 10, &esc_hex_char_table[(lo & 0xFF) * 2]); cur += 12; src += 4; goto copy_utf8; } case CHAR_ENC_ERR_1: { goto err_one; } default: break; } copy_end: *cur++ = '"'; return cur; err_one: if (esc) goto err_esc; else goto err_cpy; err_cpy: if (!inv) return NULL; *cur++ = *src++; goto copy_utf8; err_esc: if (!inv) return NULL; byte_copy_2(cur + 0, &pre); byte_copy_4(cur + 2, &rep); cur += 6; src += 1; goto copy_utf8; #undef is_valid_seq_2 #undef is_valid_seq_3 #undef is_valid_seq_4 } /*============================================================================== * Writer Utilities *============================================================================*/ /** Write null (requires 8 bytes buffer). */ static_inline u8 *write_null(u8 *cur) { v64 v = {{ 'n', 'u', 'l', 'l', ',', '\n', 0, 0 }}; byte_copy_8(cur, &v); return cur + 4; } /** Write bool (requires 8 bytes buffer). */ static_inline u8 *write_bool(u8 *cur, bool val) { v64 v0 = {{ 'f', 'a', 'l', 's', 'e', ',', '\n', 0 }}; v64 v1 = {{ 't', 'r', 'u', 'e', ',', '\n', 0, 0 }}; if (val) { byte_copy_8(cur, &v1); } else { byte_copy_8(cur, &v0); } return cur + 5 - val; } /** Write indent (requires level x 4 bytes buffer). Param spaces should not larger than 4. */ static_inline u8 *write_indent(u8 *cur, usize level, usize spaces) { while (level-- > 0) { byte_copy_4(cur, " "); cur += spaces; } return cur; } /** Write data to file pointer. */ static bool write_dat_to_fp(FILE *fp, u8 *dat, usize len, yyjson_write_err *err) { if (fwrite(dat, len, 1, fp) != 1) { err->msg = "file writing failed"; err->code = YYJSON_WRITE_ERROR_FILE_WRITE; return false; } return true; } /** Write data to file. */ static bool write_dat_to_file(const char *path, u8 *dat, usize len, yyjson_write_err *err) { #define return_err(_code, _msg) do { \ err->msg = _msg; \ err->code = YYJSON_WRITE_ERROR_##_code; \ if (file) fclose(file); \ return false; \ } while (false) FILE *file = fopen_writeonly(path); if (file == NULL) { return_err(FILE_OPEN, "file opening failed"); } if (fwrite(dat, len, 1, file) != 1) { return_err(FILE_WRITE, "file writing failed"); } if (fclose(file) != 0) { file = NULL; return_err(FILE_WRITE, "file closing failed"); } return true; #undef return_err } /*============================================================================== * JSON Writer Implementation *============================================================================*/ typedef struct yyjson_write_ctx { usize tag; } yyjson_write_ctx; static_inline void yyjson_write_ctx_set(yyjson_write_ctx *ctx, usize size, bool is_obj) { ctx->tag = (size << 1) | (usize)is_obj; } static_inline void yyjson_write_ctx_get(yyjson_write_ctx *ctx, usize *size, bool *is_obj) { usize tag = ctx->tag; *size = tag >> 1; *is_obj = (bool)(tag & 1); } /** Write single JSON value. */ static_inline u8 *yyjson_write_single(yyjson_val *val, yyjson_write_flag flg, yyjson_alc alc, usize *dat_len, yyjson_write_err *err) { #define return_err(_code, _msg) do { \ if (hdr) alc.free(alc.ctx, (void *)hdr); \ *dat_len = 0; \ err->code = YYJSON_WRITE_ERROR_##_code; \ err->msg = _msg; \ return NULL; \ } while (false) #define incr_len(_len) do { \ hdr = (u8 *)alc.malloc(alc.ctx, _len); \ if (!hdr) goto fail_alloc; \ cur = hdr; \ } while (false) #define check_str_len(_len) do { \ if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ goto fail_alloc; \ } while (false) u8 *hdr = NULL, *cur; usize str_len; const u8 *str_ptr; const char_enc_type *enc_table = get_enc_table_with_flag(flg); bool cpy = (enc_table == enc_table_cpy); bool esc = has_write_flag(ESCAPE_UNICODE) != 0; bool inv = has_write_flag(ALLOW_INVALID_UNICODE) != 0; bool newline = has_write_flag(NEWLINE_AT_END) != 0; const usize end_len = 2; /* '\n' and '\0' */ switch (unsafe_yyjson_get_type(val)) { case YYJSON_TYPE_RAW: str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len + end_len); cur = write_raw(cur, str_ptr, str_len); break; case YYJSON_TYPE_STR: str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len * 6 + 2 + end_len); if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { cur = write_string_noesc(cur, str_ptr, str_len); } else { cur = write_string(cur, esc, inv, str_ptr, str_len, enc_table); if (unlikely(!cur)) goto fail_str; } break; case YYJSON_TYPE_NUM: incr_len(32 + end_len); cur = write_number(cur, val, flg); if (unlikely(!cur)) goto fail_num; break; case YYJSON_TYPE_BOOL: incr_len(8); cur = write_bool(cur, unsafe_yyjson_get_bool(val)); break; case YYJSON_TYPE_NULL: incr_len(8); cur = write_null(cur); break; case YYJSON_TYPE_ARR: incr_len(2 + end_len); byte_copy_2(cur, "[]"); cur += 2; break; case YYJSON_TYPE_OBJ: incr_len(2 + end_len); byte_copy_2(cur, "{}"); cur += 2; break; default: goto fail_type; } if (newline) *cur++ = '\n'; *cur = '\0'; *dat_len = (usize)(cur - hdr); memset(err, 0, sizeof(yyjson_write_err)); return hdr; fail_alloc: return_err(MEMORY_ALLOCATION, "memory allocation failed"); fail_type: return_err(INVALID_VALUE_TYPE, "invalid JSON value type"); fail_num: return_err(NAN_OR_INF, "nan or inf number is not allowed"); fail_str: return_err(INVALID_STRING, "invalid utf-8 encoding in string"); #undef return_err #undef check_str_len #undef incr_len } /** Write JSON document minify. The root of this document should be a non-empty container. */ static_inline u8 *yyjson_write_minify(const yyjson_val *root, const yyjson_write_flag flg, const yyjson_alc alc, usize *dat_len, yyjson_write_err *err) { #define return_err(_code, _msg) do { \ *dat_len = 0; \ err->code = YYJSON_WRITE_ERROR_##_code; \ err->msg = _msg; \ if (hdr) alc.free(alc.ctx, hdr); \ return NULL; \ } while (false) #define incr_len(_len) do { \ ext_len = (usize)(_len); \ if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ alc_inc = yyjson_max(alc_len / 2, ext_len); \ alc_inc = size_align_up(alc_inc, sizeof(yyjson_write_ctx)); \ if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ goto fail_alloc; \ alc_len += alc_inc; \ tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ if (unlikely(!tmp)) goto fail_alloc; \ ctx_len = (usize)(end - (u8 *)ctx); \ ctx_tmp = (yyjson_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ memmove((void *)ctx_tmp, (void *)(tmp + ((u8 *)ctx - hdr)), ctx_len); \ ctx = ctx_tmp; \ cur = tmp + (cur - hdr); \ end = tmp + alc_len; \ hdr = tmp; \ } \ } while (false) #define check_str_len(_len) do { \ if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ goto fail_alloc; \ } while (false) yyjson_val *val; yyjson_type val_type; usize ctn_len, ctn_len_tmp; bool ctn_obj, ctn_obj_tmp, is_key; u8 *hdr, *cur, *end, *tmp; yyjson_write_ctx *ctx, *ctx_tmp; usize alc_len, alc_inc, ctx_len, ext_len, str_len; const u8 *str_ptr; const char_enc_type *enc_table = get_enc_table_with_flag(flg); bool cpy = (enc_table == enc_table_cpy); bool esc = has_write_flag(ESCAPE_UNICODE) != 0; bool inv = has_write_flag(ALLOW_INVALID_UNICODE) != 0; bool newline = has_write_flag(NEWLINE_AT_END) != 0; alc_len = root->uni.ofs / sizeof(yyjson_val); alc_len = alc_len * YYJSON_WRITER_ESTIMATED_MINIFY_RATIO + 64; alc_len = size_align_up(alc_len, sizeof(yyjson_write_ctx)); hdr = (u8 *)alc.malloc(alc.ctx, alc_len); if (!hdr) goto fail_alloc; cur = hdr; end = hdr + alc_len; ctx = (yyjson_write_ctx *)(void *)end; doc_begin: val = constcast(yyjson_val *)root; val_type = unsafe_yyjson_get_type(val); ctn_obj = (val_type == YYJSON_TYPE_OBJ); ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); val++; val_begin: val_type = unsafe_yyjson_get_type(val); if (val_type == YYJSON_TYPE_STR) { is_key = ((u8)ctn_obj & (u8)~ctn_len); str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len * 6 + 16); if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { cur = write_string_noesc(cur, str_ptr, str_len); } else { cur = write_string(cur, esc, inv, str_ptr, str_len, enc_table); if (unlikely(!cur)) goto fail_str; } *cur++ = is_key ? ':' : ','; goto val_end; } if (val_type == YYJSON_TYPE_NUM) { incr_len(32); cur = write_number(cur, val, flg); if (unlikely(!cur)) goto fail_num; *cur++ = ','; goto val_end; } if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { ctn_len_tmp = unsafe_yyjson_get_len(val); ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); incr_len(16); if (unlikely(ctn_len_tmp == 0)) { /* write empty container */ *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); *cur++ = ','; goto val_end; } else { /* push context, setup new container */ yyjson_write_ctx_set(--ctx, ctn_len, ctn_obj); ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; ctn_obj = ctn_obj_tmp; *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); val++; goto val_begin; } } if (val_type == YYJSON_TYPE_BOOL) { incr_len(16); cur = write_bool(cur, unsafe_yyjson_get_bool(val)); cur++; goto val_end; } if (val_type == YYJSON_TYPE_NULL) { incr_len(16); cur = write_null(cur); cur++; goto val_end; } if (val_type == YYJSON_TYPE_RAW) { str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len + 2); cur = write_raw(cur, str_ptr, str_len); *cur++ = ','; goto val_end; } goto fail_type; val_end: val++; ctn_len--; if (unlikely(ctn_len == 0)) goto ctn_end; goto val_begin; ctn_end: cur--; *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); *cur++ = ','; if (unlikely((u8 *)ctx >= end)) goto doc_end; yyjson_write_ctx_get(ctx++, &ctn_len, &ctn_obj); ctn_len--; if (likely(ctn_len > 0)) { goto val_begin; } else { goto ctn_end; } doc_end: if (newline) { incr_len(2); *(cur - 1) = '\n'; cur++; } *--cur = '\0'; *dat_len = (usize)(cur - hdr); memset(err, 0, sizeof(yyjson_write_err)); return hdr; fail_alloc: return_err(MEMORY_ALLOCATION, "memory allocation failed"); fail_type: return_err(INVALID_VALUE_TYPE, "invalid JSON value type"); fail_num: return_err(NAN_OR_INF, "nan or inf number is not allowed"); fail_str: return_err(INVALID_STRING, "invalid utf-8 encoding in string"); #undef return_err #undef incr_len #undef check_str_len } /** Write JSON document pretty. The root of this document should be a non-empty container. */ static_inline u8 *yyjson_write_pretty(const yyjson_val *root, const yyjson_write_flag flg, const yyjson_alc alc, usize *dat_len, yyjson_write_err *err) { #define return_err(_code, _msg) do { \ *dat_len = 0; \ err->code = YYJSON_WRITE_ERROR_##_code; \ err->msg = _msg; \ if (hdr) alc.free(alc.ctx, hdr); \ return NULL; \ } while (false) #define incr_len(_len) do { \ ext_len = (usize)(_len); \ if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ alc_inc = yyjson_max(alc_len / 2, ext_len); \ alc_inc = size_align_up(alc_inc, sizeof(yyjson_write_ctx)); \ if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ goto fail_alloc; \ alc_len += alc_inc; \ tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ if (unlikely(!tmp)) goto fail_alloc; \ ctx_len = (usize)(end - (u8 *)ctx); \ ctx_tmp = (yyjson_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ memmove((void *)ctx_tmp, (void *)(tmp + ((u8 *)ctx - hdr)), ctx_len); \ ctx = ctx_tmp; \ cur = tmp + (cur - hdr); \ end = tmp + alc_len; \ hdr = tmp; \ } \ } while (false) #define check_str_len(_len) do { \ if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ goto fail_alloc; \ } while (false) yyjson_val *val; yyjson_type val_type; usize ctn_len, ctn_len_tmp; bool ctn_obj, ctn_obj_tmp, is_key, no_indent; u8 *hdr, *cur, *end, *tmp; yyjson_write_ctx *ctx, *ctx_tmp; usize alc_len, alc_inc, ctx_len, ext_len, str_len, level; const u8 *str_ptr; const char_enc_type *enc_table = get_enc_table_with_flag(flg); bool cpy = (enc_table == enc_table_cpy); bool esc = has_write_flag(ESCAPE_UNICODE) != 0; bool inv = has_write_flag(ALLOW_INVALID_UNICODE) != 0; usize spaces = has_write_flag(PRETTY_TWO_SPACES) ? 2 : 4; bool newline = has_write_flag(NEWLINE_AT_END) != 0; alc_len = root->uni.ofs / sizeof(yyjson_val); alc_len = alc_len * YYJSON_WRITER_ESTIMATED_PRETTY_RATIO + 64; alc_len = size_align_up(alc_len, sizeof(yyjson_write_ctx)); hdr = (u8 *)alc.malloc(alc.ctx, alc_len); if (!hdr) goto fail_alloc; cur = hdr; end = hdr + alc_len; ctx = (yyjson_write_ctx *)(void *)end; doc_begin: val = constcast(yyjson_val *)root; val_type = unsafe_yyjson_get_type(val); ctn_obj = (val_type == YYJSON_TYPE_OBJ); ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); *cur++ = '\n'; val++; level = 1; val_begin: val_type = unsafe_yyjson_get_type(val); if (val_type == YYJSON_TYPE_STR) { is_key = (bool)((u8)ctn_obj & (u8)~ctn_len); no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len * 6 + 16 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { cur = write_string_noesc(cur, str_ptr, str_len); } else { cur = write_string(cur, esc, inv, str_ptr, str_len, enc_table); if (unlikely(!cur)) goto fail_str; } *cur++ = is_key ? ':' : ','; *cur++ = is_key ? ' ' : '\n'; goto val_end; } if (val_type == YYJSON_TYPE_NUM) { no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); incr_len(32 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); cur = write_number(cur, val, flg); if (unlikely(!cur)) goto fail_num; *cur++ = ','; *cur++ = '\n'; goto val_end; } if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); ctn_len_tmp = unsafe_yyjson_get_len(val); ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); if (unlikely(ctn_len_tmp == 0)) { /* write empty container */ incr_len(16 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); *cur++ = ','; *cur++ = '\n'; goto val_end; } else { /* push context, setup new container */ incr_len(32 + (no_indent ? 0 : level * 4)); yyjson_write_ctx_set(--ctx, ctn_len, ctn_obj); ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; ctn_obj = ctn_obj_tmp; cur = write_indent(cur, no_indent ? 0 : level, spaces); level++; *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); *cur++ = '\n'; val++; goto val_begin; } } if (val_type == YYJSON_TYPE_BOOL) { no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); incr_len(16 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); cur = write_bool(cur, unsafe_yyjson_get_bool(val)); cur += 2; goto val_end; } if (val_type == YYJSON_TYPE_NULL) { no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); incr_len(16 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); cur = write_null(cur); cur += 2; goto val_end; } if (val_type == YYJSON_TYPE_RAW) { str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len + 3); cur = write_raw(cur, str_ptr, str_len); *cur++ = ','; *cur++ = '\n'; goto val_end; } goto fail_type; val_end: val++; ctn_len--; if (unlikely(ctn_len == 0)) goto ctn_end; goto val_begin; ctn_end: cur -= 2; *cur++ = '\n'; incr_len(level * 4); cur = write_indent(cur, --level, spaces); *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); if (unlikely((u8 *)ctx >= end)) goto doc_end; yyjson_write_ctx_get(ctx++, &ctn_len, &ctn_obj); ctn_len--; *cur++ = ','; *cur++ = '\n'; if (likely(ctn_len > 0)) { goto val_begin; } else { goto ctn_end; } doc_end: if (newline) { incr_len(2); *cur++ = '\n'; } *cur = '\0'; *dat_len = (usize)(cur - hdr); memset(err, 0, sizeof(yyjson_write_err)); return hdr; fail_alloc: return_err(MEMORY_ALLOCATION, "memory allocation failed"); fail_type: return_err(INVALID_VALUE_TYPE, "invalid JSON value type"); fail_num: return_err(NAN_OR_INF, "nan or inf number is not allowed"); fail_str: return_err(INVALID_STRING, "invalid utf-8 encoding in string"); #undef return_err #undef incr_len #undef check_str_len } char *yyjson_val_write_opts(const yyjson_val *val, yyjson_write_flag flg, const yyjson_alc *alc_ptr, usize *dat_len, yyjson_write_err *err) { yyjson_write_err dummy_err; usize dummy_dat_len; yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; yyjson_val *root = constcast(yyjson_val *)val; err = err ? err : &dummy_err; dat_len = dat_len ? dat_len : &dummy_dat_len; if (unlikely(!root)) { *dat_len = 0; err->msg = "input JSON is NULL"; err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; return NULL; } if (!unsafe_yyjson_is_ctn(root) || unsafe_yyjson_get_len(root) == 0) { return (char *)yyjson_write_single(root, flg, alc, dat_len, err); } else if (flg & (YYJSON_WRITE_PRETTY | YYJSON_WRITE_PRETTY_TWO_SPACES)) { return (char *)yyjson_write_pretty(root, flg, alc, dat_len, err); } else { return (char *)yyjson_write_minify(root, flg, alc, dat_len, err); } } char *yyjson_write_opts(const yyjson_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc_ptr, usize *dat_len, yyjson_write_err *err) { yyjson_val *root = doc ? doc->root : NULL; return yyjson_val_write_opts(root, flg, alc_ptr, dat_len, err); } bool yyjson_val_write_file(const char *path, const yyjson_val *val, yyjson_write_flag flg, const yyjson_alc *alc_ptr, yyjson_write_err *err) { yyjson_write_err dummy_err; u8 *dat; usize dat_len = 0; yyjson_val *root = constcast(yyjson_val *)val; bool suc; alc_ptr = alc_ptr ? alc_ptr : &YYJSON_DEFAULT_ALC; err = err ? err : &dummy_err; if (unlikely(!path || !*path)) { err->msg = "input path is invalid"; err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; return false; } dat = (u8 *)yyjson_val_write_opts(root, flg, alc_ptr, &dat_len, err); if (unlikely(!dat)) return false; suc = write_dat_to_file(path, dat, dat_len, err); alc_ptr->free(alc_ptr->ctx, dat); return suc; } bool yyjson_val_write_fp(FILE *fp, const yyjson_val *val, yyjson_write_flag flg, const yyjson_alc *alc_ptr, yyjson_write_err *err) { yyjson_write_err dummy_err; u8 *dat; usize dat_len = 0; yyjson_val *root = constcast(yyjson_val *)val; bool suc; alc_ptr = alc_ptr ? alc_ptr : &YYJSON_DEFAULT_ALC; err = err ? err : &dummy_err; if (unlikely(!fp)) { err->msg = "input fp is invalid"; err->code = YYJSON_READ_ERROR_INVALID_PARAMETER; return false; } dat = (u8 *)yyjson_val_write_opts(root, flg, alc_ptr, &dat_len, err); if (unlikely(!dat)) return false; suc = write_dat_to_fp(fp, dat, dat_len, err); alc_ptr->free(alc_ptr->ctx, dat); return suc; } bool yyjson_write_file(const char *path, const yyjson_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc_ptr, yyjson_write_err *err) { yyjson_val *root = doc ? doc->root : NULL; return yyjson_val_write_file(path, root, flg, alc_ptr, err); } bool yyjson_write_fp(FILE *fp, const yyjson_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc_ptr, yyjson_write_err *err) { yyjson_val *root = doc ? doc->root : NULL; return yyjson_val_write_fp(fp, root, flg, alc_ptr, err); } /*============================================================================== * Mutable JSON Writer Implementation *============================================================================*/ typedef struct yyjson_mut_write_ctx { usize tag; yyjson_mut_val *ctn; } yyjson_mut_write_ctx; static_inline void yyjson_mut_write_ctx_set(yyjson_mut_write_ctx *ctx, yyjson_mut_val *ctn, usize size, bool is_obj) { ctx->tag = (size << 1) | (usize)is_obj; ctx->ctn = ctn; } static_inline void yyjson_mut_write_ctx_get(yyjson_mut_write_ctx *ctx, yyjson_mut_val **ctn, usize *size, bool *is_obj) { usize tag = ctx->tag; *size = tag >> 1; *is_obj = (bool)(tag & 1); *ctn = ctx->ctn; } /** Get the estimated number of values for the mutable JSON document. */ static_inline usize yyjson_mut_doc_estimated_val_num( const yyjson_mut_doc *doc) { usize sum = 0; yyjson_val_chunk *chunk = doc->val_pool.chunks; while (chunk) { sum += chunk->chunk_size / sizeof(yyjson_mut_val) - 1; if (chunk == doc->val_pool.chunks) { sum -= (usize)(doc->val_pool.end - doc->val_pool.cur); } chunk = chunk->next; } return sum; } /** Write single JSON value. */ static_inline u8 *yyjson_mut_write_single(yyjson_mut_val *val, yyjson_write_flag flg, yyjson_alc alc, usize *dat_len, yyjson_write_err *err) { return yyjson_write_single((yyjson_val *)val, flg, alc, dat_len, err); } /** Write JSON document minify. The root of this document should be a non-empty container. */ static_inline u8 *yyjson_mut_write_minify(const yyjson_mut_val *root, usize estimated_val_num, yyjson_write_flag flg, yyjson_alc alc, usize *dat_len, yyjson_write_err *err) { #define return_err(_code, _msg) do { \ *dat_len = 0; \ err->code = YYJSON_WRITE_ERROR_##_code; \ err->msg = _msg; \ if (hdr) alc.free(alc.ctx, hdr); \ return NULL; \ } while (false) #define incr_len(_len) do { \ ext_len = (usize)(_len); \ if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ alc_inc = yyjson_max(alc_len / 2, ext_len); \ alc_inc = size_align_up(alc_inc, sizeof(yyjson_mut_write_ctx)); \ if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ goto fail_alloc; \ alc_len += alc_inc; \ tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ if (unlikely(!tmp)) goto fail_alloc; \ ctx_len = (usize)(end - (u8 *)ctx); \ ctx_tmp = (yyjson_mut_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ memmove((void *)ctx_tmp, (void *)(tmp + ((u8 *)ctx - hdr)), ctx_len); \ ctx = ctx_tmp; \ cur = tmp + (cur - hdr); \ end = tmp + alc_len; \ hdr = tmp; \ } \ } while (false) #define check_str_len(_len) do { \ if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ goto fail_alloc; \ } while (false) yyjson_mut_val *val, *ctn; yyjson_type val_type; usize ctn_len, ctn_len_tmp; bool ctn_obj, ctn_obj_tmp, is_key; u8 *hdr, *cur, *end, *tmp; yyjson_mut_write_ctx *ctx, *ctx_tmp; usize alc_len, alc_inc, ctx_len, ext_len, str_len; const u8 *str_ptr; const char_enc_type *enc_table = get_enc_table_with_flag(flg); bool cpy = (enc_table == enc_table_cpy); bool esc = has_write_flag(ESCAPE_UNICODE) != 0; bool inv = has_write_flag(ALLOW_INVALID_UNICODE) != 0; bool newline = has_write_flag(NEWLINE_AT_END) != 0; alc_len = estimated_val_num * YYJSON_WRITER_ESTIMATED_MINIFY_RATIO + 64; alc_len = size_align_up(alc_len, sizeof(yyjson_mut_write_ctx)); hdr = (u8 *)alc.malloc(alc.ctx, alc_len); if (!hdr) goto fail_alloc; cur = hdr; end = hdr + alc_len; ctx = (yyjson_mut_write_ctx *)(void *)end; doc_begin: val = constcast(yyjson_mut_val *)root; val_type = unsafe_yyjson_get_type(val); ctn_obj = (val_type == YYJSON_TYPE_OBJ); ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); ctn = val; val = (yyjson_mut_val *)val->uni.ptr; /* tail */ val = ctn_obj ? val->next->next : val->next; val_begin: val_type = unsafe_yyjson_get_type(val); if (val_type == YYJSON_TYPE_STR) { is_key = ((u8)ctn_obj & (u8)~ctn_len); str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len * 6 + 16); if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { cur = write_string_noesc(cur, str_ptr, str_len); } else { cur = write_string(cur, esc, inv, str_ptr, str_len, enc_table); if (unlikely(!cur)) goto fail_str; } *cur++ = is_key ? ':' : ','; goto val_end; } if (val_type == YYJSON_TYPE_NUM) { incr_len(32); cur = write_number(cur, (yyjson_val *)val, flg); if (unlikely(!cur)) goto fail_num; *cur++ = ','; goto val_end; } if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { ctn_len_tmp = unsafe_yyjson_get_len(val); ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); incr_len(16); if (unlikely(ctn_len_tmp == 0)) { /* write empty container */ *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); *cur++ = ','; goto val_end; } else { /* push context, setup new container */ yyjson_mut_write_ctx_set(--ctx, ctn, ctn_len, ctn_obj); ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; ctn_obj = ctn_obj_tmp; *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); ctn = val; val = (yyjson_mut_val *)ctn->uni.ptr; /* tail */ val = ctn_obj ? val->next->next : val->next; goto val_begin; } } if (val_type == YYJSON_TYPE_BOOL) { incr_len(16); cur = write_bool(cur, unsafe_yyjson_get_bool(val)); cur++; goto val_end; } if (val_type == YYJSON_TYPE_NULL) { incr_len(16); cur = write_null(cur); cur++; goto val_end; } if (val_type == YYJSON_TYPE_RAW) { str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len + 2); cur = write_raw(cur, str_ptr, str_len); *cur++ = ','; goto val_end; } goto fail_type; val_end: ctn_len--; if (unlikely(ctn_len == 0)) goto ctn_end; val = val->next; goto val_begin; ctn_end: cur--; *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); *cur++ = ','; if (unlikely((u8 *)ctx >= end)) goto doc_end; val = ctn->next; yyjson_mut_write_ctx_get(ctx++, &ctn, &ctn_len, &ctn_obj); ctn_len--; if (likely(ctn_len > 0)) { goto val_begin; } else { goto ctn_end; } doc_end: if (newline) { incr_len(2); *(cur - 1) = '\n'; cur++; } *--cur = '\0'; *dat_len = (usize)(cur - hdr); err->code = YYJSON_WRITE_SUCCESS; err->msg = "success"; return hdr; fail_alloc: return_err(MEMORY_ALLOCATION, "memory allocation failed"); fail_type: return_err(INVALID_VALUE_TYPE, "invalid JSON value type"); fail_num: return_err(NAN_OR_INF, "nan or inf number is not allowed"); fail_str: return_err(INVALID_STRING, "invalid utf-8 encoding in string"); #undef return_err #undef incr_len #undef check_str_len } /** Write JSON document pretty. The root of this document should be a non-empty container. */ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root, usize estimated_val_num, yyjson_write_flag flg, yyjson_alc alc, usize *dat_len, yyjson_write_err *err) { #define return_err(_code, _msg) do { \ *dat_len = 0; \ err->code = YYJSON_WRITE_ERROR_##_code; \ err->msg = _msg; \ if (hdr) alc.free(alc.ctx, hdr); \ return NULL; \ } while (false) #define incr_len(_len) do { \ ext_len = (usize)(_len); \ if (unlikely((u8 *)(cur + ext_len) >= (u8 *)ctx)) { \ alc_inc = yyjson_max(alc_len / 2, ext_len); \ alc_inc = size_align_up(alc_inc, sizeof(yyjson_mut_write_ctx)); \ if ((sizeof(usize) < 8) && size_add_is_overflow(alc_len, alc_inc)) \ goto fail_alloc; \ alc_len += alc_inc; \ tmp = (u8 *)alc.realloc(alc.ctx, hdr, alc_len - alc_inc, alc_len); \ if (unlikely(!tmp)) goto fail_alloc; \ ctx_len = (usize)(end - (u8 *)ctx); \ ctx_tmp = (yyjson_mut_write_ctx *)(void *)(tmp + (alc_len - ctx_len)); \ memmove((void *)ctx_tmp, (void *)(tmp + ((u8 *)ctx - hdr)), ctx_len); \ ctx = ctx_tmp; \ cur = tmp + (cur - hdr); \ end = tmp + alc_len; \ hdr = tmp; \ } \ } while (false) #define check_str_len(_len) do { \ if ((sizeof(usize) < 8) && (_len >= (USIZE_MAX - 16) / 6)) \ goto fail_alloc; \ } while (false) yyjson_mut_val *val, *ctn; yyjson_type val_type; usize ctn_len, ctn_len_tmp; bool ctn_obj, ctn_obj_tmp, is_key, no_indent; u8 *hdr, *cur, *end, *tmp; yyjson_mut_write_ctx *ctx, *ctx_tmp; usize alc_len, alc_inc, ctx_len, ext_len, str_len, level; const u8 *str_ptr; const char_enc_type *enc_table = get_enc_table_with_flag(flg); bool cpy = (enc_table == enc_table_cpy); bool esc = has_write_flag(ESCAPE_UNICODE) != 0; bool inv = has_write_flag(ALLOW_INVALID_UNICODE) != 0; usize spaces = has_write_flag(PRETTY_TWO_SPACES) ? 2 : 4; bool newline = has_write_flag(NEWLINE_AT_END) != 0; alc_len = estimated_val_num * YYJSON_WRITER_ESTIMATED_PRETTY_RATIO + 64; alc_len = size_align_up(alc_len, sizeof(yyjson_mut_write_ctx)); hdr = (u8 *)alc.malloc(alc.ctx, alc_len); if (!hdr) goto fail_alloc; cur = hdr; end = hdr + alc_len; ctx = (yyjson_mut_write_ctx *)(void *)end; doc_begin: val = constcast(yyjson_mut_val *)root; val_type = unsafe_yyjson_get_type(val); ctn_obj = (val_type == YYJSON_TYPE_OBJ); ctn_len = unsafe_yyjson_get_len(val) << (u8)ctn_obj; *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); *cur++ = '\n'; ctn = val; val = (yyjson_mut_val *)val->uni.ptr; /* tail */ val = ctn_obj ? val->next->next : val->next; level = 1; val_begin: val_type = unsafe_yyjson_get_type(val); if (val_type == YYJSON_TYPE_STR) { is_key = (bool)((u8)ctn_obj & (u8)~ctn_len); no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len * 6 + 16 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); if (likely(cpy) && unsafe_yyjson_get_subtype(val)) { cur = write_string_noesc(cur, str_ptr, str_len); } else { cur = write_string(cur, esc, inv, str_ptr, str_len, enc_table); if (unlikely(!cur)) goto fail_str; } *cur++ = is_key ? ':' : ','; *cur++ = is_key ? ' ' : '\n'; goto val_end; } if (val_type == YYJSON_TYPE_NUM) { no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); incr_len(32 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); cur = write_number(cur, (yyjson_val *)val, flg); if (unlikely(!cur)) goto fail_num; *cur++ = ','; *cur++ = '\n'; goto val_end; } if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) == (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) { no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); ctn_len_tmp = unsafe_yyjson_get_len(val); ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ); if (unlikely(ctn_len_tmp == 0)) { /* write empty container */ incr_len(16 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); *cur++ = (u8)('[' | ((u8)ctn_obj_tmp << 5)); *cur++ = (u8)(']' | ((u8)ctn_obj_tmp << 5)); *cur++ = ','; *cur++ = '\n'; goto val_end; } else { /* push context, setup new container */ incr_len(32 + (no_indent ? 0 : level * 4)); yyjson_mut_write_ctx_set(--ctx, ctn, ctn_len, ctn_obj); ctn_len = ctn_len_tmp << (u8)ctn_obj_tmp; ctn_obj = ctn_obj_tmp; cur = write_indent(cur, no_indent ? 0 : level, spaces); level++; *cur++ = (u8)('[' | ((u8)ctn_obj << 5)); *cur++ = '\n'; ctn = val; val = (yyjson_mut_val *)ctn->uni.ptr; /* tail */ val = ctn_obj ? val->next->next : val->next; goto val_begin; } } if (val_type == YYJSON_TYPE_BOOL) { no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); incr_len(16 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); cur = write_bool(cur, unsafe_yyjson_get_bool(val)); cur += 2; goto val_end; } if (val_type == YYJSON_TYPE_NULL) { no_indent = (bool)((u8)ctn_obj & (u8)ctn_len); incr_len(16 + (no_indent ? 0 : level * 4)); cur = write_indent(cur, no_indent ? 0 : level, spaces); cur = write_null(cur); cur += 2; goto val_end; } if (val_type == YYJSON_TYPE_RAW) { str_len = unsafe_yyjson_get_len(val); str_ptr = (const u8 *)unsafe_yyjson_get_str(val); check_str_len(str_len); incr_len(str_len + 3); cur = write_raw(cur, str_ptr, str_len); *cur++ = ','; *cur++ = '\n'; goto val_end; } goto fail_type; val_end: ctn_len--; if (unlikely(ctn_len == 0)) goto ctn_end; val = val->next; goto val_begin; ctn_end: cur -= 2; *cur++ = '\n'; incr_len(level * 4); cur = write_indent(cur, --level, spaces); *cur++ = (u8)(']' | ((u8)ctn_obj << 5)); if (unlikely((u8 *)ctx >= end)) goto doc_end; val = ctn->next; yyjson_mut_write_ctx_get(ctx++, &ctn, &ctn_len, &ctn_obj); ctn_len--; *cur++ = ','; *cur++ = '\n'; if (likely(ctn_len > 0)) { goto val_begin; } else { goto ctn_end; } doc_end: if (newline) { incr_len(2); *cur++ = '\n'; } *cur = '\0'; *dat_len = (usize)(cur - hdr); err->code = YYJSON_WRITE_SUCCESS; err->msg = "success"; return hdr; fail_alloc: return_err(MEMORY_ALLOCATION, "memory allocation failed"); fail_type: return_err(INVALID_VALUE_TYPE, "invalid JSON value type"); fail_num: return_err(NAN_OR_INF, "nan or inf number is not allowed"); fail_str: return_err(INVALID_STRING, "invalid utf-8 encoding in string"); #undef return_err #undef incr_len #undef check_str_len } static char *yyjson_mut_write_opts_impl(const yyjson_mut_val *val, usize estimated_val_num, yyjson_write_flag flg, const yyjson_alc *alc_ptr, usize *dat_len, yyjson_write_err *err) { yyjson_write_err dummy_err; usize dummy_dat_len; yyjson_alc alc = alc_ptr ? *alc_ptr : YYJSON_DEFAULT_ALC; yyjson_mut_val *root = constcast(yyjson_mut_val *)val; err = err ? err : &dummy_err; dat_len = dat_len ? dat_len : &dummy_dat_len; if (unlikely(!root)) { *dat_len = 0; err->msg = "input JSON is NULL"; err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; return NULL; } if (!unsafe_yyjson_is_ctn(root) || unsafe_yyjson_get_len(root) == 0) { return (char *)yyjson_mut_write_single(root, flg, alc, dat_len, err); } else if (flg & (YYJSON_WRITE_PRETTY | YYJSON_WRITE_PRETTY_TWO_SPACES)) { return (char *)yyjson_mut_write_pretty(root, estimated_val_num, flg, alc, dat_len, err); } else { return (char *)yyjson_mut_write_minify(root, estimated_val_num, flg, alc, dat_len, err); } } char *yyjson_mut_val_write_opts(const yyjson_mut_val *val, yyjson_write_flag flg, const yyjson_alc *alc_ptr, usize *dat_len, yyjson_write_err *err) { return yyjson_mut_write_opts_impl(val, 0, flg, alc_ptr, dat_len, err); } char *yyjson_mut_write_opts(const yyjson_mut_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc_ptr, usize *dat_len, yyjson_write_err *err) { yyjson_mut_val *root; usize estimated_val_num; if (likely(doc)) { root = doc->root; estimated_val_num = yyjson_mut_doc_estimated_val_num(doc); } else { root = NULL; estimated_val_num = 0; } return yyjson_mut_write_opts_impl(root, estimated_val_num, flg, alc_ptr, dat_len, err); } bool yyjson_mut_val_write_file(const char *path, const yyjson_mut_val *val, yyjson_write_flag flg, const yyjson_alc *alc_ptr, yyjson_write_err *err) { yyjson_write_err dummy_err; u8 *dat; usize dat_len = 0; yyjson_mut_val *root = constcast(yyjson_mut_val *)val; bool suc; alc_ptr = alc_ptr ? alc_ptr : &YYJSON_DEFAULT_ALC; err = err ? err : &dummy_err; if (unlikely(!path || !*path)) { err->msg = "input path is invalid"; err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; return false; } dat = (u8 *)yyjson_mut_val_write_opts(root, flg, alc_ptr, &dat_len, err); if (unlikely(!dat)) return false; suc = write_dat_to_file(path, dat, dat_len, err); alc_ptr->free(alc_ptr->ctx, dat); return suc; } bool yyjson_mut_val_write_fp(FILE *fp, const yyjson_mut_val *val, yyjson_write_flag flg, const yyjson_alc *alc_ptr, yyjson_write_err *err) { yyjson_write_err dummy_err; u8 *dat; usize dat_len = 0; yyjson_mut_val *root = constcast(yyjson_mut_val *)val; bool suc; alc_ptr = alc_ptr ? alc_ptr : &YYJSON_DEFAULT_ALC; err = err ? err : &dummy_err; if (unlikely(!fp)) { err->msg = "input fp is invalid"; err->code = YYJSON_WRITE_ERROR_INVALID_PARAMETER; return false; } dat = (u8 *)yyjson_mut_val_write_opts(root, flg, alc_ptr, &dat_len, err); if (unlikely(!dat)) return false; suc = write_dat_to_fp(fp, dat, dat_len, err); alc_ptr->free(alc_ptr->ctx, dat); return suc; } bool yyjson_mut_write_file(const char *path, const yyjson_mut_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc_ptr, yyjson_write_err *err) { yyjson_mut_val *root = doc ? doc->root : NULL; return yyjson_mut_val_write_file(path, root, flg, alc_ptr, err); } bool yyjson_mut_write_fp(FILE *fp, const yyjson_mut_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc_ptr, yyjson_write_err *err) { yyjson_mut_val *root = doc ? doc->root : NULL; return yyjson_mut_val_write_fp(fp, root, flg, alc_ptr, err); } #endif /* YYJSON_DISABLE_WRITER */ ijl-orjson-aa8c946/include/yyjson/yyjson.h000066400000000000000000011270371505336676500207360ustar00rootroot00000000000000/*============================================================================== Copyright (c) 2020 YaoYuan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *============================================================================*/ /** @file yyjson.h @date 2019-03-09 @author YaoYuan */ #ifndef YYJSON_H #define YYJSON_H /*============================================================================== * Header Files *============================================================================*/ #include #include #include #include #include #include /*============================================================================== * Compile-time Options *============================================================================*/ /* Define as 1 to disable JSON reader if JSON parsing is not required. This will disable these functions at compile-time: - yyjson_read() - yyjson_read_opts() - yyjson_read_file() - yyjson_read_number() - yyjson_mut_read_number() This will reduce the binary size by about 60%. */ #ifndef YYJSON_DISABLE_READER #endif /* Define as 1 to disable JSON writer if JSON serialization is not required. This will disable these functions at compile-time: - yyjson_write() - yyjson_write_file() - yyjson_write_opts() - yyjson_val_write() - yyjson_val_write_file() - yyjson_val_write_opts() - yyjson_mut_write() - yyjson_mut_write_file() - yyjson_mut_write_opts() - yyjson_mut_val_write() - yyjson_mut_val_write_file() - yyjson_mut_val_write_opts() This will reduce the binary size by about 30%. */ #ifndef YYJSON_DISABLE_WRITER #endif /* Define as 1 to disable JSON Pointer, JSON Patch and JSON Merge Patch supports. This will disable these functions at compile-time: - yyjson_ptr_xxx() - yyjson_mut_ptr_xxx() - yyjson_doc_ptr_xxx() - yyjson_mut_doc_ptr_xxx() - yyjson_patch() - yyjson_mut_patch() - yyjson_merge_patch() - yyjson_mut_merge_patch() */ #ifndef YYJSON_DISABLE_UTILS #endif /* Define as 1 to disable the fast floating-point number conversion in yyjson, and use libc's `strtod/snprintf` instead. This will reduce the binary size by about 30%, but significantly slow down the floating-point read/write speed. */ #ifndef YYJSON_DISABLE_FAST_FP_CONV #endif /* Define as 1 to disable non-standard JSON support at compile-time: - Reading and writing inf/nan literal, such as `NaN`, `-Infinity`. - Single line and multiple line comments. - Single trailing comma at the end of an object or array. - Invalid unicode in string value. This will also invalidate these run-time options: - YYJSON_READ_ALLOW_INF_AND_NAN - YYJSON_READ_ALLOW_COMMENTS - YYJSON_READ_ALLOW_TRAILING_COMMAS - YYJSON_READ_ALLOW_INVALID_UNICODE - YYJSON_WRITE_ALLOW_INF_AND_NAN - YYJSON_WRITE_ALLOW_INVALID_UNICODE This will reduce the binary size by about 10%, and speed up the reading and writing speed by about 2% to 6%. */ #ifndef YYJSON_DISABLE_NON_STANDARD #endif /* Define as 1 to disable UTF-8 validation at compile time. If all input strings are guaranteed to be valid UTF-8 encoding (for example, some language's String object has already validated the encoding), using this flag can avoid redundant UTF-8 validation in yyjson. This flag can speed up the reading and writing speed of non-ASCII encoded strings by about 3% to 7%. Note: If this flag is used while passing in illegal UTF-8 strings, the following errors may occur: - Escaped characters may be ignored when parsing JSON strings. - Ending quotes may be ignored when parsing JSON strings, causing the string to be concatenated to the next value. - When accessing `yyjson_mut_val` for serialization, the string ending may be accessed out of bounds, causing a segmentation fault. */ #ifndef YYJSON_DISABLE_UTF8_VALIDATION #endif /* Define as 1 to indicate that the target architecture does not support unaligned memory access. Please refer to the comments in the C file for details. */ #ifndef YYJSON_DISABLE_UNALIGNED_MEMORY_ACCESS #endif /* Define as 1 to export symbols when building this library as Windows DLL. */ #ifndef YYJSON_EXPORTS #endif /* Define as 1 to import symbols when using this library as Windows DLL. */ #ifndef YYJSON_IMPORTS #endif /* Define as 1 to include for compiler which doesn't support C99. */ #ifndef YYJSON_HAS_STDINT_H #endif /* Define as 1 to include for compiler which doesn't support C99. */ #ifndef YYJSON_HAS_STDBOOL_H #endif /*============================================================================== * Compiler Macros *============================================================================*/ /** compiler version (MSVC) */ #ifdef _MSC_VER # define YYJSON_MSC_VER _MSC_VER #else # define YYJSON_MSC_VER 0 #endif /** compiler version (GCC) */ #ifdef __GNUC__ # define YYJSON_GCC_VER __GNUC__ # if defined(__GNUC_PATCHLEVEL__) # define yyjson_gcc_available(major, minor, patch) \ ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ >= (major * 10000 + minor * 100 + patch)) # else # define yyjson_gcc_available(major, minor, patch) \ ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) \ >= (major * 10000 + minor * 100 + patch)) # endif #else # define YYJSON_GCC_VER 0 # define yyjson_gcc_available(major, minor, patch) 0 #endif /** real gcc check */ #if !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__ICC) && \ defined(__GNUC__) # define YYJSON_IS_REAL_GCC 1 #else # define YYJSON_IS_REAL_GCC 0 #endif /** C version (STDC) */ #if defined(__STDC__) && (__STDC__ >= 1) && defined(__STDC_VERSION__) # define YYJSON_STDC_VER __STDC_VERSION__ #else # define YYJSON_STDC_VER 0 #endif /** C++ version */ #if defined(__cplusplus) # define YYJSON_CPP_VER __cplusplus #else # define YYJSON_CPP_VER 0 #endif /** compiler builtin check (since gcc 10.0, clang 2.6, icc 2021) */ #ifndef yyjson_has_builtin # ifdef __has_builtin # define yyjson_has_builtin(x) __has_builtin(x) # else # define yyjson_has_builtin(x) 0 # endif #endif /** compiler attribute check (since gcc 5.0, clang 2.9, icc 17) */ #ifndef yyjson_has_attribute # ifdef __has_attribute # define yyjson_has_attribute(x) __has_attribute(x) # else # define yyjson_has_attribute(x) 0 # endif #endif /** compiler feature check (since clang 2.6, icc 17) */ #ifndef yyjson_has_feature # ifdef __has_feature # define yyjson_has_feature(x) __has_feature(x) # else # define yyjson_has_feature(x) 0 # endif #endif /** include check (since gcc 5.0, clang 2.7, icc 16, msvc 2017 15.3) */ #ifndef yyjson_has_include # ifdef __has_include # define yyjson_has_include(x) __has_include(x) # else # define yyjson_has_include(x) 0 # endif #endif /** inline for compiler */ #ifndef yyjson_inline # if YYJSON_MSC_VER >= 1200 # define yyjson_inline __forceinline # elif defined(_MSC_VER) # define yyjson_inline __inline # elif yyjson_has_attribute(always_inline) || YYJSON_GCC_VER >= 4 # define yyjson_inline __inline__ __attribute__((always_inline)) # elif defined(__clang__) || defined(__GNUC__) # define yyjson_inline __inline__ # elif defined(__cplusplus) || YYJSON_STDC_VER >= 199901L # define yyjson_inline inline # else # define yyjson_inline # endif #endif /** noinline for compiler */ #ifndef yyjson_noinline # if YYJSON_MSC_VER >= 1400 # define yyjson_noinline __declspec(noinline) # elif yyjson_has_attribute(noinline) || YYJSON_GCC_VER >= 4 # define yyjson_noinline __attribute__((noinline)) # else # define yyjson_noinline # endif #endif /** align for compiler */ #ifndef yyjson_align # if YYJSON_MSC_VER >= 1300 # define yyjson_align(x) __declspec(align(x)) # elif yyjson_has_attribute(aligned) || defined(__GNUC__) # define yyjson_align(x) __attribute__((aligned(x))) # elif YYJSON_CPP_VER >= 201103L # define yyjson_align(x) alignas(x) # else # define yyjson_align(x) # endif #endif /** likely for compiler */ #ifndef yyjson_likely # if yyjson_has_builtin(__builtin_expect) || \ (YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5) # define yyjson_likely(expr) __builtin_expect(!!(expr), 1) # else # define yyjson_likely(expr) (expr) # endif #endif /** unlikely for compiler */ #ifndef yyjson_unlikely # if yyjson_has_builtin(__builtin_expect) || \ (YYJSON_GCC_VER >= 4 && YYJSON_GCC_VER != 5) # define yyjson_unlikely(expr) __builtin_expect(!!(expr), 0) # else # define yyjson_unlikely(expr) (expr) # endif #endif /** compile-time constant check for compiler */ #ifndef yyjson_constant_p # if yyjson_has_builtin(__builtin_constant_p) || (YYJSON_GCC_VER >= 3) # define YYJSON_HAS_CONSTANT_P 1 # define yyjson_constant_p(value) __builtin_constant_p(value) # else # define YYJSON_HAS_CONSTANT_P 0 # define yyjson_constant_p(value) 0 # endif #endif /** deprecate warning */ #ifndef yyjson_deprecated # if YYJSON_MSC_VER >= 1400 # define yyjson_deprecated(msg) __declspec(deprecated(msg)) # elif yyjson_has_feature(attribute_deprecated_with_message) || \ (YYJSON_GCC_VER > 4 || (YYJSON_GCC_VER == 4 && __GNUC_MINOR__ >= 5)) # define yyjson_deprecated(msg) __attribute__((deprecated(msg))) # elif YYJSON_GCC_VER >= 3 # define yyjson_deprecated(msg) __attribute__((deprecated)) # else # define yyjson_deprecated(msg) # endif #endif /** function export */ #ifndef yyjson_api # if defined(_WIN32) # if defined(YYJSON_EXPORTS) && YYJSON_EXPORTS # define yyjson_api __declspec(dllexport) # elif defined(YYJSON_IMPORTS) && YYJSON_IMPORTS # define yyjson_api __declspec(dllimport) # else # define yyjson_api # endif # elif yyjson_has_attribute(visibility) || YYJSON_GCC_VER >= 4 # define yyjson_api __attribute__((visibility("default"))) # else # define yyjson_api # endif #endif /** inline function export */ #ifndef yyjson_api_inline # define yyjson_api_inline static yyjson_inline #endif /** stdint (C89 compatible) */ #if (defined(YYJSON_HAS_STDINT_H) && YYJSON_HAS_STDINT_H) || \ YYJSON_MSC_VER >= 1600 || YYJSON_STDC_VER >= 199901L || \ defined(_STDINT_H) || defined(_STDINT_H_) || \ defined(__CLANG_STDINT_H) || defined(_STDINT_H_INCLUDED) || \ yyjson_has_include() # include #elif defined(_MSC_VER) # if _MSC_VER < 1300 typedef signed char int8_t; typedef signed short int16_t; typedef signed int int32_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; # else typedef signed __int8 int8_t; typedef signed __int16 int16_t; typedef signed __int32 int32_t; typedef unsigned __int8 uint8_t; typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; # endif #else # if UCHAR_MAX == 0xFFU typedef signed char int8_t; typedef unsigned char uint8_t; # else # error cannot find 8-bit integer type # endif # if USHRT_MAX == 0xFFFFU typedef unsigned short uint16_t; typedef signed short int16_t; # elif UINT_MAX == 0xFFFFU typedef unsigned int uint16_t; typedef signed int int16_t; # else # error cannot find 16-bit integer type # endif # if UINT_MAX == 0xFFFFFFFFUL typedef unsigned int uint32_t; typedef signed int int32_t; # elif ULONG_MAX == 0xFFFFFFFFUL typedef unsigned long uint32_t; typedef signed long int32_t; # elif USHRT_MAX == 0xFFFFFFFFUL typedef unsigned short uint32_t; typedef signed short int32_t; # else # error cannot find 32-bit integer type # endif # if defined(__INT64_TYPE__) && defined(__UINT64_TYPE__) typedef __INT64_TYPE__ int64_t; typedef __UINT64_TYPE__ uint64_t; # elif defined(__GNUC__) || defined(__clang__) # if !defined(_SYS_TYPES_H) && !defined(__int8_t_defined) __extension__ typedef long long int64_t; # endif __extension__ typedef unsigned long long uint64_t; # elif defined(_LONG_LONG) || defined(__MWERKS__) || defined(_CRAYC) || \ defined(__SUNPRO_C) || defined(__SUNPRO_CC) typedef long long int64_t; typedef unsigned long long uint64_t; # elif (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || \ defined(__WATCOM_INT64__) || defined (__alpha) || defined (__DECC) typedef __int64 int64_t; typedef unsigned __int64 uint64_t; # else # error cannot find 64-bit integer type # endif #endif /** stdbool (C89 compatible) */ #if (defined(YYJSON_HAS_STDBOOL_H) && YYJSON_HAS_STDBOOL_H) || \ (yyjson_has_include() && !defined(__STRICT_ANSI__)) || \ YYJSON_MSC_VER >= 1800 || YYJSON_STDC_VER >= 199901L # include #elif !defined(__bool_true_false_are_defined) # define __bool_true_false_are_defined 1 # if defined(__cplusplus) # if defined(__GNUC__) && !defined(__STRICT_ANSI__) # define _Bool bool # if __cplusplus < 201103L # define bool bool # define false false # define true true # endif # endif # else # define bool unsigned char # define true 1 # define false 0 # endif #endif /** char bit check */ #if defined(CHAR_BIT) # if CHAR_BIT != 8 # error non 8-bit char is not supported # endif #endif /** Microsoft Visual C++ 6.0 doesn't support converting number from u64 to f64: error C2520: conversion from unsigned __int64 to double not implemented. */ #ifndef YYJSON_U64_TO_F64_NO_IMPL # if (0 < YYJSON_MSC_VER) && (YYJSON_MSC_VER <= 1200) # define YYJSON_U64_TO_F64_NO_IMPL 1 # else # define YYJSON_U64_TO_F64_NO_IMPL 0 # endif #endif /*============================================================================== * Compile Hint Begin *============================================================================*/ /* extern "C" begin */ #ifdef __cplusplus extern "C" { #endif /* warning suppress begin */ #if defined(__clang__) # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunused-function" # pragma clang diagnostic ignored "-Wunused-parameter" #elif defined(__GNUC__) # if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) # pragma GCC diagnostic push # endif # pragma GCC diagnostic ignored "-Wunused-function" # pragma GCC diagnostic ignored "-Wunused-parameter" #elif defined(_MSC_VER) # pragma warning(push) # pragma warning(disable:4800) /* 'int': forcing value to 'true' or 'false' */ #endif /*============================================================================== * Version *============================================================================*/ /** The major version of yyjson. */ #define YYJSON_VERSION_MAJOR 0 /** The minor version of yyjson. */ #define YYJSON_VERSION_MINOR 9 /** The patch version of yyjson. */ #define YYJSON_VERSION_PATCH 0 /** The version of yyjson in hex: `(major << 16) | (minor << 8) | (patch)`. */ #define YYJSON_VERSION_HEX 0x000900 /** The version string of yyjson. */ #define YYJSON_VERSION_STRING "0.9.0" /** The version of yyjson in hex, same as `YYJSON_VERSION_HEX`. */ yyjson_api uint32_t yyjson_version(void); /*============================================================================== * JSON Types *============================================================================*/ /** Type of a JSON value (3 bit). */ typedef uint8_t yyjson_type; /** No type, invalid. */ #define YYJSON_TYPE_NONE ((uint8_t)0) /* _____000 */ /** Raw string type, no subtype. */ #define YYJSON_TYPE_RAW ((uint8_t)1) /* _____001 */ /** Null type: `null` literal, no subtype. */ #define YYJSON_TYPE_NULL ((uint8_t)2) /* _____010 */ /** Boolean type, subtype: TRUE, FALSE. */ #define YYJSON_TYPE_BOOL ((uint8_t)3) /* _____011 */ /** Number type, subtype: UINT, SINT, REAL. */ #define YYJSON_TYPE_NUM ((uint8_t)4) /* _____100 */ /** String type, subtype: NONE, NOESC. */ #define YYJSON_TYPE_STR ((uint8_t)5) /* _____101 */ /** Array type, no subtype. */ #define YYJSON_TYPE_ARR ((uint8_t)6) /* _____110 */ /** Object type, no subtype. */ #define YYJSON_TYPE_OBJ ((uint8_t)7) /* _____111 */ /** Subtype of a JSON value (2 bit). */ typedef uint8_t yyjson_subtype; /** No subtype. */ #define YYJSON_SUBTYPE_NONE ((uint8_t)(0 << 3)) /* ___00___ */ /** False subtype: `false` literal. */ #define YYJSON_SUBTYPE_FALSE ((uint8_t)(0 << 3)) /* ___00___ */ /** True subtype: `true` literal. */ #define YYJSON_SUBTYPE_TRUE ((uint8_t)(1 << 3)) /* ___01___ */ /** Unsigned integer subtype: `uint64_t`. */ #define YYJSON_SUBTYPE_UINT ((uint8_t)(0 << 3)) /* ___00___ */ /** Signed integer subtype: `int64_t`. */ #define YYJSON_SUBTYPE_SINT ((uint8_t)(1 << 3)) /* ___01___ */ /** Real number subtype: `double`. */ #define YYJSON_SUBTYPE_REAL ((uint8_t)(2 << 3)) /* ___10___ */ /** String that do not need to be escaped for writing (internal use). */ #define YYJSON_SUBTYPE_NOESC ((uint8_t)(1 << 3)) /* ___01___ */ /** The mask used to extract the type of a JSON value. */ #define YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */ /** The number of bits used by the type. */ #define YYJSON_TYPE_BIT ((uint8_t)3) /** The mask used to extract the subtype of a JSON value. */ #define YYJSON_SUBTYPE_MASK ((uint8_t)0x18) /* ___11___ */ /** The number of bits used by the subtype. */ #define YYJSON_SUBTYPE_BIT ((uint8_t)2) /** The mask used to extract the reserved bits of a JSON value. */ #define YYJSON_RESERVED_MASK ((uint8_t)0xE0) /* 111_____ */ /** The number of reserved bits. */ #define YYJSON_RESERVED_BIT ((uint8_t)3) /** The mask used to extract the tag of a JSON value. */ #define YYJSON_TAG_MASK ((uint8_t)0xFF) /* 11111111 */ /** The number of bits used by the tag. */ #define YYJSON_TAG_BIT ((uint8_t)8) /** Padding size for JSON reader. */ #define YYJSON_PADDING_SIZE 4 /*============================================================================== * Allocator *============================================================================*/ /** A memory allocator. Typically you don't need to use it, unless you want to customize your own memory allocator. */ typedef struct yyjson_alc { /** Same as libc's malloc(size), should not be NULL. */ void *(*malloc)(void *ctx, size_t size); /** Same as libc's realloc(ptr, size), should not be NULL. */ void *(*realloc)(void *ctx, void *ptr, size_t old_size, size_t size); /** Same as libc's free(ptr), should not be NULL. */ void (*free)(void *ctx, void *ptr); /** A context for malloc/realloc/free, can be NULL. */ void *ctx; } yyjson_alc; /** A pool allocator uses fixed length pre-allocated memory. This allocator may be used to avoid malloc/realloc calls. The pre-allocated memory should be held by the caller. The maximum amount of memory required to read a JSON can be calculated using the `yyjson_read_max_memory_usage()` function, but the amount of memory required to write a JSON cannot be directly calculated. This is not a general-purpose allocator. It is designed to handle a single JSON data at a time. If it is used for overly complex memory tasks, such as parsing multiple JSON documents using the same allocator but releasing only a few of them, it may cause memory fragmentation, resulting in performance degradation and memory waste. @param alc The allocator to be initialized. If this parameter is NULL, the function will fail and return false. If `buf` or `size` is invalid, this will be set to an empty allocator. @param buf The buffer memory for this allocator. If this parameter is NULL, the function will fail and return false. @param size The size of `buf`, in bytes. If this parameter is less than 8 words (32/64 bytes on 32/64-bit OS), the function will fail and return false. @return true if the `alc` has been successfully initialized. @par Example @code // parse JSON with stack memory char buf[1024]; yyjson_alc alc; yyjson_alc_pool_init(&alc, buf, 1024); const char *json = "{\"name\":\"Helvetica\",\"size\":16}" yyjson_doc *doc = yyjson_read_opts(json, strlen(json), 0, &alc, NULL); // the memory of `doc` is on the stack @endcode @warning This Allocator is not thread-safe. */ yyjson_api bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, size_t size); /** A dynamic allocator. This allocator has a similar usage to the pool allocator above. However, when there is not enough memory, this allocator will dynamically request more memory using libc's `malloc` function, and frees it all at once when it is destroyed. @return A new dynamic allocator, or NULL if memory allocation failed. @note The returned value should be freed with `yyjson_alc_dyn_free()`. @warning This Allocator is not thread-safe. */ yyjson_api yyjson_alc *yyjson_alc_dyn_new(void); /** Free a dynamic allocator which is created by `yyjson_alc_dyn_new()`. @param alc The dynamic allocator to be destroyed. */ yyjson_api void yyjson_alc_dyn_free(yyjson_alc *alc); /*============================================================================== * JSON Structure *============================================================================*/ /** An immutable document for reading JSON. This document holds memory for all its JSON values and strings. When it is no longer used, the user should call `yyjson_doc_free()` to free its memory. */ typedef struct yyjson_doc yyjson_doc; /** An immutable value for reading JSON. A JSON Value has the same lifetime as its document. The memory is held by its document and and cannot be freed alone. */ typedef struct yyjson_val yyjson_val; /** A mutable document for building JSON. This document holds memory for all its JSON values and strings. When it is no longer used, the user should call `yyjson_mut_doc_free()` to free its memory. */ typedef struct yyjson_mut_doc yyjson_mut_doc; /** A mutable value for building JSON. A JSON Value has the same lifetime as its document. The memory is held by its document and and cannot be freed alone. */ typedef struct yyjson_mut_val yyjson_mut_val; /*============================================================================== * JSON Reader API *============================================================================*/ /** Run-time options for JSON reader. */ typedef uint32_t yyjson_read_flag; /** Default option (RFC 8259 compliant): - Read positive integer as uint64_t. - Read negative integer as int64_t. - Read floating-point number as double with round-to-nearest mode. - Read integer which cannot fit in uint64_t or int64_t as double. - Report error if double number is infinity. - Report error if string contains invalid UTF-8 character or BOM. - Report error on trailing commas, comments, inf and nan literals. */ static const yyjson_read_flag YYJSON_READ_NOFLAG = 0; /** Read the input data in-situ. This option allows the reader to modify and use input data to store string values, which can increase reading speed slightly. The caller should hold the input data before free the document. The input data must be padded by at least `YYJSON_PADDING_SIZE` bytes. For example: `[1,2]` should be `[1,2]\0\0\0\0`, input length should be 5. */ static const yyjson_read_flag YYJSON_READ_INSITU = 1 << 0; /** Stop when done instead of issuing an error if there's additional content after a JSON document. This option may be used to parse small pieces of JSON in larger data, such as `NDJSON`. */ static const yyjson_read_flag YYJSON_READ_STOP_WHEN_DONE = 1 << 1; /** Allow single trailing comma at the end of an object or array, such as `[1,2,3,]`, `{"a":1,"b":2,}` (non-standard). */ static const yyjson_read_flag YYJSON_READ_ALLOW_TRAILING_COMMAS = 1 << 2; /** Allow C-style single line and multiple line comments (non-standard). */ static const yyjson_read_flag YYJSON_READ_ALLOW_COMMENTS = 1 << 3; /** Allow inf/nan number and literal, case-insensitive, such as 1e999, NaN, inf, -Infinity (non-standard). */ static const yyjson_read_flag YYJSON_READ_ALLOW_INF_AND_NAN = 1 << 4; /** Read all numbers as raw strings (value with `YYJSON_TYPE_RAW` type), inf/nan literal is also read as raw with `ALLOW_INF_AND_NAN` flag. */ static const yyjson_read_flag YYJSON_READ_NUMBER_AS_RAW = 1 << 5; /** Allow reading invalid unicode when parsing string values (non-standard). Invalid characters will be allowed to appear in the string values, but invalid escape sequences will still be reported as errors. This flag does not affect the performance of correctly encoded strings. @warning Strings in JSON values may contain incorrect encoding when this option is used, you need to handle these strings carefully to avoid security risks. */ static const yyjson_read_flag YYJSON_READ_ALLOW_INVALID_UNICODE = 1 << 6; /** Read big numbers as raw strings. These big numbers include integers that cannot be represented by `int64_t` and `uint64_t`, and floating-point numbers that cannot be represented by finite `double`. The flag will be overridden by `YYJSON_READ_NUMBER_AS_RAW` flag. */ static const yyjson_read_flag YYJSON_READ_BIGNUM_AS_RAW = 1 << 7; /** Result code for JSON reader. */ typedef uint32_t yyjson_read_code; /** Success, no error. */ static const yyjson_read_code YYJSON_READ_SUCCESS = 0; /** Invalid parameter, such as NULL input string or 0 input length. */ static const yyjson_read_code YYJSON_READ_ERROR_INVALID_PARAMETER = 1; /** Memory allocation failure occurs. */ static const yyjson_read_code YYJSON_READ_ERROR_MEMORY_ALLOCATION = 2; /** Input JSON string is empty. */ static const yyjson_read_code YYJSON_READ_ERROR_EMPTY_CONTENT = 3; /** Unexpected content after document, such as `[123]abc`. */ static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CONTENT = 4; /** Unexpected ending, such as `[123`. */ static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_END = 5; /** Unexpected character inside the document, such as `[abc]`. */ static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CHARACTER = 6; /** Invalid JSON structure, such as `[1,]`. */ static const yyjson_read_code YYJSON_READ_ERROR_JSON_STRUCTURE = 7; /** Invalid comment, such as unclosed multi-line comment. */ static const yyjson_read_code YYJSON_READ_ERROR_INVALID_COMMENT = 8; /** Invalid number, such as `123.e12`, `000`. */ static const yyjson_read_code YYJSON_READ_ERROR_INVALID_NUMBER = 9; /** Invalid string, such as invalid escaped character inside a string. */ static const yyjson_read_code YYJSON_READ_ERROR_INVALID_STRING = 10; /** Invalid JSON literal, such as `truu`. */ static const yyjson_read_code YYJSON_READ_ERROR_LITERAL = 11; /** Failed to open a file. */ static const yyjson_read_code YYJSON_READ_ERROR_FILE_OPEN = 12; /** Failed to read a file. */ static const yyjson_read_code YYJSON_READ_ERROR_FILE_READ = 13; /** Document exceeded YYJSON_READER_CONTAINER_RECURSION_LIMIT. */ static const yyjson_read_code YYJSON_READ_ERROR_RECURSION_DEPTH = 14; /** Error information for JSON reader. */ typedef struct yyjson_read_err { /** Error code, see `yyjson_read_code` for all possible values. */ yyjson_read_code code; /** Error message, constant, no need to free (NULL if success). */ const char *msg; /** Error byte position for input data (0 if success). */ size_t pos; } yyjson_read_err; /** Read JSON with options. This function is thread-safe when: 1. The `dat` is not modified by other threads. 2. The `alc` is thread-safe or NULL. @param dat The JSON data (UTF-8 without BOM), null-terminator is not required. If this parameter is NULL, the function will fail and return NULL. The `dat` will not be modified without the flag `YYJSON_READ_INSITU`, so you can pass a `const char *` string and case it to `char *` if you don't use the `YYJSON_READ_INSITU` flag. @param len The length of JSON data in bytes. If this parameter is 0, the function will fail and return NULL. @param alc The memory allocator used by JSON reader. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return A new JSON document, or NULL if an error occurs. When it's no longer needed, it should be freed with `yyjson_doc_free()`. */ yyjson_api yyjson_doc *yyjson_read_opts(char *dat, size_t len, const yyjson_alc *alc, yyjson_read_err *err); /** Read a JSON file. This function is thread-safe when: 1. The file is not modified by other threads. 2. The `alc` is thread-safe or NULL. @param path The JSON file's path. If this path is NULL or invalid, the function will fail and return NULL. @param flg The JSON read options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON reader. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return A new JSON document, or NULL if an error occurs. When it's no longer needed, it should be freed with `yyjson_doc_free()`. @warning On 32-bit operating system, files larger than 2GB may fail to read. */ yyjson_api yyjson_doc *yyjson_read_file(const char *path, yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err); /** Read JSON from a file pointer. @param fp The file pointer. The data will be read from the current position of the FILE to the end. If this fp is NULL or invalid, the function will fail and return NULL. @param flg The JSON read options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON reader. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return A new JSON document, or NULL if an error occurs. When it's no longer needed, it should be freed with `yyjson_doc_free()`. @warning On 32-bit operating system, files larger than 2GB may fail to read. */ yyjson_api yyjson_doc *yyjson_read_fp(FILE *fp, yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err); /** Read a JSON string. This function is thread-safe. @param dat The JSON data (UTF-8 without BOM), null-terminator is not required. If this parameter is NULL, the function will fail and return NULL. @param len The length of JSON data in bytes. If this parameter is 0, the function will fail and return NULL. @param flg The JSON read options. Multiple options can be combined with `|` operator. 0 means no options. @return A new JSON document, or NULL if an error occurs. When it's no longer needed, it should be freed with `yyjson_doc_free()`. */ yyjson_api_inline yyjson_doc *yyjson_read(const char *dat, size_t len, yyjson_read_flag flg) { flg &= ~YYJSON_READ_INSITU; /* const string cannot be modified */ return yyjson_read_opts((char *)(void *)(size_t)(const void *)dat, len, NULL, NULL); } /** Returns the size of maximum memory usage to read a JSON data. You may use this value to avoid malloc() or calloc() call inside the reader to get better performance, or read multiple JSON with one piece of memory. @param len The length of JSON data in bytes. @param flg The JSON read options. @return The maximum memory size to read this JSON, or 0 if overflow. @par Example @code // read multiple JSON with same pre-allocated memory char *dat1, *dat2, *dat3; // JSON data size_t len1, len2, len3; // JSON length size_t max_len = MAX(len1, MAX(len2, len3)); yyjson_doc *doc; // use one allocator for multiple JSON size_t size = yyjson_read_max_memory_usage(max_len, 0); void *buf = malloc(size); yyjson_alc alc; yyjson_alc_pool_init(&alc, buf, size); // no more alloc() or realloc() call during reading doc = yyjson_read_opts(dat1, len1, 0, &alc, NULL); yyjson_doc_free(doc); doc = yyjson_read_opts(dat2, len2, 0, &alc, NULL); yyjson_doc_free(doc); doc = yyjson_read_opts(dat3, len3, 0, &alc, NULL); yyjson_doc_free(doc); free(buf); @endcode @see yyjson_alc_pool_init() */ yyjson_api_inline size_t yyjson_read_max_memory_usage(size_t len, yyjson_read_flag flg) { /* 1. The max value count is (json_size / 2 + 1), for example: "[1,2,3,4]" size is 9, value count is 5. 2. Some broken JSON may cost more memory during reading, but fail at end, for example: "[[[[[[[[". 3. yyjson use 16 bytes per value, see struct yyjson_val. 4. yyjson use dynamic memory with a growth factor of 1.5. The max memory size is (json_size / 2 * 16 * 1.5 + padding). */ size_t mul = (size_t)12 + !(flg & YYJSON_READ_INSITU); size_t pad = 256; size_t max = (size_t)(~(size_t)0); if (flg & YYJSON_READ_STOP_WHEN_DONE) len = len < 256 ? 256 : len; if (len >= (max - pad - mul) / mul) return 0; return len * mul + pad; } /** Read a JSON number. This function is thread-safe when data is not modified by other threads. @param dat The JSON data (UTF-8 without BOM), null-terminator is required. If this parameter is NULL, the function will fail and return NULL. @param val The output value where result is stored. If this parameter is NULL, the function will fail and return NULL. The value will hold either UINT or SINT or REAL number; @param flg The JSON read options. Multiple options can be combined with `|` operator. 0 means no options. Supports `YYJSON_READ_NUMBER_AS_RAW` and `YYJSON_READ_ALLOW_INF_AND_NAN`. @param alc The memory allocator used for long number. It is only used when the built-in floating point reader is disabled. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return If successful, a pointer to the character after the last character used in the conversion, NULL if an error occurs. */ yyjson_api const char *yyjson_read_number(const char *dat, yyjson_val *val, yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err); /** Read a JSON number. This function is thread-safe when data is not modified by other threads. @param dat The JSON data (UTF-8 without BOM), null-terminator is required. If this parameter is NULL, the function will fail and return NULL. @param val The output value where result is stored. If this parameter is NULL, the function will fail and return NULL. The value will hold either UINT or SINT or REAL number; @param flg The JSON read options. Multiple options can be combined with `|` operator. 0 means no options. Supports `YYJSON_READ_NUMBER_AS_RAW` and `YYJSON_READ_ALLOW_INF_AND_NAN`. @param alc The memory allocator used for long number. It is only used when the built-in floating point reader is disabled. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return If successful, a pointer to the character after the last character used in the conversion, NULL if an error occurs. */ yyjson_api_inline const char *yyjson_mut_read_number(const char *dat, yyjson_mut_val *val, yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err) { return yyjson_read_number(dat, (yyjson_val *)val, flg, alc, err); } /*============================================================================== * JSON Writer API *============================================================================*/ /** Run-time options for JSON writer. */ typedef uint32_t yyjson_write_flag; /** Default option: - Write JSON minify. - Report error on inf or nan number. - Report error on invalid UTF-8 string. - Do not escape unicode or slash. */ static const yyjson_write_flag YYJSON_WRITE_NOFLAG = 0; /** Write JSON pretty with 4 space indent. */ static const yyjson_write_flag YYJSON_WRITE_PRETTY = 1 << 0; /** Escape unicode as `uXXXX`, make the output ASCII only. */ static const yyjson_write_flag YYJSON_WRITE_ESCAPE_UNICODE = 1 << 1; /** Escape '/' as '\/'. */ static const yyjson_write_flag YYJSON_WRITE_ESCAPE_SLASHES = 1 << 2; /** Write inf and nan number as 'Infinity' and 'NaN' literal (non-standard). */ static const yyjson_write_flag YYJSON_WRITE_ALLOW_INF_AND_NAN = 1 << 3; /** Write inf and nan number as null literal. This flag will override `YYJSON_WRITE_ALLOW_INF_AND_NAN` flag. */ static const yyjson_write_flag YYJSON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4; /** Allow invalid unicode when encoding string values (non-standard). Invalid characters in string value will be copied byte by byte. If `YYJSON_WRITE_ESCAPE_UNICODE` flag is also set, invalid character will be escaped as `U+FFFD` (replacement character). This flag does not affect the performance of correctly encoded strings. */ static const yyjson_write_flag YYJSON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5; /** Write JSON pretty with 2 space indent. This flag will override `YYJSON_WRITE_PRETTY` flag. */ static const yyjson_write_flag YYJSON_WRITE_PRETTY_TWO_SPACES = 1 << 6; /** Adds a newline character `\n` at the end of the JSON. This can be helpful for text editors or NDJSON. */ static const yyjson_write_flag YYJSON_WRITE_NEWLINE_AT_END = 1 << 7; /** Result code for JSON writer */ typedef uint32_t yyjson_write_code; /** Success, no error. */ static const yyjson_write_code YYJSON_WRITE_SUCCESS = 0; /** Invalid parameter, such as NULL document. */ static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_PARAMETER = 1; /** Memory allocation failure occurs. */ static const yyjson_write_code YYJSON_WRITE_ERROR_MEMORY_ALLOCATION = 2; /** Invalid value type in JSON document. */ static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_VALUE_TYPE = 3; /** NaN or Infinity number occurs. */ static const yyjson_write_code YYJSON_WRITE_ERROR_NAN_OR_INF = 4; /** Failed to open a file. */ static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_OPEN = 5; /** Failed to write a file. */ static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_WRITE = 6; /** Invalid unicode in string. */ static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_STRING = 7; /** Error information for JSON writer. */ typedef struct yyjson_write_err { /** Error code, see `yyjson_write_code` for all possible values. */ yyjson_write_code code; /** Error message, constant, no need to free (NULL if success). */ const char *msg; } yyjson_write_err; /*============================================================================== * JSON Document Writer API *============================================================================*/ /** Write a document to JSON string with options. This function is thread-safe when: The `alc` is thread-safe or NULL. @param doc The JSON document. If this doc is NULL or has no root, the function will fail and return false. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param len A pointer to receive output length in bytes (not including the null-terminator). Pass NULL if you don't need length information. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free() or alc->free(). */ yyjson_api char *yyjson_write_opts(const yyjson_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc, size_t *len, yyjson_write_err *err); /** Write a document to JSON file with options. This function is thread-safe when: 1. The file is not accessed by other threads. 2. The `alc` is thread-safe or NULL. @param path The JSON file's path. If this path is NULL or invalid, the function will fail and return false. If this file is not empty, the content will be discarded. @param doc The JSON document. If this doc is NULL or has no root, the function will fail and return false. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return true if successful, false if an error occurs. @warning On 32-bit operating system, files larger than 2GB may fail to write. */ yyjson_api bool yyjson_write_file(const char *path, const yyjson_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc, yyjson_write_err *err); /** Write a document to file pointer with options. @param fp The file pointer. The data will be written to the current position of the file. If this fp is NULL or invalid, the function will fail and return false. @param doc The JSON document. If this doc is NULL or has no root, the function will fail and return false. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return true if successful, false if an error occurs. @warning On 32-bit operating system, files larger than 2GB may fail to write. */ yyjson_api bool yyjson_write_fp(FILE *fp, const yyjson_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc, yyjson_write_err *err); /** Write a document to JSON string. This function is thread-safe. @param doc The JSON document. If this doc is NULL or has no root, the function will fail and return false. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param len A pointer to receive output length in bytes (not including the null-terminator). Pass NULL if you don't need length information. @return A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free(). */ yyjson_api_inline char *yyjson_write(const yyjson_doc *doc, yyjson_write_flag flg, size_t *len) { return yyjson_write_opts(doc, flg, NULL, len, NULL); } /** Write a document to JSON string with options. This function is thread-safe when: 1. The `doc` is not modified by other threads. 2. The `alc` is thread-safe or NULL. @param doc The mutable JSON document. If this doc is NULL or has no root, the function will fail and return false. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param len A pointer to receive output length in bytes (not including the null-terminator). Pass NULL if you don't need length information. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free() or alc->free(). */ yyjson_api char *yyjson_mut_write_opts(const yyjson_mut_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc, size_t *len, yyjson_write_err *err); /** Write a document to JSON file with options. This function is thread-safe when: 1. The file is not accessed by other threads. 2. The `doc` is not modified by other threads. 3. The `alc` is thread-safe or NULL. @param path The JSON file's path. If this path is NULL or invalid, the function will fail and return false. If this file is not empty, the content will be discarded. @param doc The mutable JSON document. If this doc is NULL or has no root, the function will fail and return false. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return true if successful, false if an error occurs. @warning On 32-bit operating system, files larger than 2GB may fail to write. */ yyjson_api bool yyjson_mut_write_file(const char *path, const yyjson_mut_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc, yyjson_write_err *err); /** Write a document to file pointer with options. @param fp The file pointer. The data will be written to the current position of the file. If this fp is NULL or invalid, the function will fail and return false. @param doc The mutable JSON document. If this doc is NULL or has no root, the function will fail and return false. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return true if successful, false if an error occurs. @warning On 32-bit operating system, files larger than 2GB may fail to write. */ yyjson_api bool yyjson_mut_write_fp(FILE *fp, const yyjson_mut_doc *doc, yyjson_write_flag flg, const yyjson_alc *alc, yyjson_write_err *err); /** Write a document to JSON string. This function is thread-safe when: The `doc` is not modified by other threads. @param doc The JSON document. If this doc is NULL or has no root, the function will fail and return false. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param len A pointer to receive output length in bytes (not including the null-terminator). Pass NULL if you don't need length information. @return A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free(). */ yyjson_api_inline char *yyjson_mut_write(const yyjson_mut_doc *doc, yyjson_write_flag flg, size_t *len) { return yyjson_mut_write_opts(doc, flg, NULL, len, NULL); } /*============================================================================== * JSON Value Writer API *============================================================================*/ /** Write a value to JSON string with options. This function is thread-safe when: The `alc` is thread-safe or NULL. @param val The JSON root value. If this parameter is NULL, the function will fail and return NULL. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param len A pointer to receive output length in bytes (not including the null-terminator). Pass NULL if you don't need length information. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free() or alc->free(). */ yyjson_api char *yyjson_val_write_opts(const yyjson_val *val, yyjson_write_flag flg, const yyjson_alc *alc, size_t *len, yyjson_write_err *err); /** Write a value to JSON file with options. This function is thread-safe when: 1. The file is not accessed by other threads. 2. The `alc` is thread-safe or NULL. @param path The JSON file's path. If this path is NULL or invalid, the function will fail and return false. If this file is not empty, the content will be discarded. @param val The JSON root value. If this parameter is NULL, the function will fail and return NULL. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return true if successful, false if an error occurs. @warning On 32-bit operating system, files larger than 2GB may fail to write. */ yyjson_api bool yyjson_val_write_file(const char *path, const yyjson_val *val, yyjson_write_flag flg, const yyjson_alc *alc, yyjson_write_err *err); /** Write a value to file pointer with options. @param fp The file pointer. The data will be written to the current position of the file. If this path is NULL or invalid, the function will fail and return false. @param val The JSON root value. If this parameter is NULL, the function will fail and return NULL. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return true if successful, false if an error occurs. @warning On 32-bit operating system, files larger than 2GB may fail to write. */ yyjson_api bool yyjson_val_write_fp(FILE *fp, const yyjson_val *val, yyjson_write_flag flg, const yyjson_alc *alc, yyjson_write_err *err); /** Write a value to JSON string. This function is thread-safe. @param val The JSON root value. If this parameter is NULL, the function will fail and return NULL. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param len A pointer to receive output length in bytes (not including the null-terminator). Pass NULL if you don't need length information. @return A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free(). */ yyjson_api_inline char *yyjson_val_write(const yyjson_val *val, yyjson_write_flag flg, size_t *len) { return yyjson_val_write_opts(val, flg, NULL, len, NULL); } /** Write a value to JSON string with options. This function is thread-safe when: 1. The `val` is not modified by other threads. 2. The `alc` is thread-safe or NULL. @param val The mutable JSON root value. If this parameter is NULL, the function will fail and return NULL. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param len A pointer to receive output length in bytes (not including the null-terminator). Pass NULL if you don't need length information. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free() or alc->free(). */ yyjson_api char *yyjson_mut_val_write_opts(const yyjson_mut_val *val, yyjson_write_flag flg, const yyjson_alc *alc, size_t *len, yyjson_write_err *err); /** Write a value to JSON file with options. This function is thread-safe when: 1. The file is not accessed by other threads. 2. The `val` is not modified by other threads. 3. The `alc` is thread-safe or NULL. @param path The JSON file's path. If this path is NULL or invalid, the function will fail and return false. If this file is not empty, the content will be discarded. @param val The mutable JSON root value. If this parameter is NULL, the function will fail and return NULL. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return true if successful, false if an error occurs. @warning On 32-bit operating system, files larger than 2GB may fail to write. */ yyjson_api bool yyjson_mut_val_write_file(const char *path, const yyjson_mut_val *val, yyjson_write_flag flg, const yyjson_alc *alc, yyjson_write_err *err); /** Write a value to JSON file with options. @param fp The file pointer. The data will be written to the current position of the file. If this path is NULL or invalid, the function will fail and return false. @param val The mutable JSON root value. If this parameter is NULL, the function will fail and return NULL. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param alc The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. @param err A pointer to receive error information. Pass NULL if you don't need error information. @return true if successful, false if an error occurs. @warning On 32-bit operating system, files larger than 2GB may fail to write. */ yyjson_api bool yyjson_mut_val_write_fp(FILE *fp, const yyjson_mut_val *val, yyjson_write_flag flg, const yyjson_alc *alc, yyjson_write_err *err); /** Write a value to JSON string. This function is thread-safe when: The `val` is not modified by other threads. @param val The JSON root value. If this parameter is NULL, the function will fail and return NULL. @param flg The JSON write options. Multiple options can be combined with `|` operator. 0 means no options. @param len A pointer to receive output length in bytes (not including the null-terminator). Pass NULL if you don't need length information. @return A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free(). */ yyjson_api_inline char *yyjson_mut_val_write(const yyjson_mut_val *val, yyjson_write_flag flg, size_t *len) { return yyjson_mut_val_write_opts(val, flg, NULL, len, NULL); } /*============================================================================== * JSON Document API *============================================================================*/ /** Returns the root value of this JSON document. Returns NULL if `doc` is NULL. */ yyjson_api_inline yyjson_val *yyjson_doc_get_root(yyjson_doc *doc); /** Returns read size of input JSON data. Returns 0 if `doc` is NULL. For example: the read size of `[1,2,3]` is 7 bytes. */ yyjson_api_inline size_t yyjson_doc_get_read_size(yyjson_doc *doc); /** Returns total value count in this JSON document. Returns 0 if `doc` is NULL. For example: the value count of `[1,2,3]` is 4. */ yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc); /** Release the JSON document and free the memory. After calling this function, the `doc` and all values from the `doc` are no longer available. This function will do nothing if the `doc` is NULL. */ yyjson_api void yyjson_doc_free(yyjson_doc *doc); /*============================================================================== * JSON Value Type API *============================================================================*/ /** Returns whether the JSON value is raw. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_raw(yyjson_val *val); /** Returns whether the JSON value is `null`. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_null(yyjson_val *val); /** Returns whether the JSON value is `true`. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_true(yyjson_val *val); /** Returns whether the JSON value is `false`. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_false(yyjson_val *val); /** Returns whether the JSON value is bool (true/false). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_bool(yyjson_val *val); /** Returns whether the JSON value is unsigned integer (uint64_t). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_uint(yyjson_val *val); /** Returns whether the JSON value is signed integer (int64_t). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_sint(yyjson_val *val); /** Returns whether the JSON value is integer (uint64_t/int64_t). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_int(yyjson_val *val); /** Returns whether the JSON value is real number (double). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_real(yyjson_val *val); /** Returns whether the JSON value is number (uint64_t/int64_t/double). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_num(yyjson_val *val); /** Returns whether the JSON value is string. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_str(yyjson_val *val); /** Returns whether the JSON value is array. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_arr(yyjson_val *val); /** Returns whether the JSON value is object. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_obj(yyjson_val *val); /** Returns whether the JSON value is container (array/object). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_is_ctn(yyjson_val *val); /*============================================================================== * JSON Value Content API *============================================================================*/ /** Returns the JSON value's type. Returns YYJSON_TYPE_NONE if `val` is NULL. */ yyjson_api_inline yyjson_type yyjson_get_type(yyjson_val *val); /** Returns the JSON value's subtype. Returns YYJSON_SUBTYPE_NONE if `val` is NULL. */ yyjson_api_inline yyjson_subtype yyjson_get_subtype(yyjson_val *val); /** Returns the JSON value's tag. Returns 0 if `val` is NULL. */ yyjson_api_inline uint8_t yyjson_get_tag(yyjson_val *val); /** Returns the JSON value's type description. The return value should be one of these strings: "raw", "null", "string", "array", "object", "true", "false", "uint", "sint", "real", "unknown". */ yyjson_api_inline const char *yyjson_get_type_desc(yyjson_val *val); /** Returns the content if the value is raw. Returns NULL if `val` is NULL or type is not raw. */ yyjson_api_inline const char *yyjson_get_raw(yyjson_val *val); /** Returns the content if the value is bool. Returns NULL if `val` is NULL or type is not bool. */ yyjson_api_inline bool yyjson_get_bool(yyjson_val *val); /** Returns the content and cast to uint64_t. Returns 0 if `val` is NULL or type is not integer(sint/uint). */ yyjson_api_inline uint64_t yyjson_get_uint(yyjson_val *val); /** Returns the content and cast to int64_t. Returns 0 if `val` is NULL or type is not integer(sint/uint). */ yyjson_api_inline int64_t yyjson_get_sint(yyjson_val *val); /** Returns the content and cast to int. Returns 0 if `val` is NULL or type is not integer(sint/uint). */ yyjson_api_inline int yyjson_get_int(yyjson_val *val); /** Returns the content if the value is real number, or 0.0 on error. Returns 0.0 if `val` is NULL or type is not real(double). */ yyjson_api_inline double yyjson_get_real(yyjson_val *val); /** Returns the content and typecast to `double` if the value is number. Returns 0.0 if `val` is NULL or type is not number(uint/sint/real). */ yyjson_api_inline double yyjson_get_num(yyjson_val *val); /** Returns the content if the value is string. Returns NULL if `val` is NULL or type is not string. */ yyjson_api_inline const char *yyjson_get_str(yyjson_val *val); /** Returns the content length (string length, array size, object size. Returns 0 if `val` is NULL or type is not string/array/object. */ yyjson_api_inline size_t yyjson_get_len(yyjson_val *val); /** Returns whether the JSON value is equals to a string. Returns false if input is NULL or type is not string. */ yyjson_api_inline bool yyjson_equals_str(yyjson_val *val, const char *str); /** Returns whether the JSON value is equals to a string. The `str` should be a UTF-8 string, null-terminator is not required. Returns false if input is NULL or type is not string. */ yyjson_api_inline bool yyjson_equals_strn(yyjson_val *val, const char *str, size_t len); /** Returns whether two JSON values are equal (deep compare). Returns false if input is NULL. @note the result may be inaccurate if object has duplicate keys. @warning This function is recursive and may cause a stack overflow if the object level is too deep. */ yyjson_api_inline bool yyjson_equals(yyjson_val *lhs, yyjson_val *rhs); /** Set the value to raw. Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_raw(yyjson_val *val, const char *raw, size_t len); /** Set the value to null. Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_null(yyjson_val *val); /** Set the value to bool. Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_bool(yyjson_val *val, bool num); /** Set the value to uint. Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_uint(yyjson_val *val, uint64_t num); /** Set the value to sint. Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_sint(yyjson_val *val, int64_t num); /** Set the value to int. Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_int(yyjson_val *val, int num); /** Set the value to real. Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_real(yyjson_val *val, double num); /** Set the value to string (null-terminated). Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_str(yyjson_val *val, const char *str); /** Set the value to string (with length). Returns false if input is NULL or `val` is object or array. @warning This will modify the `immutable` value, use with caution. */ yyjson_api_inline bool yyjson_set_strn(yyjson_val *val, const char *str, size_t len); /*============================================================================== * JSON Array API *============================================================================*/ /** Returns the number of elements in this array. Returns 0 if `arr` is NULL or type is not array. */ yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr); /** Returns the element at the specified position in this array. Returns NULL if array is NULL/empty or the index is out of bounds. @warning This function takes a linear search time if array is not flat. For example: `[1,{},3]` is flat, `[1,[2],3]` is not flat. */ yyjson_api_inline yyjson_val *yyjson_arr_get(yyjson_val *arr, size_t idx); /** Returns the first element of this array. Returns NULL if `arr` is NULL/empty or type is not array. */ yyjson_api_inline yyjson_val *yyjson_arr_get_first(yyjson_val *arr); /** Returns the last element of this array. Returns NULL if `arr` is NULL/empty or type is not array. @warning This function takes a linear search time if array is not flat. For example: `[1,{},3]` is flat, `[1,[2],3]` is not flat.*/ yyjson_api_inline yyjson_val *yyjson_arr_get_last(yyjson_val *arr); /*============================================================================== * JSON Array Iterator API *============================================================================*/ /** A JSON array iterator. @par Example @code yyjson_val *val; yyjson_arr_iter iter = yyjson_arr_iter_with(arr); while ((val = yyjson_arr_iter_next(&iter))) { your_func(val); } @endcode */ typedef struct yyjson_arr_iter { size_t idx; /**< next value's index */ size_t max; /**< maximum index (arr.size) */ yyjson_val *cur; /**< next value */ } yyjson_arr_iter; /** Initialize an iterator for this array. @param arr The array to be iterated over. If this parameter is NULL or not an array, `iter` will be set to empty. @param iter The iterator to be initialized. If this parameter is NULL, the function will fail and return false. @return true if the `iter` has been successfully initialized. @note The iterator does not need to be destroyed. */ yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr, yyjson_arr_iter *iter); /** Create an iterator with an array , same as `yyjson_arr_iter_init()`. @param arr The array to be iterated over. If this parameter is NULL or not an array, an empty iterator will returned. @return A new iterator for the array. @note The iterator does not need to be destroyed. */ yyjson_api_inline yyjson_arr_iter yyjson_arr_iter_with(yyjson_val *arr); /** Returns whether the iteration has more elements. If `iter` is NULL, this function will return false. */ yyjson_api_inline bool yyjson_arr_iter_has_next(yyjson_arr_iter *iter); /** Returns the next element in the iteration, or NULL on end. If `iter` is NULL, this function will return NULL. */ yyjson_api_inline yyjson_val *yyjson_arr_iter_next(yyjson_arr_iter *iter); /** Macro for iterating over an array. It works like iterator, but with a more intuitive API. @par Example @code size_t idx, max; yyjson_val *val; yyjson_arr_foreach(arr, idx, max, val) { your_func(idx, val); } @endcode */ #define yyjson_arr_foreach(arr, idx, max, val) \ for ((idx) = 0, \ (max) = yyjson_arr_size(arr), \ (val) = yyjson_arr_get_first(arr); \ (idx) < (max); \ (idx)++, \ (val) = unsafe_yyjson_get_next(val)) /*============================================================================== * JSON Object API *============================================================================*/ /** Returns the number of key-value pairs in this object. Returns 0 if `obj` is NULL or type is not object. */ yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj); /** Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if `obj/key` is NULL, or type is not object. The `key` should be a null-terminated UTF-8 string. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_val *yyjson_obj_get(yyjson_val *obj, const char *key); /** Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if `obj/key` is NULL, or type is not object. The `key` should be a UTF-8 string, null-terminator is not required. The `key_len` should be the length of the key, in bytes. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_val *yyjson_obj_getn(yyjson_val *obj, const char *key, size_t key_len); /*============================================================================== * JSON Object Iterator API *============================================================================*/ /** A JSON object iterator. @par Example @code yyjson_val *key, *val; yyjson_obj_iter iter = yyjson_obj_iter_with(obj); while ((key = yyjson_obj_iter_next(&iter))) { val = yyjson_obj_iter_get_val(key); your_func(key, val); } @endcode If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups: @code // {"k1":1, "k2": 3, "k3": 3} yyjson_val *key, *val; yyjson_obj_iter iter = yyjson_obj_iter_with(obj); yyjson_val *v1 = yyjson_obj_iter_get(&iter, "k1"); yyjson_val *v3 = yyjson_obj_iter_get(&iter, "k3"); @endcode @see yyjson_obj_iter_get() and yyjson_obj_iter_getn() */ typedef struct yyjson_obj_iter { size_t idx; /**< next key's index */ size_t max; /**< maximum key index (obj.size) */ yyjson_val *cur; /**< next key */ yyjson_val *obj; /**< the object being iterated */ } yyjson_obj_iter; /** Initialize an iterator for this object. @param obj The object to be iterated over. If this parameter is NULL or not an object, `iter` will be set to empty. @param iter The iterator to be initialized. If this parameter is NULL, the function will fail and return false. @return true if the `iter` has been successfully initialized. @note The iterator does not need to be destroyed. */ yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj, yyjson_obj_iter *iter); /** Create an iterator with an object, same as `yyjson_obj_iter_init()`. @param obj The object to be iterated over. If this parameter is NULL or not an object, an empty iterator will returned. @return A new iterator for the object. @note The iterator does not need to be destroyed. */ yyjson_api_inline yyjson_obj_iter yyjson_obj_iter_with(yyjson_val *obj); /** Returns whether the iteration has more elements. If `iter` is NULL, this function will return false. */ yyjson_api_inline bool yyjson_obj_iter_has_next(yyjson_obj_iter *iter); /** Returns the next key in the iteration, or NULL on end. If `iter` is NULL, this function will return NULL. */ yyjson_api_inline yyjson_val *yyjson_obj_iter_next(yyjson_obj_iter *iter); /** Returns the value for key inside the iteration. If `iter` is NULL, this function will return NULL. */ yyjson_api_inline yyjson_val *yyjson_obj_iter_get_val(yyjson_val *key); /** Iterates to a specified key and returns the value. This function does the same thing as `yyjson_obj_get()`, but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned. @param iter The object iterator, should not be NULL. @param key The key, should be a UTF-8 string with null-terminator. @return The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid. @warning This function takes a linear search time if the key is not nearby. */ yyjson_api_inline yyjson_val *yyjson_obj_iter_get(yyjson_obj_iter *iter, const char *key); /** Iterates to a specified key and returns the value. This function does the same thing as `yyjson_obj_getn()`, but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned. @param iter The object iterator, should not be NULL. @param key The key, should be a UTF-8 string, null-terminator is not required. @param key_len The the length of `key`, in bytes. @return The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid. @warning This function takes a linear search time if the key is not nearby. */ yyjson_api_inline yyjson_val *yyjson_obj_iter_getn(yyjson_obj_iter *iter, const char *key, size_t key_len); /** Macro for iterating over an object. It works like iterator, but with a more intuitive API. @par Example @code size_t idx, max; yyjson_val *key, *val; yyjson_obj_foreach(obj, idx, max, key, val) { your_func(key, val); } @endcode */ #define yyjson_obj_foreach(obj, idx, max, key, val) \ for ((idx) = 0, \ (max) = yyjson_obj_size(obj), \ (key) = (obj) ? unsafe_yyjson_get_first(obj) : NULL, \ (val) = (key) + 1; \ (idx) < (max); \ (idx)++, \ (key) = unsafe_yyjson_get_next(val), \ (val) = (key) + 1) /*============================================================================== * Mutable JSON Document API *============================================================================*/ /** Returns the root value of this JSON document. Returns NULL if `doc` is NULL. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_root(yyjson_mut_doc *doc); /** Sets the root value of this JSON document. Pass NULL to clear root value of the document. */ yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc *doc, yyjson_mut_val *root); /** Set the string pool size for a mutable document. This function does not allocate memory immediately, but uses the size when the next memory allocation is needed. If the caller knows the approximate bytes of strings that the document needs to store (e.g. copy string with `yyjson_mut_strcpy` function), setting a larger size can avoid multiple memory allocations and improve performance. @param doc The mutable document. @param len The desired string pool size in bytes (total string length). @return true if successful, false if size is 0 or overflow. */ yyjson_api bool yyjson_mut_doc_set_str_pool_size(yyjson_mut_doc *doc, size_t len); /** Set the value pool size for a mutable document. This function does not allocate memory immediately, but uses the size when the next memory allocation is needed. If the caller knows the approximate number of values that the document needs to store (e.g. create new value with `yyjson_mut_xxx` functions), setting a larger size can avoid multiple memory allocations and improve performance. @param doc The mutable document. @param count The desired value pool size (number of `yyjson_mut_val`). @return true if successful, false if size is 0 or overflow. */ yyjson_api bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, size_t count); /** Release the JSON document and free the memory. After calling this function, the `doc` and all values from the `doc` are no longer available. This function will do nothing if the `doc` is NULL. */ yyjson_api void yyjson_mut_doc_free(yyjson_mut_doc *doc); /** Creates and returns a new mutable JSON document, returns NULL on error. If allocator is NULL, the default allocator will be used. */ yyjson_api yyjson_mut_doc *yyjson_mut_doc_new(const yyjson_alc *alc); /** Copies and returns a new mutable document from input, returns NULL on error. This makes a `deep-copy` on the immutable document. If allocator is NULL, the default allocator will be used. @note `imut_doc` -> `mut_doc`. */ yyjson_api yyjson_mut_doc *yyjson_doc_mut_copy(yyjson_doc *doc, const yyjson_alc *alc); /** Copies and returns a new mutable document from input, returns NULL on error. This makes a `deep-copy` on the mutable document. If allocator is NULL, the default allocator will be used. @note `mut_doc` -> `mut_doc`. */ yyjson_api yyjson_mut_doc *yyjson_mut_doc_mut_copy(yyjson_mut_doc *doc, const yyjson_alc *alc); /** Copies and returns a new mutable value from input, returns NULL on error. This makes a `deep-copy` on the immutable value. The memory was managed by mutable document. @note `imut_val` -> `mut_val`. */ yyjson_api yyjson_mut_val *yyjson_val_mut_copy(yyjson_mut_doc *doc, yyjson_val *val); /** Copies and returns a new mutable value from input, returns NULL on error. This makes a `deep-copy` on the mutable value. The memory was managed by mutable document. @note `mut_val` -> `mut_val`. @warning This function is recursive and may cause a stack overflow if the object level is too deep. */ yyjson_api yyjson_mut_val *yyjson_mut_val_mut_copy(yyjson_mut_doc *doc, yyjson_mut_val *val); /** Copies and returns a new immutable document from input, returns NULL on error. This makes a `deep-copy` on the mutable document. The returned document should be freed with `yyjson_doc_free()`. @note `mut_doc` -> `imut_doc`. @warning This function is recursive and may cause a stack overflow if the object level is too deep. */ yyjson_api yyjson_doc *yyjson_mut_doc_imut_copy(yyjson_mut_doc *doc, const yyjson_alc *alc); /** Copies and returns a new immutable document from input, returns NULL on error. This makes a `deep-copy` on the mutable value. The returned document should be freed with `yyjson_doc_free()`. @note `mut_val` -> `imut_doc`. @warning This function is recursive and may cause a stack overflow if the object level is too deep. */ yyjson_api yyjson_doc *yyjson_mut_val_imut_copy(yyjson_mut_val *val, const yyjson_alc *alc); /*============================================================================== * Mutable JSON Value Type API *============================================================================*/ /** Returns whether the JSON value is raw. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_raw(yyjson_mut_val *val); /** Returns whether the JSON value is `null`. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_null(yyjson_mut_val *val); /** Returns whether the JSON value is `true`. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_true(yyjson_mut_val *val); /** Returns whether the JSON value is `false`. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_false(yyjson_mut_val *val); /** Returns whether the JSON value is bool (true/false). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_bool(yyjson_mut_val *val); /** Returns whether the JSON value is unsigned integer (uint64_t). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_uint(yyjson_mut_val *val); /** Returns whether the JSON value is signed integer (int64_t). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_sint(yyjson_mut_val *val); /** Returns whether the JSON value is integer (uint64_t/int64_t). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_int(yyjson_mut_val *val); /** Returns whether the JSON value is real number (double). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_real(yyjson_mut_val *val); /** Returns whether the JSON value is number (uint/sint/real). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_num(yyjson_mut_val *val); /** Returns whether the JSON value is string. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_str(yyjson_mut_val *val); /** Returns whether the JSON value is array. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_arr(yyjson_mut_val *val); /** Returns whether the JSON value is object. Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_obj(yyjson_mut_val *val); /** Returns whether the JSON value is container (array/object). Returns false if `val` is NULL. */ yyjson_api_inline bool yyjson_mut_is_ctn(yyjson_mut_val *val); /*============================================================================== * Mutable JSON Value Content API *============================================================================*/ /** Returns the JSON value's type. Returns `YYJSON_TYPE_NONE` if `val` is NULL. */ yyjson_api_inline yyjson_type yyjson_mut_get_type(yyjson_mut_val *val); /** Returns the JSON value's subtype. Returns `YYJSON_SUBTYPE_NONE` if `val` is NULL. */ yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype(yyjson_mut_val *val); /** Returns the JSON value's tag. Returns 0 if `val` is NULL. */ yyjson_api_inline uint8_t yyjson_mut_get_tag(yyjson_mut_val *val); /** Returns the JSON value's type description. The return value should be one of these strings: "raw", "null", "string", "array", "object", "true", "false", "uint", "sint", "real", "unknown". */ yyjson_api_inline const char *yyjson_mut_get_type_desc(yyjson_mut_val *val); /** Returns the content if the value is raw. Returns NULL if `val` is NULL or type is not raw. */ yyjson_api_inline const char *yyjson_mut_get_raw(yyjson_mut_val *val); /** Returns the content if the value is bool. Returns NULL if `val` is NULL or type is not bool. */ yyjson_api_inline bool yyjson_mut_get_bool(yyjson_mut_val *val); /** Returns the content and cast to uint64_t. Returns 0 if `val` is NULL or type is not integer(sint/uint). */ yyjson_api_inline uint64_t yyjson_mut_get_uint(yyjson_mut_val *val); /** Returns the content and cast to int64_t. Returns 0 if `val` is NULL or type is not integer(sint/uint). */ yyjson_api_inline int64_t yyjson_mut_get_sint(yyjson_mut_val *val); /** Returns the content and cast to int. Returns 0 if `val` is NULL or type is not integer(sint/uint). */ yyjson_api_inline int yyjson_mut_get_int(yyjson_mut_val *val); /** Returns the content if the value is real number. Returns 0.0 if `val` is NULL or type is not real(double). */ yyjson_api_inline double yyjson_mut_get_real(yyjson_mut_val *val); /** Returns the content and typecast to `double` if the value is number. Returns 0.0 if `val` is NULL or type is not number(uint/sint/real). */ yyjson_api_inline double yyjson_mut_get_num(yyjson_mut_val *val); /** Returns the content if the value is string. Returns NULL if `val` is NULL or type is not string. */ yyjson_api_inline const char *yyjson_mut_get_str(yyjson_mut_val *val); /** Returns the content length (string length, array size, object size. Returns 0 if `val` is NULL or type is not string/array/object. */ yyjson_api_inline size_t yyjson_mut_get_len(yyjson_mut_val *val); /** Returns whether the JSON value is equals to a string. The `str` should be a null-terminated UTF-8 string. Returns false if input is NULL or type is not string. */ yyjson_api_inline bool yyjson_mut_equals_str(yyjson_mut_val *val, const char *str); /** Returns whether the JSON value is equals to a string. The `str` should be a UTF-8 string, null-terminator is not required. Returns false if input is NULL or type is not string. */ yyjson_api_inline bool yyjson_mut_equals_strn(yyjson_mut_val *val, const char *str, size_t len); /** Returns whether two JSON values are equal (deep compare). Returns false if input is NULL. @note the result may be inaccurate if object has duplicate keys. @warning This function is recursive and may cause a stack overflow if the object level is too deep. */ yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val *lhs, yyjson_mut_val *rhs); /** Set the value to raw. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val *val, const char *raw, size_t len); /** Set the value to null. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val *val); /** Set the value to bool. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val *val, bool num); /** Set the value to uint. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val *val, uint64_t num); /** Set the value to sint. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val *val, int64_t num); /** Set the value to int. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val *val, int num); /** Set the value to real. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val *val, double num); /** Set the value to string (null-terminated). Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val *val, const char *str); /** Set the value to string (with length). Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val *val, const char *str, size_t len); /** Set the value to array. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val *val); /** Set the value to array. Returns false if input is NULL. @warning This function should not be used on an existing object or array. */ yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val *val); /*============================================================================== * Mutable JSON Value Creation API *============================================================================*/ /** Creates and returns a raw value, returns NULL on error. The `str` should be a null-terminated UTF-8 string. @warning The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_raw(yyjson_mut_doc *doc, const char *str); /** Creates and returns a raw value, returns NULL on error. The `str` should be a UTF-8 string, null-terminator is not required. @warning The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_rawn(yyjson_mut_doc *doc, const char *str, size_t len); /** Creates and returns a raw value, returns NULL on error. The `str` should be a null-terminated UTF-8 string. The input string is copied and held by the document. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_rawcpy(yyjson_mut_doc *doc, const char *str); /** Creates and returns a raw value, returns NULL on error. The `str` should be a UTF-8 string, null-terminator is not required. The input string is copied and held by the document. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_rawncpy(yyjson_mut_doc *doc, const char *str, size_t len); /** Creates and returns a null value, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_null(yyjson_mut_doc *doc); /** Creates and returns a true value, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_true(yyjson_mut_doc *doc); /** Creates and returns a false value, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_false(yyjson_mut_doc *doc); /** Creates and returns a bool value, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc, bool val); /** Creates and returns an unsigned integer value, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_uint(yyjson_mut_doc *doc, uint64_t num); /** Creates and returns a signed integer value, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_sint(yyjson_mut_doc *doc, int64_t num); /** Creates and returns a signed integer value, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_int(yyjson_mut_doc *doc, int64_t num); /** Creates and returns an real number value, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_real(yyjson_mut_doc *doc, double num); /** Creates and returns a string value, returns NULL on error. The `str` should be a null-terminated UTF-8 string. @warning The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_str(yyjson_mut_doc *doc, const char *str); /** Creates and returns a string value, returns NULL on error. The `str` should be a UTF-8 string, null-terminator is not required. @warning The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_strn(yyjson_mut_doc *doc, const char *str, size_t len); /** Creates and returns a string value, returns NULL on error. The `str` should be a null-terminated UTF-8 string. The input string is copied and held by the document. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_strcpy(yyjson_mut_doc *doc, const char *str); /** Creates and returns a string value, returns NULL on error. The `str` should be a UTF-8 string, null-terminator is not required. The input string is copied and held by the document. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_strncpy(yyjson_mut_doc *doc, const char *str, size_t len); /*============================================================================== * Mutable JSON Array API *============================================================================*/ /** Returns the number of elements in this array. Returns 0 if `arr` is NULL or type is not array. */ yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr); /** Returns the element at the specified position in this array. Returns NULL if array is NULL/empty or the index is out of bounds. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get(yyjson_mut_val *arr, size_t idx); /** Returns the first element of this array. Returns NULL if `arr` is NULL/empty or type is not array. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_first(yyjson_mut_val *arr); /** Returns the last element of this array. Returns NULL if `arr` is NULL/empty or type is not array. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_last(yyjson_mut_val *arr); /*============================================================================== * Mutable JSON Array Iterator API *============================================================================*/ /** A mutable JSON array iterator. @warning You should not modify the array while iterating over it, but you can use `yyjson_mut_arr_iter_remove()` to remove current value. @par Example @code yyjson_mut_val *val; yyjson_mut_arr_iter iter = yyjson_mut_arr_iter_with(arr); while ((val = yyjson_mut_arr_iter_next(&iter))) { your_func(val); if (your_val_is_unused(val)) { yyjson_mut_arr_iter_remove(&iter); } } @endcode */ typedef struct yyjson_mut_arr_iter { size_t idx; /**< next value's index */ size_t max; /**< maximum index (arr.size) */ yyjson_mut_val *cur; /**< current value */ yyjson_mut_val *pre; /**< previous value */ yyjson_mut_val *arr; /**< the array being iterated */ } yyjson_mut_arr_iter; /** Initialize an iterator for this array. @param arr The array to be iterated over. If this parameter is NULL or not an array, `iter` will be set to empty. @param iter The iterator to be initialized. If this parameter is NULL, the function will fail and return false. @return true if the `iter` has been successfully initialized. @note The iterator does not need to be destroyed. */ yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr, yyjson_mut_arr_iter *iter); /** Create an iterator with an array , same as `yyjson_mut_arr_iter_init()`. @param arr The array to be iterated over. If this parameter is NULL or not an array, an empty iterator will returned. @return A new iterator for the array. @note The iterator does not need to be destroyed. */ yyjson_api_inline yyjson_mut_arr_iter yyjson_mut_arr_iter_with( yyjson_mut_val *arr); /** Returns whether the iteration has more elements. If `iter` is NULL, this function will return false. */ yyjson_api_inline bool yyjson_mut_arr_iter_has_next( yyjson_mut_arr_iter *iter); /** Returns the next element in the iteration, or NULL on end. If `iter` is NULL, this function will return NULL. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_next( yyjson_mut_arr_iter *iter); /** Removes and returns current element in the iteration. If `iter` is NULL, this function will return NULL. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_remove( yyjson_mut_arr_iter *iter); /** Macro for iterating over an array. It works like iterator, but with a more intuitive API. @warning You should not modify the array while iterating over it. @par Example @code size_t idx, max; yyjson_mut_val *val; yyjson_mut_arr_foreach(arr, idx, max, val) { your_func(idx, val); } @endcode */ #define yyjson_mut_arr_foreach(arr, idx, max, val) \ for ((idx) = 0, \ (max) = yyjson_mut_arr_size(arr), \ (val) = yyjson_mut_arr_get_first(arr); \ (idx) < (max); \ (idx)++, \ (val) = (val)->next) /*============================================================================== * Mutable JSON Array Creation API *============================================================================*/ /** Creates and returns an empty mutable array. @param doc A mutable document, used for memory allocation only. @return The new array. NULL if input is NULL or memory allocation failed. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc); /** Creates and returns a new mutable array with the given boolean values. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of boolean values. @param count The value count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const bool vals[3] = { true, false, true }; yyjson_mut_val *arr = yyjson_mut_arr_with_bool(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool( yyjson_mut_doc *doc, const bool *vals, size_t count); /** Creates and returns a new mutable array with the given sint numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of sint numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const int64_t vals[3] = { -1, 0, 1 }; yyjson_mut_val *arr = yyjson_mut_arr_with_sint64(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint( yyjson_mut_doc *doc, const int64_t *vals, size_t count); /** Creates and returns a new mutable array with the given uint numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of uint numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const uint64_t vals[3] = { 0, 1, 0 }; yyjson_mut_val *arr = yyjson_mut_arr_with_uint(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint( yyjson_mut_doc *doc, const uint64_t *vals, size_t count); /** Creates and returns a new mutable array with the given real numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of real numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const double vals[3] = { 0.1, 0.2, 0.3 }; yyjson_mut_val *arr = yyjson_mut_arr_with_real(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_real( yyjson_mut_doc *doc, const double *vals, size_t count); /** Creates and returns a new mutable array with the given int8 numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of int8 numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const int8_t vals[3] = { -1, 0, 1 }; yyjson_mut_val *arr = yyjson_mut_arr_with_sint8(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint8( yyjson_mut_doc *doc, const int8_t *vals, size_t count); /** Creates and returns a new mutable array with the given int16 numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of int16 numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const int16_t vals[3] = { -1, 0, 1 }; yyjson_mut_val *arr = yyjson_mut_arr_with_sint16(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint16( yyjson_mut_doc *doc, const int16_t *vals, size_t count); /** Creates and returns a new mutable array with the given int32 numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of int32 numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const int32_t vals[3] = { -1, 0, 1 }; yyjson_mut_val *arr = yyjson_mut_arr_with_sint32(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint32( yyjson_mut_doc *doc, const int32_t *vals, size_t count); /** Creates and returns a new mutable array with the given int64 numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of int64 numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const int64_t vals[3] = { -1, 0, 1 }; yyjson_mut_val *arr = yyjson_mut_arr_with_sint64(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint64( yyjson_mut_doc *doc, const int64_t *vals, size_t count); /** Creates and returns a new mutable array with the given uint8 numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of uint8 numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const uint8_t vals[3] = { 0, 1, 0 }; yyjson_mut_val *arr = yyjson_mut_arr_with_uint8(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint8( yyjson_mut_doc *doc, const uint8_t *vals, size_t count); /** Creates and returns a new mutable array with the given uint16 numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of uint16 numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const uint16_t vals[3] = { 0, 1, 0 }; yyjson_mut_val *arr = yyjson_mut_arr_with_uint16(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint16( yyjson_mut_doc *doc, const uint16_t *vals, size_t count); /** Creates and returns a new mutable array with the given uint32 numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of uint32 numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const uint32_t vals[3] = { 0, 1, 0 }; yyjson_mut_val *arr = yyjson_mut_arr_with_uint32(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint32( yyjson_mut_doc *doc, const uint32_t *vals, size_t count); /** Creates and returns a new mutable array with the given uint64 numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of uint64 numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const uint64_t vals[3] = { 0, 1, 0 }; yyjson_mut_val *arr = yyjson_mut_arr_with_uint64(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint64( yyjson_mut_doc *doc, const uint64_t *vals, size_t count); /** Creates and returns a new mutable array with the given float numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of float numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const float vals[3] = { -1.0f, 0.0f, 1.0f }; yyjson_mut_val *arr = yyjson_mut_arr_with_float(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_float( yyjson_mut_doc *doc, const float *vals, size_t count); /** Creates and returns a new mutable array with the given double numbers. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of double numbers. @param count The number count. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const double vals[3] = { -1.0, 0.0, 1.0 }; yyjson_mut_val *arr = yyjson_mut_arr_with_double(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_double( yyjson_mut_doc *doc, const double *vals, size_t count); /** Creates and returns a new mutable array with the given strings, these strings will not be copied. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of UTF-8 null-terminator strings. If this array contains NULL, the function will fail and return NULL. @param count The number of values in `vals`. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @warning The input strings are not copied, you should keep these strings unmodified for the lifetime of this JSON document. If these strings will be modified, you should use `yyjson_mut_arr_with_strcpy()` instead. @par Example @code const char *vals[3] = { "a", "b", "c" }; yyjson_mut_val *arr = yyjson_mut_arr_with_str(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_str( yyjson_mut_doc *doc, const char **vals, size_t count); /** Creates and returns a new mutable array with the given strings and string lengths, these strings will not be copied. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of UTF-8 strings, null-terminator is not required. If this array contains NULL, the function will fail and return NULL. @param lens A C array of string lengths, in bytes. @param count The number of strings in `vals`. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @warning The input strings are not copied, you should keep these strings unmodified for the lifetime of this JSON document. If these strings will be modified, you should use `yyjson_mut_arr_with_strncpy()` instead. @par Example @code const char *vals[3] = { "a", "bb", "c" }; const size_t lens[3] = { 1, 2, 1 }; yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strn( yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count); /** Creates and returns a new mutable array with the given strings, these strings will be copied. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of UTF-8 null-terminator strings. If this array contains NULL, the function will fail and return NULL. @param count The number of values in `vals`. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const char *vals[3] = { "a", "b", "c" }; yyjson_mut_val *arr = yyjson_mut_arr_with_strcpy(doc, vals, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strcpy( yyjson_mut_doc *doc, const char **vals, size_t count); /** Creates and returns a new mutable array with the given strings and string lengths, these strings will be copied. @param doc A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. @param vals A C array of UTF-8 strings, null-terminator is not required. If this array contains NULL, the function will fail and return NULL. @param lens A C array of string lengths, in bytes. @param count The number of strings in `vals`. If this value is 0, an empty array will return. @return The new array. NULL if input is invalid or memory allocation failed. @par Example @code const char *vals[3] = { "a", "bb", "c" }; const size_t lens[3] = { 1, 2, 1 }; yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strncpy( yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count); /*============================================================================== * Mutable JSON Array Modification API *============================================================================*/ /** Inserts a value into an array at a given index. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param val The value to be inserted. Returns false if it is NULL. @param idx The index to which to insert the new value. Returns false if the index is out of range. @return Whether successful. @warning This function takes a linear search time. */ yyjson_api_inline bool yyjson_mut_arr_insert(yyjson_mut_val *arr, yyjson_mut_val *val, size_t idx); /** Inserts a value at the end of the array. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param val The value to be inserted. Returns false if it is NULL. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_append(yyjson_mut_val *arr, yyjson_mut_val *val); /** Inserts a value at the head of the array. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param val The value to be inserted. Returns false if it is NULL. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_prepend(yyjson_mut_val *arr, yyjson_mut_val *val); /** Replaces a value at index and returns old value. @param arr The array to which the value is to be replaced. Returns false if it is NULL or not an array. @param idx The index to which to replace the value. Returns false if the index is out of range. @param val The new value to replace. Returns false if it is NULL. @return Old value, or NULL on error. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_replace(yyjson_mut_val *arr, size_t idx, yyjson_mut_val *val); /** Removes and returns a value at index. @param arr The array from which the value is to be removed. Returns false if it is NULL or not an array. @param idx The index from which to remove the value. Returns false if the index is out of range. @return Old value, or NULL on error. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove(yyjson_mut_val *arr, size_t idx); /** Removes and returns the first value in this array. @param arr The array from which the value is to be removed. Returns false if it is NULL or not an array. @return The first value, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_first( yyjson_mut_val *arr); /** Removes and returns the last value in this array. @param arr The array from which the value is to be removed. Returns false if it is NULL or not an array. @return The last value, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_last( yyjson_mut_val *arr); /** Removes all values within a specified range in the array. @param arr The array from which the value is to be removed. Returns false if it is NULL or not an array. @param idx The start index of the range (0 is the first). @param len The number of items in the range (can be 0). @return Whether successful. @warning This function takes a linear search time. */ yyjson_api_inline bool yyjson_mut_arr_remove_range(yyjson_mut_val *arr, size_t idx, size_t len); /** Removes all values in this array. @param arr The array from which all of the values are to be removed. Returns false if it is NULL or not an array. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_clear(yyjson_mut_val *arr); /** Rotates values in this array for the given number of times. For example: `[1,2,3,4,5]` rotate 2 is `[3,4,5,1,2]`. @param arr The array to be rotated. @param idx Index (or times) to rotate. @warning This function takes a linear search time. */ yyjson_api_inline bool yyjson_mut_arr_rotate(yyjson_mut_val *arr, size_t idx); /*============================================================================== * Mutable JSON Array Modification Convenience API *============================================================================*/ /** Adds a value at the end of the array. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param val The value to be inserted. Returns false if it is NULL. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_val(yyjson_mut_val *arr, yyjson_mut_val *val); /** Adds a `null` value at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_null(yyjson_mut_doc *doc, yyjson_mut_val *arr); /** Adds a `true` value at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_true(yyjson_mut_doc *doc, yyjson_mut_val *arr); /** Adds a `false` value at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_false(yyjson_mut_doc *doc, yyjson_mut_val *arr); /** Adds a bool value at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param val The bool value to be added. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_bool(yyjson_mut_doc *doc, yyjson_mut_val *arr, bool val); /** Adds an unsigned integer value at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param num The number to be added. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_uint(yyjson_mut_doc *doc, yyjson_mut_val *arr, uint64_t num); /** Adds a signed integer value at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param num The number to be added. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_sint(yyjson_mut_doc *doc, yyjson_mut_val *arr, int64_t num); /** Adds a integer value at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param num The number to be added. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_int(yyjson_mut_doc *doc, yyjson_mut_val *arr, int64_t num); /** Adds a double value at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param num The number to be added. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_real(yyjson_mut_doc *doc, yyjson_mut_val *arr, double num); /** Adds a string value at the end of the array (no copy). @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param str A null-terminated UTF-8 string. @return Whether successful. @warning The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_arr_add_str(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str); /** Adds a string value at the end of the array (no copy). @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param str A UTF-8 string, null-terminator is not required. @param len The length of the string, in bytes. @return Whether successful. @warning The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_arr_add_strn(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str, size_t len); /** Adds a string value at the end of the array (copied). @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param str A null-terminated UTF-8 string. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str); /** Adds a string value at the end of the array (copied). @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @param str A UTF-8 string, null-terminator is not required. @param len The length of the string, in bytes. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_arr_add_strncpy(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str, size_t len); /** Creates and adds a new array at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @return The new array, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_arr(yyjson_mut_doc *doc, yyjson_mut_val *arr); /** Creates and adds a new object at the end of the array. @param doc The `doc` is only used for memory allocation. @param arr The array to which the value is to be inserted. Returns false if it is NULL or not an array. @return The new object, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_obj(yyjson_mut_doc *doc, yyjson_mut_val *arr); /*============================================================================== * Mutable JSON Object API *============================================================================*/ /** Returns the number of key-value pairs in this object. Returns 0 if `obj` is NULL or type is not object. */ yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj); /** Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if `obj/key` is NULL, or type is not object. The `key` should be a null-terminated UTF-8 string. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_get(yyjson_mut_val *obj, const char *key); /** Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if `obj/key` is NULL, or type is not object. The `key` should be a UTF-8 string, null-terminator is not required. The `key_len` should be the length of the key, in bytes. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_getn(yyjson_mut_val *obj, const char *key, size_t key_len); /*============================================================================== * Mutable JSON Object Iterator API *============================================================================*/ /** A mutable JSON object iterator. @warning You should not modify the object while iterating over it, but you can use `yyjson_mut_obj_iter_remove()` to remove current value. @par Example @code yyjson_mut_val *key, *val; yyjson_mut_obj_iter iter = yyjson_mut_obj_iter_with(obj); while ((key = yyjson_mut_obj_iter_next(&iter))) { val = yyjson_mut_obj_iter_get_val(key); your_func(key, val); if (your_val_is_unused(key, val)) { yyjson_mut_obj_iter_remove(&iter); } } @endcode If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups: @code // {"k1":1, "k2": 3, "k3": 3} yyjson_mut_val *key, *val; yyjson_mut_obj_iter iter = yyjson_mut_obj_iter_with(obj); yyjson_mut_val *v1 = yyjson_mut_obj_iter_get(&iter, "k1"); yyjson_mut_val *v3 = yyjson_mut_obj_iter_get(&iter, "k3"); @endcode @see `yyjson_mut_obj_iter_get()` and `yyjson_mut_obj_iter_getn()` */ typedef struct yyjson_mut_obj_iter { size_t idx; /**< next key's index */ size_t max; /**< maximum key index (obj.size) */ yyjson_mut_val *cur; /**< current key */ yyjson_mut_val *pre; /**< previous key */ yyjson_mut_val *obj; /**< the object being iterated */ } yyjson_mut_obj_iter; /** Initialize an iterator for this object. @param obj The object to be iterated over. If this parameter is NULL or not an array, `iter` will be set to empty. @param iter The iterator to be initialized. If this parameter is NULL, the function will fail and return false. @return true if the `iter` has been successfully initialized. @note The iterator does not need to be destroyed. */ yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj, yyjson_mut_obj_iter *iter); /** Create an iterator with an object, same as `yyjson_obj_iter_init()`. @param obj The object to be iterated over. If this parameter is NULL or not an object, an empty iterator will returned. @return A new iterator for the object. @note The iterator does not need to be destroyed. */ yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with( yyjson_mut_val *obj); /** Returns whether the iteration has more elements. If `iter` is NULL, this function will return false. */ yyjson_api_inline bool yyjson_mut_obj_iter_has_next( yyjson_mut_obj_iter *iter); /** Returns the next key in the iteration, or NULL on end. If `iter` is NULL, this function will return NULL. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_next( yyjson_mut_obj_iter *iter); /** Returns the value for key inside the iteration. If `iter` is NULL, this function will return NULL. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get_val( yyjson_mut_val *key); /** Removes current key-value pair in the iteration, returns the removed value. If `iter` is NULL, this function will return NULL. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_remove( yyjson_mut_obj_iter *iter); /** Iterates to a specified key and returns the value. This function does the same thing as `yyjson_mut_obj_get()`, but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned. @param iter The object iterator, should not be NULL. @param key The key, should be a UTF-8 string with null-terminator. @return The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid. @warning This function takes a linear search time if the key is not nearby. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get( yyjson_mut_obj_iter *iter, const char *key); /** Iterates to a specified key and returns the value. This function does the same thing as `yyjson_mut_obj_getn()` but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned. @param iter The object iterator, should not be NULL. @param key The key, should be a UTF-8 string, null-terminator is not required. @param key_len The the length of `key`, in bytes. @return The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid. @warning This function takes a linear search time if the key is not nearby. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_getn( yyjson_mut_obj_iter *iter, const char *key, size_t key_len); /** Macro for iterating over an object. It works like iterator, but with a more intuitive API. @warning You should not modify the object while iterating over it. @par Example @code size_t idx, max; yyjson_val *key, *val; yyjson_obj_foreach(obj, idx, max, key, val) { your_func(key, val); } @endcode */ #define yyjson_mut_obj_foreach(obj, idx, max, key, val) \ for ((idx) = 0, \ (max) = yyjson_mut_obj_size(obj), \ (key) = (max) ? ((yyjson_mut_val *)(obj)->uni.ptr)->next->next : NULL, \ (val) = (key) ? (key)->next : NULL; \ (idx) < (max); \ (idx)++, \ (key) = (val)->next, \ (val) = (key)->next) /*============================================================================== * Mutable JSON Object Creation API *============================================================================*/ /** Creates and returns a mutable object, returns NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj(yyjson_mut_doc *doc); /** Creates and returns a mutable object with keys and values, returns NULL on error. The keys and values are not copied. The strings should be a null-terminated UTF-8 string. @warning The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document. @par Example @code const char *keys[2] = { "id", "name" }; const char *vals[2] = { "01", "Harry" }; yyjson_mut_val *obj = yyjson_mut_obj_with_str(doc, keys, vals, 2); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_str(yyjson_mut_doc *doc, const char **keys, const char **vals, size_t count); /** Creates and returns a mutable object with key-value pairs and pair count, returns NULL on error. The keys and values are not copied. The strings should be a null-terminated UTF-8 string. @warning The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document. @par Example @code const char *kv_pairs[4] = { "id", "01", "name", "Harry" }; yyjson_mut_val *obj = yyjson_mut_obj_with_kv(doc, kv_pairs, 2); @endcode */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_kv(yyjson_mut_doc *doc, const char **kv_pairs, size_t pair_count); /*============================================================================== * Mutable JSON Object Modification API *============================================================================*/ /** Adds a key-value pair at the end of the object. This function allows duplicated key in one object. @param obj The object to which the new key-value pair is to be added. @param key The key, should be a string which is created by `yyjson_mut_str()`, `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. @param val The value to add to the object. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_obj_add(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val); /** Sets a key-value pair at the end of the object. This function may remove all key-value pairs for the given key before add. @param obj The object to which the new key-value pair is to be added. @param key The key, should be a string which is created by `yyjson_mut_str()`, `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. @param val The value to add to the object. If this value is null, the behavior is same as `yyjson_mut_obj_remove()`. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val); /** Inserts a key-value pair to the object at the given position. This function allows duplicated key in one object. @param obj The object to which the new key-value pair is to be added. @param key The key, should be a string which is created by `yyjson_mut_str()`, `yyjson_mut_strn()`, `yyjson_mut_strcpy()` or `yyjson_mut_strncpy()`. @param val The value to add to the object. @param idx The index to which to insert the new pair. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_obj_insert(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val, size_t idx); /** Removes all key-value pair from the object with given key. @param obj The object from which the key-value pair is to be removed. @param key The key, should be a string value. @return The first matched value, or NULL if no matched value. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove(yyjson_mut_val *obj, yyjson_mut_val *key); /** Removes all key-value pair from the object with given key. @param obj The object from which the key-value pair is to be removed. @param key The key, should be a UTF-8 string with null-terminator. @return The first matched value, or NULL if no matched value. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_key( yyjson_mut_val *obj, const char *key); /** Removes all key-value pair from the object with given key. @param obj The object from which the key-value pair is to be removed. @param key The key, should be a UTF-8 string, null-terminator is not required. @param key_len The length of the key. @return The first matched value, or NULL if no matched value. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_keyn( yyjson_mut_val *obj, const char *key, size_t key_len); /** Removes all key-value pairs in this object. @param obj The object from which all of the values are to be removed. @return Whether successful. */ yyjson_api_inline bool yyjson_mut_obj_clear(yyjson_mut_val *obj); /** Replaces value from the object with given key. If the key is not exist, or the value is NULL, it will fail. @param obj The object to which the value is to be replaced. @param key The key, should be a string value. @param val The value to replace into the object. @return Whether successful. @warning This function takes a linear search time. */ yyjson_api_inline bool yyjson_mut_obj_replace(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val); /** Rotates key-value pairs in the object for the given number of times. For example: `{"a":1,"b":2,"c":3,"d":4}` rotate 1 is `{"b":2,"c":3,"d":4,"a":1}`. @param obj The object to be rotated. @param idx Index (or times) to rotate. @return Whether successful. @warning This function takes a linear search time. */ yyjson_api_inline bool yyjson_mut_obj_rotate(yyjson_mut_val *obj, size_t idx); /*============================================================================== * Mutable JSON Object Modification Convenience API *============================================================================*/ /** Adds a `null` value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_null(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key); /** Adds a `true` value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_true(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key); /** Adds a `false` value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_false(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key); /** Adds a bool value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, bool val); /** Adds an unsigned integer value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_uint(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, uint64_t val); /** Adds a signed integer value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_sint(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, int64_t val); /** Adds an int value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, int64_t val); /** Adds a double value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, double val); /** Adds a string value at the end of the object. The `key` and `val` should be null-terminated UTF-8 strings. This function allows duplicated key in one object. @warning The key/value strings are not copied, you should keep these strings unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_str(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *val); /** Adds a string value at the end of the object. The `key` should be a null-terminated UTF-8 string. The `val` should be a UTF-8 string, null-terminator is not required. The `len` should be the length of the `val`, in bytes. This function allows duplicated key in one object. @warning The key/value strings are not copied, you should keep these strings unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_strn(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *val, size_t len); /** Adds a string value at the end of the object. The `key` and `val` should be null-terminated UTF-8 strings. The value string is copied. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *val); /** Adds a string value at the end of the object. The `key` should be a null-terminated UTF-8 string. The `val` should be a UTF-8 string, null-terminator is not required. The `len` should be the length of the `val`, in bytes. This function allows duplicated key in one object. @warning The key strings are not copied, you should keep these strings unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *val, size_t len); /** Creates and adds a new array to the target object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep these strings unmodified for the lifetime of this JSON document. @return The new array, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_arr(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key); /** Creates and adds a new object to the target object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep these strings unmodified for the lifetime of this JSON document. @return The new object, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_obj(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key); /** Adds a JSON value at the end of the object. The `key` should be a null-terminated UTF-8 string. This function allows duplicated key in one object. @warning The key string is not copied, you should keep the string unmodified for the lifetime of this JSON document. */ yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, yyjson_mut_val *val); /** Removes all key-value pairs for the given key. Returns the first value to which the specified key is mapped or NULL if this object contains no mapping for the key. The `key` should be a null-terminated UTF-8 string. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_str( yyjson_mut_val *obj, const char *key); /** Removes all key-value pairs for the given key. Returns the first value to which the specified key is mapped or NULL if this object contains no mapping for the key. The `key` should be a UTF-8 string, null-terminator is not required. The `len` should be the length of the key, in bytes. @warning This function takes a linear search time. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_strn( yyjson_mut_val *obj, const char *key, size_t len); /** Replaces all matching keys with the new key. Returns true if at least one key was renamed. The `key` and `new_key` should be a null-terminated UTF-8 string. The `new_key` is copied and held by doc. @warning This function takes a linear search time. If `new_key` already exists, it will cause duplicate keys. */ yyjson_api_inline bool yyjson_mut_obj_rename_key(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *new_key); /** Replaces all matching keys with the new key. Returns true if at least one key was renamed. The `key` and `new_key` should be a UTF-8 string, null-terminator is not required. The `new_key` is copied and held by doc. @warning This function takes a linear search time. If `new_key` already exists, it will cause duplicate keys. */ yyjson_api_inline bool yyjson_mut_obj_rename_keyn(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, size_t len, const char *new_key, size_t new_len); /*============================================================================== * JSON Pointer API (RFC 6901) * https://tools.ietf.org/html/rfc6901 *============================================================================*/ /** JSON Pointer error code. */ typedef uint32_t yyjson_ptr_code; /** No JSON pointer error. */ static const yyjson_ptr_code YYJSON_PTR_ERR_NONE = 0; /** Invalid input parameter, such as NULL input. */ static const yyjson_ptr_code YYJSON_PTR_ERR_PARAMETER = 1; /** JSON pointer syntax error, such as invalid escape, token no prefix. */ static const yyjson_ptr_code YYJSON_PTR_ERR_SYNTAX = 2; /** JSON pointer resolve failed, such as index out of range, key not found. */ static const yyjson_ptr_code YYJSON_PTR_ERR_RESOLVE = 3; /** Document's root is NULL, but it is required for the function call. */ static const yyjson_ptr_code YYJSON_PTR_ERR_NULL_ROOT = 4; /** Cannot set root as the target is not a document. */ static const yyjson_ptr_code YYJSON_PTR_ERR_SET_ROOT = 5; /** The memory allocation failed and a new value could not be created. */ static const yyjson_ptr_code YYJSON_PTR_ERR_MEMORY_ALLOCATION = 6; /** Error information for JSON pointer. */ typedef struct yyjson_ptr_err { /** Error code, see `yyjson_ptr_code` for all possible values. */ yyjson_ptr_code code; /** Error message, constant, no need to free (NULL if no error). */ const char *msg; /** Error byte position for input JSON pointer (0 if no error). */ size_t pos; } yyjson_ptr_err; /** A context for JSON pointer operation. This struct stores the context of JSON Pointer operation result. The struct can be used with three helper functions: `ctx_append()`, `ctx_replace()`, and `ctx_remove()`, which perform the corresponding operations on the container without re-parsing the JSON Pointer. For example: @code // doc before: {"a":[0,1,null]} // ptr: "/a/2" val = yyjson_mut_doc_ptr_getx(doc, ptr, strlen(ptr), &ctx, &err); if (yyjson_is_null(val)) { yyjson_ptr_ctx_remove(&ctx); } // doc after: {"a":[0,1]} @endcode */ typedef struct yyjson_ptr_ctx { /** The container (parent) of the target value. It can be either an array or an object. If the target location has no value, but all its parent containers exist, and the target location can be used to insert a new value, then `ctn` is the parent container of the target location. Otherwise, `ctn` is NULL. */ yyjson_mut_val *ctn; /** The previous sibling of the target value. It can be either a value in an array or a key in an object. As the container is a `circular linked list` of elements, `pre` is the previous node of the target value. If the operation is `add` or `set`, then `pre` is the previous node of the new value, not the original target value. If the target value does not exist, `pre` is NULL. */ yyjson_mut_val *pre; /** The removed value if the operation is `set`, `replace` or `remove`. It can be used to restore the original state of the document if needed. */ yyjson_mut_val *old; } yyjson_ptr_ctx; /** Get value by a JSON Pointer. @param doc The JSON document to be queried. @param ptr The JSON pointer string (UTF-8 with null-terminator). @return The value referenced by the JSON pointer. NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_val *yyjson_doc_ptr_get(yyjson_doc *doc, const char *ptr); /** Get value by a JSON Pointer. @param doc The JSON document to be queried. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @return The value referenced by the JSON pointer. NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_val *yyjson_doc_ptr_getn(yyjson_doc *doc, const char *ptr, size_t len); /** Get value by a JSON Pointer. @param doc The JSON document to be queried. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param err A pointer to store the error information, or NULL if not needed. @return The value referenced by the JSON pointer. NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_val *yyjson_doc_ptr_getx(yyjson_doc *doc, const char *ptr, size_t len, yyjson_ptr_err *err); /** Get value by a JSON Pointer. @param val The JSON value to be queried. @param ptr The JSON pointer string (UTF-8 with null-terminator). @return The value referenced by the JSON pointer. NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_val *yyjson_ptr_get(yyjson_val *val, const char *ptr); /** Get value by a JSON Pointer. @param val The JSON value to be queried. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @return The value referenced by the JSON pointer. NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_val *yyjson_ptr_getn(yyjson_val *val, const char *ptr, size_t len); /** Get value by a JSON Pointer. @param val The JSON value to be queried. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param err A pointer to store the error information, or NULL if not needed. @return The value referenced by the JSON pointer. NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_val *yyjson_ptr_getx(yyjson_val *val, const char *ptr, size_t len, yyjson_ptr_err *err); /** Get value by a JSON Pointer. @param doc The JSON document to be queried. @param ptr The JSON pointer string (UTF-8 with null-terminator). @return The value referenced by the JSON pointer. NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_get(yyjson_mut_doc *doc, const char *ptr); /** Get value by a JSON Pointer. @param doc The JSON document to be queried. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @return The value referenced by the JSON pointer. NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getn(yyjson_mut_doc *doc, const char *ptr, size_t len); /** Get value by a JSON Pointer. @param doc The JSON document to be queried. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return The value referenced by the JSON pointer. NULL if `doc` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getx(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Get value by a JSON Pointer. @param val The JSON value to be queried. @param ptr The JSON pointer string (UTF-8 with null-terminator). @return The value referenced by the JSON pointer. NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_get(yyjson_mut_val *val, const char *ptr); /** Get value by a JSON Pointer. @param val The JSON value to be queried. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @return The value referenced by the JSON pointer. NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getn(yyjson_mut_val *val, const char *ptr, size_t len); /** Get value by a JSON Pointer. @param val The JSON value to be queried. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return The value referenced by the JSON pointer. NULL if `val` or `ptr` is NULL, or the JSON pointer cannot be resolved. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getx(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Add (insert) value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8 with null-terminator). @param new_val The value to be added. @return true if JSON pointer is valid and new value is added, false otherwise. @note The parent nodes will be created if they do not exist. */ yyjson_api_inline bool yyjson_mut_doc_ptr_add(yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val); /** Add (insert) value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The value to be added. @return true if JSON pointer is valid and new value is added, false otherwise. @note The parent nodes will be created if they do not exist. */ yyjson_api_inline bool yyjson_mut_doc_ptr_addn(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val); /** Add (insert) value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The value to be added. @param create_parent Whether to create parent nodes if not exist. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return true if JSON pointer is valid and new value is added, false otherwise. */ yyjson_api_inline bool yyjson_mut_doc_ptr_addx(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, bool create_parent, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Add (insert) value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8 with null-terminator). @param doc Only used to create new values when needed. @param new_val The value to be added. @return true if JSON pointer is valid and new value is added, false otherwise. @note The parent nodes will be created if they do not exist. */ yyjson_api_inline bool yyjson_mut_ptr_add(yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val, yyjson_mut_doc *doc); /** Add (insert) value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param doc Only used to create new values when needed. @param new_val The value to be added. @return true if JSON pointer is valid and new value is added, false otherwise. @note The parent nodes will be created if they do not exist. */ yyjson_api_inline bool yyjson_mut_ptr_addn(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc); /** Add (insert) value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param doc Only used to create new values when needed. @param new_val The value to be added. @param create_parent Whether to create parent nodes if not exist. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return true if JSON pointer is valid and new value is added, false otherwise. */ yyjson_api_inline bool yyjson_mut_ptr_addx(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Set value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8 with null-terminator). @param new_val The value to be set, pass NULL to remove. @return true if JSON pointer is valid and new value is set, false otherwise. @note The parent nodes will be created if they do not exist. If the target value already exists, it will be replaced by the new value. */ yyjson_api_inline bool yyjson_mut_doc_ptr_set(yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val); /** Set value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The value to be set, pass NULL to remove. @return true if JSON pointer is valid and new value is set, false otherwise. @note The parent nodes will be created if they do not exist. If the target value already exists, it will be replaced by the new value. */ yyjson_api_inline bool yyjson_mut_doc_ptr_setn(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val); /** Set value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The value to be set, pass NULL to remove. @param create_parent Whether to create parent nodes if not exist. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return true if JSON pointer is valid and new value is set, false otherwise. @note If the target value already exists, it will be replaced by the new value. */ yyjson_api_inline bool yyjson_mut_doc_ptr_setx(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, bool create_parent, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Set value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8 with null-terminator). @param new_val The value to be set, pass NULL to remove. @param doc Only used to create new values when needed. @return true if JSON pointer is valid and new value is set, false otherwise. @note The parent nodes will be created if they do not exist. If the target value already exists, it will be replaced by the new value. */ yyjson_api_inline bool yyjson_mut_ptr_set(yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val, yyjson_mut_doc *doc); /** Set value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The value to be set, pass NULL to remove. @param doc Only used to create new values when needed. @return true if JSON pointer is valid and new value is set, false otherwise. @note The parent nodes will be created if they do not exist. If the target value already exists, it will be replaced by the new value. */ yyjson_api_inline bool yyjson_mut_ptr_setn(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc); /** Set value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The value to be set, pass NULL to remove. @param doc Only used to create new values when needed. @param create_parent Whether to create parent nodes if not exist. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return true if JSON pointer is valid and new value is set, false otherwise. @note If the target value already exists, it will be replaced by the new value. */ yyjson_api_inline bool yyjson_mut_ptr_setx(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Replace value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8 with null-terminator). @param new_val The new value to replace the old one. @return The old value that was replaced, or NULL if not found. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replace( yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val); /** Replace value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The new value to replace the old one. @return The old value that was replaced, or NULL if not found. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacen( yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val); /** Replace value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The new value to replace the old one. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return The old value that was replaced, or NULL if not found. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacex( yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Replace value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8 with null-terminator). @param new_val The new value to replace the old one. @return The old value that was replaced, or NULL if not found. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replace( yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val); /** Replace value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The new value to replace the old one. @return The old value that was replaced, or NULL if not found. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacen( yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val); /** Replace value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param new_val The new value to replace the old one. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return The old value that was replaced, or NULL if not found. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacex( yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Remove value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8 with null-terminator). @return The removed value, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_remove( yyjson_mut_doc *doc, const char *ptr); /** Remove value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @return The removed value, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removen( yyjson_mut_doc *doc, const char *ptr, size_t len); /** Remove value by a JSON pointer. @param doc The target JSON document. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return The removed value, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removex( yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Remove value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8 with null-terminator). @return The removed value, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_remove(yyjson_mut_val *val, const char *ptr); /** Remove value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @return The removed value, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removen(yyjson_mut_val *val, const char *ptr, size_t len); /** Remove value by a JSON pointer. @param val The target JSON value. @param ptr The JSON pointer string (UTF-8, null-terminator is not required). @param len The length of `ptr` in bytes. @param ctx A pointer to store the result context, or NULL if not needed. @param err A pointer to store the error information, or NULL if not needed. @return The removed value, or NULL on error. */ yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removex(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /** Append value by JSON pointer context. @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. @param key New key if `ctx->ctn` is object, or NULL if `ctx->ctn` is array. @param val New value to be added. @return true on success or false on fail. */ yyjson_api_inline bool yyjson_ptr_ctx_append(yyjson_ptr_ctx *ctx, yyjson_mut_val *key, yyjson_mut_val *val); /** Replace value by JSON pointer context. @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. @param val New value to be replaced. @return true on success or false on fail. @note If success, the old value will be returned via `ctx->old`. */ yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx *ctx, yyjson_mut_val *val); /** Remove value by JSON pointer context. @param ctx The context from the `yyjson_mut_ptr_xxx()` calls. @return true on success or false on fail. @note If success, the old value will be returned via `ctx->old`. */ yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx); /*============================================================================== * JSON Patch API (RFC 6902) * https://tools.ietf.org/html/rfc6902 *============================================================================*/ /** Result code for JSON patch. */ typedef uint32_t yyjson_patch_code; /** Success, no error. */ static const yyjson_patch_code YYJSON_PATCH_SUCCESS = 0; /** Invalid parameter, such as NULL input or non-array patch. */ static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_PARAMETER = 1; /** Memory allocation failure occurs. */ static const yyjson_patch_code YYJSON_PATCH_ERROR_MEMORY_ALLOCATION = 2; /** JSON patch operation is not object type. */ static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_OPERATION = 3; /** JSON patch operation is missing a required key. */ static const yyjson_patch_code YYJSON_PATCH_ERROR_MISSING_KEY = 4; /** JSON patch operation member is invalid. */ static const yyjson_patch_code YYJSON_PATCH_ERROR_INVALID_MEMBER = 5; /** JSON patch operation `test` not equal. */ static const yyjson_patch_code YYJSON_PATCH_ERROR_EQUAL = 6; /** JSON patch operation failed on JSON pointer. */ static const yyjson_patch_code YYJSON_PATCH_ERROR_POINTER = 7; /** Error information for JSON patch. */ typedef struct yyjson_patch_err { /** Error code, see `yyjson_patch_code` for all possible values. */ yyjson_patch_code code; /** Index of the error operation (0 if no error). */ size_t idx; /** Error message, constant, no need to free (NULL if no error). */ const char *msg; /** JSON pointer error if `code == YYJSON_PATCH_ERROR_POINTER`. */ yyjson_ptr_err ptr; } yyjson_patch_err; /** Creates and returns a patched JSON value (RFC 6902). The memory of the returned value is allocated by the `doc`. The `err` is used to receive error information, pass NULL if not needed. Returns NULL if the patch could not be applied. */ yyjson_api yyjson_mut_val *yyjson_patch(yyjson_mut_doc *doc, yyjson_val *orig, yyjson_val *patch, yyjson_patch_err *err); /** Creates and returns a patched JSON value (RFC 6902). The memory of the returned value is allocated by the `doc`. The `err` is used to receive error information, pass NULL if not needed. Returns NULL if the patch could not be applied. */ yyjson_api yyjson_mut_val *yyjson_mut_patch(yyjson_mut_doc *doc, yyjson_mut_val *orig, yyjson_mut_val *patch, yyjson_patch_err *err); /*============================================================================== * JSON Merge-Patch API (RFC 7386) * https://tools.ietf.org/html/rfc7386 *============================================================================*/ /** Creates and returns a merge-patched JSON value (RFC 7386). The memory of the returned value is allocated by the `doc`. Returns NULL if the patch could not be applied. @warning This function is recursive and may cause a stack overflow if the object level is too deep. */ yyjson_api yyjson_mut_val *yyjson_merge_patch(yyjson_mut_doc *doc, yyjson_val *orig, yyjson_val *patch); /** Creates and returns a merge-patched JSON value (RFC 7386). The memory of the returned value is allocated by the `doc`. Returns NULL if the patch could not be applied. @warning This function is recursive and may cause a stack overflow if the object level is too deep. */ yyjson_api yyjson_mut_val *yyjson_mut_merge_patch(yyjson_mut_doc *doc, yyjson_mut_val *orig, yyjson_mut_val *patch); /*============================================================================== * JSON Structure (Implementation) *============================================================================*/ /** Payload of a JSON value (8 bytes). */ typedef union yyjson_val_uni { uint64_t u64; int64_t i64; double f64; const char *str; void *ptr; size_t ofs; } yyjson_val_uni; /** Immutable JSON value, 16 bytes. */ struct yyjson_val { uint64_t tag; /**< type, subtype and length */ yyjson_val_uni uni; /**< payload */ }; struct yyjson_doc { /** Root value of the document (nonnull). */ yyjson_val *root; /** Allocator used by document (nonnull). */ yyjson_alc alc; /** The total number of bytes read when parsing JSON (nonzero). */ size_t dat_read; /** The total number of value read when parsing JSON (nonzero). */ size_t val_read; /** The string pool used by JSON values (nullable). */ char *str_pool; }; /*============================================================================== * Unsafe JSON Value API (Implementation) *============================================================================*/ /* Whether the string does not need to be escaped for serialization. This function is used to optimize the writing speed of small constant strings. This function works only if the compiler can evaluate it at compile time. Clang supports it since v8.0, earlier versions do not support constant_p(strlen) and return false. GCC supports it since at least v4.4, earlier versions may compile it as run-time instructions. ICC supports it since at least v16, earlier versions are uncertain. @param str The C string. @param len The returnd value from strlen(str). */ yyjson_api_inline bool unsafe_yyjson_is_str_noesc(const char *str, size_t len) { #if YYJSON_HAS_CONSTANT_P && \ (!YYJSON_IS_REAL_GCC || yyjson_gcc_available(4, 4, 0)) if (yyjson_constant_p(len) && len <= 32) { /* Same as the following loop: for (size_t i = 0; i < len; i++) { char c = str[i]; if (c < ' ' || c > '~' || c == '"' || c == '\\') return false; } GCC evaluates it at compile time only if the string length is within 17 and -O3 (which turns on the -fpeel-loops flag) is used. So the loop is unrolled for GCC. */ # define yyjson_repeat32_incr(x) \ x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) \ x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) \ x(16) x(17) x(18) x(19) x(20) x(21) x(22) x(23) \ x(24) x(25) x(26) x(27) x(28) x(29) x(30) x(31) # define yyjson_check_char_noesc(i) \ if (i < len) { \ char c = str[i]; \ if (c < ' ' || c > '~' || c == '"' || c == '\\') return false; } yyjson_repeat32_incr(yyjson_check_char_noesc) # undef yyjson_repeat32_incr # undef yyjson_check_char_noesc return true; } #else (void)str; (void)len; #endif return false; } yyjson_api_inline yyjson_type unsafe_yyjson_get_type(void *val) { uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; return (yyjson_type)(tag & YYJSON_TYPE_MASK); } yyjson_api_inline yyjson_subtype unsafe_yyjson_get_subtype(void *val) { uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; return (yyjson_subtype)(tag & YYJSON_SUBTYPE_MASK); } yyjson_api_inline uint8_t unsafe_yyjson_get_tag(void *val) { uint8_t tag = (uint8_t)((yyjson_val *)val)->tag; return (uint8_t)(tag & YYJSON_TAG_MASK); } yyjson_api_inline bool unsafe_yyjson_is_raw(void *val) { return unsafe_yyjson_get_type(val) == YYJSON_TYPE_RAW; } yyjson_api_inline bool unsafe_yyjson_is_null(void *val) { return unsafe_yyjson_get_type(val) == YYJSON_TYPE_NULL; } yyjson_api_inline bool unsafe_yyjson_is_bool(void *val) { return unsafe_yyjson_get_type(val) == YYJSON_TYPE_BOOL; } yyjson_api_inline bool unsafe_yyjson_is_num(void *val) { return unsafe_yyjson_get_type(val) == YYJSON_TYPE_NUM; } yyjson_api_inline bool unsafe_yyjson_is_str(void *val) { return unsafe_yyjson_get_type(val) == YYJSON_TYPE_STR; } yyjson_api_inline bool unsafe_yyjson_is_arr(void *val) { return unsafe_yyjson_get_type(val) == YYJSON_TYPE_ARR; } yyjson_api_inline bool unsafe_yyjson_is_obj(void *val) { return unsafe_yyjson_get_type(val) == YYJSON_TYPE_OBJ; } yyjson_api_inline bool unsafe_yyjson_is_ctn(void *val) { uint8_t mask = YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ; return (unsafe_yyjson_get_tag(val) & mask) == mask; } yyjson_api_inline bool unsafe_yyjson_is_uint(void *val) { const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; return unsafe_yyjson_get_tag(val) == patt; } yyjson_api_inline bool unsafe_yyjson_is_sint(void *val) { const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; return unsafe_yyjson_get_tag(val) == patt; } yyjson_api_inline bool unsafe_yyjson_is_int(void *val) { const uint8_t mask = YYJSON_TAG_MASK & (~YYJSON_SUBTYPE_SINT); const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; return (unsafe_yyjson_get_tag(val) & mask) == patt; } yyjson_api_inline bool unsafe_yyjson_is_real(void *val) { const uint8_t patt = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; return unsafe_yyjson_get_tag(val) == patt; } yyjson_api_inline bool unsafe_yyjson_is_true(void *val) { const uint8_t patt = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE; return unsafe_yyjson_get_tag(val) == patt; } yyjson_api_inline bool unsafe_yyjson_is_false(void *val) { const uint8_t patt = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE; return unsafe_yyjson_get_tag(val) == patt; } yyjson_api_inline bool unsafe_yyjson_arr_is_flat(yyjson_val *val) { size_t ofs = val->uni.ofs; size_t len = (size_t)(val->tag >> YYJSON_TAG_BIT); return len * sizeof(yyjson_val) + sizeof(yyjson_val) == ofs; } yyjson_api_inline const char *unsafe_yyjson_get_raw(void *val) { return ((yyjson_val *)val)->uni.str; } yyjson_api_inline bool unsafe_yyjson_get_bool(void *val) { uint8_t tag = unsafe_yyjson_get_tag(val); return (bool)((tag & YYJSON_SUBTYPE_MASK) >> YYJSON_TYPE_BIT); } yyjson_api_inline uint64_t unsafe_yyjson_get_uint(void *val) { return ((yyjson_val *)val)->uni.u64; } yyjson_api_inline int64_t unsafe_yyjson_get_sint(void *val) { return ((yyjson_val *)val)->uni.i64; } yyjson_api_inline int unsafe_yyjson_get_int(void *val) { return (int)((yyjson_val *)val)->uni.i64; } yyjson_api_inline double unsafe_yyjson_get_real(void *val) { return ((yyjson_val *)val)->uni.f64; } yyjson_api_inline double unsafe_yyjson_get_num(void *val) { uint8_t tag = unsafe_yyjson_get_tag(val); if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL)) { return ((yyjson_val *)val)->uni.f64; } else if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT)) { return (double)((yyjson_val *)val)->uni.i64; } else if (tag == (YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT)) { #if YYJSON_U64_TO_F64_NO_IMPL uint64_t msb = ((uint64_t)1) << 63; uint64_t num = ((yyjson_val *)val)->uni.u64; if ((num & msb) == 0) { return (double)(int64_t)num; } else { return ((double)(int64_t)((num >> 1) | (num & 1))) * (double)2.0; } #else return (double)((yyjson_val *)val)->uni.u64; #endif } return 0.0; } yyjson_api_inline const char *unsafe_yyjson_get_str(void *val) { return ((yyjson_val *)val)->uni.str; } yyjson_api_inline size_t unsafe_yyjson_get_len(void *val) { return (size_t)(((yyjson_val *)val)->tag >> YYJSON_TAG_BIT); } yyjson_api_inline yyjson_val *unsafe_yyjson_get_first(yyjson_val *ctn) { return ctn + 1; } yyjson_api_inline yyjson_val *unsafe_yyjson_get_next(yyjson_val *val) { bool is_ctn = unsafe_yyjson_is_ctn(val); size_t ctn_ofs = val->uni.ofs; size_t ofs = (is_ctn ? ctn_ofs : sizeof(yyjson_val)); return (yyjson_val *)(void *)((uint8_t *)val + ofs); } yyjson_api_inline bool unsafe_yyjson_equals_strn(void *val, const char *str, size_t len) { return unsafe_yyjson_get_len(val) == len && memcmp(((yyjson_val *)val)->uni.str, str, len) == 0; } yyjson_api_inline bool unsafe_yyjson_equals_str(void *val, const char *str) { return unsafe_yyjson_equals_strn(val, str, strlen(str)); } yyjson_api_inline void unsafe_yyjson_set_type(void *val, yyjson_type type, yyjson_subtype subtype) { uint8_t tag = (type | subtype); uint64_t new_tag = ((yyjson_val *)val)->tag; new_tag = (new_tag & (~(uint64_t)YYJSON_TAG_MASK)) | (uint64_t)tag; ((yyjson_val *)val)->tag = new_tag; } yyjson_api_inline void unsafe_yyjson_set_len(void *val, size_t len) { uint64_t tag = ((yyjson_val *)val)->tag & YYJSON_TAG_MASK; tag |= (uint64_t)len << YYJSON_TAG_BIT; ((yyjson_val *)val)->tag = tag; } yyjson_api_inline void unsafe_yyjson_inc_len(void *val) { uint64_t tag = ((yyjson_val *)val)->tag; tag += (uint64_t)(1 << YYJSON_TAG_BIT); ((yyjson_val *)val)->tag = tag; } yyjson_api_inline void unsafe_yyjson_set_raw(void *val, const char *raw, size_t len) { unsafe_yyjson_set_type(val, YYJSON_TYPE_RAW, YYJSON_SUBTYPE_NONE); unsafe_yyjson_set_len(val, len); ((yyjson_val *)val)->uni.str = raw; } yyjson_api_inline void unsafe_yyjson_set_null(void *val) { unsafe_yyjson_set_type(val, YYJSON_TYPE_NULL, YYJSON_SUBTYPE_NONE); unsafe_yyjson_set_len(val, 0); } yyjson_api_inline void unsafe_yyjson_set_bool(void *val, bool num) { yyjson_subtype subtype = num ? YYJSON_SUBTYPE_TRUE : YYJSON_SUBTYPE_FALSE; unsafe_yyjson_set_type(val, YYJSON_TYPE_BOOL, subtype); unsafe_yyjson_set_len(val, 0); } yyjson_api_inline void unsafe_yyjson_set_uint(void *val, uint64_t num) { unsafe_yyjson_set_type(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_UINT); unsafe_yyjson_set_len(val, 0); ((yyjson_val *)val)->uni.u64 = num; } yyjson_api_inline void unsafe_yyjson_set_sint(void *val, int64_t num) { unsafe_yyjson_set_type(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_SINT); unsafe_yyjson_set_len(val, 0); ((yyjson_val *)val)->uni.i64 = num; } yyjson_api_inline void unsafe_yyjson_set_real(void *val, double num) { unsafe_yyjson_set_type(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_REAL); unsafe_yyjson_set_len(val, 0); ((yyjson_val *)val)->uni.f64 = num; } yyjson_api_inline void unsafe_yyjson_set_str(void *val, const char *str) { size_t len = strlen(str); bool noesc = unsafe_yyjson_is_str_noesc(str, len); yyjson_subtype sub = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; unsafe_yyjson_set_type(val, YYJSON_TYPE_STR, sub); unsafe_yyjson_set_len(val, len); ((yyjson_val *)val)->uni.str = str; } yyjson_api_inline void unsafe_yyjson_set_strn(void *val, const char *str, size_t len) { unsafe_yyjson_set_type(val, YYJSON_TYPE_STR, YYJSON_SUBTYPE_NONE); unsafe_yyjson_set_len(val, len); ((yyjson_val *)val)->uni.str = str; } yyjson_api_inline void unsafe_yyjson_set_arr(void *val, size_t size) { unsafe_yyjson_set_type(val, YYJSON_TYPE_ARR, YYJSON_SUBTYPE_NONE); unsafe_yyjson_set_len(val, size); } yyjson_api_inline void unsafe_yyjson_set_obj(void *val, size_t size) { unsafe_yyjson_set_type(val, YYJSON_TYPE_OBJ, YYJSON_SUBTYPE_NONE); unsafe_yyjson_set_len(val, size); } /*============================================================================== * JSON Document API (Implementation) *============================================================================*/ yyjson_api_inline yyjson_val *yyjson_doc_get_root(yyjson_doc *doc) { return doc ? doc->root : NULL; } yyjson_api_inline size_t yyjson_doc_get_read_size(yyjson_doc *doc) { return doc ? doc->dat_read : 0; } yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc) { return doc ? doc->val_read : 0; } yyjson_api void yyjson_doc_free(yyjson_doc *doc) { if (doc) { yyjson_alc alc = doc->alc; memset(&doc->alc, 0, sizeof(alc)); if (doc->str_pool) alc.free(alc.ctx, doc->str_pool); alc.free(alc.ctx, doc); } } /*============================================================================== * JSON Value Type API (Implementation) *============================================================================*/ yyjson_api_inline bool yyjson_is_raw(yyjson_val *val) { return val ? unsafe_yyjson_is_raw(val) : false; } yyjson_api_inline bool yyjson_is_null(yyjson_val *val) { return val ? unsafe_yyjson_is_null(val) : false; } yyjson_api_inline bool yyjson_is_true(yyjson_val *val) { return val ? unsafe_yyjson_is_true(val) : false; } yyjson_api_inline bool yyjson_is_false(yyjson_val *val) { return val ? unsafe_yyjson_is_false(val) : false; } yyjson_api_inline bool yyjson_is_bool(yyjson_val *val) { return val ? unsafe_yyjson_is_bool(val) : false; } yyjson_api_inline bool yyjson_is_uint(yyjson_val *val) { return val ? unsafe_yyjson_is_uint(val) : false; } yyjson_api_inline bool yyjson_is_sint(yyjson_val *val) { return val ? unsafe_yyjson_is_sint(val) : false; } yyjson_api_inline bool yyjson_is_int(yyjson_val *val) { return val ? unsafe_yyjson_is_int(val) : false; } yyjson_api_inline bool yyjson_is_real(yyjson_val *val) { return val ? unsafe_yyjson_is_real(val) : false; } yyjson_api_inline bool yyjson_is_num(yyjson_val *val) { return val ? unsafe_yyjson_is_num(val) : false; } yyjson_api_inline bool yyjson_is_str(yyjson_val *val) { return val ? unsafe_yyjson_is_str(val) : false; } yyjson_api_inline bool yyjson_is_arr(yyjson_val *val) { return val ? unsafe_yyjson_is_arr(val) : false; } yyjson_api_inline bool yyjson_is_obj(yyjson_val *val) { return val ? unsafe_yyjson_is_obj(val) : false; } yyjson_api_inline bool yyjson_is_ctn(yyjson_val *val) { return val ? unsafe_yyjson_is_ctn(val) : false; } /*============================================================================== * JSON Value Content API (Implementation) *============================================================================*/ yyjson_api_inline yyjson_type yyjson_get_type(yyjson_val *val) { return val ? unsafe_yyjson_get_type(val) : YYJSON_TYPE_NONE; } yyjson_api_inline yyjson_subtype yyjson_get_subtype(yyjson_val *val) { return val ? unsafe_yyjson_get_subtype(val) : YYJSON_SUBTYPE_NONE; } yyjson_api_inline uint8_t yyjson_get_tag(yyjson_val *val) { return val ? unsafe_yyjson_get_tag(val) : 0; } yyjson_api_inline const char *yyjson_get_type_desc(yyjson_val *val) { switch (yyjson_get_tag(val)) { case YYJSON_TYPE_RAW | YYJSON_SUBTYPE_NONE: return "raw"; case YYJSON_TYPE_NULL | YYJSON_SUBTYPE_NONE: return "null"; case YYJSON_TYPE_STR | YYJSON_SUBTYPE_NONE: return "string"; case YYJSON_TYPE_STR | YYJSON_SUBTYPE_NOESC: return "string"; case YYJSON_TYPE_ARR | YYJSON_SUBTYPE_NONE: return "array"; case YYJSON_TYPE_OBJ | YYJSON_SUBTYPE_NONE: return "object"; case YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE: return "true"; case YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE: return "false"; case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT: return "uint"; case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT: return "sint"; case YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL: return "real"; default: return "unknown"; } } yyjson_api_inline const char *yyjson_get_raw(yyjson_val *val) { return yyjson_is_raw(val) ? unsafe_yyjson_get_raw(val) : NULL; } yyjson_api_inline bool yyjson_get_bool(yyjson_val *val) { return yyjson_is_bool(val) ? unsafe_yyjson_get_bool(val) : false; } yyjson_api_inline uint64_t yyjson_get_uint(yyjson_val *val) { return yyjson_is_int(val) ? unsafe_yyjson_get_uint(val) : 0; } yyjson_api_inline int64_t yyjson_get_sint(yyjson_val *val) { return yyjson_is_int(val) ? unsafe_yyjson_get_sint(val) : 0; } yyjson_api_inline int yyjson_get_int(yyjson_val *val) { return yyjson_is_int(val) ? unsafe_yyjson_get_int(val) : 0; } yyjson_api_inline double yyjson_get_real(yyjson_val *val) { return yyjson_is_real(val) ? unsafe_yyjson_get_real(val) : 0.0; } yyjson_api_inline double yyjson_get_num(yyjson_val *val) { return val ? unsafe_yyjson_get_num(val) : 0.0; } yyjson_api_inline const char *yyjson_get_str(yyjson_val *val) { return yyjson_is_str(val) ? unsafe_yyjson_get_str(val) : NULL; } yyjson_api_inline size_t yyjson_get_len(yyjson_val *val) { return val ? unsafe_yyjson_get_len(val) : 0; } yyjson_api_inline bool yyjson_equals_str(yyjson_val *val, const char *str) { if (yyjson_likely(val && str)) { return unsafe_yyjson_is_str(val) && unsafe_yyjson_equals_str(val, str); } return false; } yyjson_api_inline bool yyjson_equals_strn(yyjson_val *val, const char *str, size_t len) { if (yyjson_likely(val && str)) { return unsafe_yyjson_is_str(val) && unsafe_yyjson_equals_strn(val, str, len); } return false; } yyjson_api bool unsafe_yyjson_equals(yyjson_val *lhs, yyjson_val *rhs); yyjson_api_inline bool yyjson_equals(yyjson_val *lhs, yyjson_val *rhs) { if (yyjson_unlikely(!lhs || !rhs)) return false; return unsafe_yyjson_equals(lhs, rhs); } yyjson_api_inline bool yyjson_set_raw(yyjson_val *val, const char *raw, size_t len) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; unsafe_yyjson_set_raw(val, raw, len); return true; } yyjson_api_inline bool yyjson_set_null(yyjson_val *val) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; unsafe_yyjson_set_null(val); return true; } yyjson_api_inline bool yyjson_set_bool(yyjson_val *val, bool num) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; unsafe_yyjson_set_bool(val, num); return true; } yyjson_api_inline bool yyjson_set_uint(yyjson_val *val, uint64_t num) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; unsafe_yyjson_set_uint(val, num); return true; } yyjson_api_inline bool yyjson_set_sint(yyjson_val *val, int64_t num) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; unsafe_yyjson_set_sint(val, num); return true; } yyjson_api_inline bool yyjson_set_int(yyjson_val *val, int num) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; unsafe_yyjson_set_sint(val, (int64_t)num); return true; } yyjson_api_inline bool yyjson_set_real(yyjson_val *val, double num) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; unsafe_yyjson_set_real(val, num); return true; } yyjson_api_inline bool yyjson_set_str(yyjson_val *val, const char *str) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; if (yyjson_unlikely(!str)) return false; unsafe_yyjson_set_str(val, str); return true; } yyjson_api_inline bool yyjson_set_strn(yyjson_val *val, const char *str, size_t len) { if (yyjson_unlikely(!val || unsafe_yyjson_is_ctn(val))) return false; if (yyjson_unlikely(!str)) return false; unsafe_yyjson_set_strn(val, str, len); return true; } /*============================================================================== * JSON Array API (Implementation) *============================================================================*/ yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr) { return yyjson_is_arr(arr) ? unsafe_yyjson_get_len(arr) : 0; } yyjson_api_inline yyjson_val *yyjson_arr_get(yyjson_val *arr, size_t idx) { if (yyjson_likely(yyjson_is_arr(arr))) { if (yyjson_likely(unsafe_yyjson_get_len(arr) > idx)) { yyjson_val *val = unsafe_yyjson_get_first(arr); if (unsafe_yyjson_arr_is_flat(arr)) { return val + idx; } else { while (idx-- > 0) val = unsafe_yyjson_get_next(val); return val; } } } return NULL; } yyjson_api_inline yyjson_val *yyjson_arr_get_first(yyjson_val *arr) { if (yyjson_likely(yyjson_is_arr(arr))) { if (yyjson_likely(unsafe_yyjson_get_len(arr) > 0)) { return unsafe_yyjson_get_first(arr); } } return NULL; } yyjson_api_inline yyjson_val *yyjson_arr_get_last(yyjson_val *arr) { if (yyjson_likely(yyjson_is_arr(arr))) { size_t len = unsafe_yyjson_get_len(arr); if (yyjson_likely(len > 0)) { yyjson_val *val = unsafe_yyjson_get_first(arr); if (unsafe_yyjson_arr_is_flat(arr)) { return val + (len - 1); } else { while (len-- > 1) val = unsafe_yyjson_get_next(val); return val; } } } return NULL; } /*============================================================================== * JSON Array Iterator API (Implementation) *============================================================================*/ yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr, yyjson_arr_iter *iter) { if (yyjson_likely(yyjson_is_arr(arr) && iter)) { iter->idx = 0; iter->max = unsafe_yyjson_get_len(arr); iter->cur = unsafe_yyjson_get_first(arr); return true; } if (iter) memset(iter, 0, sizeof(yyjson_arr_iter)); return false; } yyjson_api_inline yyjson_arr_iter yyjson_arr_iter_with(yyjson_val *arr) { yyjson_arr_iter iter; yyjson_arr_iter_init(arr, &iter); return iter; } yyjson_api_inline bool yyjson_arr_iter_has_next(yyjson_arr_iter *iter) { return iter ? iter->idx < iter->max : false; } yyjson_api_inline yyjson_val *yyjson_arr_iter_next(yyjson_arr_iter *iter) { yyjson_val *val; if (iter && iter->idx < iter->max) { val = iter->cur; iter->cur = unsafe_yyjson_get_next(val); iter->idx++; return val; } return NULL; } /*============================================================================== * JSON Object API (Implementation) *============================================================================*/ yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj) { return yyjson_is_obj(obj) ? unsafe_yyjson_get_len(obj) : 0; } yyjson_api_inline yyjson_val *yyjson_obj_get(yyjson_val *obj, const char *key) { return yyjson_obj_getn(obj, key, key ? strlen(key) : 0); } yyjson_api_inline yyjson_val *yyjson_obj_getn(yyjson_val *obj, const char *_key, size_t key_len) { if (yyjson_likely(yyjson_is_obj(obj) && _key)) { size_t len = unsafe_yyjson_get_len(obj); yyjson_val *key = unsafe_yyjson_get_first(obj); while (len-- > 0) { if (unsafe_yyjson_equals_strn(key, _key, key_len)) return key + 1; key = unsafe_yyjson_get_next(key + 1); } } return NULL; } /*============================================================================== * JSON Object Iterator API (Implementation) *============================================================================*/ yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj, yyjson_obj_iter *iter) { if (yyjson_likely(yyjson_is_obj(obj) && iter)) { iter->idx = 0; iter->max = unsafe_yyjson_get_len(obj); iter->cur = unsafe_yyjson_get_first(obj); iter->obj = obj; return true; } if (iter) memset(iter, 0, sizeof(yyjson_obj_iter)); return false; } yyjson_api_inline yyjson_obj_iter yyjson_obj_iter_with(yyjson_val *obj) { yyjson_obj_iter iter; yyjson_obj_iter_init(obj, &iter); return iter; } yyjson_api_inline bool yyjson_obj_iter_has_next(yyjson_obj_iter *iter) { return iter ? iter->idx < iter->max : false; } yyjson_api_inline yyjson_val *yyjson_obj_iter_next(yyjson_obj_iter *iter) { if (iter && iter->idx < iter->max) { yyjson_val *key = iter->cur; iter->idx++; iter->cur = unsafe_yyjson_get_next(key + 1); return key; } return NULL; } yyjson_api_inline yyjson_val *yyjson_obj_iter_get_val(yyjson_val *key) { return key ? key + 1 : NULL; } yyjson_api_inline yyjson_val *yyjson_obj_iter_get(yyjson_obj_iter *iter, const char *key) { return yyjson_obj_iter_getn(iter, key, key ? strlen(key) : 0); } yyjson_api_inline yyjson_val *yyjson_obj_iter_getn(yyjson_obj_iter *iter, const char *key, size_t key_len) { if (iter && key) { size_t idx = iter->idx; size_t max = iter->max; yyjson_val *cur = iter->cur; if (yyjson_unlikely(idx == max)) { idx = 0; cur = unsafe_yyjson_get_first(iter->obj); } while (idx++ < max) { yyjson_val *next = unsafe_yyjson_get_next(cur + 1); if (unsafe_yyjson_equals_strn(cur, key, key_len)) { iter->idx = idx; iter->cur = next; return cur + 1; } cur = next; if (idx == iter->max && iter->idx < iter->max) { idx = 0; max = iter->idx; cur = unsafe_yyjson_get_first(iter->obj); } } } return NULL; } /*============================================================================== * Mutable JSON Structure (Implementation) *============================================================================*/ /** Mutable JSON value, 24 bytes. The 'tag' and 'uni' field is same as immutable value. The 'next' field links all elements inside the container to be a cycle. */ struct yyjson_mut_val { uint64_t tag; /**< type, subtype and length */ yyjson_val_uni uni; /**< payload */ yyjson_mut_val *next; /**< the next value in circular linked list */ }; /** A memory chunk in string memory pool. */ typedef struct yyjson_str_chunk { struct yyjson_str_chunk *next; /* next chunk linked list */ size_t chunk_size; /* chunk size in bytes */ /* char str[]; flexible array member */ } yyjson_str_chunk; /** A memory pool to hold all strings in a mutable document. */ typedef struct yyjson_str_pool { char *cur; /* cursor inside current chunk */ char *end; /* the end of current chunk */ size_t chunk_size; /* chunk size in bytes while creating new chunk */ size_t chunk_size_max; /* maximum chunk size in bytes */ yyjson_str_chunk *chunks; /* a linked list of chunks, nullable */ } yyjson_str_pool; /** A memory chunk in value memory pool. `sizeof(yyjson_val_chunk)` should not larger than `sizeof(yyjson_mut_val)`. */ typedef struct yyjson_val_chunk { struct yyjson_val_chunk *next; /* next chunk linked list */ size_t chunk_size; /* chunk size in bytes */ /* char pad[sizeof(yyjson_mut_val) - sizeof(yyjson_val_chunk)]; padding */ /* yyjson_mut_val vals[]; flexible array member */ } yyjson_val_chunk; /** A memory pool to hold all values in a mutable document. */ typedef struct yyjson_val_pool { yyjson_mut_val *cur; /* cursor inside current chunk */ yyjson_mut_val *end; /* the end of current chunk */ size_t chunk_size; /* chunk size in bytes while creating new chunk */ size_t chunk_size_max; /* maximum chunk size in bytes */ yyjson_val_chunk *chunks; /* a linked list of chunks, nullable */ } yyjson_val_pool; struct yyjson_mut_doc { yyjson_mut_val *root; /**< root value of the JSON document, nullable */ yyjson_alc alc; /**< a valid allocator, nonnull */ yyjson_str_pool str_pool; /**< string memory pool */ yyjson_val_pool val_pool; /**< value memory pool */ }; /* Ensures the capacity to at least equal to the specified byte length. */ yyjson_api bool unsafe_yyjson_str_pool_grow(yyjson_str_pool *pool, const yyjson_alc *alc, size_t len); /* Ensures the capacity to at least equal to the specified value count. */ yyjson_api bool unsafe_yyjson_val_pool_grow(yyjson_val_pool *pool, const yyjson_alc *alc, size_t count); /* Allocate memory for string. */ yyjson_api_inline char *unsafe_yyjson_mut_str_alc(yyjson_mut_doc *doc, size_t len) { char *mem; const yyjson_alc *alc = &doc->alc; yyjson_str_pool *pool = &doc->str_pool; if (yyjson_unlikely((size_t)(pool->end - pool->cur) <= len)) { if (yyjson_unlikely(!unsafe_yyjson_str_pool_grow(pool, alc, len + 1))) { return NULL; } } mem = pool->cur; pool->cur = mem + len + 1; return mem; } yyjson_api_inline char *unsafe_yyjson_mut_strncpy(yyjson_mut_doc *doc, const char *str, size_t len) { char *mem = unsafe_yyjson_mut_str_alc(doc, len); if (yyjson_unlikely(!mem)) return NULL; memcpy((void *)mem, (const void *)str, len); mem[len] = '\0'; return mem; } yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_val(yyjson_mut_doc *doc, size_t count) { yyjson_mut_val *val; yyjson_alc *alc = &doc->alc; yyjson_val_pool *pool = &doc->val_pool; if (yyjson_unlikely((size_t)(pool->end - pool->cur) < count)) { if (yyjson_unlikely(!unsafe_yyjson_val_pool_grow(pool, alc, count))) { return NULL; } } val = pool->cur; pool->cur += count; return val; } /*============================================================================== * Mutable JSON Document API (Implementation) *============================================================================*/ yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_root(yyjson_mut_doc *doc) { return doc ? doc->root : NULL; } yyjson_api_inline void yyjson_mut_doc_set_root(yyjson_mut_doc *doc, yyjson_mut_val *root) { if (doc) doc->root = root; } /*============================================================================== * Mutable JSON Value Type API (Implementation) *============================================================================*/ yyjson_api_inline bool yyjson_mut_is_raw(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_raw(val) : false; } yyjson_api_inline bool yyjson_mut_is_null(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_null(val) : false; } yyjson_api_inline bool yyjson_mut_is_true(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_true(val) : false; } yyjson_api_inline bool yyjson_mut_is_false(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_false(val) : false; } yyjson_api_inline bool yyjson_mut_is_bool(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_bool(val) : false; } yyjson_api_inline bool yyjson_mut_is_uint(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_uint(val) : false; } yyjson_api_inline bool yyjson_mut_is_sint(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_sint(val) : false; } yyjson_api_inline bool yyjson_mut_is_int(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_int(val) : false; } yyjson_api_inline bool yyjson_mut_is_real(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_real(val) : false; } yyjson_api_inline bool yyjson_mut_is_num(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_num(val) : false; } yyjson_api_inline bool yyjson_mut_is_str(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_str(val) : false; } yyjson_api_inline bool yyjson_mut_is_arr(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_arr(val) : false; } yyjson_api_inline bool yyjson_mut_is_obj(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_obj(val) : false; } yyjson_api_inline bool yyjson_mut_is_ctn(yyjson_mut_val *val) { return val ? unsafe_yyjson_is_ctn(val) : false; } /*============================================================================== * Mutable JSON Value Content API (Implementation) *============================================================================*/ yyjson_api_inline yyjson_type yyjson_mut_get_type(yyjson_mut_val *val) { return yyjson_get_type((yyjson_val *)val); } yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype(yyjson_mut_val *val) { return yyjson_get_subtype((yyjson_val *)val); } yyjson_api_inline uint8_t yyjson_mut_get_tag(yyjson_mut_val *val) { return yyjson_get_tag((yyjson_val *)val); } yyjson_api_inline const char *yyjson_mut_get_type_desc(yyjson_mut_val *val) { return yyjson_get_type_desc((yyjson_val *)val); } yyjson_api_inline const char *yyjson_mut_get_raw(yyjson_mut_val *val) { return yyjson_get_raw((yyjson_val *)val); } yyjson_api_inline bool yyjson_mut_get_bool(yyjson_mut_val *val) { return yyjson_get_bool((yyjson_val *)val); } yyjson_api_inline uint64_t yyjson_mut_get_uint(yyjson_mut_val *val) { return yyjson_get_uint((yyjson_val *)val); } yyjson_api_inline int64_t yyjson_mut_get_sint(yyjson_mut_val *val) { return yyjson_get_sint((yyjson_val *)val); } yyjson_api_inline int yyjson_mut_get_int(yyjson_mut_val *val) { return yyjson_get_int((yyjson_val *)val); } yyjson_api_inline double yyjson_mut_get_real(yyjson_mut_val *val) { return yyjson_get_real((yyjson_val *)val); } yyjson_api_inline double yyjson_mut_get_num(yyjson_mut_val *val) { return yyjson_get_num((yyjson_val *)val); } yyjson_api_inline const char *yyjson_mut_get_str(yyjson_mut_val *val) { return yyjson_get_str((yyjson_val *)val); } yyjson_api_inline size_t yyjson_mut_get_len(yyjson_mut_val *val) { return yyjson_get_len((yyjson_val *)val); } yyjson_api_inline bool yyjson_mut_equals_str(yyjson_mut_val *val, const char *str) { return yyjson_equals_str((yyjson_val *)val, str); } yyjson_api_inline bool yyjson_mut_equals_strn(yyjson_mut_val *val, const char *str, size_t len) { return yyjson_equals_strn((yyjson_val *)val, str, len); } yyjson_api bool unsafe_yyjson_mut_equals(yyjson_mut_val *lhs, yyjson_mut_val *rhs); yyjson_api_inline bool yyjson_mut_equals(yyjson_mut_val *lhs, yyjson_mut_val *rhs) { if (yyjson_unlikely(!lhs || !rhs)) return false; return unsafe_yyjson_mut_equals(lhs, rhs); } yyjson_api_inline bool yyjson_mut_set_raw(yyjson_mut_val *val, const char *raw, size_t len) { if (yyjson_unlikely(!val || !raw)) return false; unsafe_yyjson_set_raw(val, raw, len); return true; } yyjson_api_inline bool yyjson_mut_set_null(yyjson_mut_val *val) { if (yyjson_unlikely(!val)) return false; unsafe_yyjson_set_null(val); return true; } yyjson_api_inline bool yyjson_mut_set_bool(yyjson_mut_val *val, bool num) { if (yyjson_unlikely(!val)) return false; unsafe_yyjson_set_bool(val, num); return true; } yyjson_api_inline bool yyjson_mut_set_uint(yyjson_mut_val *val, uint64_t num) { if (yyjson_unlikely(!val)) return false; unsafe_yyjson_set_uint(val, num); return true; } yyjson_api_inline bool yyjson_mut_set_sint(yyjson_mut_val *val, int64_t num) { if (yyjson_unlikely(!val)) return false; unsafe_yyjson_set_sint(val, num); return true; } yyjson_api_inline bool yyjson_mut_set_int(yyjson_mut_val *val, int num) { if (yyjson_unlikely(!val)) return false; unsafe_yyjson_set_sint(val, (int64_t)num); return true; } yyjson_api_inline bool yyjson_mut_set_real(yyjson_mut_val *val, double num) { if (yyjson_unlikely(!val)) return false; unsafe_yyjson_set_real(val, num); return true; } yyjson_api_inline bool yyjson_mut_set_str(yyjson_mut_val *val, const char *str) { if (yyjson_unlikely(!val || !str)) return false; unsafe_yyjson_set_str(val, str); return true; } yyjson_api_inline bool yyjson_mut_set_strn(yyjson_mut_val *val, const char *str, size_t len) { if (yyjson_unlikely(!val || !str)) return false; unsafe_yyjson_set_strn(val, str, len); return true; } yyjson_api_inline bool yyjson_mut_set_arr(yyjson_mut_val *val) { if (yyjson_unlikely(!val)) return false; unsafe_yyjson_set_arr(val, 0); return true; } yyjson_api_inline bool yyjson_mut_set_obj(yyjson_mut_val *val) { if (yyjson_unlikely(!val)) return false; unsafe_yyjson_set_obj(val, 0); return true; } /*============================================================================== * Mutable JSON Value Creation API (Implementation) *============================================================================*/ yyjson_api_inline yyjson_mut_val *yyjson_mut_raw(yyjson_mut_doc *doc, const char *str) { if (yyjson_likely(str)) return yyjson_mut_rawn(doc, str, strlen(str)); return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_rawn(yyjson_mut_doc *doc, const char *str, size_t len) { if (yyjson_likely(doc && str)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; val->uni.str = str; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_rawcpy(yyjson_mut_doc *doc, const char *str) { if (yyjson_likely(str)) return yyjson_mut_rawncpy(doc, str, strlen(str)); return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_rawncpy(yyjson_mut_doc *doc, const char *str, size_t len) { if (yyjson_likely(doc && str)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); if (yyjson_likely(val && new_str)) { val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | YYJSON_TYPE_RAW; val->uni.str = new_str; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_null(yyjson_mut_doc *doc) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = YYJSON_TYPE_NULL | YYJSON_SUBTYPE_NONE; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_true(yyjson_mut_doc *doc) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_false(yyjson_mut_doc *doc) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc, bool _val) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { _val = !!_val; val->tag = YYJSON_TYPE_BOOL | (uint8_t)((uint8_t)_val << 3); return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_uint(yyjson_mut_doc *doc, uint64_t num) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; val->uni.u64 = num; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_sint(yyjson_mut_doc *doc, int64_t num) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; val->uni.i64 = num; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_int(yyjson_mut_doc *doc, int64_t num) { return yyjson_mut_sint(doc, num); } yyjson_api_inline yyjson_mut_val *yyjson_mut_real(yyjson_mut_doc *doc, double num) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; val->uni.f64 = num; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_str(yyjson_mut_doc *doc, const char *str) { if (yyjson_likely(doc && str)) { size_t len = strlen(str); bool noesc = unsafe_yyjson_is_str_noesc(str, len); yyjson_subtype sub = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | (uint64_t)(YYJSON_TYPE_STR | sub); val->uni.str = str; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_strn(yyjson_mut_doc *doc, const char *str, size_t len) { if (yyjson_likely(doc && str)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = str; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_strcpy(yyjson_mut_doc *doc, const char *str) { if (yyjson_likely(doc && str)) { size_t len = strlen(str); bool noesc = unsafe_yyjson_is_str_noesc(str, len); yyjson_subtype sub = noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); if (yyjson_likely(val && new_str)) { val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | (uint64_t)(YYJSON_TYPE_STR | sub); val->uni.str = new_str; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_strncpy(yyjson_mut_doc *doc, const char *str, size_t len) { if (yyjson_likely(doc && str)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); char *new_str = unsafe_yyjson_mut_strncpy(doc, str, len); if (yyjson_likely(val && new_str)) { val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = new_str; return val; } } return NULL; } /*============================================================================== * Mutable JSON Array API (Implementation) *============================================================================*/ yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr) { return yyjson_mut_is_arr(arr) ? unsafe_yyjson_get_len(arr) : 0; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get(yyjson_mut_val *arr, size_t idx) { if (yyjson_likely(idx < yyjson_mut_arr_size(arr))) { yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; while (idx-- > 0) val = val->next; return val->next; } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_first( yyjson_mut_val *arr) { if (yyjson_likely(yyjson_mut_arr_size(arr) > 0)) { return ((yyjson_mut_val *)arr->uni.ptr)->next; } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_get_last( yyjson_mut_val *arr) { if (yyjson_likely(yyjson_mut_arr_size(arr) > 0)) { return ((yyjson_mut_val *)arr->uni.ptr); } return NULL; } /*============================================================================== * Mutable JSON Array Iterator API (Implementation) *============================================================================*/ yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr, yyjson_mut_arr_iter *iter) { if (yyjson_likely(yyjson_mut_is_arr(arr) && iter)) { iter->idx = 0; iter->max = unsafe_yyjson_get_len(arr); iter->cur = iter->max ? (yyjson_mut_val *)arr->uni.ptr : NULL; iter->pre = NULL; iter->arr = arr; return true; } if (iter) memset(iter, 0, sizeof(yyjson_mut_arr_iter)); return false; } yyjson_api_inline yyjson_mut_arr_iter yyjson_mut_arr_iter_with( yyjson_mut_val *arr) { yyjson_mut_arr_iter iter; yyjson_mut_arr_iter_init(arr, &iter); return iter; } yyjson_api_inline bool yyjson_mut_arr_iter_has_next(yyjson_mut_arr_iter *iter) { return iter ? iter->idx < iter->max : false; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_next( yyjson_mut_arr_iter *iter) { if (iter && iter->idx < iter->max) { yyjson_mut_val *val = iter->cur; iter->pre = val; iter->cur = val->next; iter->idx++; return iter->cur; } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_iter_remove( yyjson_mut_arr_iter *iter) { if (yyjson_likely(iter && 0 < iter->idx && iter->idx <= iter->max)) { yyjson_mut_val *prev = iter->pre; yyjson_mut_val *cur = iter->cur; yyjson_mut_val *next = cur->next; if (yyjson_unlikely(iter->idx == iter->max)) iter->arr->uni.ptr = prev; iter->idx--; iter->max--; unsafe_yyjson_set_len(iter->arr, iter->max); prev->next = next; iter->cur = next; return cur; } return NULL; } /*============================================================================== * Mutable JSON Array Creation API (Implementation) *============================================================================*/ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = YYJSON_TYPE_ARR | YYJSON_SUBTYPE_NONE; return val; } } return NULL; } #define yyjson_mut_arr_with_func(func) \ if (yyjson_likely(doc && ((0 < count && count < \ (~(size_t)0) / sizeof(yyjson_mut_val) && vals) || count == 0))) { \ yyjson_mut_val *arr = unsafe_yyjson_mut_val(doc, 1 + count); \ if (yyjson_likely(arr)) { \ arr->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_ARR; \ if (count > 0) { \ size_t i; \ for (i = 0; i < count; i++) { \ yyjson_mut_val *val = arr + i + 1; \ func \ val->next = val + 1; \ } \ arr[count].next = arr + 1; \ arr->uni.ptr = arr + count; \ } \ return arr; \ } \ } \ return NULL yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool( yyjson_mut_doc *doc, const bool *vals, size_t count) { yyjson_mut_arr_with_func({ bool _val = !!vals[i]; val->tag = YYJSON_TYPE_BOOL | (uint8_t)((uint8_t)_val << 3); }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint( yyjson_mut_doc *doc, const int64_t *vals, size_t count) { return yyjson_mut_arr_with_sint64(doc, vals, count); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint( yyjson_mut_doc *doc, const uint64_t *vals, size_t count) { return yyjson_mut_arr_with_uint64(doc, vals, count); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_real( yyjson_mut_doc *doc, const double *vals, size_t count) { return yyjson_mut_arr_with_double(doc, vals, count); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint8( yyjson_mut_doc *doc, const int8_t *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; val->uni.i64 = (int64_t)vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint16( yyjson_mut_doc *doc, const int16_t *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; val->uni.i64 = vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint32( yyjson_mut_doc *doc, const int32_t *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; val->uni.i64 = vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_sint64( yyjson_mut_doc *doc, const int64_t *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; val->uni.i64 = vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint8( yyjson_mut_doc *doc, const uint8_t *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; val->uni.u64 = vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint16( yyjson_mut_doc *doc, const uint16_t *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; val->uni.u64 = vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint32( yyjson_mut_doc *doc, const uint32_t *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; val->uni.u64 = vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_uint64( yyjson_mut_doc *doc, const uint64_t *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; val->uni.u64 = vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_float( yyjson_mut_doc *doc, const float *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; val->uni.f64 = (double)vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_double( yyjson_mut_doc *doc, const double *vals, size_t count) { yyjson_mut_arr_with_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; val->uni.f64 = vals[i]; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_str( yyjson_mut_doc *doc, const char **vals, size_t count) { yyjson_mut_arr_with_func({ uint64_t len = (uint64_t)strlen(vals[i]); val->tag = (len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = vals[i]; if (yyjson_unlikely(!val->uni.str)) return NULL; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strn( yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count) { if (yyjson_unlikely(count > 0 && !lens)) return NULL; yyjson_mut_arr_with_func({ val->tag = ((uint64_t)lens[i] << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = vals[i]; if (yyjson_unlikely(!val->uni.str)) return NULL; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strcpy( yyjson_mut_doc *doc, const char **vals, size_t count) { size_t len; const char *str; yyjson_mut_arr_with_func({ str = vals[i]; if (!str) return NULL; len = strlen(str); val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = unsafe_yyjson_mut_strncpy(doc, str, len); if (yyjson_unlikely(!val->uni.str)) return NULL; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_strncpy( yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count) { size_t len; const char *str; if (yyjson_unlikely(count > 0 && !lens)) return NULL; yyjson_mut_arr_with_func({ str = vals[i]; len = lens[i]; val->tag = ((uint64_t)len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = unsafe_yyjson_mut_strncpy(doc, str, len); if (yyjson_unlikely(!val->uni.str)) return NULL; }); } #undef yyjson_mut_arr_with_func /*============================================================================== * Mutable JSON Array Modification API (Implementation) *============================================================================*/ yyjson_api_inline bool yyjson_mut_arr_insert(yyjson_mut_val *arr, yyjson_mut_val *val, size_t idx) { if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { size_t len = unsafe_yyjson_get_len(arr); if (yyjson_likely(idx <= len)) { unsafe_yyjson_set_len(arr, len + 1); if (len == 0) { val->next = val; arr->uni.ptr = val; } else { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); yyjson_mut_val *next = prev->next; if (idx == len) { prev->next = val; val->next = next; arr->uni.ptr = val; } else { while (idx-- > 0) { prev = next; next = next->next; } prev->next = val; val->next = next; } } return true; } } return false; } yyjson_api_inline bool yyjson_mut_arr_append(yyjson_mut_val *arr, yyjson_mut_val *val) { if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { size_t len = unsafe_yyjson_get_len(arr); unsafe_yyjson_set_len(arr, len + 1); if (len == 0) { val->next = val; } else { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); yyjson_mut_val *next = prev->next; prev->next = val; val->next = next; } arr->uni.ptr = val; return true; } return false; } yyjson_api_inline bool yyjson_mut_arr_prepend(yyjson_mut_val *arr, yyjson_mut_val *val) { if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { size_t len = unsafe_yyjson_get_len(arr); unsafe_yyjson_set_len(arr, len + 1); if (len == 0) { val->next = val; arr->uni.ptr = val; } else { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); yyjson_mut_val *next = prev->next; prev->next = val; val->next = next; } return true; } return false; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_replace(yyjson_mut_val *arr, size_t idx, yyjson_mut_val *val) { if (yyjson_likely(yyjson_mut_is_arr(arr) && val)) { size_t len = unsafe_yyjson_get_len(arr); if (yyjson_likely(idx < len)) { if (yyjson_likely(len > 1)) { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); yyjson_mut_val *next = prev->next; while (idx-- > 0) { prev = next; next = next->next; } prev->next = val; val->next = next->next; if ((void *)next == arr->uni.ptr) arr->uni.ptr = val; return next; } else { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); val->next = val; arr->uni.ptr = val; return prev; } } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove(yyjson_mut_val *arr, size_t idx) { if (yyjson_likely(yyjson_mut_is_arr(arr))) { size_t len = unsafe_yyjson_get_len(arr); if (yyjson_likely(idx < len)) { unsafe_yyjson_set_len(arr, len - 1); if (yyjson_likely(len > 1)) { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); yyjson_mut_val *next = prev->next; while (idx-- > 0) { prev = next; next = next->next; } prev->next = next->next; if ((void *)next == arr->uni.ptr) arr->uni.ptr = prev; return next; } else { return ((yyjson_mut_val *)arr->uni.ptr); } } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_first( yyjson_mut_val *arr) { if (yyjson_likely(yyjson_mut_is_arr(arr))) { size_t len = unsafe_yyjson_get_len(arr); if (len > 1) { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); yyjson_mut_val *next = prev->next; prev->next = next->next; unsafe_yyjson_set_len(arr, len - 1); return next; } else if (len == 1) { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); unsafe_yyjson_set_len(arr, 0); return prev; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_remove_last( yyjson_mut_val *arr) { if (yyjson_likely(yyjson_mut_is_arr(arr))) { size_t len = unsafe_yyjson_get_len(arr); if (yyjson_likely(len > 1)) { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); yyjson_mut_val *next = prev->next; unsafe_yyjson_set_len(arr, len - 1); while (--len > 0) prev = prev->next; prev->next = next; next = (yyjson_mut_val *)arr->uni.ptr; arr->uni.ptr = prev; return next; } else if (len == 1) { yyjson_mut_val *prev = ((yyjson_mut_val *)arr->uni.ptr); unsafe_yyjson_set_len(arr, 0); return prev; } } return NULL; } yyjson_api_inline bool yyjson_mut_arr_remove_range(yyjson_mut_val *arr, size_t _idx, size_t _len) { if (yyjson_likely(yyjson_mut_is_arr(arr))) { yyjson_mut_val *prev, *next; bool tail_removed; size_t len = unsafe_yyjson_get_len(arr); if (yyjson_unlikely(_idx + _len > len)) return false; if (yyjson_unlikely(_len == 0)) return true; unsafe_yyjson_set_len(arr, len - _len); if (yyjson_unlikely(len == _len)) return true; tail_removed = (_idx + _len == len); prev = ((yyjson_mut_val *)arr->uni.ptr); while (_idx-- > 0) prev = prev->next; next = prev->next; while (_len-- > 0) next = next->next; prev->next = next; if (yyjson_unlikely(tail_removed)) arr->uni.ptr = prev; return true; } return false; } yyjson_api_inline bool yyjson_mut_arr_clear(yyjson_mut_val *arr) { if (yyjson_likely(yyjson_mut_is_arr(arr))) { unsafe_yyjson_set_len(arr, 0); return true; } return false; } yyjson_api_inline bool yyjson_mut_arr_rotate(yyjson_mut_val *arr, size_t idx) { if (yyjson_likely(yyjson_mut_is_arr(arr) && unsafe_yyjson_get_len(arr) > idx)) { yyjson_mut_val *val = (yyjson_mut_val *)arr->uni.ptr; while (idx-- > 0) val = val->next; arr->uni.ptr = (void *)val; return true; } return false; } /*============================================================================== * Mutable JSON Array Modification Convenience API (Implementation) *============================================================================*/ yyjson_api_inline bool yyjson_mut_arr_add_val(yyjson_mut_val *arr, yyjson_mut_val *val) { return yyjson_mut_arr_append(arr, val); } yyjson_api_inline bool yyjson_mut_arr_add_null(yyjson_mut_doc *doc, yyjson_mut_val *arr) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_null(doc); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_true(yyjson_mut_doc *doc, yyjson_mut_val *arr) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_true(doc); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_false(yyjson_mut_doc *doc, yyjson_mut_val *arr) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_false(doc); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_bool(yyjson_mut_doc *doc, yyjson_mut_val *arr, bool _val) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_bool(doc, _val); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_uint(yyjson_mut_doc *doc, yyjson_mut_val *arr, uint64_t num) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_uint(doc, num); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_sint(yyjson_mut_doc *doc, yyjson_mut_val *arr, int64_t num) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_sint(doc, num); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_int(yyjson_mut_doc *doc, yyjson_mut_val *arr, int64_t num) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_sint(doc, num); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_real(yyjson_mut_doc *doc, yyjson_mut_val *arr, double num) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_real(doc, num); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_str(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_str(doc, str); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_strn(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str, size_t len) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_strn(doc, str, len); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_strcpy(doc, str); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline bool yyjson_mut_arr_add_strncpy(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str, size_t len) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_strncpy(doc, str, len); return yyjson_mut_arr_append(arr, val); } return false; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_arr(yyjson_mut_doc *doc, yyjson_mut_val *arr) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_arr(doc); return yyjson_mut_arr_append(arr, val) ? val : NULL; } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_add_obj(yyjson_mut_doc *doc, yyjson_mut_val *arr) { if (yyjson_likely(doc && yyjson_mut_is_arr(arr))) { yyjson_mut_val *val = yyjson_mut_obj(doc); return yyjson_mut_arr_append(arr, val) ? val : NULL; } return NULL; } /*============================================================================== * Mutable JSON Object API (Implementation) *============================================================================*/ yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj) { return yyjson_mut_is_obj(obj) ? unsafe_yyjson_get_len(obj) : 0; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_get(yyjson_mut_val *obj, const char *key) { return yyjson_mut_obj_getn(obj, key, key ? strlen(key) : 0); } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_getn(yyjson_mut_val *obj, const char *_key, size_t key_len) { size_t len = yyjson_mut_obj_size(obj); if (yyjson_likely(len && _key)) { yyjson_mut_val *key = ((yyjson_mut_val *)obj->uni.ptr)->next->next; while (len-- > 0) { if (unsafe_yyjson_equals_strn(key, _key, key_len)) return key->next; key = key->next->next; } } return NULL; } /*============================================================================== * Mutable JSON Object Iterator API (Implementation) *============================================================================*/ yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj, yyjson_mut_obj_iter *iter) { if (yyjson_likely(yyjson_mut_is_obj(obj) && iter)) { iter->idx = 0; iter->max = unsafe_yyjson_get_len(obj); iter->cur = iter->max ? (yyjson_mut_val *)obj->uni.ptr : NULL; iter->pre = NULL; iter->obj = obj; return true; } if (iter) memset(iter, 0, sizeof(yyjson_mut_obj_iter)); return false; } yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with( yyjson_mut_val *obj) { yyjson_mut_obj_iter iter; yyjson_mut_obj_iter_init(obj, &iter); return iter; } yyjson_api_inline bool yyjson_mut_obj_iter_has_next(yyjson_mut_obj_iter *iter) { return iter ? iter->idx < iter->max : false; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_next( yyjson_mut_obj_iter *iter) { if (iter && iter->idx < iter->max) { yyjson_mut_val *key = iter->cur; iter->pre = key; iter->cur = key->next->next; iter->idx++; return iter->cur; } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get_val( yyjson_mut_val *key) { return key ? key->next : NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_remove( yyjson_mut_obj_iter *iter) { if (yyjson_likely(iter && 0 < iter->idx && iter->idx <= iter->max)) { yyjson_mut_val *prev = iter->pre; yyjson_mut_val *cur = iter->cur; yyjson_mut_val *next = cur->next->next; if (yyjson_unlikely(iter->idx == iter->max)) iter->obj->uni.ptr = prev; iter->idx--; iter->max--; unsafe_yyjson_set_len(iter->obj, iter->max); prev->next->next = next; iter->cur = prev; return cur->next; } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_get( yyjson_mut_obj_iter *iter, const char *key) { return yyjson_mut_obj_iter_getn(iter, key, key ? strlen(key) : 0); } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_iter_getn( yyjson_mut_obj_iter *iter, const char *key, size_t key_len) { if (iter && key) { size_t idx = 0; size_t max = iter->max; yyjson_mut_val *pre, *cur = iter->cur; while (idx++ < max) { pre = cur; cur = cur->next->next; if (unsafe_yyjson_equals_strn(cur, key, key_len)) { iter->idx += idx; if (iter->idx > max) iter->idx -= max + 1; iter->pre = pre; iter->cur = cur; return cur->next; } } } return NULL; } /*============================================================================== * Mutable JSON Object Creation API (Implementation) *============================================================================*/ yyjson_api_inline yyjson_mut_val *yyjson_mut_obj(yyjson_mut_doc *doc) { if (yyjson_likely(doc)) { yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1); if (yyjson_likely(val)) { val->tag = YYJSON_TYPE_OBJ | YYJSON_SUBTYPE_NONE; return val; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_str(yyjson_mut_doc *doc, const char **keys, const char **vals, size_t count) { if (yyjson_likely(doc && ((count > 0 && keys && vals) || (count == 0)))) { yyjson_mut_val *obj = unsafe_yyjson_mut_val(doc, 1 + count * 2); if (yyjson_likely(obj)) { obj->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_OBJ; if (count > 0) { size_t i; for (i = 0; i < count; i++) { yyjson_mut_val *key = obj + (i * 2 + 1); yyjson_mut_val *val = obj + (i * 2 + 2); uint64_t key_len = (uint64_t)strlen(keys[i]); uint64_t val_len = (uint64_t)strlen(vals[i]); key->tag = (key_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->tag = (val_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; key->uni.str = keys[i]; val->uni.str = vals[i]; key->next = val; val->next = val + 1; } obj[count * 2].next = obj + 1; obj->uni.ptr = obj + (count * 2 - 1); } return obj; } } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_with_kv(yyjson_mut_doc *doc, const char **pairs, size_t count) { if (yyjson_likely(doc && ((count > 0 && pairs) || (count == 0)))) { yyjson_mut_val *obj = unsafe_yyjson_mut_val(doc, 1 + count * 2); if (yyjson_likely(obj)) { obj->tag = ((uint64_t)count << YYJSON_TAG_BIT) | YYJSON_TYPE_OBJ; if (count > 0) { size_t i; for (i = 0; i < count; i++) { yyjson_mut_val *key = obj + (i * 2 + 1); yyjson_mut_val *val = obj + (i * 2 + 2); const char *key_str = pairs[i * 2 + 0]; const char *val_str = pairs[i * 2 + 1]; uint64_t key_len = (uint64_t)strlen(key_str); uint64_t val_len = (uint64_t)strlen(val_str); key->tag = (key_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->tag = (val_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; key->uni.str = key_str; val->uni.str = val_str; key->next = val; val->next = val + 1; } obj[count * 2].next = obj + 1; obj->uni.ptr = obj + (count * 2 - 1); } return obj; } } return NULL; } /*============================================================================== * Mutable JSON Object Modification API (Implementation) *============================================================================*/ yyjson_api_inline void unsafe_yyjson_mut_obj_add(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val, size_t len) { if (yyjson_likely(len)) { yyjson_mut_val *prev_val = ((yyjson_mut_val *)obj->uni.ptr)->next; yyjson_mut_val *next_key = prev_val->next; prev_val->next = key; val->next = next_key; } else { val->next = key; } key->next = val; obj->uni.ptr = (void *)key; unsafe_yyjson_set_len(obj, len + 1); } yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_obj_remove( yyjson_mut_val *obj, const char *key, size_t key_len) { size_t obj_len = unsafe_yyjson_get_len(obj); if (obj_len) { yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr; yyjson_mut_val *cur_key = pre_key->next->next; yyjson_mut_val *removed_item = NULL; size_t i; for (i = 0; i < obj_len; i++) { if (unsafe_yyjson_equals_strn(cur_key, key, key_len)) { if (!removed_item) removed_item = cur_key->next; cur_key = cur_key->next->next; pre_key->next->next = cur_key; if (i + 1 == obj_len) obj->uni.ptr = pre_key; i--; obj_len--; } else { pre_key = cur_key; cur_key = cur_key->next->next; } } unsafe_yyjson_set_len(obj, obj_len); return removed_item; } else { return NULL; } } yyjson_api_inline bool unsafe_yyjson_mut_obj_replace(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val) { size_t key_len = unsafe_yyjson_get_len(key); size_t obj_len = unsafe_yyjson_get_len(obj); if (obj_len) { yyjson_mut_val *pre_key = (yyjson_mut_val *)obj->uni.ptr; yyjson_mut_val *cur_key = pre_key->next->next; size_t i; for (i = 0; i < obj_len; i++) { if (unsafe_yyjson_equals_strn(cur_key, key->uni.str, key_len)) { cur_key->next->tag = val->tag; cur_key->next->uni.u64 = val->uni.u64; return true; } else { cur_key = cur_key->next->next; } } } return false; } yyjson_api_inline void unsafe_yyjson_mut_obj_rotate(yyjson_mut_val *obj, size_t idx) { yyjson_mut_val *key = (yyjson_mut_val *)obj->uni.ptr; while (idx-- > 0) key = key->next->next; obj->uni.ptr = (void *)key; } yyjson_api_inline bool yyjson_mut_obj_add(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val) { if (yyjson_likely(yyjson_mut_is_obj(obj) && yyjson_mut_is_str(key) && val)) { unsafe_yyjson_mut_obj_add(obj, key, val, unsafe_yyjson_get_len(obj)); return true; } return false; } yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val) { bool replaced = false; size_t key_len; yyjson_mut_obj_iter iter; yyjson_mut_val *cur_key; if (yyjson_unlikely(!yyjson_mut_is_obj(obj) || !yyjson_mut_is_str(key))) return false; key_len = unsafe_yyjson_get_len(key); yyjson_mut_obj_iter_init(obj, &iter); while ((cur_key = yyjson_mut_obj_iter_next(&iter)) != 0) { if (unsafe_yyjson_equals_strn(cur_key, key->uni.str, key_len)) { if (!replaced && val) { replaced = true; val->next = cur_key->next->next; cur_key->next = val; } else { yyjson_mut_obj_iter_remove(&iter); } } } if (!replaced && val) unsafe_yyjson_mut_obj_add(obj, key, val, iter.max); return true; } yyjson_api_inline bool yyjson_mut_obj_insert(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val, size_t idx) { if (yyjson_likely(yyjson_mut_is_obj(obj) && yyjson_mut_is_str(key) && val)) { size_t len = unsafe_yyjson_get_len(obj); if (yyjson_likely(len >= idx)) { if (len > idx) { void *ptr = obj->uni.ptr; unsafe_yyjson_mut_obj_rotate(obj, idx); unsafe_yyjson_mut_obj_add(obj, key, val, len); obj->uni.ptr = ptr; } else { unsafe_yyjson_mut_obj_add(obj, key, val, len); } return true; } } return false; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove(yyjson_mut_val *obj, yyjson_mut_val *key) { if (yyjson_likely(yyjson_mut_is_obj(obj) && yyjson_mut_is_str(key))) { return unsafe_yyjson_mut_obj_remove(obj, key->uni.str, unsafe_yyjson_get_len(key)); } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_key( yyjson_mut_val *obj, const char *key) { if (yyjson_likely(yyjson_mut_is_obj(obj) && key)) { size_t key_len = strlen(key); return unsafe_yyjson_mut_obj_remove(obj, key, key_len); } return NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_keyn( yyjson_mut_val *obj, const char *key, size_t key_len) { if (yyjson_likely(yyjson_mut_is_obj(obj) && key)) { return unsafe_yyjson_mut_obj_remove(obj, key, key_len); } return NULL; } yyjson_api_inline bool yyjson_mut_obj_clear(yyjson_mut_val *obj) { if (yyjson_likely(yyjson_mut_is_obj(obj))) { unsafe_yyjson_set_len(obj, 0); return true; } return false; } yyjson_api_inline bool yyjson_mut_obj_replace(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val) { if (yyjson_likely(yyjson_mut_is_obj(obj) && yyjson_mut_is_str(key) && val)) { return unsafe_yyjson_mut_obj_replace(obj, key, val); } return false; } yyjson_api_inline bool yyjson_mut_obj_rotate(yyjson_mut_val *obj, size_t idx) { if (yyjson_likely(yyjson_mut_is_obj(obj) && unsafe_yyjson_get_len(obj) > idx)) { unsafe_yyjson_mut_obj_rotate(obj, idx); return true; } return false; } /*============================================================================== * Mutable JSON Object Modification Convenience API (Implementation) *============================================================================*/ #define yyjson_mut_obj_add_func(func) \ if (yyjson_likely(doc && yyjson_mut_is_obj(obj) && _key)) { \ yyjson_mut_val *key = unsafe_yyjson_mut_val(doc, 2); \ if (yyjson_likely(key)) { \ size_t len = unsafe_yyjson_get_len(obj); \ yyjson_mut_val *val = key + 1; \ size_t key_len = strlen(_key); \ bool noesc = unsafe_yyjson_is_str_noesc(_key, key_len); \ key->tag = YYJSON_TYPE_STR; \ key->tag |= noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; \ key->tag |= (uint64_t)strlen(_key) << YYJSON_TAG_BIT; \ key->uni.str = _key; \ func \ unsafe_yyjson_mut_obj_add(obj, key, val, len); \ return true; \ } \ } \ return false yyjson_api_inline bool yyjson_mut_obj_add_null(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key) { yyjson_mut_obj_add_func({ val->tag = YYJSON_TYPE_NULL | YYJSON_SUBTYPE_NONE; }); } yyjson_api_inline bool yyjson_mut_obj_add_true(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key) { yyjson_mut_obj_add_func({ val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE; }); } yyjson_api_inline bool yyjson_mut_obj_add_false(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key) { yyjson_mut_obj_add_func({ val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_FALSE; }); } yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, bool _val) { yyjson_mut_obj_add_func({ _val = !!_val; val->tag = YYJSON_TYPE_BOOL | (uint8_t)((uint8_t)(_val) << 3); }); } yyjson_api_inline bool yyjson_mut_obj_add_uint(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, uint64_t _val) { yyjson_mut_obj_add_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_UINT; val->uni.u64 = _val; }); } yyjson_api_inline bool yyjson_mut_obj_add_sint(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, int64_t _val) { yyjson_mut_obj_add_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; val->uni.i64 = _val; }); } yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, int64_t _val) { yyjson_mut_obj_add_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_SINT; val->uni.i64 = _val; }); } yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, double _val) { yyjson_mut_obj_add_func({ val->tag = YYJSON_TYPE_NUM | YYJSON_SUBTYPE_REAL; val->uni.f64 = _val; }); } yyjson_api_inline bool yyjson_mut_obj_add_str(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, const char *_val) { if (yyjson_unlikely(!_val)) return false; yyjson_mut_obj_add_func({ size_t val_len = strlen(_val); bool val_noesc = unsafe_yyjson_is_str_noesc(_val, val_len); val->tag = ((uint64_t)strlen(_val) << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->tag |= val_noesc ? YYJSON_SUBTYPE_NOESC : YYJSON_SUBTYPE_NONE; val->uni.str = _val; }); } yyjson_api_inline bool yyjson_mut_obj_add_strn(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, const char *_val, size_t _len) { if (yyjson_unlikely(!_val)) return false; yyjson_mut_obj_add_func({ val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; val->uni.str = _val; }); } yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, const char *_val) { if (yyjson_unlikely(!_val)) return false; yyjson_mut_obj_add_func({ size_t _len = strlen(_val); val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len); if (yyjson_unlikely(!val->uni.str)) return false; val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; }); } yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, const char *_val, size_t _len) { if (yyjson_unlikely(!_val)) return false; yyjson_mut_obj_add_func({ val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len); if (yyjson_unlikely(!val->uni.str)) return false; val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_arr(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key) { yyjson_mut_val *key = yyjson_mut_str(doc, _key); yyjson_mut_val *val = yyjson_mut_arr(doc); return yyjson_mut_obj_add(obj, key, val) ? val : NULL; } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_add_obj(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key) { yyjson_mut_val *key = yyjson_mut_str(doc, _key); yyjson_mut_val *val = yyjson_mut_obj(doc); return yyjson_mut_obj_add(obj, key, val) ? val : NULL; } yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, yyjson_mut_val *_val) { if (yyjson_unlikely(!_val)) return false; yyjson_mut_obj_add_func({ val = _val; }); } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_str(yyjson_mut_val *obj, const char *key) { return yyjson_mut_obj_remove_strn(obj, key, key ? strlen(key) : 0); } yyjson_api_inline yyjson_mut_val *yyjson_mut_obj_remove_strn( yyjson_mut_val *obj, const char *_key, size_t _len) { if (yyjson_likely(yyjson_mut_is_obj(obj) && _key)) { yyjson_mut_val *key; yyjson_mut_obj_iter iter; yyjson_mut_val *val_removed = NULL; yyjson_mut_obj_iter_init(obj, &iter); while ((key = yyjson_mut_obj_iter_next(&iter)) != NULL) { if (unsafe_yyjson_equals_strn(key, _key, _len)) { if (!val_removed) val_removed = key->next; yyjson_mut_obj_iter_remove(&iter); } } return val_removed; } return NULL; } yyjson_api_inline bool yyjson_mut_obj_rename_key(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *new_key) { if (!key || !new_key) return false; return yyjson_mut_obj_rename_keyn(doc, obj, key, strlen(key), new_key, strlen(new_key)); } yyjson_api_inline bool yyjson_mut_obj_rename_keyn(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, size_t len, const char *new_key, size_t new_len) { char *cpy_key = NULL; yyjson_mut_val *old_key; yyjson_mut_obj_iter iter; if (!doc || !obj || !key || !new_key) return false; yyjson_mut_obj_iter_init(obj, &iter); while ((old_key = yyjson_mut_obj_iter_next(&iter))) { if (unsafe_yyjson_equals_strn((void *)old_key, key, len)) { if (!cpy_key) { cpy_key = unsafe_yyjson_mut_strncpy(doc, new_key, new_len); if (!cpy_key) return false; } yyjson_mut_set_strn(old_key, cpy_key, new_len); } } return cpy_key != NULL; } /*============================================================================== * JSON Pointer API (Implementation) *============================================================================*/ #define yyjson_ptr_set_err(_code, _msg) do { \ if (err) { \ err->code = YYJSON_PTR_ERR_##_code; \ err->msg = _msg; \ err->pos = 0; \ } \ } while(false) /* require: val != NULL, *ptr == '/', len > 0 */ yyjson_api yyjson_val *unsafe_yyjson_ptr_getx(yyjson_val *val, const char *ptr, size_t len, yyjson_ptr_err *err); /* require: val != NULL, *ptr == '/', len > 0 */ yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_getx(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /* require: val/new_val/doc != NULL, *ptr == '/', len > 0 */ yyjson_api bool unsafe_yyjson_mut_ptr_putx(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent, bool insert_new, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /* require: val/err != NULL, *ptr == '/', len > 0 */ yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_replacex( yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); /* require: val/err != NULL, *ptr == '/', len > 0 */ yyjson_api yyjson_mut_val *unsafe_yyjson_mut_ptr_removex(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err); yyjson_api_inline yyjson_val *yyjson_doc_ptr_get(yyjson_doc *doc, const char *ptr) { if (yyjson_unlikely(!ptr)) return NULL; return yyjson_doc_ptr_getn(doc, ptr, strlen(ptr)); } yyjson_api_inline yyjson_val *yyjson_doc_ptr_getn(yyjson_doc *doc, const char *ptr, size_t len) { return yyjson_doc_ptr_getx(doc, ptr, len, NULL); } yyjson_api_inline yyjson_val *yyjson_doc_ptr_getx(yyjson_doc *doc, const char *ptr, size_t len, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (yyjson_unlikely(!doc || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } if (yyjson_unlikely(!doc->root)) { yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); return NULL; } if (yyjson_unlikely(len == 0)) { return doc->root; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; } return unsafe_yyjson_ptr_getx(doc->root, ptr, len, err); } yyjson_api_inline yyjson_val *yyjson_ptr_get(yyjson_val *val, const char *ptr) { if (yyjson_unlikely(!ptr)) return NULL; return yyjson_ptr_getn(val, ptr, strlen(ptr)); } yyjson_api_inline yyjson_val *yyjson_ptr_getn(yyjson_val *val, const char *ptr, size_t len) { return yyjson_ptr_getx(val, ptr, len, NULL); } yyjson_api_inline yyjson_val *yyjson_ptr_getx(yyjson_val *val, const char *ptr, size_t len, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (yyjson_unlikely(!val || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } if (yyjson_unlikely(len == 0)) { return val; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; } return unsafe_yyjson_ptr_getx(val, ptr, len, err); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_get(yyjson_mut_doc *doc, const char *ptr) { if (!ptr) return NULL; return yyjson_mut_doc_ptr_getn(doc, ptr, strlen(ptr)); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getn(yyjson_mut_doc *doc, const char *ptr, size_t len) { return yyjson_mut_doc_ptr_getx(doc, ptr, len, NULL, NULL); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_getx(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } if (yyjson_unlikely(!doc->root)) { yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); return NULL; } if (yyjson_unlikely(len == 0)) { return doc->root; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; } return unsafe_yyjson_mut_ptr_getx(doc->root, ptr, len, ctx, err); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_get(yyjson_mut_val *val, const char *ptr) { if (!ptr) return NULL; return yyjson_mut_ptr_getn(val, ptr, strlen(ptr)); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getn(yyjson_mut_val *val, const char *ptr, size_t len) { return yyjson_mut_ptr_getx(val, ptr, len, NULL, NULL); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_getx(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } if (yyjson_unlikely(len == 0)) { return val; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; } return unsafe_yyjson_mut_ptr_getx(val, ptr, len, ctx, err); } yyjson_api_inline bool yyjson_mut_doc_ptr_add(yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val) { if (yyjson_unlikely(!ptr)) return false; return yyjson_mut_doc_ptr_addn(doc, ptr, strlen(ptr), new_val); } yyjson_api_inline bool yyjson_mut_doc_ptr_addn(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val) { return yyjson_mut_doc_ptr_addx(doc, ptr, len, new_val, true, NULL, NULL); } yyjson_api_inline bool yyjson_mut_doc_ptr_addx(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, bool create_parent, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr || !new_val)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return false; } if (yyjson_unlikely(len == 0)) { if (doc->root) { yyjson_ptr_set_err(SET_ROOT, "cannot set document's root"); return false; } else { doc->root = new_val; return true; } } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return false; } if (yyjson_unlikely(!doc->root && !create_parent)) { yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); return false; } if (yyjson_unlikely(!doc->root)) { yyjson_mut_val *root = yyjson_mut_obj(doc); if (yyjson_unlikely(!root)) { yyjson_ptr_set_err(MEMORY_ALLOCATION, "failed to create value"); return false; } if (unsafe_yyjson_mut_ptr_putx(root, ptr, len, new_val, doc, create_parent, true, ctx, err)) { doc->root = root; return true; } return false; } return unsafe_yyjson_mut_ptr_putx(doc->root, ptr, len, new_val, doc, create_parent, true, ctx, err); } yyjson_api_inline bool yyjson_mut_ptr_add(yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val, yyjson_mut_doc *doc) { if (yyjson_unlikely(!ptr)) return false; return yyjson_mut_ptr_addn(val, ptr, strlen(ptr), new_val, doc); } yyjson_api_inline bool yyjson_mut_ptr_addn(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc) { return yyjson_mut_ptr_addx(val, ptr, len, new_val, doc, true, NULL, NULL); } yyjson_api_inline bool yyjson_mut_ptr_addx(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr || !new_val || !doc)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return false; } if (yyjson_unlikely(len == 0)) { yyjson_ptr_set_err(SET_ROOT, "cannot set root"); return false; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return false; } return unsafe_yyjson_mut_ptr_putx(val, ptr, len, new_val, doc, create_parent, true, ctx, err); } yyjson_api_inline bool yyjson_mut_doc_ptr_set(yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val) { if (yyjson_unlikely(!ptr)) return false; return yyjson_mut_doc_ptr_setn(doc, ptr, strlen(ptr), new_val); } yyjson_api_inline bool yyjson_mut_doc_ptr_setn(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val) { return yyjson_mut_doc_ptr_setx(doc, ptr, len, new_val, true, NULL, NULL); } yyjson_api_inline bool yyjson_mut_doc_ptr_setx(yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, bool create_parent, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return false; } if (yyjson_unlikely(len == 0)) { if (ctx) ctx->old = doc->root; doc->root = new_val; return true; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return false; } if (!new_val) { if (!doc->root) { yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved"); return false; } return !!unsafe_yyjson_mut_ptr_removex(doc->root, ptr, len, ctx, err); } if (yyjson_unlikely(!doc->root && !create_parent)) { yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); return false; } if (yyjson_unlikely(!doc->root)) { yyjson_mut_val *root = yyjson_mut_obj(doc); if (yyjson_unlikely(!root)) { yyjson_ptr_set_err(MEMORY_ALLOCATION, "failed to create value"); return false; } if (unsafe_yyjson_mut_ptr_putx(root, ptr, len, new_val, doc, create_parent, false, ctx, err)) { doc->root = root; return true; } return false; } return unsafe_yyjson_mut_ptr_putx(doc->root, ptr, len, new_val, doc, create_parent, false, ctx, err); } yyjson_api_inline bool yyjson_mut_ptr_set(yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val, yyjson_mut_doc *doc) { if (yyjson_unlikely(!ptr)) return false; return yyjson_mut_ptr_setn(val, ptr, strlen(ptr), new_val, doc); } yyjson_api_inline bool yyjson_mut_ptr_setn(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc) { return yyjson_mut_ptr_setx(val, ptr, len, new_val, doc, true, NULL, NULL); } yyjson_api_inline bool yyjson_mut_ptr_setx(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_mut_doc *doc, bool create_parent, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr || !doc)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return false; } if (yyjson_unlikely(len == 0)) { yyjson_ptr_set_err(SET_ROOT, "cannot set root"); return false; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return false; } if (!new_val) { return !!unsafe_yyjson_mut_ptr_removex(val, ptr, len, ctx, err); } return unsafe_yyjson_mut_ptr_putx(val, ptr, len, new_val, doc, create_parent, false, ctx, err); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replace( yyjson_mut_doc *doc, const char *ptr, yyjson_mut_val *new_val) { if (!ptr) return NULL; return yyjson_mut_doc_ptr_replacen(doc, ptr, strlen(ptr), new_val); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacen( yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val) { return yyjson_mut_doc_ptr_replacex(doc, ptr, len, new_val, NULL, NULL); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_replacex( yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr || !new_val)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } if (yyjson_unlikely(len == 0)) { yyjson_mut_val *root = doc->root; if (yyjson_unlikely(!root)) { yyjson_ptr_set_err(RESOLVE, "JSON pointer cannot be resolved"); return NULL; } if (ctx) ctx->old = root; doc->root = new_val; return root; } if (yyjson_unlikely(!doc->root)) { yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); return NULL; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; } return unsafe_yyjson_mut_ptr_replacex(doc->root, ptr, len, new_val, ctx, err); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replace( yyjson_mut_val *val, const char *ptr, yyjson_mut_val *new_val) { if (!ptr) return NULL; return yyjson_mut_ptr_replacen(val, ptr, strlen(ptr), new_val); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacen( yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val) { return yyjson_mut_ptr_replacex(val, ptr, len, new_val, NULL, NULL); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_replacex( yyjson_mut_val *val, const char *ptr, size_t len, yyjson_mut_val *new_val, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr || !new_val)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } if (yyjson_unlikely(len == 0)) { yyjson_ptr_set_err(SET_ROOT, "cannot set root"); return NULL; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; } return unsafe_yyjson_mut_ptr_replacex(val, ptr, len, new_val, ctx, err); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_remove( yyjson_mut_doc *doc, const char *ptr) { if (!ptr) return NULL; return yyjson_mut_doc_ptr_removen(doc, ptr, strlen(ptr)); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removen( yyjson_mut_doc *doc, const char *ptr, size_t len) { return yyjson_mut_doc_ptr_removex(doc, ptr, len, NULL, NULL); } yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_ptr_removex( yyjson_mut_doc *doc, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!doc || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } if (yyjson_unlikely(!doc->root)) { yyjson_ptr_set_err(NULL_ROOT, "document's root is NULL"); return NULL; } if (yyjson_unlikely(len == 0)) { yyjson_mut_val *root = doc->root; if (ctx) ctx->old = root; doc->root = NULL; return root; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; } return unsafe_yyjson_mut_ptr_removex(doc->root, ptr, len, ctx, err); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_remove(yyjson_mut_val *val, const char *ptr) { if (!ptr) return NULL; return yyjson_mut_ptr_removen(val, ptr, strlen(ptr)); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removen(yyjson_mut_val *val, const char *ptr, size_t len) { return yyjson_mut_ptr_removex(val, ptr, len, NULL, NULL); } yyjson_api_inline yyjson_mut_val *yyjson_mut_ptr_removex(yyjson_mut_val *val, const char *ptr, size_t len, yyjson_ptr_ctx *ctx, yyjson_ptr_err *err) { yyjson_ptr_set_err(NONE, NULL); if (ctx) memset(ctx, 0, sizeof(*ctx)); if (yyjson_unlikely(!val || !ptr)) { yyjson_ptr_set_err(PARAMETER, "input parameter is NULL"); return NULL; } if (yyjson_unlikely(len == 0)) { yyjson_ptr_set_err(SET_ROOT, "cannot set root"); return NULL; } if (yyjson_unlikely(*ptr != '/')) { yyjson_ptr_set_err(SYNTAX, "no prefix '/'"); return NULL; } return unsafe_yyjson_mut_ptr_removex(val, ptr, len, ctx, err); } yyjson_api_inline bool yyjson_ptr_ctx_append(yyjson_ptr_ctx *ctx, yyjson_mut_val *key, yyjson_mut_val *val) { yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val; if (!ctx || !ctx->ctn || !val) return false; ctn = ctx->ctn; if (yyjson_mut_is_obj(ctn)) { if (!key) return false; key->next = val; pre_key = ctx->pre; if (unsafe_yyjson_get_len(ctn) == 0) { val->next = key; ctn->uni.ptr = key; ctx->pre = key; } else if (!pre_key) { pre_key = (yyjson_mut_val *)ctn->uni.ptr; pre_val = pre_key->next; val->next = pre_val->next; pre_val->next = key; ctn->uni.ptr = key; ctx->pre = pre_key; } else { cur_key = pre_key->next->next; cur_val = cur_key->next; val->next = cur_val->next; cur_val->next = key; if (ctn->uni.ptr == cur_key) ctn->uni.ptr = key; ctx->pre = cur_key; } } else { pre_val = ctx->pre; if (unsafe_yyjson_get_len(ctn) == 0) { val->next = val; ctn->uni.ptr = val; ctx->pre = val; } else if (!pre_val) { pre_val = (yyjson_mut_val *)ctn->uni.ptr; val->next = pre_val->next; pre_val->next = val; ctn->uni.ptr = val; ctx->pre = pre_val; } else { cur_val = pre_val->next; val->next = cur_val->next; cur_val->next = val; if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val; ctx->pre = cur_val; } } unsafe_yyjson_inc_len(ctn); return true; } yyjson_api_inline bool yyjson_ptr_ctx_replace(yyjson_ptr_ctx *ctx, yyjson_mut_val *val) { yyjson_mut_val *ctn, *pre_key, *cur_key, *pre_val, *cur_val; if (!ctx || !ctx->ctn || !ctx->pre || !val) return false; ctn = ctx->ctn; if (yyjson_mut_is_obj(ctn)) { pre_key = ctx->pre; pre_val = pre_key->next; cur_key = pre_val->next; cur_val = cur_key->next; /* replace current value */ cur_key->next = val; val->next = cur_val->next; ctx->old = cur_val; } else { pre_val = ctx->pre; cur_val = pre_val->next; /* replace current value */ if (pre_val != cur_val) { val->next = cur_val->next; pre_val->next = val; if (ctn->uni.ptr == cur_val) ctn->uni.ptr = val; } else { val->next = val; ctn->uni.ptr = val; ctx->pre = val; } ctx->old = cur_val; } return true; } yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx) { yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val; size_t len; if (!ctx || !ctx->ctn || !ctx->pre) return false; ctn = ctx->ctn; if (yyjson_mut_is_obj(ctn)) { pre_key = ctx->pre; pre_val = pre_key->next; cur_key = pre_val->next; cur_val = cur_key->next; /* remove current key-value */ pre_val->next = cur_val->next; if (ctn->uni.ptr == cur_key) ctn->uni.ptr = pre_key; ctx->pre = NULL; ctx->old = cur_val; } else { pre_val = ctx->pre; cur_val = pre_val->next; /* remove current key-value */ pre_val->next = cur_val->next; if (ctn->uni.ptr == cur_val) ctn->uni.ptr = pre_val; ctx->pre = NULL; ctx->old = cur_val; } len = unsafe_yyjson_get_len(ctn) - 1; if (len == 0) ctn->uni.ptr = NULL; unsafe_yyjson_set_len(ctn, len); return true; } #undef yyjson_ptr_set_err /*============================================================================== * JSON Value at Pointer API (Implementation) *============================================================================*/ /** Set provided `value` if the JSON Pointer (RFC 6901) exists and is type bool. Returns true if value at `ptr` exists and is the correct type, otherwise false. */ yyjson_api_inline bool yyjson_ptr_get_bool( yyjson_val *root, const char *ptr, bool *value) { yyjson_val *val = yyjson_ptr_get(root, ptr); if (value && yyjson_is_bool(val)) { *value = unsafe_yyjson_get_bool(val); return true; } else { return false; } } /** Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer that fits in `uint64_t`. Returns true if successful, otherwise false. */ yyjson_api_inline bool yyjson_ptr_get_uint( yyjson_val *root, const char *ptr, uint64_t *value) { yyjson_val *val = yyjson_ptr_get(root, ptr); if (value && val) { uint64_t ret = val->uni.u64; if (unsafe_yyjson_is_uint(val) || (unsafe_yyjson_is_sint(val) && !(ret >> 63))) { *value = ret; return true; } } return false; } /** Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer that fits in `int64_t`. Returns true if successful, otherwise false. */ yyjson_api_inline bool yyjson_ptr_get_sint( yyjson_val *root, const char *ptr, int64_t *value) { yyjson_val *val = yyjson_ptr_get(root, ptr); if (value && val) { int64_t ret = val->uni.i64; if (unsafe_yyjson_is_sint(val) || (unsafe_yyjson_is_uint(val) && ret >= 0)) { *value = ret; return true; } } return false; } /** Set provided `value` if the JSON Pointer (RFC 6901) exists and is type real. Returns true if value at `ptr` exists and is the correct type, otherwise false. */ yyjson_api_inline bool yyjson_ptr_get_real( yyjson_val *root, const char *ptr, double *value) { yyjson_val *val = yyjson_ptr_get(root, ptr); if (value && yyjson_is_real(val)) { *value = unsafe_yyjson_get_real(val); return true; } else { return false; } } /** Set provided `value` if the JSON Pointer (RFC 6901) exists and is type sint, uint or real. Returns true if value at `ptr` exists and is the correct type, otherwise false. */ yyjson_api_inline bool yyjson_ptr_get_num( yyjson_val *root, const char *ptr, double *value) { yyjson_val *val = yyjson_ptr_get(root, ptr); if (value && yyjson_is_num(val)) { *value = unsafe_yyjson_get_num(val); return true; } else { return false; } } /** Set provided `value` if the JSON Pointer (RFC 6901) exists and is type string. Returns true if value at `ptr` exists and is the correct type, otherwise false. */ yyjson_api_inline bool yyjson_ptr_get_str( yyjson_val *root, const char *ptr, const char **value) { yyjson_val *val = yyjson_ptr_get(root, ptr); if (value && yyjson_is_str(val)) { *value = unsafe_yyjson_get_str(val); return true; } else { return false; } } /*============================================================================== * Deprecated *============================================================================*/ /** @deprecated renamed to `yyjson_doc_ptr_get` */ yyjson_deprecated("renamed to yyjson_doc_ptr_get") yyjson_api_inline yyjson_val *yyjson_doc_get_pointer(yyjson_doc *doc, const char *ptr) { return yyjson_doc_ptr_get(doc, ptr); } /** @deprecated renamed to `yyjson_doc_ptr_getn` */ yyjson_deprecated("renamed to yyjson_doc_ptr_getn") yyjson_api_inline yyjson_val *yyjson_doc_get_pointern(yyjson_doc *doc, const char *ptr, size_t len) { return yyjson_doc_ptr_getn(doc, ptr, len); } /** @deprecated renamed to `yyjson_mut_doc_ptr_get` */ yyjson_deprecated("renamed to yyjson_mut_doc_ptr_get") yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_pointer( yyjson_mut_doc *doc, const char *ptr) { return yyjson_mut_doc_ptr_get(doc, ptr); } /** @deprecated renamed to `yyjson_mut_doc_ptr_getn` */ yyjson_deprecated("renamed to yyjson_mut_doc_ptr_getn") yyjson_api_inline yyjson_mut_val *yyjson_mut_doc_get_pointern( yyjson_mut_doc *doc, const char *ptr, size_t len) { return yyjson_mut_doc_ptr_getn(doc, ptr, len); } /** @deprecated renamed to `yyjson_ptr_get` */ yyjson_deprecated("renamed to yyjson_ptr_get") yyjson_api_inline yyjson_val *yyjson_get_pointer(yyjson_val *val, const char *ptr) { return yyjson_ptr_get(val, ptr); } /** @deprecated renamed to `yyjson_ptr_getn` */ yyjson_deprecated("renamed to yyjson_ptr_getn") yyjson_api_inline yyjson_val *yyjson_get_pointern(yyjson_val *val, const char *ptr, size_t len) { return yyjson_ptr_getn(val, ptr, len); } /** @deprecated renamed to `yyjson_mut_ptr_get` */ yyjson_deprecated("renamed to yyjson_mut_ptr_get") yyjson_api_inline yyjson_mut_val *yyjson_mut_get_pointer(yyjson_mut_val *val, const char *ptr) { return yyjson_mut_ptr_get(val, ptr); } /** @deprecated renamed to `yyjson_mut_ptr_getn` */ yyjson_deprecated("renamed to yyjson_mut_ptr_getn") yyjson_api_inline yyjson_mut_val *yyjson_mut_get_pointern(yyjson_mut_val *val, const char *ptr, size_t len) { return yyjson_mut_ptr_getn(val, ptr, len); } /** @deprecated renamed to `yyjson_mut_ptr_getn` */ yyjson_deprecated("renamed to unsafe_yyjson_ptr_getn") yyjson_api_inline yyjson_val *unsafe_yyjson_get_pointer(yyjson_val *val, const char *ptr, size_t len) { yyjson_ptr_err err; return unsafe_yyjson_ptr_getx(val, ptr, len, &err); } /** @deprecated renamed to `unsafe_yyjson_mut_ptr_getx` */ yyjson_deprecated("renamed to unsafe_yyjson_mut_ptr_getx") yyjson_api_inline yyjson_mut_val *unsafe_yyjson_mut_get_pointer( yyjson_mut_val *val, const char *ptr, size_t len) { yyjson_ptr_err err; return unsafe_yyjson_mut_ptr_getx(val, ptr, len, NULL, &err); } /*============================================================================== * Compiler Hint End *============================================================================*/ #if defined(__clang__) # pragma clang diagnostic pop #elif defined(__GNUC__) # if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) # pragma GCC diagnostic pop # endif #elif defined(_MSC_VER) # pragma warning(pop) #endif /* warning suppress end */ #ifdef __cplusplus } #endif /* extern "C" end */ #endif /* YYJSON_H */ ijl-orjson-aa8c946/integration/000077500000000000000000000000001505336676500165645ustar00rootroot00000000000000ijl-orjson-aa8c946/integration/client000077500000000000000000000011531505336676500177700ustar00rootroot00000000000000#!/usr/bin/env python3 import asyncio import sys import time import httpx port = sys.argv[1] url = f"http://127.0.0.1:{port}" timeout = httpx.Timeout(5.0) client = httpx.AsyncClient(timeout=timeout) stop_time = time.time() + 5 TEST_MESSAGE = "http test running..." async def main(): sys.stdout.write(TEST_MESSAGE) sys.stdout.flush() count = 0 while time.time() < stop_time: res = await client.get(url) count += 1 sys.stdout.write(f"\r{TEST_MESSAGE} ok, {count} requests made\n") loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) asyncio.run(main()) loop.close() ijl-orjson-aa8c946/integration/http000077500000000000000000000002321505336676500174660ustar00rootroot00000000000000#!/usr/bin/env bash set -e _dir="$(dirname "${BASH_SOURCE[0]}")" PYTHONPATH=${_dir} gunicorn --preload --bind localhost:8001 --workers 2 "$@" wsgi:app ijl-orjson-aa8c946/integration/init000077500000000000000000000012661505336676500174620ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import multiprocessing.pool import sys import orjson NUM_PROC = 16 TEST_MESSAGE = "parallel import of orjson running..." class Custom: pass def default(_): return None def func(_): orjson.dumps(Custom(), option=orjson.OPT_SERIALIZE_NUMPY, default=default) orjson.loads(b'{"a":1,"b":2,"c":3}') def main(): sys.stdout.write(TEST_MESSAGE) sys.stdout.flush() with multiprocessing.pool.ThreadPool(processes=NUM_PROC) as pool: pool.map(func, (i for i in range(NUM_PROC))) sys.stdout.write(f"\r{TEST_MESSAGE} ok\n") sys.stdout.flush() if __name__ == "__main__": main() ijl-orjson-aa8c946/integration/requirements.txt000066400000000000000000000001311505336676500220430ustar00rootroot00000000000000flask;sys_platform!="win" gunicorn;sys_platform!="win" httpx==0.28.1;sys_platform!="win" ijl-orjson-aa8c946/integration/run000077500000000000000000000010161505336676500173140ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail _dir="$(dirname "${BASH_SOURCE[0]}")" to_run="${@:-thread http init}" export PYTHONMALLOC="debug" if [[ $to_run == *"thread"* ]]; then "${_dir}"/thread fi if [[ $to_run == *"http"* ]]; then "${_dir}"/http --daemon sleep 2 "${_dir}"/client 8001 set +e pkill -f 'wsgi:app' # pkill not present on all CI envs set -e fi if [[ $to_run == *"typestubs"* ]]; then python "${_dir}"/typestubs.py mypy "${_dir}"/typestubs.py fi if [[ $to_run == *"init"* ]]; then "${_dir}"/init fi ijl-orjson-aa8c946/integration/thread000077500000000000000000000022161505336676500177620ustar00rootroot00000000000000#!/usr/bin/env python3 import sys import traceback from concurrent.futures import ThreadPoolExecutor from operator import itemgetter from threading import get_ident import orjson DATA = sorted( [ { "id": i, "name": "90as90ji0123ioj2390as90as90", "body": "哈哈89asu89as😊89as9as90jas-😋0apjzxiojzx89hq23n", "score": 901290129.1, "bool": True, "int": 9832, "none": None, } for i in range(10) ], key=itemgetter("id"), ) STATUS = 0 TEST_MESSAGE = "thread test running..." sys.stdout.write(TEST_MESSAGE) sys.stdout.flush() def test_func(n): try: assert sorted(orjson.loads(orjson.dumps(DATA)), key=itemgetter("id")) == DATA except Exception: traceback.print_exc() print(f"thread {get_ident()}: {n} dumps, loads ERROR") with ThreadPoolExecutor(max_workers=4) as executor: executor.map(test_func, range(50000), chunksize=1000) executor.shutdown(wait=True) if STATUS == 0: sys.stdout.write(f"\r{TEST_MESSAGE} ok\n") else: sys.stdout.write(f"\r{TEST_MESSAGE} error\n") sys.exit(STATUS) ijl-orjson-aa8c946/integration/typestubs.py000066400000000000000000000002411505336676500211750ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import orjson orjson.JSONDecodeError(msg="the_msg", doc="the_doc", pos=1) orjson.dumps(orjson.Fragment(b"{}")) ijl-orjson-aa8c946/integration/wsgi.py000066400000000000000000000011651505336676500201120ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) from datetime import datetime, timezone from uuid import uuid4 from flask import Flask import orjson app = Flask(__name__) NOW = datetime.now(timezone.utc) @app.route("/") def root(): data = { "uuid": uuid4(), "updated_at": NOW, "data": [1, 2.2, None, True, False, orjson.Fragment(b"{}")], } payload = orjson.dumps( data, option=orjson.OPT_NAIVE_UTC | orjson.OPT_OMIT_MICROSECONDS, ) return app.response_class( response=payload, status=200, mimetype="application/json; charset=utf-8", ) ijl-orjson-aa8c946/pyproject.toml000066400000000000000000000051001505336676500171510ustar00rootroot00000000000000[project] name = "orjson" version = "3.11.3" repository = "https://github.com/ijl/orjson" description = "Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy" requires-python = ">=3.9" classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "License :: OSI Approved :: MIT License", "Operating System :: MacOS", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python", "Programming Language :: Rust", "Typing :: Typed", ] readme = "README.md" license = "Apache-2.0 OR MIT" [project.urls] source = "https://github.com/ijl/orjson" documentation = "https://github.com/ijl/orjson" changelog = "https://github.com/ijl/orjson/blob/master/CHANGELOG.md" [build-system] build-backend = "maturin" requires = ["maturin>=1,<2"] [tool.maturin] python-source = "pysrc" include = [ { format = "sdist", path = ".cargo/*" }, { format = "sdist", path = "build.rs" }, { format = "sdist", path = "Cargo.lock" }, { format = "sdist", path = "include/cargo/**/*" }, { format = "sdist", path = "include/yyjson/**/*" }, ] [tool.ruff] line-length = 88 target-version = "py39" [tool.ruff.lint] select = [ "A", "ASYNC", "B", "COM", "DTZ", "E", "EXE", "F", "FLY", "I", "ISC", "PIE", "PLC", "PLE", "PLR", "PLW", "RUF", "TCH", "TID", "UP", "W", ] ignore = [ "B005", # Using `.strip()` with multi-character strings is misleading "DTZ001", # `datetime.datetime()` called without a `tzinfo` argument "DTZ005", # `datetime.datetime.now()` called without a `tz` argument "E402", # Module level import not at top of file "E501", # line too long "F601", # Dictionary key literal ... repeated "PIE810", # Call `startswith` once with a `tuple` "PLR2004", # Magic value used in comparison "UP012", # Unnecessary call to encode as UTF-8 ] [tool.ruff.lint.isort] known-first-party = ["orjson"] [tool.mypy] python_version = "3.9" [[tool.mypy.overrides]] module = ["dateutil", "pytz"] ignore_missing_imports = true ijl-orjson-aa8c946/pysrc/000077500000000000000000000000001505336676500154015ustar00rootroot00000000000000ijl-orjson-aa8c946/pysrc/orjson/000077500000000000000000000000001505336676500167135ustar00rootroot00000000000000ijl-orjson-aa8c946/pysrc/orjson/__init__.py000066400000000000000000000011151505336676500210220ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) from .orjson import * from .orjson import __version__ __all__ = ( "__version__", "dumps", "Fragment", "JSONDecodeError", "JSONEncodeError", "loads", "OPT_APPEND_NEWLINE", "OPT_INDENT_2", "OPT_NAIVE_UTC", "OPT_NON_STR_KEYS", "OPT_OMIT_MICROSECONDS", "OPT_PASSTHROUGH_DATACLASS", "OPT_PASSTHROUGH_DATETIME", "OPT_PASSTHROUGH_SUBCLASS", "OPT_SERIALIZE_DATACLASS", "OPT_SERIALIZE_NUMPY", "OPT_SERIALIZE_UUID", "OPT_SORT_KEYS", "OPT_STRICT_INTEGER", "OPT_UTC_Z", ) ijl-orjson-aa8c946/pysrc/orjson/__init__.pyi000066400000000000000000000013301505336676500211720ustar00rootroot00000000000000import json from typing import Any, Callable __version__: str def dumps( __obj: Any, default: Callable[[Any], Any] | None = ..., option: int | None = ..., ) -> bytes: ... def loads(__obj: bytes | bytearray | memoryview | str) -> Any: ... class JSONDecodeError(json.JSONDecodeError): ... class JSONEncodeError(TypeError): ... class Fragment(tuple): contents: bytes | str OPT_APPEND_NEWLINE: int OPT_INDENT_2: int OPT_NAIVE_UTC: int OPT_NON_STR_KEYS: int OPT_OMIT_MICROSECONDS: int OPT_PASSTHROUGH_DATACLASS: int OPT_PASSTHROUGH_DATETIME: int OPT_PASSTHROUGH_SUBCLASS: int OPT_SERIALIZE_DATACLASS: int OPT_SERIALIZE_NUMPY: int OPT_SERIALIZE_UUID: int OPT_SORT_KEYS: int OPT_STRICT_INTEGER: int OPT_UTC_Z: int ijl-orjson-aa8c946/pysrc/orjson/py.typed000066400000000000000000000000001505336676500204000ustar00rootroot00000000000000ijl-orjson-aa8c946/requirements.txt000066400000000000000000000001771505336676500175320ustar00rootroot00000000000000-r bench/requirements.txt -r integration/requirements.txt -r test/requirements.txt maturin>=1,<2 mypy==1.15.0 ruff>=0.12,<0.13 ijl-orjson-aa8c946/script/000077500000000000000000000000001505336676500155455ustar00rootroot00000000000000ijl-orjson-aa8c946/script/cargo000077500000000000000000000003441505336676500165670ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail export UNSAFE_PYO3_BUILD_FREE_THREADED=1 export UNSAFE_PYO3_SKIP_VERSION_CHECK=1 RUSTFLAGS="-C panic=abort -Z panic_abort_tests" cargo "$@" --target="${TARGET:-x86_64-unknown-linux-gnu}" ijl-orjson-aa8c946/script/check-pypi000077500000000000000000000055011505336676500175300ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import sys from pathlib import Path import tomllib dist = sys.argv[1] pyproject_doc = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8")) pyproject_version = pyproject_doc["project"]["version"] prefix = f"orjson-{pyproject_version}" abis = ( "cp39-cp39", "cp310-cp310", "cp311-cp311", "cp312-cp312", "cp313-cp313", ) per_abi_tags = ( "macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2", "manylinux_2_17_aarch64.manylinux2014_aarch64", "manylinux_2_17_armv7l.manylinux2014_armv7l", "manylinux_2_17_ppc64le.manylinux2014_ppc64le", "manylinux_2_17_s390x.manylinux2014_s390x", "manylinux_2_17_x86_64.manylinux2014_x86_64", "manylinux_2_17_i686.manylinux2014_i686", "musllinux_1_2_aarch64", "musllinux_1_2_armv7l", "musllinux_1_2_i686", "musllinux_1_2_x86_64", "win32", "win_amd64", ) wheels_matrix = set() # orjson-3.10.15-cp310-cp310-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl for abi in abis: for tag in per_abi_tags: wheels_matrix.add(f"{prefix}-{abi}-{tag}.whl") wheels_prerelease = { f"{prefix}-cp314-cp314-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl", f"{prefix}-cp314-cp314-macosx_15_0_arm64.whl", f"{prefix}-cp314-cp314-manylinux_2_34_aarch64.whl", f"{prefix}-cp314-cp314-manylinux_2_34_x86_64.whl", f"{prefix}-cp314-cp314-musllinux_1_2_aarch64.whl", f"{prefix}-cp314-cp314-musllinux_1_2_armv7l.whl", f"{prefix}-cp314-cp314-musllinux_1_2_i686.whl", f"{prefix}-cp314-cp314-musllinux_1_2_x86_64.whl", f"{prefix}-cp314-cp314-win32.whl", f"{prefix}-cp314-cp314-win_amd64.whl", f"{prefix}-cp314-cp314-win_arm64.whl", } wheels_unique = { f"{prefix}-cp311-cp311-macosx_15_0_arm64.whl", f"{prefix}-cp311-cp311-win_arm64.whl", f"{prefix}-cp312-cp312-macosx_15_0_arm64.whl", f"{prefix}-cp312-cp312-win_arm64.whl", f"{prefix}-cp313-cp313-macosx_15_0_arm64.whl", f"{prefix}-cp313-cp313-win_arm64.whl", } wheels_expected = wheels_matrix | wheels_unique | wheels_prerelease wheels_queued = set( str(each).replace(f"{dist}/", "") for each in Path(dist).glob("*.whl") ) exit_code = 0 # sdist sdist_path = Path(f"{dist}/{prefix}.tar.gz") if sdist_path.exists(): print("sdist present\n") else: exit_code = 1 print(f"Missing sdist:\n{sdist_path}\n") # whl if wheels_expected == wheels_queued: print(f"Wheels as expected, {len(wheels_queued)} total\n") else: exit_code = 1 missing = "\n".join(sorted(wheels_expected - wheels_queued)) if missing: print(f"Missing wheels:\n{missing}\n") additional = "\n".join(sorted(wheels_queued - wheels_expected)) if additional: print(f"Unexpected wheels:\n{additional}\n") sys.exit(exit_code) ijl-orjson-aa8c946/script/check-version000077500000000000000000000010061505336676500202300ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) from pathlib import Path import tomllib cargo_doc = tomllib.loads(Path("Cargo.toml").read_text(encoding="utf-8")) pyproject_doc = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8")) cargo_version = cargo_doc["package"]["version"] pyproject_version = pyproject_doc["project"]["version"] print(f"Cargo.toml version: {cargo_version}") print(f"pyproject.toml version: {pyproject_version}") assert cargo_version == pyproject_version ijl-orjson-aa8c946/script/debug000077500000000000000000000013061505336676500165610ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail rm -rf .cargo rm -f ${CARGO_TARGET_DIR}/wheels/*.whl export UNSAFE_PYO3_BUILD_FREE_THREADED=1 export UNSAFE_PYO3_SKIP_VERSION_CHECK=1 export CC="${CC:-clang}" export LD="${LD:-lld}" export TARGET="${TARGET:-x86_64-unknown-linux-gnu}" export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-target}" export ORJSON_FEATURES="${ORJSON_FEATURES:-yyjson}" export CFLAGS="-Os -fstrict-aliasing" export RUSTFLAGS="-C panic=unwind -C linker=${CC} -C link-arg=-fuse-ld=${LD}" maturin build --profile=dev --target=${TARGET} --features="${ORJSON_FEATURES}" --interpreter "${PYTHON}" uv pip install ${CARGO_TARGET_DIR}/wheels/*.whl pytest -v test mkdir .cargo cp ci/config.toml .cargo ijl-orjson-aa8c946/script/develop000077500000000000000000000014361505336676500171350ustar00rootroot00000000000000#!/bin/sh -e rm -f target/wheels/* export UNSAFE_PYO3_BUILD_FREE_THREADED=1 export UNSAFE_PYO3_SKIP_VERSION_CHECK=1 export CC="${CC:-clang}" export LD="${LD:-lld}" export TARGET="${TARGET:-x86_64-unknown-linux-gnu}" export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-target}" echo "CC: ${CC}, LD: ${LD}, LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}" export CFLAGS="-O2 -fstrict-aliasing -fno-plt -emit-llvm" export LDFLAGS="-fuse-ld=${LD} -Wl,-plugin-opt=also-emit-llvm -Wl,--as-needed -Wl,-zrelro,-znow" export RUSTFLAGS="-C linker=${CC} -C link-arg=-fuse-ld=${LD} -C linker-plugin-lto -C lto=fat -C link-arg=-Wl,-zrelro,-znow -Z mir-opt-level=4 -Z threads=8" rm -f ${CARGO_TARGET_DIR}/wheels/*.whl maturin build --target="${TARGET}" "$@" uv pip install --link-mode=copy ${CARGO_TARGET_DIR}/wheels/*.whl ijl-orjson-aa8c946/script/generate-yyjson000077500000000000000000000013301505336676500206130ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail _repo="$(dirname "$(dirname "${BASH_SOURCE[0]}")")" bindgen \ "${_repo}/include/yyjson/yyjson.h" \ --size_t-is-usize \ --disable-header-comment \ --no-derive-copy \ --no-derive-debug \ --no-doc-comments \ --no-layout-tests \ --allowlist-function=yyjson_alc_pool_init \ --allowlist-function=yyjson_doc_free \ --allowlist-function=yyjson_read_opts \ --allowlist-type=yyjson_alc \ --allowlist-type=yyjson_doc \ --allowlist-type=yyjson_read_code \ --allowlist-type=yyjson_read_err \ --allowlist-type=yyjson_val \ --allowlist-var=YYJSON_READ_NOFLAG \ --allowlist-var=YYJSON_READ_SUCCESS \ > "${_repo}/src/ffi/yyjson.rs" ijl-orjson-aa8c946/script/graph000077500000000000000000000106351505336676500166010ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import collections import io import math import os import pandas as pd import seaborn as sns from matplotlib import pyplot as plt from tabulate import tabulate import orjson LIBRARIES = ("orjson", "json") def aggregate(): benchmarks_dir = os.path.join(".benchmarks", os.listdir(".benchmarks")[0]) res = collections.defaultdict(dict) for filename in os.listdir(benchmarks_dir): with open(os.path.join(benchmarks_dir, filename)) as fileh: data = orjson.loads(fileh.read()) for each in data["benchmarks"]: res[each["group"]][each["extra_info"]["lib"]] = { "data": [val * 1000 for val in each["stats"]["data"]], "median": each["stats"]["median"] * 1000, "ops": each["stats"]["ops"], "correct": each["extra_info"]["correct"], } return res def tab(obj): buf = io.StringIO() headers = ( "Library", "Median latency (milliseconds)", "Operations per second", "Relative (latency)", ) sns.set(rc={"figure.facecolor": (0, 0, 0, 0)}) sns.set_style("darkgrid") barplot_data = [] for group, val in sorted(obj.items(), reverse=True): buf.write("\n" + "#### " + group + "\n\n") table = [] for lib in LIBRARIES: correct = val[lib]["correct"] table.append( [ lib, val[lib]["median"] if correct else None, int(val[lib]["ops"]) if correct else None, 0, ], ) barplot_data.append( { "operation": "deserialization" if "deserialization" in group else "serialization", "group": group.strip("serialization") .strip("deserialization") .strip(), "library": lib, "latency": val[lib]["median"], "operations": int(val[lib]["ops"]) if correct else None, }, ) orjson_baseline = table[0][1] for each in table: each[3] = ( "%.1f" % (each[1] / orjson_baseline) if isinstance(each[1], float) else None ) if group.startswith("github"): each[1] = f"{each[1]:.2f}" if isinstance(each[1], float) else None else: each[1] = f"{each[1]:.1f}" if isinstance(each[1], float) else None buf.write(tabulate(table, headers, tablefmt="github") + "\n") for operation in ("deserialization", "serialization"): per_op_data = list( each for each in barplot_data if each["operation"] == operation ) if not per_op_data: continue max_y = 0 json_baseline = {} for each in per_op_data: if each["group"] == "witter.json": each["group"] = "twitter.json" if each["library"] == "json": json_baseline[each["group"]] = each["operations"] for each in per_op_data: relative = each["operations"] / json_baseline[each["group"]] each["relative"] = relative max_y = max(max_y, relative) p = pd.DataFrame.from_dict(per_op_data) p.groupby("group") graph = sns.barplot( p, x="group", y="relative", orient="x", hue="library", errorbar="sd", legend="brief", ) graph.set_xlabel("Document") graph.set_ylabel("Operations/second relative to stdlib json") plt.title(operation) # ensure Y range max_y = math.ceil(max_y) if max_y > 10 and max_y % 2 > 0: max_y = max_y + 1 plt.gca().set_yticks( list( {1, max_y}.union( set(int(y) for y in plt.gca().get_yticks() if int(y) <= max_y), ), ), ) # print Y as percent plt.gca().set_yticklabels([f"{x}x" for x in plt.gca().get_yticks()]) # reference for stdlib plt.axhline(y=1, color="#999", linestyle="dashed") plt.savefig(fname=f"doc/{operation}", dpi=300) plt.close() print(buf.getvalue()) tab(aggregate()) ijl-orjson-aa8c946/script/install-fedora000077500000000000000000000012551505336676500204020ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail export VENV="${VENV:-.venv}" export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-target}" rm /etc/yum.repos.d/fedora-cisco-openh264.repo || true dnf install --setopt=install_weak_deps=false -y rustup clang lld "${PYTHON_PACKAGE}" python3-uv rustup-init --default-toolchain "${RUST_TOOLCHAIN}-${TARGET}" --profile minimal --component rust-src -y source "${HOME}/.cargo/env" mkdir -p .cargo cp ci/config.toml .cargo/config.toml cargo fetch --target="${TARGET}" & rm -rf "${VENV}" uv venv --python "${PYTHON}" "${VENV}" source "${VENV}/bin/activate" uv pip install --upgrade "maturin>=1,<2" -r test/requirements.txt -r integration/requirements.txt ijl-orjson-aa8c946/script/lint000077500000000000000000000007351505336676500164460ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail to_lint="./bench/*.py ./pysrc/orjson/__init__.pyi ./test/*.py script/pydataclass script/pysort script/pynumpy script/pynonstr script/pycorrectness script/graph integration/init integration/wsgi.py integration/typestubs.py integration/thread script/check-version script/check-pypi" ruff check ${to_lint} --fix ruff format ${to_lint} mypy --ignore-missing-imports --check-untyped-defs ./bench/*.py ./pysrc/orjson/__init__.pyi ./test/*.py ijl-orjson-aa8c946/script/profile000077500000000000000000000002231505336676500171300ustar00rootroot00000000000000#!/bin/sh -e # usage: ./profile data/citm_catalog.json.xz loads perf record -g --delay 250 ./bench/run_func "$@" perf report --percent-limit 0.1 ijl-orjson-aa8c946/script/pybench000077500000000000000000000004001505336676500171150ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail pytest \ --verbose \ --benchmark-min-time=1 \ --benchmark-max-time=5 \ --benchmark-disable-gc \ --benchmark-autosave \ --benchmark-save-data \ --random-order \ "bench/benchmark_$1.py" ijl-orjson-aa8c946/script/pybench-empty000077500000000000000000000004231505336676500202560ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail pytest \ --verbose \ --benchmark-min-time=1 \ --benchmark-max-time=5 \ --benchmark-disable-gc \ --benchmark-autosave \ --benchmark-save-data \ --random-order \ -k orjson \ "bench/benchmark_empty.py" ijl-orjson-aa8c946/script/pycorrectness000077500000000000000000000076031505336676500204040ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import collections import io import json import lzma import os from pathlib import Path from tabulate import tabulate import orjson dirname = os.path.join(os.path.dirname(__file__), "..", "data") LIBRARIES = ["orjson", "json"] LIBRARY_FUNC_MAP = { "orjson": orjson.loads, "json": json.loads, } def read_fixture_bytes(filename, subdir=None): if subdir is None: parts = (dirname, filename) else: parts = (dirname, subdir, filename) path = Path(*parts) if path.suffix == ".xz": contents = lzma.decompress(path.read_bytes()) else: contents = path.read_bytes() return contents PARSING = { filename: read_fixture_bytes(filename, "parsing") for filename in os.listdir("data/parsing") } JSONCHECKER = { filename: read_fixture_bytes(filename, "jsonchecker") for filename in os.listdir("data/jsonchecker") } RESULTS = collections.defaultdict(dict) def test_passed(libname, fixture): passed = [] loads = LIBRARY_FUNC_MAP[libname] try: passed.append(loads(fixture) == orjson.loads(fixture)) passed.append( loads(fixture.decode("utf-8")) == orjson.loads(fixture.decode("utf-8")), ) except Exception: passed.append(False) return all(passed) def test_failed(libname, fixture): rejected_as_bytes = False loads = LIBRARY_FUNC_MAP[libname] try: loads(fixture) except Exception: rejected_as_bytes = True rejected_as_str = False try: loads(fixture.decode("utf-8")) except Exception: rejected_as_str = True return rejected_as_bytes and rejected_as_str MISTAKEN_PASSES = {key: 0 for key in LIBRARIES} MISTAKEN_FAILS = {key: 0 for key in LIBRARIES} PASS_WHITELIST = ("fail01.json", "fail18.json") def should_pass(filename): return ( filename.startswith("y_") or filename.startswith("pass") or filename in PASS_WHITELIST ) def should_fail(filename): return ( filename.startswith("n_") or filename.startswith("i_string") or filename.startswith("i_object") or filename.startswith("fail") ) and filename not in PASS_WHITELIST for libname in LIBRARIES: for fixture_set in (PARSING, JSONCHECKER): for filename, fixture in fixture_set.items(): if should_pass(filename): res = test_passed(libname, fixture) RESULTS[filename][libname] = res if not res: MISTAKEN_PASSES[libname] += 1 elif should_fail(filename): res = test_failed(libname, fixture) RESULTS[filename][libname] = res if not res: MISTAKEN_FAILS[libname] += 1 elif filename.startswith("i_"): continue else: raise NotImplementedError FILENAMES = sorted(list(PARSING.keys()) + list(JSONCHECKER.keys())) tab_results = [] for filename in FILENAMES: entry = [ filename, ] for libname in LIBRARIES: try: entry.append("ok" if RESULTS[filename][libname] else "fail") except KeyError: continue tab_results.append(entry) buf = io.StringIO() buf.write(tabulate(tab_results, ["Fixture", *LIBRARIES], tablefmt="github")) buf.write("\n") print(buf.getvalue()) failure_results = [ [libname, MISTAKEN_FAILS[libname], MISTAKEN_PASSES[libname]] for libname in LIBRARIES ] buf = io.StringIO() buf.write( tabulate( failure_results, [ "Library", "Invalid JSON documents not rejected", "Valid JSON documents not deserialized", ], tablefmt="github", ), ) buf.write("\n") print(buf.getvalue()) num_results = len([each for each in tab_results if len(each) > 1]) print(f"{num_results} documents tested") ijl-orjson-aa8c946/script/pydataclass000077500000000000000000000047011505336676500200050ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import dataclasses import io import json import os from timeit import timeit from tabulate import tabulate import orjson os.sched_setaffinity(os.getpid(), {0, 1}) @dataclasses.dataclass class Member: id: int active: bool @dataclasses.dataclass class Object: id: int name: str members: list[Member] objects_as_dataclass = [ Object(i, str(i) * 3, [Member(j, True) for j in range(10)]) for i in range(100000, 102000) ] objects_as_dict = [dataclasses.asdict(each) for each in objects_as_dataclass] output_in_kib = len(orjson.dumps(objects_as_dict)) / 1024 print(f"{output_in_kib:,.0f}KiB output (orjson)") def default(__obj): if dataclasses.is_dataclass(__obj): return dataclasses.asdict(__obj) headers = ("Library", "dict (ms)", "dataclass (ms)", "vs. orjson") LIBRARIES = ("orjson", "json") ITERATIONS = 100 def per_iter_latency(val): if val is None: return None return (val * 1000) / ITERATIONS table = [] for lib_name in LIBRARIES: if lib_name == "json": as_dict = timeit( lambda: json.dumps(objects_as_dict).encode("utf-8"), number=ITERATIONS, ) as_dataclass = timeit( lambda: json.dumps(objects_as_dataclass, default=default).encode("utf-8"), number=ITERATIONS, ) elif lib_name == "orjson": as_dict = timeit(lambda: orjson.dumps(objects_as_dict), number=ITERATIONS) as_dataclass = timeit( lambda: orjson.dumps( objects_as_dataclass, None, orjson.OPT_SERIALIZE_DATACLASS, ), number=ITERATIONS, ) orjson_as_dataclass = per_iter_latency(as_dataclass) else: raise NotImplementedError as_dict = per_iter_latency(as_dict) as_dataclass = per_iter_latency(as_dataclass) if lib_name == "orjson": compared_to_orjson = 1 elif as_dataclass: compared_to_orjson = int(as_dataclass / orjson_as_dataclass) else: compared_to_orjson = None table.append( ( lib_name, f"{as_dict:,.2f}" if as_dict else "", f"{as_dataclass:,.2f}" if as_dataclass else "", f"{compared_to_orjson:d}" if compared_to_orjson else "", ), ) buf = io.StringIO() buf.write(tabulate(table, headers, tablefmt="github")) buf.write("\n") print(buf.getvalue()) ijl-orjson-aa8c946/script/pyindent000077500000000000000000000055441505336676500173350ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import io import json import lzma import os import sys from pathlib import Path from timeit import timeit from tabulate import tabulate import orjson os.sched_setaffinity(os.getpid(), {0, 1}) dirname = os.path.join(os.path.dirname(__file__), "..", "data") def read_fixture_obj(filename): path = Path(dirname, filename) if path.suffix == ".xz": contents = lzma.decompress(path.read_bytes()) else: contents = path.read_bytes() return orjson.loads(contents) filename = sys.argv[1] if len(sys.argv) >= 1 else "" data = read_fixture_obj(f"{filename}.json.xz") headers = ("Library", "compact (ms)", "pretty (ms)", "vs. orjson") LIBRARIES = ("orjson", "json") output_in_kib_compact = len(orjson.dumps(data)) / 1024 output_in_kib_pretty = len(orjson.dumps(data, option=orjson.OPT_INDENT_2)) / 1024 # minimum 2s runtime for orjson compact ITERATIONS = int(2 / (timeit(lambda: orjson.dumps(data), number=20) / 20)) print( f"{output_in_kib_compact:,.0f}KiB compact, {output_in_kib_pretty:,.0f}KiB pretty, {ITERATIONS} iterations" ) def per_iter_latency(val): if val is None: return None return (val * 1000) / ITERATIONS def test_correctness(serialized): return orjson.loads(serialized) == data table = [] for lib_name in LIBRARIES: print(f"{lib_name}...") if lib_name == "json": time_compact = timeit( lambda: json.dumps(data).encode("utf-8"), number=ITERATIONS, ) time_pretty = timeit( lambda: json.dumps(data, indent=2).encode("utf-8"), number=ITERATIONS, ) correct = test_correctness(json.dumps(data, indent=2).encode("utf-8")) elif lib_name == "orjson": time_compact = timeit(lambda: orjson.dumps(data), number=ITERATIONS) time_pretty = timeit( lambda: orjson.dumps(data, None, orjson.OPT_INDENT_2), number=ITERATIONS, ) correct = test_correctness(orjson.dumps(data, None, orjson.OPT_INDENT_2)) orjson_time_pretty = per_iter_latency(time_pretty) else: raise NotImplementedError time_compact = per_iter_latency(time_compact) if not correct: time_pretty = None else: time_pretty = per_iter_latency(time_pretty) if lib_name == "orjson": compared_to_orjson = 1 elif time_pretty: compared_to_orjson = time_pretty / orjson_time_pretty else: compared_to_orjson = None table.append( ( lib_name, f"{time_compact:,.2f}" if time_compact else "", f"{time_pretty:,.2f}" if time_pretty else "", f"{compared_to_orjson:,.1f}" if compared_to_orjson else "", ) ) buf = io.StringIO() buf.write(tabulate(table, headers, tablefmt="github")) buf.write("\n") print(buf.getvalue()) ijl-orjson-aa8c946/script/pynonstr000077500000000000000000000057161505336676500174000ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import datetime import io import json import os import random from time import mktime from timeit import timeit from tabulate import tabulate import orjson os.sched_setaffinity(os.getpid(), {0, 1}) data_as_obj = [] for year in range(1920, 2020): start = datetime.date(year, 1, 1) array = [ (int(mktime((start + datetime.timedelta(days=i)).timetuple())), i + 1) for i in range(365) ] array.append(("other", 0)) random.shuffle(array) data_as_obj.append(dict(array)) data_as_str = orjson.loads(orjson.dumps(data_as_obj, option=orjson.OPT_NON_STR_KEYS)) headers = ("Library", "str keys (ms)", "int keys (ms)", "int keys sorted (ms)") LIBRARIES = ("orjson", "json") ITERATIONS = 500 output_in_kib = len(orjson.dumps(data_as_str)) / 1024 print(f"{output_in_kib:,.0f}KiB output (orjson)") def per_iter_latency(val): if val is None: return None return (val * 1000) / ITERATIONS def test_correctness(serialized): return orjson.loads(serialized) == data_as_str table = [] for lib_name in LIBRARIES: print(f"{lib_name}...") if lib_name == "json": time_as_str = timeit( lambda: json.dumps(data_as_str).encode("utf-8"), number=ITERATIONS, ) time_as_obj = timeit( lambda: json.dumps(data_as_obj).encode("utf-8"), number=ITERATIONS, ) time_as_obj_sorted = ( None # TypeError: '<' not supported between instances of 'str' and 'int' ) correct = False elif lib_name == "orjson": time_as_str = timeit( lambda: orjson.dumps(data_as_str, None, orjson.OPT_NON_STR_KEYS), number=ITERATIONS, ) time_as_obj = timeit( lambda: orjson.dumps(data_as_obj, None, orjson.OPT_NON_STR_KEYS), number=ITERATIONS, ) time_as_obj_sorted = timeit( lambda: orjson.dumps( data_as_obj, None, orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS, ), number=ITERATIONS, ) correct = test_correctness( orjson.dumps( data_as_obj, None, orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS, ), ) else: raise NotImplementedError time_as_str = per_iter_latency(time_as_str) time_as_obj = per_iter_latency(time_as_obj) if not correct: time_as_obj_sorted = None else: time_as_obj_sorted = per_iter_latency(time_as_obj_sorted) table.append( ( lib_name, f"{time_as_str:,.2f}" if time_as_str else "", f"{time_as_obj:,.2f}" if time_as_obj else "", f"{time_as_obj_sorted:,.2f}" if time_as_obj_sorted else "", ), ) buf = io.StringIO() buf.write(tabulate(table, headers, tablefmt="github")) buf.write("\n") print(buf.getvalue()) ijl-orjson-aa8c946/script/pynumpy000077500000000000000000000072011505336676500172140ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import gc import io import json import os import sys import time from timeit import timeit import numpy as np import psutil from memory_profiler import memory_usage from tabulate import tabulate import orjson os.sched_setaffinity(os.getpid(), {0, 1}) kind = sys.argv[1] if len(sys.argv) >= 1 else "" if kind == "float16": dtype = np.float16 array = np.random.random(size=(50000, 100)).astype(dtype) elif kind == "float32": dtype = np.float32 array = np.random.random(size=(50000, 100)).astype(dtype) elif kind == "float64": dtype = np.float64 array = np.random.random(size=(50000, 100)) assert array.dtype == np.float64 elif kind == "bool": dtype = np.bool_ array = np.random.choice((True, False), size=(100000, 200)) elif kind == "int8": dtype = np.int8 array = np.random.randint(((2**7) - 1), size=(100000, 100), dtype=dtype) elif kind == "int16": dtype = np.int16 array = np.random.randint(((2**15) - 1), size=(100000, 100), dtype=dtype) elif kind == "int32": dtype = np.int32 array = np.random.randint(((2**31) - 1), size=(100000, 100), dtype=dtype) elif kind == "uint8": dtype = np.uint8 array = np.random.randint(((2**8) - 1), size=(100000, 100), dtype=dtype) elif kind == "uint16": dtype = np.uint16 array = np.random.randint(((2**16) - 1), size=(100000, 100), dtype=dtype) elif kind == "uint32": dtype = np.uint32 array = np.random.randint(((2**31) - 1), size=(100000, 100), dtype=dtype) else: print( "usage: pynumpy (bool|int16|int32|float16|float32|float64|int8|uint8|uint16|uint32)", ) sys.exit(1) proc = psutil.Process() def default(__obj): if isinstance(__obj, np.ndarray): return __obj.tolist() raise TypeError headers = ("Library", "Latency (ms)", "RSS diff (MiB)", "vs. orjson") LIBRARIES = ("orjson", "json") ITERATIONS = 10 def orjson_dumps(): return orjson.dumps(array, option=orjson.OPT_SERIALIZE_NUMPY) def json_dumps(): return json.dumps(array, default=default).encode("utf-8") output_in_mib = len(orjson_dumps()) / 1024 / 1024 print(f"{output_in_mib:,.1f}MiB {kind} output (orjson)") gc.collect() mem_before = proc.memory_full_info().rss / 1024 / 1024 def per_iter_latency(val): if val is None: return None return (val * 1000) / ITERATIONS def test_correctness(func): return np.array_equal(array, np.array(orjson.loads(func()), dtype=dtype)) table = [] for lib_name in LIBRARIES: gc.collect() print(f"{lib_name}...") func = locals()[f"{lib_name}_dumps"] if func is None: total_latency = None latency = None mem = None correct = False else: total_latency = timeit( func, number=ITERATIONS, ) latency = per_iter_latency(total_latency) time.sleep(1) mem = max(memory_usage((func,), interval=0.001, timeout=latency * 2)) correct = test_correctness(func) if lib_name == "orjson": compared_to_orjson = 1 orjson_latency = latency elif latency: compared_to_orjson = latency / orjson_latency else: compared_to_orjson = None if not correct: latency = None mem = 0 mem_diff = mem - mem_before table.append( ( lib_name, f"{latency:,.0f}" if latency else "", f"{mem_diff:,.0f}" if mem else "", f"{compared_to_orjson:,.1f}" if (latency and compared_to_orjson) else "", ), ) buf = io.StringIO() buf.write(tabulate(table, headers, tablefmt="github")) buf.write("\n") print(buf.getvalue()) ijl-orjson-aa8c946/script/pysort000077500000000000000000000042011505336676500170300ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: (Apache-2.0 OR MIT) import io import json import lzma import os from pathlib import Path from timeit import timeit from tabulate import tabulate import orjson os.sched_setaffinity(os.getpid(), {0, 1}) dirname = os.path.join(os.path.dirname(__file__), "..", "data") def read_fixture_obj(filename): path = Path(dirname, filename) if path.suffix == ".xz": contents = lzma.decompress(path.read_bytes()) else: contents = path.read_bytes() return orjson.loads(contents) data = read_fixture_obj("twitter.json.xz") headers = ("Library", "unsorted (ms)", "sorted (ms)", "vs. orjson") LIBRARIES = ("orjson", "json") ITERATIONS = 500 def per_iter_latency(val): if val is None: return None return (val * 1000) / ITERATIONS table = [] for lib_name in LIBRARIES: if lib_name == "json": time_unsorted = timeit( lambda: json.dumps(data).encode("utf-8"), number=ITERATIONS, ) time_sorted = timeit( lambda: json.dumps(data, sort_keys=True).encode("utf-8"), number=ITERATIONS, ) elif lib_name == "orjson": time_unsorted = timeit(lambda: orjson.dumps(data), number=ITERATIONS) time_sorted = timeit( lambda: orjson.dumps(data, None, orjson.OPT_SORT_KEYS), number=ITERATIONS, ) orjson_time_sorted = per_iter_latency(time_sorted) else: raise NotImplementedError time_unsorted = per_iter_latency(time_unsorted) time_sorted = per_iter_latency(time_sorted) if lib_name == "orjson": compared_to_orjson = 1 elif time_unsorted: compared_to_orjson = time_sorted / orjson_time_sorted else: compared_to_orjson = None table.append( ( lib_name, f"{time_unsorted:,.2f}" if time_unsorted else "", f"{time_sorted:,.2f}" if time_sorted else "", f"{compared_to_orjson:,.1f}" if compared_to_orjson else "", ), ) buf = io.StringIO() buf.write(tabulate(table, headers, tablefmt="github")) buf.write("\n") print(buf.getvalue()) ijl-orjson-aa8c946/script/pytest000077500000000000000000000000621505336676500170210ustar00rootroot00000000000000#!/bin/sh -e PYTHONMALLOC="debug" pytest -s test ijl-orjson-aa8c946/script/valgrind000077500000000000000000000001421505336676500172760ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail valgrind "$@" pytest -v --ignore=test/test_memory.py test ijl-orjson-aa8c946/script/vendor-yyjson000077500000000000000000000032601505336676500203220ustar00rootroot00000000000000#!/usr/bin/env bash set -eou pipefail yyjson_version="b21c02904188add942d3c7cd4885422e4335f115" curl -Ls -o include/yyjson/yyjson.c "https://raw.githubusercontent.com/ibireme/yyjson/${yyjson_version}/src/yyjson.c" curl -Ls -o include/yyjson/yyjson.h "https://raw.githubusercontent.com/ibireme/yyjson/${yyjson_version}/src/yyjson.h" sed -i 's/yyjson_api_inline void yyjson_doc_free/yyjson_api void yyjson_doc_free/g' include/yyjson/yyjson.h sed -i 's/(flg & (YYJSON_READ_NUMBER_AS_RAW | YYJSON_READ_BIGNUM_AS_RAW)) != 0/false/g' include/yyjson/yyjson.c sed -i 's/if (pre)/if (false)/g' include/yyjson/yyjson.c sed -i 's/!false/true/g' include/yyjson/yyjson.c sed -i 's/ && true//g' include/yyjson/yyjson.c sed -i 's/true && //g' include/yyjson/yyjson.c sed -i 's/unlikely(false)/false/g' include/yyjson/yyjson.c sed -i 's/YYJSON_TYPE_STR | YYJSON_SUBTYPE_NOESC/YYJSON_TYPE_STR/g' include/yyjson/yyjson.c sed -i 's/unlikely(pos == src)/false/g' include/yyjson/yyjson.c sed -i 's/ yyjson_read_err dummy_err;//g' include/yyjson/yyjson.c sed -i 's/ if (!err) err = &dummy_err;//g' include/yyjson/yyjson.c sed -i 's/likely(!alc_ptr)/!alc_ptr/g' include/yyjson/yyjson.c sed -i 's/unlikely(read_flag_eq(flg, YYJSON_READ_##_flag))/false/g' include/yyjson/yyjson.c sed -i 's/has_read_flag(ALLOW_INF_AND_NAN)/false/g' include/yyjson/yyjson.c sed -i 's/has_read_flag(ALLOW_COMMENTS)/false/g' include/yyjson/yyjson.c sed -i 's/has_read_flag(BIGNUM_AS_RAW)/false/g' include/yyjson/yyjson.c sed -i 's/if (pre && \*pre)/if (false)/g' include/yyjson/yyjson.c sed -i 's/(pre && !false)/(false)/g' include/yyjson/yyjson.c git apply include/yyjson-recursion-limit.patch git apply include/yyjson-reduce-unused.patch ijl-orjson-aa8c946/src/000077500000000000000000000000001505336676500150305ustar00rootroot00000000000000ijl-orjson-aa8c946/src/alloc.rs000066400000000000000000000020541505336676500164710ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use core::alloc::{GlobalAlloc, Layout}; use core::ffi::c_void; struct PyMemAllocator {} #[global_allocator] static ALLOCATOR: PyMemAllocator = PyMemAllocator {}; unsafe impl Sync for PyMemAllocator {} unsafe impl GlobalAlloc for PyMemAllocator { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe { pyo3_ffi::PyMem_Malloc(layout.size()).cast::() } } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { unsafe { pyo3_ffi::PyMem_Free(ptr.cast::()) } } #[inline] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { unsafe { let len = layout.size(); let ptr = pyo3_ffi::PyMem_Malloc(len).cast::(); core::ptr::write_bytes(ptr, 0, len); ptr } } #[inline] unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 { unsafe { pyo3_ffi::PyMem_Realloc(ptr.cast::(), new_size).cast::() } } } ijl-orjson-aa8c946/src/deserialize/000077500000000000000000000000001505336676500173305ustar00rootroot00000000000000ijl-orjson-aa8c946/src/deserialize/backend/000077500000000000000000000000001505336676500207175ustar00rootroot00000000000000ijl-orjson-aa8c946/src/deserialize/backend/json.rs000066400000000000000000000072601505336676500222430ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::deserialize::pyobject::*; use crate::deserialize::DeserializeError; use crate::str::PyStr; use core::ptr::NonNull; use serde::de::{self, DeserializeSeed, Deserializer, MapAccess, SeqAccess, Visitor}; use smallvec::SmallVec; use std::borrow::Cow; use std::fmt; pub(crate) fn deserialize( data: &'static str, ) -> Result, DeserializeError<'static>> { let mut deserializer = serde_json::Deserializer::from_str(data); let seed = JsonValue {}; match seed.deserialize(&mut deserializer) { Ok(obj) => { deserializer.end().map_err(|e| { DeserializeError::from_json(Cow::Owned(e.to_string()), e.line(), e.column(), data) })?; Ok(obj) } Err(e) => Err(DeserializeError::from_json( Cow::Owned(e.to_string()), e.line(), e.column(), data, )), } } #[derive(Clone, Copy)] struct JsonValue; impl<'de> DeserializeSeed<'de> for JsonValue { type Value = NonNull; fn deserialize(self, deserializer: D) -> Result where D: Deserializer<'de>, { deserializer.deserialize_any(self) } } impl<'de> Visitor<'de> for JsonValue { type Value = NonNull; fn expecting(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { Ok(()) } fn visit_unit(self) -> Result { Ok(parse_none()) } fn visit_bool(self, value: bool) -> Result where E: de::Error, { Ok(parse_bool(value)) } fn visit_i64(self, value: i64) -> Result where E: de::Error, { Ok(parse_i64(value)) } fn visit_u64(self, value: u64) -> Result where E: de::Error, { Ok(parse_u64(value)) } fn visit_f64(self, value: f64) -> Result where E: de::Error, { Ok(parse_f64(value)) } fn visit_borrowed_str(self, value: &str) -> Result where E: de::Error, { Ok(PyStr::from_str(value).as_non_null_ptr()) } fn visit_str(self, value: &str) -> Result where E: de::Error, { Ok(PyStr::from_str(value).as_non_null_ptr()) } fn visit_seq(self, mut seq: A) -> Result where A: SeqAccess<'de>, { match seq.next_element_seed(self) { Ok(None) => Ok(nonnull!(ffi!(PyList_New(0)))), Ok(Some(elem)) => { let mut elements: SmallVec<[*mut pyo3_ffi::PyObject; 8]> = SmallVec::with_capacity(8); elements.push(elem.as_ptr()); while let Some(elem) = seq.next_element_seed(self)? { elements.push(elem.as_ptr()); } let ptr = ffi!(PyList_New(elements.len() as isize)); for (i, &obj) in elements.iter().enumerate() { ffi!(PyList_SET_ITEM(ptr, i as isize, obj)); } Ok(nonnull!(ptr)) } Err(err) => Result::Err(err), } } fn visit_map(self, mut map: A) -> Result where A: MapAccess<'de>, { let dict_ptr = ffi!(PyDict_New()); while let Some(key) = map.next_key::>()? { let pykey = get_unicode_key(&key); let pyval = map.next_value_seed(self)?; pydict_setitem!(dict_ptr, pykey.as_ptr(), pyval.as_ptr()); } Ok(nonnull!(dict_ptr)) } } ijl-orjson-aa8c946/src/deserialize/backend/mod.rs000066400000000000000000000004061505336676500220440ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) #[cfg(not(feature = "yyjson"))] mod json; #[cfg(feature = "yyjson")] mod yyjson; #[cfg(feature = "yyjson")] pub(crate) use yyjson::deserialize; #[cfg(not(feature = "yyjson"))] pub(crate) use json::deserialize; ijl-orjson-aa8c946/src/deserialize/backend/yyjson.rs000066400000000000000000000243271505336676500226300ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::deserialize::pyobject::{ get_unicode_key, parse_f64, parse_false, parse_i64, parse_none, parse_true, parse_u64, }; use crate::deserialize::DeserializeError; use crate::ffi::yyjson::{ yyjson_alc_pool_init, yyjson_doc, yyjson_read_err, yyjson_read_opts, yyjson_val, YYJSON_READ_SUCCESS, }; use crate::str::PyStr; use crate::util::usize_to_isize; use core::ffi::c_char; use core::ptr::{null, null_mut, NonNull}; use std::borrow::Cow; const YYJSON_TAG_BIT: u8 = 8; const YYJSON_VAL_SIZE: usize = core::mem::size_of::(); const TAG_ARRAY: u8 = 0b00000110; const TAG_DOUBLE: u8 = 0b00010100; const TAG_FALSE: u8 = 0b00000011; const TAG_INT64: u8 = 0b00001100; const TAG_NULL: u8 = 0b00000010; const TAG_OBJECT: u8 = 0b00000111; const TAG_STRING: u8 = 0b00000101; const TAG_TRUE: u8 = 0b00001011; const TAG_UINT64: u8 = 0b00000100; macro_rules! is_yyjson_tag { ($elem:expr, $tag:expr) => { unsafe { (*$elem).tag as u8 == $tag } }; } fn yyjson_doc_get_root(doc: *mut yyjson_doc) -> *mut yyjson_val { unsafe { (*doc).root } } fn unsafe_yyjson_get_len(val: *mut yyjson_val) -> usize { unsafe { ((*val).tag >> YYJSON_TAG_BIT) as usize } } fn unsafe_yyjson_get_first(ctn: *mut yyjson_val) -> *mut yyjson_val { unsafe { ctn.add(1) } } const MINIMUM_BUFFER_CAPACITY: usize = 4096; fn buffer_capacity_to_allocate(len: usize) -> usize { // The max memory size is (json_size / 2 * 16 * 1.5 + padding). (((len / 2) * 24) + 256 + (MINIMUM_BUFFER_CAPACITY - 1)) & !(MINIMUM_BUFFER_CAPACITY - 1) } fn unsafe_yyjson_is_ctn(val: *mut yyjson_val) -> bool { unsafe { (*val).tag as u8 & 0b00000110 == 0b00000110 } } #[allow(clippy::cast_ptr_alignment)] fn unsafe_yyjson_get_next_container(val: *mut yyjson_val) -> *mut yyjson_val { unsafe { (val.cast::().add((*val).uni.ofs)).cast::() } } #[allow(clippy::cast_ptr_alignment)] fn unsafe_yyjson_get_next_non_container(val: *mut yyjson_val) -> *mut yyjson_val { unsafe { (val.cast::().add(YYJSON_VAL_SIZE)).cast::() } } pub(crate) fn deserialize( data: &'static str, ) -> Result, DeserializeError<'static>> { assume!(!data.is_empty()); let buffer_capacity = buffer_capacity_to_allocate(data.len()); let buffer_ptr = ffi!(PyMem_Malloc(buffer_capacity)); if unlikely!(buffer_ptr.is_null()) { return Err(DeserializeError::from_yyjson( Cow::Borrowed("Not enough memory to allocate buffer for parsing"), 0, data, )); } let mut alloc = crate::ffi::yyjson::yyjson_alc { malloc: None, realloc: None, free: None, ctx: null_mut(), }; unsafe { yyjson_alc_pool_init(&raw mut alloc, buffer_ptr, buffer_capacity); } let mut err = yyjson_read_err { code: YYJSON_READ_SUCCESS, msg: null(), pos: 0, }; let doc = unsafe { yyjson_read_opts( data.as_ptr().cast::().cast_mut(), data.len(), &raw const alloc, &raw mut err, ) }; if unlikely!(doc.is_null()) { ffi!(PyMem_Free(buffer_ptr)); let msg: Cow = unsafe { core::ffi::CStr::from_ptr(err.msg).to_string_lossy() }; return Err(DeserializeError::from_yyjson(msg, err.pos as i64, data)); } let val = yyjson_doc_get_root(doc); let pyval = { if unlikely!(!unsafe_yyjson_is_ctn(val)) { match ElementType::from_tag(val) { ElementType::String => parse_yy_string(val), ElementType::Uint64 => parse_yy_u64(val), ElementType::Int64 => parse_yy_i64(val), ElementType::Double => parse_yy_f64(val), ElementType::Null => parse_none(), ElementType::True => parse_true(), ElementType::False => parse_false(), ElementType::Array | ElementType::Object => unreachable_unchecked!(), } } else if is_yyjson_tag!(val, TAG_ARRAY) { let pyval = nonnull!(ffi!(PyList_New(usize_to_isize(unsafe_yyjson_get_len(val))))); if unsafe_yyjson_get_len(val) > 0 { populate_yy_array(pyval.as_ptr(), val); } pyval } else { let pyval = nonnull!(ffi!(_PyDict_NewPresized(usize_to_isize( unsafe_yyjson_get_len(val) )))); if unsafe_yyjson_get_len(val) > 0 { populate_yy_object(pyval.as_ptr(), val); } pyval } }; ffi!(PyMem_Free(buffer_ptr)); Ok(pyval) } enum ElementType { String, Uint64, Int64, Double, Null, True, False, Array, Object, } impl ElementType { fn from_tag(elem: *mut yyjson_val) -> Self { match unsafe { (*elem).tag as u8 } { TAG_STRING => Self::String, TAG_UINT64 => Self::Uint64, TAG_INT64 => Self::Int64, TAG_DOUBLE => Self::Double, TAG_NULL => Self::Null, TAG_TRUE => Self::True, TAG_FALSE => Self::False, TAG_ARRAY => Self::Array, TAG_OBJECT => Self::Object, _ => unreachable_unchecked!(), } } } #[inline(always)] fn parse_yy_string(elem: *mut yyjson_val) -> NonNull { PyStr::from_str(str_from_slice!( (*elem).uni.str_.cast::(), unsafe_yyjson_get_len(elem) )) .as_non_null_ptr() } #[inline(always)] fn parse_yy_u64(elem: *mut yyjson_val) -> NonNull { parse_u64(unsafe { (*elem).uni.u64_ }) } #[inline(always)] fn parse_yy_i64(elem: *mut yyjson_val) -> NonNull { parse_i64(unsafe { (*elem).uni.i64_ }) } #[inline(always)] fn parse_yy_f64(elem: *mut yyjson_val) -> NonNull { parse_f64(unsafe { (*elem).uni.f64_ }) } macro_rules! append_to_list { ($dptr:expr, $pyval:expr) => { unsafe { core::ptr::write($dptr, $pyval); $dptr = $dptr.add(1); } }; } #[inline(never)] fn populate_yy_array(list: *mut pyo3_ffi::PyObject, elem: *mut yyjson_val) { unsafe { let len = unsafe_yyjson_get_len(elem); assume!(len >= 1); let mut next = unsafe_yyjson_get_first(elem); let mut dptr = (*list.cast::()).ob_item; for _ in 0..len { let val = next; if unlikely!(unsafe_yyjson_is_ctn(val)) { next = unsafe_yyjson_get_next_container(val); if is_yyjson_tag!(val, TAG_ARRAY) { let pyval = ffi!(PyList_New(usize_to_isize(unsafe_yyjson_get_len(val)))); append_to_list!(dptr, pyval); if unsafe_yyjson_get_len(val) > 0 { populate_yy_array(pyval, val); } } else { let pyval = ffi!(_PyDict_NewPresized(usize_to_isize(unsafe_yyjson_get_len( val )))); append_to_list!(dptr, pyval); if unsafe_yyjson_get_len(val) > 0 { populate_yy_object(pyval, val); } } } else { next = unsafe_yyjson_get_next_non_container(val); let pyval = match ElementType::from_tag(val) { ElementType::String => parse_yy_string(val), ElementType::Uint64 => parse_yy_u64(val), ElementType::Int64 => parse_yy_i64(val), ElementType::Double => parse_yy_f64(val), ElementType::Null => parse_none(), ElementType::True => parse_true(), ElementType::False => parse_false(), ElementType::Array | ElementType::Object => unreachable_unchecked!(), }; append_to_list!(dptr, pyval.as_ptr()); } } } } #[inline(never)] fn populate_yy_object(dict: *mut pyo3_ffi::PyObject, elem: *mut yyjson_val) { unsafe { let len = unsafe_yyjson_get_len(elem); assume!(len >= 1); let mut next_key = unsafe_yyjson_get_first(elem); let mut next_val = next_key.add(1); for _ in 0..len { let val = next_val; let pykey = { let key_str = str_from_slice!( (*next_key).uni.str_.cast::(), unsafe_yyjson_get_len(next_key) ); get_unicode_key(key_str) }; if unlikely!(unsafe_yyjson_is_ctn(val)) { next_key = unsafe_yyjson_get_next_container(val); next_val = next_key.add(1); if is_yyjson_tag!(val, TAG_ARRAY) { let pyval = ffi!(PyList_New(usize_to_isize(unsafe_yyjson_get_len(val)))); pydict_setitem!(dict, pykey.as_ptr(), pyval); if unsafe_yyjson_get_len(val) > 0 { populate_yy_array(pyval, val); } } else { let pyval = ffi!(_PyDict_NewPresized(usize_to_isize(unsafe_yyjson_get_len( val )))); pydict_setitem!(dict, pykey.as_ptr(), pyval); if unsafe_yyjson_get_len(val) > 0 { populate_yy_object(pyval, val); } } } else { next_key = unsafe_yyjson_get_next_non_container(val); next_val = next_key.add(1); let pyval = match ElementType::from_tag(val) { ElementType::String => parse_yy_string(val), ElementType::Uint64 => parse_yy_u64(val), ElementType::Int64 => parse_yy_i64(val), ElementType::Double => parse_yy_f64(val), ElementType::Null => parse_none(), ElementType::True => parse_true(), ElementType::False => parse_false(), ElementType::Array | ElementType::Object => unreachable_unchecked!(), }; pydict_setitem!(dict, pykey.as_ptr(), pyval.as_ptr()); } } } } ijl-orjson-aa8c946/src/deserialize/cache.rs000066400000000000000000000016521505336676500207450ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::str::PyStr; use associative_cache::{AssociativeCache, Capacity2048, HashDirectMapped, RoundRobinReplacement}; use once_cell::unsync::OnceCell; #[repr(transparent)] pub(crate) struct CachedKey { ptr: PyStr, } unsafe impl Send for CachedKey {} unsafe impl Sync for CachedKey {} impl CachedKey { pub fn new(ptr: PyStr) -> CachedKey { CachedKey { ptr: ptr } } pub fn get(&mut self) -> PyStr { let ptr = self.ptr.as_ptr(); debug_assert!(ffi!(Py_REFCNT(ptr)) >= 1); ffi!(Py_INCREF(ptr)); self.ptr } } impl Drop for CachedKey { fn drop(&mut self) { ffi!(Py_DECREF(self.ptr.as_ptr().cast::())); } } pub(crate) type KeyMap = AssociativeCache; pub(crate) static mut KEY_MAP: OnceCell = OnceCell::new(); ijl-orjson-aa8c946/src/deserialize/deserializer.rs000066400000000000000000000016411505336676500223620ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::deserialize::utf8::read_input_to_buf; use crate::deserialize::DeserializeError; use crate::typeref::EMPTY_UNICODE; use core::ptr::NonNull; pub(crate) fn deserialize( ptr: *mut pyo3_ffi::PyObject, ) -> Result, DeserializeError<'static>> { debug_assert!(ffi!(Py_REFCNT(ptr)) >= 1); let buffer = read_input_to_buf(ptr)?; debug_assert!(!buffer.is_empty()); if unlikely!(buffer.len() == 2) { if buffer == b"[]" { return Ok(nonnull!(ffi!(PyList_New(0)))); } else if buffer == b"{}" { return Ok(nonnull!(ffi!(PyDict_New()))); } else if buffer == b"\"\"" { unsafe { return Ok(nonnull!(use_immortal!(EMPTY_UNICODE))) } } } let buffer_str = unsafe { core::str::from_utf8_unchecked(buffer) }; crate::deserialize::backend::deserialize(buffer_str) } ijl-orjson-aa8c946/src/deserialize/error.rs000066400000000000000000000061651505336676500210370ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use std::borrow::Cow; pub(crate) struct DeserializeError<'a> { pub message: Cow<'a, str>, #[cfg(not(feature = "yyjson"))] pub line: usize, // start at 1 #[cfg(not(feature = "yyjson"))] pub column: usize, // start at 1 pub data: Option<&'a str>, #[cfg(feature = "yyjson")] pub pos: i64, } impl<'a> DeserializeError<'a> { #[cold] pub fn invalid(message: Cow<'a, str>) -> Self { DeserializeError { message: message, #[cfg(not(feature = "yyjson"))] line: 0, #[cfg(not(feature = "yyjson"))] column: 0, data: None, #[cfg(feature = "yyjson")] pos: 0, } } #[cold] #[cfg(not(feature = "yyjson"))] pub fn from_json(message: Cow<'a, str>, line: usize, column: usize, data: &'a str) -> Self { DeserializeError { message, line, column, data: Some(data), } } #[cold] #[cfg(feature = "yyjson")] pub fn from_yyjson(message: Cow<'a, str>, pos: i64, data: &'a str) -> Self { DeserializeError { message: message, data: Some(data), pos: pos, } } /// Return position of the error in the deserialized data #[cold] #[cfg(feature = "yyjson")] #[cfg_attr(feature = "optimize", optimize(size))] pub fn pos(&self) -> i64 { match self.data { Some(as_str) => as_str[0..self.pos as usize].chars().count() as i64, None => 0, } } /// Return position of the error in the deserialized data #[cold] #[cfg(not(feature = "yyjson"))] #[cfg_attr(feature = "optimize", optimize(size))] pub fn pos(&self) -> i64 { if self.line == 0 || self.data.is_none() { return 1; } let val = self.data.unwrap() .split('\n') // take only the relevant lines .take(self.line) .enumerate() .map(|(idx, s)| { if idx == self.line - 1 { // Last line: only characters until the column of the error are relevant. // Note: Rust uses bytes whereas Python uses chars: we hence cannot // directly use the `column` field if self.column == 0 { return 0; } // Find a column we can safely slice on let mut column = self.column - 1; while column > 0 && !s.is_char_boundary(column) { column -= 1; } let chars_count = s[..column].chars().count(); if chars_count == s.chars().count() - 1 { chars_count + 1 } else { chars_count } } else { // Other lines s.chars().count() } }) .sum::() // add missed '\n' characters + (self.line - 1); val as i64 } } ijl-orjson-aa8c946/src/deserialize/mod.rs000066400000000000000000000004641505336676500204610ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) mod backend; #[cfg(not(Py_GIL_DISABLED))] mod cache; mod deserializer; mod error; mod pyobject; mod utf8; #[cfg(not(Py_GIL_DISABLED))] pub(crate) use cache::{KeyMap, KEY_MAP}; pub(crate) use deserializer::deserialize; pub(crate) use error::DeserializeError; ijl-orjson-aa8c946/src/deserialize/pyobject.rs000066400000000000000000000036701505336676500215230ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) #[cfg(not(Py_GIL_DISABLED))] use crate::deserialize::cache::{CachedKey, KEY_MAP}; use crate::str::PyStr; use crate::typeref::{FALSE, NONE, TRUE}; use core::ptr::NonNull; #[cfg(not(Py_GIL_DISABLED))] #[inline(always)] pub(crate) fn get_unicode_key(key_str: &str) -> PyStr { if unlikely!(key_str.len() > 64) { PyStr::from_str_with_hash(key_str) } else { assume!(key_str.len() <= 64); let hash = xxhash_rust::xxh3::xxh3_64(key_str.as_bytes()); unsafe { let entry = KEY_MAP .get_mut() .unwrap_or_else(|| unreachable_unchecked!()) .entry(&hash) .or_insert_with( || hash, || CachedKey::new(PyStr::from_str_with_hash(key_str)), ); unsafe { entry.get() } } } } #[cfg(Py_GIL_DISABLED)] #[inline(always)] pub(crate) fn get_unicode_key(key_str: &str) -> PyStr { PyStr::from_str_with_hash(key_str) } #[allow(dead_code)] #[inline(always)] pub(crate) fn parse_bool(val: bool) -> NonNull { if val { parse_true() } else { parse_false() } } #[inline(always)] pub(crate) fn parse_true() -> NonNull { nonnull!(use_immortal!(TRUE)) } #[inline(always)] pub(crate) fn parse_false() -> NonNull { nonnull!(use_immortal!(FALSE)) } #[inline(always)] pub(crate) fn parse_i64(val: i64) -> NonNull { nonnull!(ffi!(PyLong_FromLongLong(val))) } #[inline(always)] pub(crate) fn parse_u64(val: u64) -> NonNull { nonnull!(ffi!(PyLong_FromUnsignedLongLong(val))) } #[inline(always)] pub(crate) fn parse_f64(val: f64) -> NonNull { nonnull!(ffi!(PyFloat_FromDouble(val))) } #[inline(always)] pub(crate) fn parse_none() -> NonNull { nonnull!(use_immortal!(NONE)) } ijl-orjson-aa8c946/src/deserialize/utf8.rs000066400000000000000000000067541505336676500206000ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::deserialize::DeserializeError; use crate::ffi::{PyBytes_AS_STRING, PyBytes_GET_SIZE, PyMemoryView_GET_BUFFER}; use crate::str::PyStr; use crate::typeref::{BYTEARRAY_TYPE, BYTES_TYPE, MEMORYVIEW_TYPE, STR_TYPE}; use crate::util::isize_to_usize; use crate::util::INVALID_STR; use core::ffi::c_char; use std::borrow::Cow; #[cfg(all(target_arch = "x86_64", not(target_feature = "avx2")))] fn is_valid_utf8(buf: &[u8]) -> bool { if std::is_x86_feature_detected!("avx2") { unsafe { simdutf8::basic::imp::x86::avx2::validate_utf8(buf).is_ok() } } else { encoding_rs::Encoding::utf8_valid_up_to(buf) == buf.len() } } #[cfg(all(target_arch = "x86_64", target_feature = "avx2"))] fn is_valid_utf8(buf: &[u8]) -> bool { simdutf8::basic::from_utf8(buf).is_ok() } #[cfg(target_arch = "aarch64")] fn is_valid_utf8(buf: &[u8]) -> bool { unsafe { simdutf8::basic::imp::aarch64::neon::validate_utf8(buf).is_ok() } } #[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))] fn is_valid_utf8(buf: &[u8]) -> bool { std::str::from_utf8(buf).is_ok() } pub(crate) fn read_input_to_buf( ptr: *mut pyo3_ffi::PyObject, ) -> Result<&'static [u8], DeserializeError<'static>> { let obj_type_ptr = ob_type!(ptr); let buffer: &[u8]; if is_type!(obj_type_ptr, BYTES_TYPE) { buffer = unsafe { core::slice::from_raw_parts( PyBytes_AS_STRING(ptr).cast::(), isize_to_usize(PyBytes_GET_SIZE(ptr)), ) }; if !is_valid_utf8(buffer) { return Err(DeserializeError::invalid(Cow::Borrowed(INVALID_STR))); } } else if is_type!(obj_type_ptr, STR_TYPE) { let pystr = unsafe { PyStr::from_ptr_unchecked(ptr) }; let uni = pystr.to_str(); if unlikely!(uni.is_none()) { return Err(DeserializeError::invalid(Cow::Borrowed(INVALID_STR))); } let as_str = uni.unwrap(); buffer = unsafe { core::slice::from_raw_parts(as_str.as_ptr(), as_str.len()) }; } else if unlikely!(is_type!(obj_type_ptr, MEMORYVIEW_TYPE)) { let membuf = unsafe { PyMemoryView_GET_BUFFER(ptr) }; if unsafe { pyo3_ffi::PyBuffer_IsContiguous(membuf, b'C' as c_char) == 0 } { return Err(DeserializeError::invalid(Cow::Borrowed( "Input type memoryview must be a C contiguous buffer", ))); } buffer = unsafe { core::slice::from_raw_parts( (*membuf).buf.cast::().cast_const(), isize_to_usize((*membuf).len), ) }; if !is_valid_utf8(buffer) { return Err(DeserializeError::invalid(Cow::Borrowed(INVALID_STR))); } } else if unlikely!(is_type!(obj_type_ptr, BYTEARRAY_TYPE)) { buffer = unsafe { core::slice::from_raw_parts( ffi!(PyByteArray_AsString(ptr)).cast::().cast_const(), isize_to_usize(ffi!(PyByteArray_Size(ptr))), ) }; if !is_valid_utf8(buffer) { return Err(DeserializeError::invalid(Cow::Borrowed(INVALID_STR))); } } else { return Err(DeserializeError::invalid(Cow::Borrowed( "Input must be bytes, bytearray, memoryview, or str", ))); } if unlikely!(buffer.is_empty()) { Err(DeserializeError::invalid(Cow::Borrowed( "Input is a zero-length, empty document", ))) } else { Ok(buffer) } } ijl-orjson-aa8c946/src/ffi/000077500000000000000000000000001505336676500155745ustar00rootroot00000000000000ijl-orjson-aa8c946/src/ffi/buffer.rs000066400000000000000000000014541505336676500174170ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use core::ffi::c_int; use pyo3_ffi::{PyObject, PyVarObject, Py_buffer, Py_hash_t, Py_ssize_t}; #[repr(C)] pub(crate) struct _PyManagedBufferObject { pub ob_base: *mut pyo3_ffi::PyObject, pub flags: c_int, pub exports: Py_ssize_t, pub master: *mut Py_buffer, } #[repr(C)] pub(crate) struct PyMemoryViewObject { pub ob_base: PyVarObject, pub mbuf: *mut _PyManagedBufferObject, pub hash: Py_hash_t, pub flags: c_int, pub exports: Py_ssize_t, pub view: Py_buffer, pub weakreflist: *mut PyObject, pub ob_array: [Py_ssize_t; 1], } #[allow(non_snake_case)] #[inline(always)] pub(crate) unsafe fn PyMemoryView_GET_BUFFER(op: *mut PyObject) -> *const Py_buffer { unsafe { &(*op.cast::()).view } } ijl-orjson-aa8c946/src/ffi/bytes.rs000066400000000000000000000010321505336676500172640ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use core::ffi::c_char; use pyo3_ffi::{PyBytesObject, PyObject, Py_ssize_t}; use super::compat::Py_SIZE; #[allow(non_snake_case)] #[inline(always)] pub(crate) unsafe fn PyBytes_AS_STRING(op: *mut PyObject) -> *const c_char { unsafe { (&raw const (*op.cast::()).ob_sval).cast::() } } #[allow(non_snake_case)] #[inline(always)] pub(crate) unsafe fn PyBytes_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { unsafe { Py_SIZE(op.cast::()) } } ijl-orjson-aa8c946/src/ffi/compat.rs000066400000000000000000000120641505336676500174300ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) #[cfg(Py_GIL_DISABLED)] #[allow(non_upper_case_globals)] pub(crate) const _Py_IMMORTAL_REFCNT_LOCAL: u32 = u32::MAX; #[cfg(all(Py_3_14, target_pointer_width = "32"))] #[allow(non_upper_case_globals)] pub(crate) const _Py_IMMORTAL_MINIMUM_REFCNT: pyo3_ffi::Py_ssize_t = ((1 as core::ffi::c_long) << (30 as core::ffi::c_long)) as pyo3_ffi::Py_ssize_t; #[cfg(all(Py_3_12, not(Py_3_14)))] #[allow(non_upper_case_globals)] pub(crate) const _Py_IMMORTAL_REFCNT: pyo3_ffi::Py_ssize_t = { if cfg!(target_pointer_width = "64") { core::ffi::c_uint::MAX as pyo3_ffi::Py_ssize_t } else { // for 32-bit systems, use the lower 30 bits (see comment in CPython's object.h) (core::ffi::c_uint::MAX >> 2) as pyo3_ffi::Py_ssize_t } }; #[cfg(all(Py_3_12, not(Py_GIL_DISABLED)))] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn _Py_IsImmortal(op: *mut pyo3_ffi::PyObject) -> core::ffi::c_int { unsafe { #[cfg(all(target_pointer_width = "64", not(Py_GIL_DISABLED)))] { (((*op).ob_refcnt.ob_refcnt as pyo3_ffi::PY_INT32_T) < 0) as core::ffi::c_int } #[cfg(all(target_pointer_width = "32", not(Py_GIL_DISABLED)))] { #[cfg(not(Py_3_14))] { ((*op).ob_refcnt.ob_refcnt == _Py_IMMORTAL_REFCNT) as core::ffi::c_int } #[cfg(Py_3_14)] { ((*op).ob_refcnt.ob_refcnt >= _Py_IMMORTAL_MINIMUM_REFCNT) as core::ffi::c_int } } #[cfg(Py_GIL_DISABLED)] { ((*op) .ob_ref_local .load(std::sync::atomic::Ordering::Relaxed) == _Py_IMMORTAL_REFCNT_LOCAL) as core::ffi::c_int } } } #[cfg(CPython)] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn Py_SIZE(op: *mut pyo3_ffi::PyVarObject) -> pyo3_ffi::Py_ssize_t { unsafe { (*op).ob_size } } #[cfg(not(CPython))] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn Py_SIZE(op: *mut pyo3_ffi::PyVarObject) -> pyo3_ffi::Py_ssize_t { unsafe { pyo3_ffi::Py_SIZE(op.cast::()) } } #[cfg(CPython)] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn Py_SET_SIZE(op: *mut pyo3_ffi::PyVarObject, size: pyo3_ffi::Py_ssize_t) { unsafe { (*op).ob_size = size } } #[cfg(not(CPython))] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn Py_SET_SIZE(op: *mut pyo3_ffi::PyVarObject, size: pyo3_ffi::Py_ssize_t) { unimplemented!() } #[cfg(CPython)] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn PyTuple_GET_ITEM( op: *mut pyo3_ffi::PyObject, i: pyo3_ffi::Py_ssize_t, ) -> *mut pyo3_ffi::PyObject { unsafe { pyo3_ffi::PyTuple_GET_ITEM(op, i) } } #[cfg(not(CPython))] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn PyTuple_GET_ITEM( op: *mut pyo3_ffi::PyObject, i: pyo3_ffi::Py_ssize_t, ) -> *mut pyo3_ffi::PyObject { unsafe { pyo3_ffi::PyTuple_GetItem(op, i) } } #[cfg(CPython)] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn PyTuple_SET_ITEM( op: *mut pyo3_ffi::PyObject, i: pyo3_ffi::Py_ssize_t, v: *mut pyo3_ffi::PyObject, ) { unsafe { pyo3_ffi::PyTuple_SET_ITEM(op, i, v) } } #[cfg(not(CPython))] #[inline(always)] #[allow(non_snake_case)] pub(crate) unsafe fn PyTuple_SET_ITEM( op: *mut pyo3_ffi::PyObject, i: pyo3_ffi::Py_ssize_t, v: *mut pyo3_ffi::PyObject, ) { unsafe { pyo3_ffi::PyTuple_SetItem(op, i, v); } } unsafe extern "C" { pub fn _PyDict_Next( mp: *mut pyo3_ffi::PyObject, pos: *mut pyo3_ffi::Py_ssize_t, key: *mut *mut pyo3_ffi::PyObject, value: *mut *mut pyo3_ffi::PyObject, hash: *mut pyo3_ffi::Py_hash_t, ) -> core::ffi::c_int; #[cfg(Py_3_10)] pub fn _PyDict_Contains_KnownHash( op: *mut pyo3_ffi::PyObject, key: *mut pyo3_ffi::PyObject, hash: pyo3_ffi::Py_hash_t, ) -> core::ffi::c_int; #[cfg(not(Py_3_13))] pub(crate) fn _PyDict_SetItem_KnownHash( mp: *mut pyo3_ffi::PyObject, name: *mut pyo3_ffi::PyObject, value: *mut pyo3_ffi::PyObject, hash: pyo3_ffi::Py_hash_t, ) -> core::ffi::c_int; #[cfg(Py_3_13)] pub(crate) fn _PyDict_SetItem_KnownHash_LockHeld( mp: *mut pyo3_ffi::PyDictObject, name: *mut pyo3_ffi::PyObject, value: *mut pyo3_ffi::PyObject, hash: pyo3_ffi::Py_hash_t, ) -> core::ffi::c_int; #[cfg(Py_3_13)] pub(crate) fn _PyLong_AsByteArray( v: *mut pyo3_ffi::PyLongObject, bytes: *mut core::ffi::c_uchar, n: pyo3_ffi::Py_ssize_t, little_endian: core::ffi::c_int, is_signed: core::ffi::c_int, with_exceptions: core::ffi::c_int, ) -> core::ffi::c_int; #[cfg(not(Py_3_13))] pub(crate) fn _PyLong_AsByteArray( v: *mut pyo3_ffi::PyLongObject, bytes: *mut core::ffi::c_uchar, n: pyo3_ffi::Py_ssize_t, little_endian: core::ffi::c_int, is_signed: core::ffi::c_int, ) -> core::ffi::c_int; } ijl-orjson-aa8c946/src/ffi/fragment.rs000066400000000000000000000155201505336676500177500ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use core::ffi::c_char; #[cfg(Py_GIL_DISABLED)] use std::sync::atomic::{AtomicIsize, AtomicU32}; #[cfg(all(Py_GIL_DISABLED, feature = "c_ulong_32"))] pub(crate) type AtomicCULong = std::sync::atomic::AtomicU32; #[cfg(all(Py_GIL_DISABLED, not(feature = "c_ulong_32")))] pub(crate) type AtomicCULong = std::sync::atomic::AtomicU64; use core::ptr::null_mut; use pyo3_ffi::{ PyErr_SetObject, PyExc_TypeError, PyObject, PyTypeObject, PyType_Ready, PyType_Type, PyUnicode_FromStringAndSize, PyVarObject, Py_DECREF, Py_INCREF, Py_SIZE, Py_TPFLAGS_DEFAULT, }; // https://docs.python.org/3/c-api/typeobj.html#typedef-examples #[cfg(Py_GIL_DISABLED)] macro_rules! pymutex_new { () => { unsafe { std::mem::zeroed() } }; } #[repr(C)] pub(crate) struct Fragment { #[cfg(Py_GIL_DISABLED)] pub ob_tid: usize, #[cfg(all(Py_GIL_DISABLED, Py_3_14))] pub ob_flags: u16, #[cfg(all(Py_GIL_DISABLED, not(Py_3_14)))] pub _padding: u16, #[cfg(Py_GIL_DISABLED)] pub ob_mutex: pyo3_ffi::PyMutex, #[cfg(Py_GIL_DISABLED)] pub ob_gc_bits: u8, #[cfg(Py_GIL_DISABLED)] pub ob_ref_local: AtomicU32, #[cfg(Py_GIL_DISABLED)] pub ob_ref_shared: AtomicIsize, #[cfg(not(Py_GIL_DISABLED))] pub ob_refcnt: pyo3_ffi::Py_ssize_t, pub ob_type: *mut pyo3_ffi::PyTypeObject, pub contents: *mut pyo3_ffi::PyObject, } #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] fn raise_args_exception() { unsafe { let msg = "orjson.Fragment() takes exactly 1 positional argument"; let err_msg = PyUnicode_FromStringAndSize(msg.as_ptr().cast::(), msg.len() as isize); PyErr_SetObject(PyExc_TypeError, err_msg); Py_DECREF(err_msg); }; } #[unsafe(no_mangle)] #[cold] #[cfg_attr(feature = "optimize", optimize(size))] pub(crate) unsafe extern "C" fn orjson_fragment_tp_new( _subtype: *mut PyTypeObject, args: *mut PyObject, kwds: *mut PyObject, ) -> *mut PyObject { unsafe { if Py_SIZE(args) != 1 || !kwds.is_null() { raise_args_exception(); null_mut() } else { let contents = crate::ffi::PyTuple_GET_ITEM(args, 0); Py_INCREF(contents); let obj = Box::new(Fragment { #[cfg(Py_GIL_DISABLED)] ob_tid: 0, #[cfg(all(Py_GIL_DISABLED, Py_3_14))] ob_flags: 0, #[cfg(all(Py_GIL_DISABLED, not(Py_3_14)))] _padding: 0, #[cfg(Py_GIL_DISABLED)] ob_mutex: pymutex_new!(), #[cfg(Py_GIL_DISABLED)] ob_gc_bits: 0, #[cfg(Py_GIL_DISABLED)] ob_ref_local: AtomicU32::new(0), #[cfg(Py_GIL_DISABLED)] ob_ref_shared: AtomicIsize::new(0), #[cfg(not(Py_GIL_DISABLED))] ob_refcnt: 1, ob_type: crate::typeref::FRAGMENT_TYPE, contents: contents, }); Box::into_raw(obj).cast::() } } } #[unsafe(no_mangle)] #[cold] #[cfg_attr(feature = "optimize", optimize(size))] pub(crate) unsafe extern "C" fn orjson_fragment_dealloc(object: *mut PyObject) { unsafe { Py_DECREF((*object.cast::()).contents); std::alloc::dealloc(object.cast::(), core::alloc::Layout::new::()); } } #[cfg(Py_GIL_DISABLED)] const FRAGMENT_TP_FLAGS: AtomicCULong = AtomicCULong::new(Py_TPFLAGS_DEFAULT | pyo3_ffi::Py_TPFLAGS_IMMUTABLETYPE); #[cfg(all(Py_3_10, not(Py_GIL_DISABLED)))] const FRAGMENT_TP_FLAGS: core::ffi::c_ulong = Py_TPFLAGS_DEFAULT | pyo3_ffi::Py_TPFLAGS_IMMUTABLETYPE; #[cfg(not(Py_3_10))] const FRAGMENT_TP_FLAGS: core::ffi::c_ulong = Py_TPFLAGS_DEFAULT; #[unsafe(no_mangle)] #[cold] #[cfg_attr(feature = "optimize", optimize(size))] pub(crate) unsafe extern "C" fn orjson_fragmenttype_new() -> *mut PyTypeObject { unsafe { let ob = Box::new(PyTypeObject { ob_base: PyVarObject { ob_base: PyObject { #[cfg(Py_GIL_DISABLED)] ob_tid: 0, #[cfg(all(Py_GIL_DISABLED, Py_3_14))] ob_flags: 0, #[cfg(all(Py_GIL_DISABLED, not(Py_3_14)))] _padding: 0, #[cfg(Py_GIL_DISABLED)] ob_mutex: pymutex_new!(), #[cfg(Py_GIL_DISABLED)] ob_gc_bits: 0, #[cfg(Py_GIL_DISABLED)] ob_ref_local: AtomicU32::new(crate::ffi::compat::_Py_IMMORTAL_REFCNT_LOCAL), #[cfg(Py_GIL_DISABLED)] ob_ref_shared: AtomicIsize::new(0), #[cfg(all(Py_3_12, not(Py_GIL_DISABLED)))] ob_refcnt: pyo3_ffi::PyObjectObRefcnt { ob_refcnt: 0 }, #[cfg(not(Py_3_12))] ob_refcnt: 0, ob_type: &raw mut PyType_Type, }, ob_size: 0, }, tp_name: c"orjson.Fragment".as_ptr(), tp_basicsize: core::mem::size_of::() as isize, tp_itemsize: 0, tp_dealloc: Some(orjson_fragment_dealloc), tp_init: None, tp_new: Some(orjson_fragment_tp_new), tp_flags: FRAGMENT_TP_FLAGS, // ... tp_bases: null_mut(), tp_cache: null_mut(), tp_del: None, tp_finalize: None, tp_free: None, tp_is_gc: None, tp_mro: null_mut(), tp_subclasses: null_mut(), tp_vectorcall: None, tp_version_tag: 0, tp_weaklist: null_mut(), tp_vectorcall_offset: 0, tp_getattr: None, tp_setattr: None, tp_as_async: null_mut(), tp_repr: None, tp_as_number: null_mut(), tp_as_sequence: null_mut(), tp_as_mapping: null_mut(), tp_hash: None, tp_call: None, tp_str: None, tp_getattro: None, tp_setattro: None, tp_as_buffer: null_mut(), tp_doc: core::ptr::null_mut(), tp_traverse: None, tp_clear: None, tp_richcompare: None, tp_weaklistoffset: 0, tp_iter: None, tp_iternext: None, tp_methods: null_mut(), tp_members: null_mut(), tp_getset: null_mut(), tp_base: null_mut(), tp_dict: null_mut(), tp_descr_get: None, tp_descr_set: None, tp_dictoffset: 0, tp_alloc: None, #[cfg(Py_3_12)] tp_watched: 0, }); let ob_ptr = Box::into_raw(ob); PyType_Ready(ob_ptr); ob_ptr } } ijl-orjson-aa8c946/src/ffi/long.rs000066400000000000000000000053351505336676500171070ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) // longintrepr.h, _longobject, _PyLongValue #[allow(dead_code)] #[cfg(Py_3_12)] #[allow(non_upper_case_globals)] const SIGN_MASK: usize = 3; #[cfg(all(Py_3_12, feature = "inline_int"))] #[allow(non_upper_case_globals)] const SIGN_ZERO: usize = 1; #[cfg(all(Py_3_12, feature = "inline_int"))] #[allow(non_upper_case_globals)] const NON_SIZE_BITS: usize = 3; #[cfg(Py_3_12)] #[repr(C)] pub(crate) struct _PyLongValue { pub lv_tag: usize, pub ob_digit: u32, } #[cfg(Py_3_12)] #[repr(C)] pub(crate) struct PyLongObject { pub ob_base: pyo3_ffi::PyObject, pub long_value: _PyLongValue, } #[allow(dead_code)] #[cfg(not(Py_3_12))] #[repr(C)] pub(crate) struct PyLongObject { pub ob_base: pyo3_ffi::PyVarObject, pub ob_digit: u32, } #[cfg(Py_3_12)] #[inline(always)] pub(crate) fn pylong_is_unsigned(ptr: *mut pyo3_ffi::PyObject) -> bool { unsafe { (*ptr.cast::()).long_value.lv_tag & SIGN_MASK == 0 } } #[cfg(not(Py_3_12))] #[inline(always)] pub(crate) fn pylong_is_unsigned(ptr: *mut pyo3_ffi::PyObject) -> bool { unsafe { super::compat::Py_SIZE(ptr.cast::()) > 0 } } #[cfg(all(Py_3_12, feature = "inline_int"))] #[inline(always)] pub(crate) fn pylong_fits_in_i32(ptr: *mut pyo3_ffi::PyObject) -> bool { unsafe { (*ptr.cast::()).long_value.lv_tag < (2 << NON_SIZE_BITS) } } #[cfg(all(not(Py_3_12), feature = "inline_int"))] #[inline(always)] pub(crate) fn pylong_fits_in_i32(ptr: *mut pyo3_ffi::PyObject) -> bool { unsafe { isize::abs(super::compat::Py_SIZE(ptr.cast::())) == 1 } } #[cfg(all(Py_3_12, feature = "inline_int"))] #[inline(always)] pub(crate) fn pylong_is_zero(ptr: *mut pyo3_ffi::PyObject) -> bool { unsafe { (*ptr.cast::()).long_value.lv_tag & SIGN_MASK == SIGN_ZERO } } #[cfg(all(not(Py_3_12), feature = "inline_int"))] #[inline(always)] pub(crate) fn pylong_is_zero(ptr: *mut pyo3_ffi::PyObject) -> bool { unsafe { super::compat::Py_SIZE(ptr.cast::()) == 0 } } #[cfg(all(Py_3_12, feature = "inline_int"))] #[inline(always)] pub(crate) fn pylong_get_inline_value(ptr: *mut pyo3_ffi::PyObject) -> i64 { unsafe { if pylong_is_unsigned(ptr) { i64::from((*ptr.cast::()).long_value.ob_digit) } else { -i64::from((*ptr.cast::()).long_value.ob_digit) } } } #[cfg(all(not(Py_3_12), feature = "inline_int"))] #[inline(always)] pub(crate) fn pylong_get_inline_value(ptr: *mut pyo3_ffi::PyObject) -> i64 { unsafe { super::compat::Py_SIZE(ptr.cast::()) as i64 * i64::from(unsafe { (*ptr.cast::()).ob_digit }) } } ijl-orjson-aa8c946/src/ffi/mod.rs000066400000000000000000000007221505336676500167220ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) mod buffer; mod bytes; pub(crate) mod compat; mod fragment; mod long; #[cfg(feature = "yyjson")] pub(crate) mod yyjson; pub(crate) use buffer::*; pub(crate) use bytes::*; pub(crate) use compat::*; pub(crate) use fragment::{orjson_fragmenttype_new, Fragment}; pub(crate) use long::pylong_is_unsigned; #[cfg(feature = "inline_int")] pub(crate) use long::{pylong_fits_in_i32, pylong_get_inline_value, pylong_is_zero}; ijl-orjson-aa8c946/src/ffi/yyjson.rs000066400000000000000000000032531505336676500175000ustar00rootroot00000000000000#[repr(C)] pub(crate) struct yyjson_alc { pub malloc: ::core::option::Option< unsafe extern "C" fn( ctx: *mut ::core::ffi::c_void, size: usize, ) -> *mut ::core::ffi::c_void, >, pub realloc: ::core::option::Option< unsafe extern "C" fn( ctx: *mut ::core::ffi::c_void, ptr: *mut ::core::ffi::c_void, size: usize, ) -> *mut ::core::ffi::c_void, >, pub free: ::core::option::Option< unsafe extern "C" fn(ctx: *mut ::core::ffi::c_void, ptr: *mut ::core::ffi::c_void), >, pub ctx: *mut ::core::ffi::c_void, } pub(crate) type yyjson_read_code = u32; pub(crate) const YYJSON_READ_SUCCESS: yyjson_read_code = 0; #[repr(C)] pub(crate) struct yyjson_read_err { pub code: yyjson_read_code, pub msg: *const ::core::ffi::c_char, pub pos: usize, } #[repr(C)] pub(crate) union yyjson_val_uni { pub u64_: u64, pub i64_: i64, pub f64_: f64, pub str_: *const ::core::ffi::c_char, pub ptr: *mut ::core::ffi::c_void, pub ofs: usize, } #[repr(C)] pub(crate) struct yyjson_val { pub tag: u64, pub uni: yyjson_val_uni, } #[repr(C)] pub(crate) struct yyjson_doc { pub root: *mut yyjson_val, pub alc: yyjson_alc, pub dat_read: usize, pub val_read: usize, pub str_pool: *mut ::core::ffi::c_char, } unsafe extern "C" { pub fn yyjson_read_opts( dat: *mut ::core::ffi::c_char, len: usize, alc: *const yyjson_alc, err: *mut yyjson_read_err, ) -> *mut yyjson_doc; pub fn yyjson_alc_pool_init( alc: *mut yyjson_alc, buf: *mut ::core::ffi::c_void, size: usize, ) -> bool; } ijl-orjson-aa8c946/src/lib.rs000066400000000000000000000372261505336676500161560ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) #![cfg_attr(feature = "intrinsics", feature(core_intrinsics))] #![cfg_attr(feature = "optimize", feature(optimize_attribute))] #![cfg_attr(feature = "generic_simd", feature(portable_simd))] #![allow(internal_features)] // core_intrinsics #![allow(non_camel_case_types)] #![allow(stable_features)] // MSRV #![allow(static_mut_refs)] #![allow(unknown_lints)] // internal_features #![allow(unused_unsafe)] #![warn(clippy::correctness)] #![warn(clippy::suspicious)] #![warn(clippy::complexity)] #![warn(clippy::perf)] #![warn(clippy::style)] #![allow(clippy::absolute_paths)] #![allow(clippy::allow_attributes)] #![allow(clippy::allow_attributes_without_reason)] #![allow(clippy::arbitrary_source_item_ordering)] #![allow(clippy::arithmetic_side_effects)] #![allow(clippy::decimal_literal_representation)] #![allow(clippy::default_numeric_fallback)] #![allow(clippy::doc_markdown)] #![allow(clippy::explicit_iter_loop)] #![allow(clippy::host_endian_bytes)] #![allow(clippy::if_not_else)] #![allow(clippy::implicit_return)] #![allow(clippy::inline_always)] #![allow(clippy::let_underscore_untyped)] #![allow(clippy::missing_assert_message)] #![allow(clippy::missing_docs_in_private_items)] #![allow(clippy::missing_inline_in_public_items)] #![allow(clippy::missing_panics_doc)] #![allow(clippy::missing_safety_doc)] #![allow(clippy::module_name_repetitions)] #![allow(clippy::multiple_unsafe_ops_per_block)] #![allow(clippy::needless_lifetimes)] #![allow(clippy::question_mark_used)] #![allow(clippy::redundant_else)] #![allow(clippy::redundant_field_names)] #![allow(clippy::renamed_function_params)] #![allow(clippy::semicolon_outside_block)] #![allow(clippy::single_call_fn)] #![allow(clippy::undocumented_unsafe_blocks)] #![allow(clippy::unreachable)] #![allow(clippy::unreadable_literal)] #![allow(clippy::unusual_byte_groupings)] #![allow(clippy::unwrap_in_result)] #![allow(clippy::unwrap_used)] #![allow(clippy::upper_case_acronyms)] #![allow(clippy::zero_prefixed_literal)] #![warn(clippy::elidable_lifetime_names)] #![warn(clippy::ptr_arg)] #![warn(clippy::ptr_as_ptr)] #![warn(clippy::ptr_cast_constness)] #![warn(clippy::ptr_eq)] #![warn(clippy::redundant_allocation)] #![warn(clippy::redundant_clone)] #![warn(clippy::redundant_locals)] #![warn(clippy::redundant_slicing)] #![warn(clippy::semicolon_inside_block)] #![warn(clippy::size_of_ref)] #![warn(clippy::std_instead_of_core)] #![warn(clippy::trivially_copy_pass_by_ref)] #![warn(clippy::unnecessary_semicolon)] #![warn(clippy::unnecessary_wraps)] #![warn(clippy::zero_ptr)] #[cfg(feature = "unwind")] extern crate unwinding; #[macro_use] mod util; mod alloc; mod deserialize; mod ffi; mod opt; mod serialize; mod str; mod typeref; use core::ffi::{c_char, c_int, c_void}; use pyo3_ffi::{ PyCFunction_NewEx, PyErr_SetObject, PyLong_AsLong, PyLong_FromLongLong, PyMethodDef, PyMethodDefPointer, PyModuleDef, PyModuleDef_HEAD_INIT, PyModuleDef_Slot, PyObject, PyTuple_New, PyUnicode_FromStringAndSize, PyUnicode_InternFromString, PyVectorcall_NARGS, Py_DECREF, Py_SIZE, Py_ssize_t, METH_KEYWORDS, METH_O, }; use crate::util::{isize_to_usize, usize_to_isize}; #[allow(unused_imports)] use core::ptr::{null, null_mut, NonNull}; #[cfg(Py_3_13)] macro_rules! add { ($mptr:expr, $name:expr, $obj:expr) => { pyo3_ffi::PyModule_Add($mptr, $name.as_ptr(), $obj); }; } #[cfg(all(Py_3_10, not(Py_3_13)))] macro_rules! add { ($mptr:expr, $name:expr, $obj:expr) => { pyo3_ffi::PyModule_AddObjectRef($mptr, $name.as_ptr(), $obj); }; } #[cfg(not(Py_3_10))] macro_rules! add { ($mptr:expr, $name:expr, $obj:expr) => { pyo3_ffi::PyModule_AddObject($mptr, $name.as_ptr(), $obj); }; } macro_rules! opt { ($mptr:expr, $name:expr, $opt:expr) => { #[cfg(all(not(target_os = "windows"), target_pointer_width = "64"))] pyo3_ffi::PyModule_AddIntConstant($mptr, $name.as_ptr(), i64::from($opt)); #[cfg(all(not(target_os = "windows"), target_pointer_width = "32"))] pyo3_ffi::PyModule_AddIntConstant($mptr, $name.as_ptr(), $opt as i32); #[cfg(target_os = "windows")] pyo3_ffi::PyModule_AddIntConstant($mptr, $name.as_ptr(), $opt as i32); }; } #[allow(non_snake_case)] #[unsafe(no_mangle)] #[cold] #[cfg_attr(not(Py_3_10), allow(deprecated))] // _PyCFunctionFastWithKeywords #[cfg_attr(feature = "optimize", optimize(size))] pub(crate) unsafe extern "C" fn orjson_init_exec(mptr: *mut PyObject) -> c_int { unsafe { typeref::init_typerefs(); { let version = env!("CARGO_PKG_VERSION"); let pyversion = PyUnicode_FromStringAndSize( version.as_ptr().cast::(), usize_to_isize(version.len()), ); add!(mptr, c"__version__", pyversion); } { let dumps_doc = c"dumps(obj, /, default=None, option=None)\n--\n\nSerialize Python objects to JSON."; let wrapped_dumps = PyMethodDef { ml_name: c"dumps".as_ptr(), ml_meth: PyMethodDefPointer { #[cfg(Py_3_10)] PyCFunctionFastWithKeywords: dumps, #[cfg(not(Py_3_10))] _PyCFunctionFastWithKeywords: dumps, }, ml_flags: pyo3_ffi::METH_FASTCALL | METH_KEYWORDS, ml_doc: dumps_doc.as_ptr(), }; let func = PyCFunction_NewEx( Box::into_raw(Box::new(wrapped_dumps)), null_mut(), PyUnicode_InternFromString(c"orjson".as_ptr()), ); add!(mptr, c"dumps", func); } { let loads_doc = c"loads(obj, /)\n--\n\nDeserialize JSON to Python objects."; let wrapped_loads = PyMethodDef { ml_name: c"loads".as_ptr(), ml_meth: PyMethodDefPointer { PyCFunction: loads }, ml_flags: METH_O, ml_doc: loads_doc.as_ptr(), }; let func = PyCFunction_NewEx( Box::into_raw(Box::new(wrapped_loads)), null_mut(), PyUnicode_InternFromString(c"orjson".as_ptr()), ); add!(mptr, c"loads", func); } add!(mptr, c"Fragment", typeref::FRAGMENT_TYPE.cast::()); opt!(mptr, c"OPT_APPEND_NEWLINE", opt::APPEND_NEWLINE); opt!(mptr, c"OPT_INDENT_2", opt::INDENT_2); opt!(mptr, c"OPT_NAIVE_UTC", opt::NAIVE_UTC); opt!(mptr, c"OPT_NON_STR_KEYS", opt::NON_STR_KEYS); opt!(mptr, c"OPT_OMIT_MICROSECONDS", opt::OMIT_MICROSECONDS); opt!( mptr, c"OPT_PASSTHROUGH_DATACLASS", opt::PASSTHROUGH_DATACLASS ); opt!(mptr, c"OPT_PASSTHROUGH_DATETIME", opt::PASSTHROUGH_DATETIME); opt!(mptr, c"OPT_PASSTHROUGH_SUBCLASS", opt::PASSTHROUGH_SUBCLASS); opt!(mptr, c"OPT_SERIALIZE_DATACLASS", opt::SERIALIZE_DATACLASS); opt!(mptr, c"OPT_SERIALIZE_NUMPY", opt::SERIALIZE_NUMPY); opt!(mptr, c"OPT_SERIALIZE_UUID", opt::SERIALIZE_UUID); opt!(mptr, c"OPT_SORT_KEYS", opt::SORT_KEYS); opt!(mptr, c"OPT_STRICT_INTEGER", opt::STRICT_INTEGER); opt!(mptr, c"OPT_UTC_Z", opt::UTC_Z); add!(mptr, c"JSONDecodeError", typeref::JsonDecodeError); add!(mptr, c"JSONEncodeError", typeref::JsonEncodeError); 0 } } #[cfg(not(Py_3_12))] const PYMODULEDEF_LEN: usize = 2; #[cfg(all(Py_3_12, not(Py_3_13)))] const PYMODULEDEF_LEN: usize = 3; #[cfg(Py_3_13)] const PYMODULEDEF_LEN: usize = 4; #[allow(non_snake_case)] #[unsafe(no_mangle)] #[cold] #[cfg_attr(feature = "optimize", optimize(size))] pub(crate) unsafe extern "C" fn PyInit_orjson() -> *mut PyModuleDef { unsafe { let mod_slots: Box<[PyModuleDef_Slot; PYMODULEDEF_LEN]> = Box::new([ PyModuleDef_Slot { slot: pyo3_ffi::Py_mod_exec, #[allow(clippy::fn_to_numeric_cast_any, clippy::as_conversions)] value: orjson_init_exec as *mut c_void, }, #[cfg(Py_3_12)] PyModuleDef_Slot { slot: pyo3_ffi::Py_mod_multiple_interpreters, value: pyo3_ffi::Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED, }, #[cfg(Py_3_13)] PyModuleDef_Slot { slot: pyo3_ffi::Py_mod_gil, value: pyo3_ffi::Py_MOD_GIL_USED, }, PyModuleDef_Slot { slot: 0, value: null_mut(), }, ]); let init = Box::new(PyModuleDef { m_base: PyModuleDef_HEAD_INIT, m_name: c"orjson".as_ptr(), m_doc: null(), m_size: 0, m_methods: null_mut(), m_slots: Box::into_raw(mod_slots).cast::(), m_traverse: None, m_clear: None, m_free: None, }); let init_ptr = Box::into_raw(init); ffi!(PyModuleDef_Init(init_ptr)); init_ptr } } #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] fn raise_loads_exception(err: deserialize::DeserializeError) -> *mut PyObject { unsafe { let err_pos = err.pos(); let msg = err.message; let doc = match err.data { Some(as_str) => PyUnicode_FromStringAndSize( as_str.as_ptr().cast::(), usize_to_isize(as_str.len()), ), None => { use_immortal!(crate::typeref::EMPTY_UNICODE) } }; let err_msg = PyUnicode_FromStringAndSize(msg.as_ptr().cast::(), usize_to_isize(msg.len())); let args = PyTuple_New(3); let pos = PyLong_FromLongLong(err_pos); crate::ffi::PyTuple_SET_ITEM(args, 0, err_msg); crate::ffi::PyTuple_SET_ITEM(args, 1, doc); crate::ffi::PyTuple_SET_ITEM(args, 2, pos); PyErr_SetObject(typeref::JsonDecodeError, args); debug_assert!(ffi!(Py_REFCNT(args)) <= 2); Py_DECREF(args); } null_mut() } #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] fn raise_dumps_exception_fixed(msg: &str) -> *mut PyObject { unsafe { let err_msg = PyUnicode_FromStringAndSize(msg.as_ptr().cast::(), usize_to_isize(msg.len())); PyErr_SetObject(typeref::JsonEncodeError, err_msg); debug_assert!(ffi!(Py_REFCNT(err_msg)) <= 2); Py_DECREF(err_msg); } null_mut() } #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] #[cfg(Py_3_12)] fn raise_dumps_exception_dynamic(err: &str) -> *mut PyObject { unsafe { let cause_exc: *mut PyObject = pyo3_ffi::PyErr_GetRaisedException(); let err_msg = PyUnicode_FromStringAndSize(err.as_ptr().cast::(), usize_to_isize(err.len())); PyErr_SetObject(typeref::JsonEncodeError, err_msg); debug_assert!(ffi!(Py_REFCNT(err_msg)) <= 2); Py_DECREF(err_msg); if !cause_exc.is_null() { let exc: *mut PyObject = pyo3_ffi::PyErr_GetRaisedException(); pyo3_ffi::PyException_SetCause(exc, cause_exc); pyo3_ffi::PyErr_SetRaisedException(exc); } } null_mut() } #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] #[cfg(not(Py_3_12))] fn raise_dumps_exception_dynamic(err: &str) -> *mut PyObject { unsafe { let mut cause_tp: *mut PyObject = null_mut(); let mut cause_val: *mut PyObject = null_mut(); let mut cause_traceback: *mut PyObject = null_mut(); pyo3_ffi::PyErr_Fetch(&mut cause_tp, &mut cause_val, &mut cause_traceback); let err_msg = PyUnicode_FromStringAndSize(err.as_ptr().cast::(), usize_to_isize(err.len())); PyErr_SetObject(typeref::JsonEncodeError, err_msg); debug_assert!(ffi!(Py_REFCNT(err_msg)) == 2); Py_DECREF(err_msg); let mut tp: *mut PyObject = null_mut(); let mut val: *mut PyObject = null_mut(); let mut traceback: *mut PyObject = null_mut(); pyo3_ffi::PyErr_Fetch(&mut tp, &mut val, &mut traceback); pyo3_ffi::PyErr_NormalizeException(&mut tp, &mut val, &mut traceback); if !cause_tp.is_null() { pyo3_ffi::PyErr_NormalizeException(&mut cause_tp, &mut cause_val, &mut cause_traceback); pyo3_ffi::PyException_SetCause(val, cause_val); Py_DECREF(cause_tp); } if !cause_traceback.is_null() { Py_DECREF(cause_traceback); } pyo3_ffi::PyErr_Restore(tp, val, traceback); } null_mut() } #[unsafe(no_mangle)] pub(crate) unsafe extern "C" fn loads(_self: *mut PyObject, obj: *mut PyObject) -> *mut PyObject { match crate::deserialize::deserialize(obj) { Ok(val) => val.as_ptr(), Err(err) => raise_loads_exception(err), } } #[unsafe(no_mangle)] pub(crate) unsafe extern "C" fn dumps( _self: *mut PyObject, args: *const *mut PyObject, nargs: Py_ssize_t, kwnames: *mut PyObject, ) -> *mut PyObject { unsafe { let mut default: Option> = None; let mut optsptr: Option> = None; let num_args = PyVectorcall_NARGS(isize_to_usize(nargs)); if unlikely!(num_args == 0) { return raise_dumps_exception_fixed( "dumps() missing 1 required positional argument: 'obj'", ); } if num_args & 2 == 2 { default = Some(NonNull::new_unchecked(*args.offset(1))); } if num_args & 3 == 3 { optsptr = Some(NonNull::new_unchecked(*args.offset(2))); } if unlikely!(!kwnames.is_null()) { for i in 0..=Py_SIZE(kwnames).saturating_sub(1) { let arg = crate::ffi::PyTuple_GET_ITEM(kwnames, i as Py_ssize_t); if core::ptr::eq(arg, typeref::DEFAULT) { if unlikely!(num_args & 2 == 2) { return raise_dumps_exception_fixed( "dumps() got multiple values for argument: 'default'", ); } default = Some(NonNull::new_unchecked(*args.offset(num_args + i))); } else if core::ptr::eq(arg, typeref::OPTION) { if unlikely!(num_args & 3 == 3) { return raise_dumps_exception_fixed( "dumps() got multiple values for argument: 'option'", ); } optsptr = Some(NonNull::new_unchecked(*args.offset(num_args + i))); } else { return raise_dumps_exception_fixed( "dumps() got an unexpected keyword argument", ); } } } let mut optsbits: i32 = 0; if unlikely!(optsptr.is_some()) { let opts = optsptr.unwrap(); if core::ptr::eq((*opts.as_ptr()).ob_type, typeref::INT_TYPE) { #[allow(clippy::cast_possible_truncation)] let tmp = PyLong_AsLong(optsptr.unwrap().as_ptr()) as i32; // stmt_expr_attributes optsbits = tmp; if unlikely!(!(0..=opt::MAX_OPT).contains(&optsbits)) { return raise_dumps_exception_fixed("Invalid opts"); } } else if unlikely!(!core::ptr::eq(opts.as_ptr(), typeref::NONE)) { return raise_dumps_exception_fixed("Invalid opts"); } } #[allow(clippy::cast_sign_loss)] match crate::serialize::serialize(*args, default, optsbits as opt::Opt) { Ok(val) => val.as_ptr(), Err(err) => raise_dumps_exception_dynamic(err.as_str()), } } } ijl-orjson-aa8c946/src/opt.rs000066400000000000000000000024201505336676500161760ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) pub(crate) type Opt = u32; pub(crate) const INDENT_2: Opt = 1; pub(crate) const NAIVE_UTC: Opt = 1 << 1; pub(crate) const NON_STR_KEYS: Opt = 1 << 2; pub(crate) const OMIT_MICROSECONDS: Opt = 1 << 3; pub(crate) const SERIALIZE_NUMPY: Opt = 1 << 4; pub(crate) const SORT_KEYS: Opt = 1 << 5; pub(crate) const STRICT_INTEGER: Opt = 1 << 6; pub(crate) const UTC_Z: Opt = 1 << 7; pub(crate) const PASSTHROUGH_SUBCLASS: Opt = 1 << 8; pub(crate) const PASSTHROUGH_DATETIME: Opt = 1 << 9; pub(crate) const APPEND_NEWLINE: Opt = 1 << 10; pub(crate) const PASSTHROUGH_DATACLASS: Opt = 1 << 11; // deprecated pub(crate) const SERIALIZE_DATACLASS: Opt = 0; pub(crate) const SERIALIZE_UUID: Opt = 0; pub(crate) const SORT_OR_NON_STR_KEYS: Opt = SORT_KEYS | NON_STR_KEYS; pub(crate) const NOT_PASSTHROUGH: Opt = !(PASSTHROUGH_DATETIME | PASSTHROUGH_DATACLASS | PASSTHROUGH_SUBCLASS); #[allow(clippy::cast_possible_wrap)] pub(crate) const MAX_OPT: i32 = (APPEND_NEWLINE | INDENT_2 | NAIVE_UTC | NON_STR_KEYS | OMIT_MICROSECONDS | PASSTHROUGH_DATETIME | PASSTHROUGH_DATACLASS | PASSTHROUGH_SUBCLASS | SERIALIZE_DATACLASS | SERIALIZE_NUMPY | SERIALIZE_UUID | SORT_KEYS | STRICT_INTEGER | UTC_Z) as i32; ijl-orjson-aa8c946/src/serialize/000077500000000000000000000000001505336676500170175ustar00rootroot00000000000000ijl-orjson-aa8c946/src/serialize/buffer.rs000066400000000000000000000032371505336676500206430ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use bytes::{buf::UninitSlice, BufMut}; use core::mem::MaybeUninit; const BUFFER_LENGTH: usize = 64 - core::mem::size_of::(); /// For use to serialize fixed-size UUIDs and DateTime. #[repr(align(64))] pub(crate) struct SmallFixedBuffer { idx: usize, bytes: [MaybeUninit; BUFFER_LENGTH], } impl SmallFixedBuffer { #[inline] pub fn new() -> Self { Self { idx: 0, bytes: [MaybeUninit::::uninit(); BUFFER_LENGTH], } } #[inline] pub fn as_ptr(&self) -> *const u8 { (&raw const self.bytes).cast::() } #[inline] pub fn len(&self) -> usize { self.idx } } unsafe impl BufMut for SmallFixedBuffer { #[inline] unsafe fn advance_mut(&mut self, cnt: usize) { self.idx += cnt; } #[inline] fn chunk_mut(&mut self) -> &mut UninitSlice { UninitSlice::uninit(&mut self.bytes) } #[inline] fn remaining_mut(&self) -> usize { BUFFER_LENGTH - self.idx } #[inline] fn put_u8(&mut self, value: u8) { debug_assert!(self.remaining_mut() > 1); unsafe { core::ptr::write((&raw mut self.bytes).cast::().add(self.idx), value); self.advance_mut(1); }; } #[inline] fn put_slice(&mut self, src: &[u8]) { debug_assert!(self.remaining_mut() > src.len()); unsafe { core::ptr::copy_nonoverlapping( src.as_ptr(), (&raw mut self.bytes).cast::().add(self.idx), src.len(), ); self.advance_mut(src.len()); } } } ijl-orjson-aa8c946/src/serialize/error.rs000066400000000000000000000054521505336676500205240ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use core::ffi::CStr; use core::ptr::NonNull; pub(crate) enum SerializeError { DatetimeLibraryUnsupported, DefaultRecursionLimit, Integer53Bits, Integer64Bits, InvalidStr, InvalidFragment, KeyMustBeStr, RecursionLimit, TimeHasTzinfo, DictIntegerKey64Bit, DictKeyInvalidType, NumpyMalformed, NumpyNotCContiguous, NumpyNotNativeEndian, NumpyUnsupportedDatatype, UnsupportedType(NonNull), } impl core::fmt::Display for SerializeError { #[cold] #[cfg_attr(feature = "optimize", optimize(size))] fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match *self { SerializeError::DatetimeLibraryUnsupported => write!( f, "datetime's timezone library is not supported: use datetime.timezone.utc, pendulum, pytz, or dateutil" ), SerializeError::DefaultRecursionLimit => { write!(f, "default serializer exceeds recursion limit") } SerializeError::Integer53Bits => write!(f, "Integer exceeds 53-bit range"), SerializeError::Integer64Bits => write!(f, "Integer exceeds 64-bit range"), SerializeError::InvalidStr => write!(f, "{}", crate::util::INVALID_STR), SerializeError::InvalidFragment => { write!(f, "orjson.Fragment's content is not of type bytes or str") } SerializeError::KeyMustBeStr => write!(f, "Dict key must be str"), SerializeError::RecursionLimit => write!(f, "Recursion limit reached"), SerializeError::TimeHasTzinfo => write!(f, "datetime.time must not have tzinfo set"), SerializeError::DictIntegerKey64Bit => { write!(f, "Dict integer key must be within 64-bit range") } SerializeError::DictKeyInvalidType => { write!(f, "Dict key must a type serializable with OPT_NON_STR_KEYS") } SerializeError::NumpyMalformed => write!(f, "numpy array is malformed"), SerializeError::NumpyNotCContiguous => write!( f, "numpy array is not C contiguous; use ndarray.tolist() in default" ), SerializeError::NumpyNotNativeEndian => { write!(f, "numpy array is not native-endianness") } SerializeError::NumpyUnsupportedDatatype => { write!(f, "unsupported datatype in numpy array") } SerializeError::UnsupportedType(ptr) => { let name = unsafe { CStr::from_ptr((*ob_type!(ptr.as_ptr())).tp_name).to_string_lossy() }; write!(f, "Type is not JSON serializable: {name}") } } } } ijl-orjson-aa8c946/src/serialize/mod.rs000066400000000000000000000002731505336676500201460ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) mod buffer; mod error; mod obtype; mod per_type; mod serializer; mod state; pub(crate) mod writer; pub(crate) use serializer::serialize; ijl-orjson-aa8c946/src/serialize/obtype.rs000066400000000000000000000063161505336676500206750ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::opt::{ Opt, PASSTHROUGH_DATACLASS, PASSTHROUGH_DATETIME, PASSTHROUGH_SUBCLASS, SERIALIZE_NUMPY, }; use crate::serialize::per_type::{is_numpy_array, is_numpy_scalar}; use crate::typeref::{ BOOL_TYPE, DATACLASS_FIELDS_STR, DATETIME_TYPE, DATE_TYPE, DICT_TYPE, ENUM_TYPE, FLOAT_TYPE, FRAGMENT_TYPE, INT_TYPE, LIST_TYPE, NONE_TYPE, STR_TYPE, TIME_TYPE, TUPLE_TYPE, UUID_TYPE, }; #[repr(u32)] pub(crate) enum ObType { Str, Int, Bool, None, Float, List, Dict, Datetime, Date, Time, Tuple, Uuid, Dataclass, NumpyScalar, NumpyArray, Enum, StrSubclass, Fragment, Unknown, } pub(crate) fn pyobject_to_obtype(obj: *mut pyo3_ffi::PyObject, opts: Opt) -> ObType { let ob_type = ob_type!(obj); if is_class_by_type!(ob_type, STR_TYPE) { ObType::Str } else if is_class_by_type!(ob_type, INT_TYPE) { ObType::Int } else if is_class_by_type!(ob_type, BOOL_TYPE) { ObType::Bool } else if is_class_by_type!(ob_type, NONE_TYPE) { ObType::None } else if is_class_by_type!(ob_type, FLOAT_TYPE) { ObType::Float } else if is_class_by_type!(ob_type, LIST_TYPE) { ObType::List } else if is_class_by_type!(ob_type, DICT_TYPE) { ObType::Dict } else if is_class_by_type!(ob_type, DATETIME_TYPE) && opt_disabled!(opts, PASSTHROUGH_DATETIME) { ObType::Datetime } else { pyobject_to_obtype_unlikely(ob_type, opts) } } #[cfg_attr(feature = "optimize", optimize(size))] #[inline(never)] pub(crate) fn pyobject_to_obtype_unlikely( ob_type: *mut pyo3_ffi::PyTypeObject, opts: Opt, ) -> ObType { if is_class_by_type!(ob_type, UUID_TYPE) { return ObType::Uuid; } else if is_class_by_type!(ob_type, TUPLE_TYPE) { return ObType::Tuple; } else if is_class_by_type!(ob_type, FRAGMENT_TYPE) { return ObType::Fragment; } if opt_disabled!(opts, PASSTHROUGH_DATETIME) { if is_class_by_type!(ob_type, DATE_TYPE) { return ObType::Date; } else if is_class_by_type!(ob_type, TIME_TYPE) { return ObType::Time; } } let tp_flags = tp_flags!(ob_type); if opt_disabled!(opts, PASSTHROUGH_SUBCLASS) { if is_subclass_by_flag!(tp_flags, Py_TPFLAGS_UNICODE_SUBCLASS) { return ObType::StrSubclass; } else if is_subclass_by_flag!(tp_flags, Py_TPFLAGS_LONG_SUBCLASS) { return ObType::Int; } else if is_subclass_by_flag!(tp_flags, Py_TPFLAGS_LIST_SUBCLASS) { return ObType::List; } else if is_subclass_by_flag!(tp_flags, Py_TPFLAGS_DICT_SUBCLASS) { return ObType::Dict; } } if is_subclass_by_type!(ob_type, ENUM_TYPE) { return ObType::Enum; } if opt_disabled!(opts, PASSTHROUGH_DATACLASS) && pydict_contains!(ob_type, DATACLASS_FIELDS_STR) { return ObType::Dataclass; } if unlikely!(opt_enabled!(opts, SERIALIZE_NUMPY)) { if is_numpy_scalar(ob_type) { return ObType::NumpyScalar; } else if is_numpy_array(ob_type) { return ObType::NumpyArray; } } ObType::Unknown } ijl-orjson-aa8c946/src/serialize/per_type/000077500000000000000000000000001505336676500206465ustar00rootroot00000000000000ijl-orjson-aa8c946/src/serialize/per_type/dataclass.rs000066400000000000000000000147451505336676500231660ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::serialize::error::SerializeError; use crate::serialize::per_type::dict::ZeroDictSerializer; use crate::serialize::serializer::PyObjectSerializer; use crate::serialize::state::SerializerState; use crate::str::PyStr; use crate::typeref::{ DATACLASS_FIELDS_STR, DICT_STR, FIELD_TYPE, FIELD_TYPE_STR, SLOTS_STR, STR_TYPE, }; use crate::util::isize_to_usize; use serde::ser::{Serialize, SerializeMap, Serializer}; use core::ptr::NonNull; #[repr(transparent)] pub(crate) struct DataclassGenericSerializer<'a> { previous: &'a PyObjectSerializer, } impl<'a> DataclassGenericSerializer<'a> { pub fn new(previous: &'a PyObjectSerializer) -> Self { Self { previous: previous } } } impl Serialize for DataclassGenericSerializer<'_> { #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { if unlikely!(self.previous.state.recursion_limit()) { err!(SerializeError::RecursionLimit) } let dict = ffi!(PyObject_GetAttr(self.previous.ptr, DICT_STR)); let ob_type = ob_type!(self.previous.ptr); if unlikely!(dict.is_null()) { ffi!(PyErr_Clear()); DataclassFallbackSerializer::new( self.previous.ptr, self.previous.state, self.previous.default, ) .serialize(serializer) } else if pydict_contains!(ob_type, SLOTS_STR) { let ret = DataclassFallbackSerializer::new( self.previous.ptr, self.previous.state, self.previous.default, ) .serialize(serializer); ffi!(Py_DECREF(dict)); ret } else { let ret = DataclassFastSerializer::new(dict, self.previous.state, self.previous.default) .serialize(serializer); ffi!(Py_DECREF(dict)); ret } } } pub(crate) struct DataclassFastSerializer { ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, } impl DataclassFastSerializer { pub fn new( ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, ) -> Self { DataclassFastSerializer { ptr: ptr, state: state.copy_for_recursive_call(), default: default, } } } impl Serialize for DataclassFastSerializer { #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let len = isize_to_usize(ffi!(Py_SIZE(self.ptr))); if unlikely!(len == 0) { return ZeroDictSerializer::new().serialize(serializer); } let mut map = serializer.serialize_map(None).unwrap(); let mut pos = 0; let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value); for _ in 0..len { let key = next_key; let value = next_value; pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value); let key_as_str = { let key_ob_type = ob_type!(key); if unlikely!(!is_class_by_type!(key_ob_type, STR_TYPE)) { err!(SerializeError::KeyMustBeStr) } match unsafe { PyStr::from_ptr_unchecked(key).to_str() } { Some(uni) => uni, None => err!(SerializeError::InvalidStr), } }; if unlikely!(key_as_str.as_bytes()[0] == b'_') { continue; } let pyvalue = PyObjectSerializer::new(value, self.state, self.default); map.serialize_key(key_as_str).unwrap(); map.serialize_value(&pyvalue)?; } map.end() } } pub(crate) struct DataclassFallbackSerializer { ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, } impl DataclassFallbackSerializer { pub fn new( ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, ) -> Self { DataclassFallbackSerializer { ptr: ptr, state: state.copy_for_recursive_call(), default: default, } } } impl Serialize for DataclassFallbackSerializer { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let fields = ffi!(PyObject_GetAttr(self.ptr, DATACLASS_FIELDS_STR)); debug_assert!(ffi!(Py_REFCNT(fields)) >= 2); ffi!(Py_DECREF(fields)); let len = isize_to_usize(ffi!(Py_SIZE(fields))); if unlikely!(len == 0) { return ZeroDictSerializer::new().serialize(serializer); } let mut map = serializer.serialize_map(None).unwrap(); let mut pos = 0; let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); pydict_next!(fields, &mut pos, &mut next_key, &mut next_value); for _ in 0..len { let attr = next_key; let field = next_value; pydict_next!(fields, &mut pos, &mut next_key, &mut next_value); let field_type = ffi!(PyObject_GetAttr(field, FIELD_TYPE_STR)); debug_assert!(ffi!(Py_REFCNT(field_type)) >= 2); ffi!(Py_DECREF(field_type)); if unsafe { !core::ptr::eq(field_type.cast::(), FIELD_TYPE) } { continue; } let key_as_str = match unsafe { PyStr::from_ptr_unchecked(attr).to_str() } { Some(uni) => uni, None => err!(SerializeError::InvalidStr), }; if key_as_str.as_bytes()[0] == b'_' { continue; } let value = ffi!(PyObject_GetAttr(self.ptr, attr)); debug_assert!(ffi!(Py_REFCNT(value)) >= 2); ffi!(Py_DECREF(value)); let pyvalue = PyObjectSerializer::new(value, self.state, self.default); map.serialize_key(key_as_str).unwrap(); map.serialize_value(&pyvalue)?; } map.end() } } ijl-orjson-aa8c946/src/serialize/per_type/datetime.rs000066400000000000000000000177641505336676500230270ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::opt::{Opt, OMIT_MICROSECONDS}; use crate::serialize::buffer::SmallFixedBuffer; use crate::serialize::error::SerializeError; use crate::serialize::per_type::datetimelike::{DateTimeError, DateTimeLike, Offset}; use crate::typeref::{ CONVERT_METHOD_STR, DST_STR, NORMALIZE_METHOD_STR, UTCOFFSET_METHOD_STR, ZONEINFO_TYPE, }; use serde::ser::{Serialize, Serializer}; macro_rules! write_double_digit { ($buf:ident, $value:ident) => { if $value < 10 { $buf.put_u8(b'0'); } $buf.put_slice(itoa::Buffer::new().format($value).as_bytes()); }; } macro_rules! write_microsecond { ($buf:ident, $microsecond:ident) => { if $microsecond != 0 { let mut buf = itoa::Buffer::new(); let formatted = buf.format($microsecond); $buf.put_slice(&[b'.', b'0', b'0', b'0', b'0', b'0', b'0'][..(7 - formatted.len())]); $buf.put_slice(formatted.as_bytes()); } }; } #[repr(transparent)] pub(crate) struct Date { ptr: *mut pyo3_ffi::PyObject, } impl Date { pub fn new(ptr: *mut pyo3_ffi::PyObject) -> Self { Date { ptr: ptr } } #[inline(never)] pub fn write_buf(&self, buf: &mut B) where B: bytes::BufMut, { { let year = ffi!(PyDateTime_GET_YEAR(self.ptr)); let mut yearbuf = itoa::Buffer::new(); let formatted = yearbuf.format(year); if unlikely!(year < 1000) { // date-fullyear = 4DIGIT buf.put_slice(&[b'0', b'0', b'0', b'0'][..(4 - formatted.len())]); } buf.put_slice(formatted.as_bytes()); } buf.put_u8(b'-'); { let val_py = ffi!(PyDateTime_GET_MONTH(self.ptr)); debug_assert!(val_py >= 0); #[allow(clippy::cast_sign_loss)] let val = val_py as u32; write_double_digit!(buf, val); } buf.put_u8(b'-'); { let val_py = ffi!(PyDateTime_GET_DAY(self.ptr)); debug_assert!(val_py >= 0); #[allow(clippy::cast_sign_loss)] let val = val_py as u32; write_double_digit!(buf, val); } } } impl Serialize for Date { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut buf = SmallFixedBuffer::new(); self.write_buf(&mut buf); serializer.serialize_unit_struct(str_from_slice!(buf.as_ptr(), buf.len())) } } pub(crate) enum TimeError { HasTimezone, } pub(crate) struct Time { ptr: *mut pyo3_ffi::PyObject, opts: Opt, } impl Time { pub fn new(ptr: *mut pyo3_ffi::PyObject, opts: Opt) -> Self { Time { ptr: ptr, opts: opts, } } #[inline(never)] pub fn write_buf(&self, buf: &mut B) -> Result<(), TimeError> where B: bytes::BufMut, { if unsafe { (*self.ptr.cast::()).hastzinfo == 1 } { return Err(TimeError::HasTimezone); } let hour = ffi!(PyDateTime_TIME_GET_HOUR(self.ptr)) as u8; write_double_digit!(buf, hour); buf.put_u8(b':'); let minute = ffi!(PyDateTime_TIME_GET_MINUTE(self.ptr)) as u8; write_double_digit!(buf, minute); buf.put_u8(b':'); let second = ffi!(PyDateTime_TIME_GET_SECOND(self.ptr)) as u8; write_double_digit!(buf, second); if opt_disabled!(self.opts, OMIT_MICROSECONDS) { let microsecond = ffi!(PyDateTime_TIME_GET_MICROSECOND(self.ptr)) as u32; write_microsecond!(buf, microsecond); } Ok(()) } } impl Serialize for Time { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut buf = SmallFixedBuffer::new(); if self.write_buf(&mut buf).is_err() { err!(SerializeError::DatetimeLibraryUnsupported) } serializer.serialize_unit_struct(str_from_slice!(buf.as_ptr(), buf.len())) } } pub(crate) struct DateTime { ptr: *mut pyo3_ffi::PyObject, opts: Opt, } impl DateTime { pub fn new(ptr: *mut pyo3_ffi::PyObject, opts: Opt) -> Self { DateTime { ptr: ptr, opts: opts, } } } macro_rules! pydatetime_get { ($fn: ident, $pyfn: ident, $ty: ident) => { fn $fn(&self) -> $ty { let ret = ffi!($pyfn(self.ptr)); debug_assert!(ret >= 0); #[allow(clippy::cast_sign_loss)] let ret2 = ret as $ty; // stmt_expr_attributes ret2 } }; } impl DateTimeLike for DateTime { pydatetime_get!(year, PyDateTime_GET_YEAR, i32); pydatetime_get!(month, PyDateTime_GET_MONTH, u8); pydatetime_get!(day, PyDateTime_GET_DAY, u8); pydatetime_get!(hour, PyDateTime_DATE_GET_HOUR, u8); pydatetime_get!(minute, PyDateTime_DATE_GET_MINUTE, u8); pydatetime_get!(second, PyDateTime_DATE_GET_SECOND, u8); pydatetime_get!(microsecond, PyDateTime_DATE_GET_MICROSECOND, u32); fn nanosecond(&self) -> u32 { self.microsecond() * 1_000 } fn has_tz(&self) -> bool { unsafe { (*(self.ptr.cast::())).hastzinfo == 1 } } #[inline(never)] fn slow_offset(&self) -> Result { let tzinfo = ffi!(PyDateTime_DATE_GET_TZINFO(self.ptr)); if ffi!(PyObject_HasAttr(tzinfo, CONVERT_METHOD_STR)) == 1 { // pendulum let py_offset = call_method!(self.ptr, UTCOFFSET_METHOD_STR); let offset = Offset { second: ffi!(PyDateTime_DELTA_GET_SECONDS(py_offset)), day: ffi!(PyDateTime_DELTA_GET_DAYS(py_offset)), }; ffi!(Py_DECREF(py_offset)); Ok(offset) } else if ffi!(PyObject_HasAttr(tzinfo, NORMALIZE_METHOD_STR)) == 1 { // pytz let method_ptr = call_method!(tzinfo, NORMALIZE_METHOD_STR, self.ptr); let py_offset = call_method!(method_ptr, UTCOFFSET_METHOD_STR); ffi!(Py_DECREF(method_ptr)); let offset = Offset { second: ffi!(PyDateTime_DELTA_GET_SECONDS(py_offset)), day: ffi!(PyDateTime_DELTA_GET_DAYS(py_offset)), }; ffi!(Py_DECREF(py_offset)); Ok(offset) } else if ffi!(PyObject_HasAttr(tzinfo, DST_STR)) == 1 { // dateutil/arrow, datetime.timezone.utc let py_offset = call_method!(tzinfo, UTCOFFSET_METHOD_STR, self.ptr); let offset = Offset { second: ffi!(PyDateTime_DELTA_GET_SECONDS(py_offset)), day: ffi!(PyDateTime_DELTA_GET_DAYS(py_offset)), }; ffi!(Py_DECREF(py_offset)); Ok(offset) } else { Err(DateTimeError::LibraryUnsupported) } } #[inline] fn offset(&self) -> Result { if !self.has_tz() { Ok(Offset::default()) } else { let tzinfo = ffi!(PyDateTime_DATE_GET_TZINFO(self.ptr)); if unsafe { core::ptr::eq(ob_type!(tzinfo), ZONEINFO_TYPE) } { // zoneinfo let py_offset = call_method!(tzinfo, UTCOFFSET_METHOD_STR, self.ptr); let offset = Offset { second: ffi!(PyDateTime_DELTA_GET_SECONDS(py_offset)), day: ffi!(PyDateTime_DELTA_GET_DAYS(py_offset)), }; ffi!(Py_DECREF(py_offset)); Ok(offset) } else { self.slow_offset() } } } } impl Serialize for DateTime { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut buf = SmallFixedBuffer::new(); if self.write_buf(&mut buf, self.opts).is_err() { err!(SerializeError::DatetimeLibraryUnsupported) } serializer.serialize_unit_struct(str_from_slice!(buf.as_ptr(), buf.len())) } } ijl-orjson-aa8c946/src/serialize/per_type/datetimelike.rs000066400000000000000000000124651505336676500236650ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::opt::{Opt, NAIVE_UTC, OMIT_MICROSECONDS, UTC_Z}; pub(crate) enum DateTimeError { LibraryUnsupported, } macro_rules! write_double_digit { ($buf:ident, $value:expr) => { if $value < 10 { $buf.put_u8(b'0'); } $buf.put_slice(itoa::Buffer::new().format($value).as_bytes()); }; } macro_rules! write_triple_digit { ($buf:ident, $value:expr) => { if $value < 100 { $buf.put_u8(b'0'); } if $value < 10 { $buf.put_u8(b'0'); } $buf.put_slice(itoa::Buffer::new().format($value).as_bytes()); }; } #[derive(Default)] pub(crate) struct Offset { pub day: i32, pub second: i32, } /// Trait providing a method to write a datetime-like object to a buffer in an RFC3339-compatible format. /// /// The provided `write_buf` method does not allocate, and is faster /// than writing to a heap-allocated string. pub(crate) trait DateTimeLike { /// Returns the year component of the datetime. fn year(&self) -> i32; /// Returns the month component of the datetime. fn month(&self) -> u8; /// Returns the day component of the datetime. fn day(&self) -> u8; /// Returns the hour component of the datetime. fn hour(&self) -> u8; /// Returns the minute component of the datetime. fn minute(&self) -> u8; /// Returns the second component of the datetime. fn second(&self) -> u8; /// Returns the number of microseconds since the whole non-leap second. fn microsecond(&self) -> u32; /// Returns the number of nanoseconds since the whole non-leap second. fn nanosecond(&self) -> u32; /// Is the object time-zone aware? fn has_tz(&self) -> bool; //// Non-zoneinfo implementation of offset() fn slow_offset(&self) -> Result; /// The offset of the timezone. fn offset(&self) -> Result; /// Write `self` to a buffer in RFC3339 format, using `opts` to /// customise if desired. #[inline(never)] fn write_buf(&self, buf: &mut B, opts: Opt) -> Result<(), DateTimeError> where B: bytes::BufMut, { { let year = self.year(); let mut yearbuf = itoa::Buffer::new(); let formatted = yearbuf.format(year); if unlikely!(year < 1000) { // date-fullyear = 4DIGIT buf.put_slice(&[b'0', b'0', b'0', b'0'][..(4 - formatted.len())]); } buf.put_slice(formatted.as_bytes()); } buf.put_u8(b'-'); write_double_digit!(buf, self.month()); buf.put_u8(b'-'); write_double_digit!(buf, self.day()); buf.put_u8(b'T'); write_double_digit!(buf, self.hour()); buf.put_u8(b':'); write_double_digit!(buf, self.minute()); buf.put_u8(b':'); write_double_digit!(buf, self.second()); if opt_disabled!(opts, OMIT_MICROSECONDS) { let microsecond = self.microsecond(); if microsecond != 0 { buf.put_u8(b'.'); write_triple_digit!(buf, microsecond / 1_000); write_triple_digit!(buf, microsecond % 1_000); // Don't support writing nanoseconds for now. // If requested, something like the following should work, // and `SmallFixedBuffer` needs at least length 35. // let nanosecond = self.nanosecond(); // if nanosecond % 1_000 != 0 { // write_triple_digit!(buf, nanosecond % 1_000); // } } } if self.has_tz() || opt_enabled!(opts, NAIVE_UTC) { let offset = self.offset()?; let mut offset_second = offset.second; if offset_second == 0 { if opt_enabled!(opts, UTC_Z) { buf.put_u8(b'Z'); } else { buf.put_slice(b"+00:00"); } } else { // This branch is only really hit by the Python datetime implementation, // since numpy datetimes are all converted to UTC. if offset.day == -1 { // datetime.timedelta(days=-1, seconds=68400) -> -05:00 buf.put_u8(b'-'); offset_second = 86400 - offset_second; } else { // datetime.timedelta(seconds=37800) -> +10:30 buf.put_u8(b'+'); } let offset_minute = offset_second / 60; let offset_hour = offset_minute / 60; write_double_digit!(buf, offset_hour); buf.put_u8(b':'); let mut offset_minute_print = offset_minute % 60; // https://tools.ietf.org/html/rfc3339#section-5.8 // "exactly 19 minutes and 32.13 seconds ahead of UTC" // "closest representable UTC offset" // "+20:00" let offset_excess_second = offset_second - (offset_minute_print * 60 + offset_hour * 3600); if offset_excess_second >= 30 { offset_minute_print += 1; } write_double_digit!(buf, offset_minute_print); } } Ok(()) } } ijl-orjson-aa8c946/src/serialize/per_type/default.rs000066400000000000000000000043131505336676500226410ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::serialize::error::SerializeError; use crate::serialize::serializer::PyObjectSerializer; use serde::ser::{Serialize, Serializer}; #[repr(transparent)] pub(crate) struct DefaultSerializer<'a> { previous: &'a PyObjectSerializer, } impl<'a> DefaultSerializer<'a> { pub fn new(previous: &'a PyObjectSerializer) -> Self { Self { previous: previous } } } impl Serialize for DefaultSerializer<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { match self.previous.default { Some(callable) => { if unlikely!(self.previous.state.default_calls_limit()) { err!(SerializeError::DefaultRecursionLimit) } #[cfg(not(Py_3_10))] let default_obj = ffi!(PyObject_CallFunctionObjArgs( callable.as_ptr(), self.previous.ptr, core::ptr::null_mut::() )); #[cfg(Py_3_10)] #[allow(clippy::cast_sign_loss)] let nargs = ffi!(PyVectorcall_NARGS(1)) as usize; #[cfg(Py_3_10)] let default_obj = unsafe { pyo3_ffi::PyObject_Vectorcall( callable.as_ptr(), &raw const self.previous.ptr, nargs, core::ptr::null_mut(), ) }; if unlikely!(default_obj.is_null()) { err!(SerializeError::UnsupportedType(nonnull!(self.previous.ptr))) } else { let res = PyObjectSerializer::new( default_obj, self.previous.state.copy_for_default_call(), self.previous.default, ) .serialize(serializer); ffi!(Py_DECREF(default_obj)); res } } None => err!(SerializeError::UnsupportedType(nonnull!(self.previous.ptr))), } } } ijl-orjson-aa8c946/src/serialize/per_type/dict.rs000066400000000000000000000426651505336676500221540ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::opt::{NON_STR_KEYS, NOT_PASSTHROUGH, SORT_KEYS, SORT_OR_NON_STR_KEYS}; use crate::serialize::buffer::SmallFixedBuffer; use crate::serialize::error::SerializeError; use crate::serialize::obtype::{pyobject_to_obtype, ObType}; use crate::serialize::per_type::datetimelike::DateTimeLike; use crate::serialize::per_type::{ BoolSerializer, DataclassGenericSerializer, Date, DateTime, DefaultSerializer, EnumSerializer, FloatSerializer, FragmentSerializer, IntSerializer, ListTupleSerializer, NoneSerializer, NumpyScalar, NumpySerializer, StrSerializer, StrSubclassSerializer, Time, ZeroListSerializer, UUID, }; use crate::serialize::serializer::PyObjectSerializer; use crate::serialize::state::SerializerState; use crate::str::{PyStr, PyStrSubclass}; use crate::typeref::{STR_TYPE, TRUE, VALUE_STR}; use crate::util::isize_to_usize; use core::ptr::NonNull; use serde::ser::{Serialize, SerializeMap, Serializer}; use smallvec::SmallVec; pub(crate) struct ZeroDictSerializer; impl ZeroDictSerializer { pub const fn new() -> Self { Self {} } } impl Serialize for ZeroDictSerializer { #[inline(always)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_bytes(b"{}") } } pub(crate) struct DictGenericSerializer { ptr: *mut pyo3_ffi::PyObject, state: SerializerState, #[allow(dead_code)] default: Option>, } impl DictGenericSerializer { pub fn new( ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, ) -> Self { DictGenericSerializer { ptr: ptr, state: state.copy_for_recursive_call(), default: default, } } } impl Serialize for DictGenericSerializer { #[inline(always)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { if unlikely!(self.state.recursion_limit()) { err!(SerializeError::RecursionLimit) } if unlikely!(ffi!(Py_SIZE(self.ptr)) == 0) { ZeroDictSerializer::new().serialize(serializer) } else if likely!(opt_disabled!(self.state.opts(), SORT_OR_NON_STR_KEYS)) { unsafe { (*(core::ptr::from_ref::(self)).cast::()) .serialize(serializer) } } else if opt_enabled!(self.state.opts(), NON_STR_KEYS) { unsafe { (*(core::ptr::from_ref::(self)).cast::()) .serialize(serializer) } } else { unsafe { (*(core::ptr::from_ref::(self)).cast::()) .serialize(serializer) } } } } macro_rules! impl_serialize_entry { ($map:expr, $self:expr, $key:expr, $value:expr) => { match pyobject_to_obtype($value, $self.state.opts()) { ObType::Str => { $map.serialize_key($key).unwrap(); $map.serialize_value(&StrSerializer::new($value))?; } ObType::StrSubclass => { $map.serialize_key($key).unwrap(); $map.serialize_value(&StrSubclassSerializer::new($value))?; } ObType::Int => { $map.serialize_key($key).unwrap(); $map.serialize_value(&IntSerializer::new($value, $self.state.opts()))?; } ObType::None => { $map.serialize_key($key).unwrap(); $map.serialize_value(&NoneSerializer::new()).unwrap(); } ObType::Float => { $map.serialize_key($key).unwrap(); $map.serialize_value(&FloatSerializer::new($value))?; } ObType::Bool => { $map.serialize_key($key).unwrap(); $map.serialize_value(&BoolSerializer::new($value)).unwrap(); } ObType::Datetime => { $map.serialize_key($key).unwrap(); $map.serialize_value(&DateTime::new($value, $self.state.opts()))?; } ObType::Date => { $map.serialize_key($key).unwrap(); $map.serialize_value(&Date::new($value))?; } ObType::Time => { $map.serialize_key($key).unwrap(); $map.serialize_value(&Time::new($value, $self.state.opts()))?; } ObType::Uuid => { $map.serialize_key($key).unwrap(); $map.serialize_value(&UUID::new($value)).unwrap(); } ObType::Dict => { let pyvalue = DictGenericSerializer::new($value, $self.state, $self.default); $map.serialize_key($key).unwrap(); $map.serialize_value(&pyvalue)?; } ObType::List => { if ffi!(Py_SIZE($value)) == 0 { $map.serialize_key($key).unwrap(); $map.serialize_value(&ZeroListSerializer::new()).unwrap(); } else { let pyvalue = ListTupleSerializer::from_list($value, $self.state, $self.default); $map.serialize_key($key).unwrap(); $map.serialize_value(&pyvalue)?; } } ObType::Tuple => { if ffi!(Py_SIZE($value)) == 0 { $map.serialize_key($key).unwrap(); $map.serialize_value(&ZeroListSerializer::new()).unwrap(); } else { let pyvalue = ListTupleSerializer::from_tuple($value, $self.state, $self.default); $map.serialize_key($key).unwrap(); $map.serialize_value(&pyvalue)?; } } ObType::Dataclass => { $map.serialize_key($key).unwrap(); $map.serialize_value(&DataclassGenericSerializer::new(&PyObjectSerializer::new( $value, $self.state, $self.default, )))?; } ObType::Enum => { $map.serialize_key($key).unwrap(); $map.serialize_value(&EnumSerializer::new(&PyObjectSerializer::new( $value, $self.state, $self.default, )))?; } ObType::NumpyArray => { $map.serialize_key($key).unwrap(); $map.serialize_value(&NumpySerializer::new(&PyObjectSerializer::new( $value, $self.state, $self.default, )))?; } ObType::NumpyScalar => { $map.serialize_key($key).unwrap(); $map.serialize_value(&NumpyScalar::new($value, $self.state.opts()))?; } ObType::Fragment => { $map.serialize_key($key).unwrap(); $map.serialize_value(&FragmentSerializer::new($value))?; } ObType::Unknown => { $map.serialize_key($key).unwrap(); $map.serialize_value(&DefaultSerializer::new(&PyObjectSerializer::new( $value, $self.state, $self.default, )))?; } } }; } pub(crate) struct Dict { ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, } impl Serialize for Dict { #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut pos = 0; let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value); let mut map = serializer.serialize_map(None).unwrap(); let len = isize_to_usize(ffi!(Py_SIZE(self.ptr))); assume!(len > 0); for _ in 0..len { let key = next_key; let value = next_value; pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value); // key let key_ob_type = ob_type!(key); if unlikely!(!is_class_by_type!(key_ob_type, STR_TYPE)) { err!(SerializeError::KeyMustBeStr) } let pystr = unsafe { PyStr::from_ptr_unchecked(key) }; let uni = pystr.to_str(); if unlikely!(uni.is_none()) { err!(SerializeError::InvalidStr) } let key_as_str = uni.unwrap(); // value impl_serialize_entry!(map, self, key_as_str, value); } map.end() } } pub(crate) struct DictSortedKey { ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, } impl Serialize for DictSortedKey { #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut pos = 0; let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value); let len = isize_to_usize(ffi!(Py_SIZE(self.ptr))); assume!(len > 0); let mut items: SmallVec<[(&str, *mut pyo3_ffi::PyObject); 8]> = SmallVec::with_capacity(len); for _ in 0..len as usize { let key = next_key; let value = next_value; pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value); if unlikely!(unsafe { !core::ptr::eq(ob_type!(key), STR_TYPE) }) { err!(SerializeError::KeyMustBeStr) } let pystr = unsafe { PyStr::from_ptr_unchecked(key) }; let uni = pystr.to_str(); if unlikely!(uni.is_none()) { err!(SerializeError::InvalidStr) } let key_as_str = uni.unwrap(); items.push((key_as_str, value)); } sort_dict_items(&mut items); let mut map = serializer.serialize_map(None).unwrap(); for (key, val) in items.iter() { let pyvalue = PyObjectSerializer::new(*val, self.state, self.default); map.serialize_key(key).unwrap(); map.serialize_value(&pyvalue)?; } map.end() } } #[inline(never)] fn non_str_str(key: *mut pyo3_ffi::PyObject) -> Result { // because of ObType::Enum let uni = unsafe { PyStr::from_ptr_unchecked(key).to_str() }; if unlikely!(uni.is_none()) { Err(SerializeError::InvalidStr) } else { Ok(String::from(uni.unwrap())) } } #[cold] #[inline(never)] fn non_str_str_subclass(key: *mut pyo3_ffi::PyObject) -> Result { let uni = unsafe { PyStrSubclass::from_ptr_unchecked(key).to_str() }; if unlikely!(uni.is_none()) { Err(SerializeError::InvalidStr) } else { Ok(String::from(uni.unwrap())) } } #[allow(clippy::unnecessary_wraps)] #[inline(never)] fn non_str_date(key: *mut pyo3_ffi::PyObject) -> Result { let mut buf = SmallFixedBuffer::new(); Date::new(key).write_buf(&mut buf); let key_as_str = str_from_slice!(buf.as_ptr(), buf.len()); Ok(String::from(key_as_str)) } #[inline(never)] fn non_str_datetime( key: *mut pyo3_ffi::PyObject, opts: crate::opt::Opt, ) -> Result { let mut buf = SmallFixedBuffer::new(); let dt = DateTime::new(key, opts); if dt.write_buf(&mut buf, opts).is_err() { return Err(SerializeError::DatetimeLibraryUnsupported); } let key_as_str = str_from_slice!(buf.as_ptr(), buf.len()); Ok(String::from(key_as_str)) } #[cold] #[inline(never)] fn non_str_time( key: *mut pyo3_ffi::PyObject, opts: crate::opt::Opt, ) -> Result { let mut buf = SmallFixedBuffer::new(); let time = Time::new(key, opts); if time.write_buf(&mut buf).is_err() { return Err(SerializeError::TimeHasTzinfo); } let key_as_str = str_from_slice!(buf.as_ptr(), buf.len()); Ok(String::from(key_as_str)) } #[allow(clippy::unnecessary_wraps)] #[inline(never)] fn non_str_uuid(key: *mut pyo3_ffi::PyObject) -> Result { let mut buf = SmallFixedBuffer::new(); UUID::new(key).write_buf(&mut buf); let key_as_str = str_from_slice!(buf.as_ptr(), buf.len()); Ok(String::from(key_as_str)) } #[allow(clippy::unnecessary_wraps)] #[cold] #[inline(never)] fn non_str_float(key: *mut pyo3_ffi::PyObject) -> Result { let val = ffi!(PyFloat_AS_DOUBLE(key)); if !val.is_finite() { Ok(String::from("null")) } else { Ok(String::from(ryu::Buffer::new().format_finite(val))) } } #[allow(clippy::unnecessary_wraps)] #[inline(never)] fn non_str_int(key: *mut pyo3_ffi::PyObject) -> Result { let ival = ffi!(PyLong_AsLongLong(key)); if unlikely!(ival == -1 && !ffi!(PyErr_Occurred()).is_null()) { ffi!(PyErr_Clear()); let uval = ffi!(PyLong_AsUnsignedLongLong(key)); if unlikely!(uval == u64::MAX && !ffi!(PyErr_Occurred()).is_null()) { return Err(SerializeError::DictIntegerKey64Bit); } Ok(String::from(itoa::Buffer::new().format(uval))) } else { Ok(String::from(itoa::Buffer::new().format(ival))) } } #[inline(never)] fn sort_dict_items(items: &mut SmallVec<[(&str, *mut pyo3_ffi::PyObject); 8]>) { items.sort_unstable_by(|a, b| a.0.cmp(b.0)); } pub(crate) struct DictNonStrKey { ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, } impl DictNonStrKey { fn pyobject_to_string( key: *mut pyo3_ffi::PyObject, opts: crate::opt::Opt, ) -> Result { match pyobject_to_obtype(key, opts) { ObType::None => Ok(String::from("null")), ObType::Bool => { if unsafe { core::ptr::eq(key, TRUE) } { Ok(String::from("true")) } else { Ok(String::from("false")) } } ObType::Int => non_str_int(key), ObType::Float => non_str_float(key), ObType::Datetime => non_str_datetime(key, opts), ObType::Date => non_str_date(key), ObType::Time => non_str_time(key, opts), ObType::Uuid => non_str_uuid(key), ObType::Enum => { let value = ffi!(PyObject_GetAttr(key, VALUE_STR)); debug_assert!(ffi!(Py_REFCNT(value)) >= 2); let ret = Self::pyobject_to_string(value, opts); ffi!(Py_DECREF(value)); ret } ObType::Str => non_str_str(key), ObType::StrSubclass => non_str_str_subclass(key), ObType::Tuple | ObType::NumpyScalar | ObType::NumpyArray | ObType::Dict | ObType::List | ObType::Dataclass | ObType::Fragment | ObType::Unknown => Err(SerializeError::DictKeyInvalidType), } } } impl Serialize for DictNonStrKey { #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut pos = 0; let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut(); pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value); let opts = self.state.opts() & NOT_PASSTHROUGH; let len = isize_to_usize(ffi!(Py_SIZE(self.ptr))); assume!(len > 0); let mut items: SmallVec<[(String, *mut pyo3_ffi::PyObject); 8]> = SmallVec::with_capacity(len); for _ in 0..len { let key = next_key; let value = next_value; pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value); if is_type!(ob_type!(key), STR_TYPE) { match unsafe { PyStr::from_ptr_unchecked(key).to_str() } { Some(uni) => { items.push((String::from(uni), value)); } None => err!(SerializeError::InvalidStr), } } else { match Self::pyobject_to_string(key, opts) { Ok(key_as_str) => items.push((key_as_str, value)), Err(err) => err!(err), } } } let mut items_as_str: SmallVec<[(&str, *mut pyo3_ffi::PyObject); 8]> = SmallVec::with_capacity(len); items .iter() .for_each(|(key, val)| items_as_str.push(((*key).as_str(), *val))); if opt_enabled!(opts, SORT_KEYS) { sort_dict_items(&mut items_as_str); } let mut map = serializer.serialize_map(None).unwrap(); for (key, val) in items_as_str.iter() { let pyvalue = PyObjectSerializer::new(*val, self.state, self.default); map.serialize_key(key).unwrap(); map.serialize_value(&pyvalue)?; } map.end() } } ijl-orjson-aa8c946/src/serialize/per_type/float.rs000066400000000000000000000010501505336676500223150ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use serde::ser::{Serialize, Serializer}; #[repr(transparent)] pub(crate) struct FloatSerializer { ptr: *mut pyo3_ffi::PyObject, } impl FloatSerializer { pub fn new(ptr: *mut pyo3_ffi::PyObject) -> Self { FloatSerializer { ptr: ptr } } } impl Serialize for FloatSerializer { #[inline(always)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_f64(ffi!(PyFloat_AS_DOUBLE(self.ptr))) } } ijl-orjson-aa8c946/src/serialize/per_type/fragment.rs000066400000000000000000000031611505336676500230200ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::ffi::{Fragment, PyBytes_AS_STRING, PyBytes_GET_SIZE}; use crate::serialize::error::SerializeError; use crate::str::PyStr; use crate::typeref::{BYTES_TYPE, STR_TYPE}; use crate::util::isize_to_usize; use serde::ser::{Serialize, Serializer}; #[repr(transparent)] pub(crate) struct FragmentSerializer { ptr: *mut pyo3_ffi::PyObject, } impl FragmentSerializer { pub fn new(ptr: *mut pyo3_ffi::PyObject) -> Self { FragmentSerializer { ptr: ptr } } } impl Serialize for FragmentSerializer { #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let buffer: &[u8]; unsafe { let fragment: *mut Fragment = self.ptr.cast::(); let ob_type = ob_type!((*fragment).contents); if core::ptr::eq(ob_type, BYTES_TYPE) { buffer = core::slice::from_raw_parts( PyBytes_AS_STRING((*fragment).contents).cast::(), isize_to_usize(PyBytes_GET_SIZE((*fragment).contents)), ); } else if core::ptr::eq(ob_type, STR_TYPE) { match unsafe { PyStr::from_ptr_unchecked((*fragment).contents).to_str() } { Some(uni) => buffer = uni.as_bytes(), None => err!(SerializeError::InvalidStr), } } else { err!(SerializeError::InvalidFragment) } } serializer.serialize_bytes(buffer) } } ijl-orjson-aa8c946/src/serialize/per_type/int.rs000066400000000000000000000107241505336676500220120ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::opt::{Opt, STRICT_INTEGER}; use crate::serialize::error::SerializeError; use serde::ser::{Serialize, Serializer}; // https://tools.ietf.org/html/rfc7159#section-6 // "[-(2**53)+1, (2**53)-1]" const STRICT_INT_MIN: i64 = -9007199254740991; const STRICT_INT_MAX: i64 = 9007199254740991; pub(crate) struct IntSerializer { ptr: *mut pyo3_ffi::PyObject, opts: Opt, } impl IntSerializer { pub fn new(ptr: *mut pyo3_ffi::PyObject, opts: Opt) -> Self { IntSerializer { ptr: ptr, opts: opts, } } } impl Serialize for IntSerializer { #[inline(always)] #[cfg(feature = "inline_int")] fn serialize(&self, serializer: S) -> Result where S: Serializer, { unsafe { if crate::ffi::pylong_is_zero(self.ptr) { return serializer.serialize_bytes(b"0"); } let is_signed = i32::from(!crate::ffi::pylong_is_unsigned(self.ptr)); if crate::ffi::pylong_fits_in_i32(self.ptr) { if is_signed == 0 { #[allow(clippy::cast_sign_loss)] serializer.serialize_u64(crate::ffi::pylong_get_inline_value(self.ptr) as u64) } else { serializer.serialize_i64(crate::ffi::pylong_get_inline_value(self.ptr)) } } else { let mut buffer: [u8; 8] = [0; 8]; #[cfg(not(Py_3_13))] let ret = crate::ffi::_PyLong_AsByteArray( self.ptr.cast::(), buffer.as_mut_ptr().cast::(), 8, 1, is_signed, ); #[cfg(Py_3_13)] let ret = crate::ffi::_PyLong_AsByteArray( self.ptr.cast::(), buffer.as_mut_ptr().cast::(), 8, 1, is_signed, 0, ); if unlikely!(ret == -1) { #[cfg(not(Py_3_13))] ffi!(PyErr_Clear()); err!(SerializeError::Integer64Bits) } if is_signed == 0 { let val = u64::from_ne_bytes(buffer); if unlikely!(opt_enabled!(self.opts, STRICT_INTEGER)) && val > STRICT_INT_MAX as u64 { err!(SerializeError::Integer53Bits) } serializer.serialize_u64(val) } else { let val = i64::from_ne_bytes(buffer); if unlikely!(opt_enabled!(self.opts, STRICT_INTEGER)) && !(STRICT_INT_MIN..=STRICT_INT_MAX).contains(&val) { err!(SerializeError::Integer53Bits) } serializer.serialize_i64(val) } } } } #[inline(always)] #[cfg(not(feature = "inline_int"))] fn serialize(&self, serializer: S) -> Result where S: Serializer, { unsafe { if crate::ffi::pylong_is_unsigned(self.ptr) { let val = ffi!(PyLong_AsUnsignedLongLong(self.ptr)); if unlikely!(val == u64::MAX) && !ffi!(PyErr_Occurred()).is_null() { ffi!(PyErr_Clear()); err!(SerializeError::Integer64Bits) } else if unlikely!(opt_enabled!(self.opts, STRICT_INTEGER)) && val > STRICT_INT_MAX as u64 { err!(SerializeError::Integer53Bits) } else { serializer.serialize_u64(val) } } else { let val = ffi!(PyLong_AsLongLong(self.ptr)); if unlikely!(val == -1) && !ffi!(PyErr_Occurred()).is_null() { ffi!(PyErr_Clear()); err!(SerializeError::Integer64Bits) } else if unlikely!(opt_enabled!(self.opts, STRICT_INTEGER)) && !(STRICT_INT_MIN..=STRICT_INT_MAX).contains(&val) { err!(SerializeError::Integer53Bits) } else { serializer.serialize_i64(val) } } } } } ijl-orjson-aa8c946/src/serialize/per_type/list.rs000066400000000000000000000153461505336676500222000ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::serialize::error::SerializeError; use crate::serialize::obtype::{pyobject_to_obtype, ObType}; use crate::serialize::per_type::{ BoolSerializer, DataclassGenericSerializer, Date, DateTime, DefaultSerializer, DictGenericSerializer, EnumSerializer, FloatSerializer, FragmentSerializer, IntSerializer, NoneSerializer, NumpyScalar, NumpySerializer, StrSerializer, StrSubclassSerializer, Time, UUID, }; use crate::serialize::serializer::PyObjectSerializer; use crate::serialize::state::SerializerState; use crate::typeref::{LIST_TYPE, TUPLE_TYPE}; use crate::util::isize_to_usize; use core::ptr::NonNull; use serde::ser::{Serialize, SerializeSeq, Serializer}; pub(crate) struct ZeroListSerializer; impl ZeroListSerializer { pub const fn new() -> Self { Self {} } } impl Serialize for ZeroListSerializer { #[inline(always)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_bytes(b"[]") } } pub(crate) struct ListTupleSerializer { data_ptr: *const *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, len: usize, } impl ListTupleSerializer { pub fn from_list( ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, ) -> Self { debug_assert!( is_type!(ob_type!(ptr), LIST_TYPE) || is_subclass_by_flag!(tp_flags!(ob_type!(ptr)), Py_TPFLAGS_LIST_SUBCLASS) ); let data_ptr = unsafe { (*ptr.cast::()).ob_item }; let len = isize_to_usize(ffi!(Py_SIZE(ptr))); Self { data_ptr: data_ptr, len: len, state: state.copy_for_recursive_call(), default: default, } } pub fn from_tuple( ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, ) -> Self { debug_assert!( is_type!(ob_type!(ptr), TUPLE_TYPE) || is_subclass_by_flag!(tp_flags!(ob_type!(ptr)), Py_TPFLAGS_TUPLE_SUBCLASS) ); let data_ptr = unsafe { (*ptr.cast::()).ob_item.as_ptr() }; let len = isize_to_usize(ffi!(Py_SIZE(ptr))); Self { data_ptr: data_ptr, len: len, state: state.copy_for_recursive_call(), default: default, } } } impl Serialize for ListTupleSerializer { #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { if unlikely!(self.state.recursion_limit()) { err!(SerializeError::RecursionLimit) } debug_assert!(self.len >= 1); let mut seq = serializer.serialize_seq(None).unwrap(); for idx in 0..self.len { let value = unsafe { *((self.data_ptr).add(idx)) }; match pyobject_to_obtype(value, self.state.opts()) { ObType::Str => { seq.serialize_element(&StrSerializer::new(value))?; } ObType::StrSubclass => { seq.serialize_element(&StrSubclassSerializer::new(value))?; } ObType::Int => { seq.serialize_element(&IntSerializer::new(value, self.state.opts()))?; } ObType::None => { seq.serialize_element(&NoneSerializer::new()).unwrap(); } ObType::Float => { seq.serialize_element(&FloatSerializer::new(value))?; } ObType::Bool => { seq.serialize_element(&BoolSerializer::new(value)).unwrap(); } ObType::Datetime => { seq.serialize_element(&DateTime::new(value, self.state.opts()))?; } ObType::Date => { seq.serialize_element(&Date::new(value))?; } ObType::Time => { seq.serialize_element(&Time::new(value, self.state.opts()))?; } ObType::Uuid => { seq.serialize_element(&UUID::new(value)).unwrap(); } ObType::Dict => { let pyvalue = DictGenericSerializer::new(value, self.state, self.default); seq.serialize_element(&pyvalue)?; } ObType::List => { if ffi!(Py_SIZE(value)) == 0 { seq.serialize_element(&ZeroListSerializer::new()).unwrap(); } else { let pyvalue = ListTupleSerializer::from_list(value, self.state, self.default); seq.serialize_element(&pyvalue)?; } } ObType::Tuple => { if ffi!(Py_SIZE(value)) == 0 { seq.serialize_element(&ZeroListSerializer::new()).unwrap(); } else { let pyvalue = ListTupleSerializer::from_tuple(value, self.state, self.default); seq.serialize_element(&pyvalue)?; } } ObType::Dataclass => { seq.serialize_element(&DataclassGenericSerializer::new( &PyObjectSerializer::new(value, self.state, self.default), ))?; } ObType::Enum => { seq.serialize_element(&EnumSerializer::new(&PyObjectSerializer::new( value, self.state, self.default, )))?; } ObType::NumpyArray => { seq.serialize_element(&NumpySerializer::new(&PyObjectSerializer::new( value, self.state, self.default, )))?; } ObType::NumpyScalar => { seq.serialize_element(&NumpyScalar::new(value, self.state.opts()))?; } ObType::Fragment => { seq.serialize_element(&FragmentSerializer::new(value))?; } ObType::Unknown => { seq.serialize_element(&DefaultSerializer::new(&PyObjectSerializer::new( value, self.state, self.default, )))?; } } } seq.end() } } ijl-orjson-aa8c946/src/serialize/per_type/mod.rs000066400000000000000000000017231505336676500217760ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) mod dataclass; mod datetime; mod pybool; #[macro_use] mod datetimelike; mod default; mod dict; mod float; mod fragment; mod int; mod list; mod none; mod numpy; mod pyenum; mod unicode; mod uuid; pub(crate) use dataclass::DataclassGenericSerializer; pub(crate) use datetime::{Date, DateTime, Time}; pub(crate) use datetimelike::{DateTimeError, DateTimeLike, Offset}; pub(crate) use default::DefaultSerializer; pub(crate) use dict::DictGenericSerializer; pub(crate) use float::FloatSerializer; pub(crate) use fragment::FragmentSerializer; pub(crate) use int::IntSerializer; pub(crate) use list::{ListTupleSerializer, ZeroListSerializer}; pub(crate) use none::NoneSerializer; pub(crate) use numpy::{is_numpy_array, is_numpy_scalar, NumpyScalar, NumpySerializer}; pub(crate) use pybool::BoolSerializer; pub(crate) use pyenum::EnumSerializer; pub(crate) use unicode::{StrSerializer, StrSubclassSerializer}; pub(crate) use uuid::UUID; ijl-orjson-aa8c946/src/serialize/per_type/none.rs000066400000000000000000000006301505336676500221520ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use serde::ser::{Serialize, Serializer}; pub(crate) struct NoneSerializer; impl NoneSerializer { pub const fn new() -> Self { Self {} } } impl Serialize for NoneSerializer { #[inline] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_unit() } } ijl-orjson-aa8c946/src/serialize/per_type/numpy.rs000066400000000000000000001140251505336676500223670ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::opt::Opt; use crate::serialize::buffer::SmallFixedBuffer; use crate::serialize::error::SerializeError; use crate::serialize::per_type::{ DateTimeError, DateTimeLike, DefaultSerializer, Offset, ZeroListSerializer, }; use crate::serialize::serializer::PyObjectSerializer; use crate::str::PyStr; use crate::typeref::{load_numpy_types, ARRAY_STRUCT_STR, DESCR_STR, DTYPE_STR, NUMPY_TYPES}; use crate::util::isize_to_usize; use core::ffi::{c_char, c_int, c_void}; use jiff::civil::DateTime; use jiff::Timestamp; use pyo3_ffi::{PyObject, PyTypeObject, Py_intptr_t, Py_ssize_t}; use serde::ser::{self, Serialize, SerializeSeq, Serializer}; use std::fmt; #[repr(transparent)] pub(crate) struct NumpySerializer<'a> { previous: &'a PyObjectSerializer, } impl<'a> NumpySerializer<'a> { pub fn new(previous: &'a PyObjectSerializer) -> Self { Self { previous: previous } } } impl Serialize for NumpySerializer<'_> { #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] fn serialize(&self, serializer: S) -> Result where S: Serializer, { match NumpyArray::new(self.previous.ptr, self.previous.state.opts()) { Ok(val) => val.serialize(serializer), Err(PyArrayError::Malformed) => err!(SerializeError::NumpyMalformed), Err(PyArrayError::NotContiguous | PyArrayError::UnsupportedDataType) if self.previous.default.is_some() => { DefaultSerializer::new(self.previous).serialize(serializer) } Err(PyArrayError::NotContiguous) => { err!(SerializeError::NumpyNotCContiguous) } Err(PyArrayError::NotNativeEndian) => { err!(SerializeError::NumpyNotNativeEndian) } Err(PyArrayError::UnsupportedDataType) => { err!(SerializeError::NumpyUnsupportedDatatype) } } } } macro_rules! slice { ($ptr:expr, $size:expr) => { unsafe { core::slice::from_raw_parts($ptr, $size) } }; } #[cold] pub(crate) fn is_numpy_scalar(ob_type: *mut PyTypeObject) -> bool { let numpy_types = unsafe { NUMPY_TYPES.get_or_init(load_numpy_types) }; if numpy_types.is_none() { false } else { let scalar_types = unsafe { numpy_types.unwrap().as_ref() }; core::ptr::eq(ob_type, scalar_types.float64) || core::ptr::eq(ob_type, scalar_types.float32) || core::ptr::eq(ob_type, scalar_types.float16) || core::ptr::eq(ob_type, scalar_types.int64) || core::ptr::eq(ob_type, scalar_types.int16) || core::ptr::eq(ob_type, scalar_types.int32) || core::ptr::eq(ob_type, scalar_types.int8) || core::ptr::eq(ob_type, scalar_types.uint64) || core::ptr::eq(ob_type, scalar_types.uint32) || core::ptr::eq(ob_type, scalar_types.uint8) || core::ptr::eq(ob_type, scalar_types.uint16) || core::ptr::eq(ob_type, scalar_types.bool_) || core::ptr::eq(ob_type, scalar_types.datetime64) } } #[cold] pub(crate) fn is_numpy_array(ob_type: *mut PyTypeObject) -> bool { let numpy_types = unsafe { NUMPY_TYPES.get_or_init(load_numpy_types) }; if numpy_types.is_none() { false } else { let scalar_types = unsafe { numpy_types.unwrap().as_ref() }; unsafe { core::ptr::eq(ob_type, scalar_types.array) } } } #[repr(C)] pub(crate) struct PyCapsule { pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, pub pointer: *mut c_void, pub name: *const c_char, pub context: *mut c_void, pub destructor: *mut c_void, // should be typedef void (*PyCapsule_Destructor)(PyObject *); } // https://docs.scipy.org/doc/numpy/reference/arrays.interface.html#c.__array_struct__ const NPY_ARRAY_C_CONTIGUOUS: c_int = 0x1; const NPY_ARRAY_NOTSWAPPED: c_int = 0x200; #[repr(C)] pub(crate) struct PyArrayInterface { pub two: c_int, pub nd: c_int, pub typekind: c_char, pub itemsize: c_int, pub flags: c_int, pub shape: *mut Py_intptr_t, pub strides: *mut Py_intptr_t, pub data: *mut c_void, pub descr: *mut PyObject, } #[derive(Clone, Copy)] pub(crate) enum ItemType { BOOL, DATETIME64(NumpyDatetimeUnit), F16, F32, F64, I8, I16, I32, I64, U8, U16, U32, U64, } impl ItemType { fn find(array: *mut PyArrayInterface, ptr: *mut PyObject) -> Option { match unsafe { ((*array).typekind, (*array).itemsize) } { (098, 1) => Some(ItemType::BOOL), (077, 8) => { let unit = NumpyDatetimeUnit::from_pyobject(ptr); Some(ItemType::DATETIME64(unit)) } (102, 2) => Some(ItemType::F16), (102, 4) => Some(ItemType::F32), (102, 8) => Some(ItemType::F64), (105, 1) => Some(ItemType::I8), (105, 2) => Some(ItemType::I16), (105, 4) => Some(ItemType::I32), (105, 8) => Some(ItemType::I64), (117, 1) => Some(ItemType::U8), (117, 2) => Some(ItemType::U16), (117, 4) => Some(ItemType::U32), (117, 8) => Some(ItemType::U64), _ => None, } } } pub(crate) enum PyArrayError { Malformed, NotContiguous, NotNativeEndian, UnsupportedDataType, } // >>> arr = numpy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], numpy.int32) // >>> arr.ndim // 3 // >>> arr.shape // (2, 2, 2) // >>> arr.strides // (16, 8, 4) pub(crate) struct NumpyArray { array: *mut PyArrayInterface, position: Vec, children: Vec, depth: usize, capsule: *mut PyCapsule, kind: ItemType, opts: Opt, } impl NumpyArray { #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] pub fn new(ptr: *mut PyObject, opts: Opt) -> Result { let capsule = ffi!(PyObject_GetAttr(ptr, ARRAY_STRUCT_STR)); let array = unsafe { (*capsule.cast::()) .pointer .cast::() }; if unsafe { (*array).two != 2 } { ffi!(Py_DECREF(capsule)); Err(PyArrayError::Malformed) } else if unsafe { (*array).flags } & NPY_ARRAY_C_CONTIGUOUS != NPY_ARRAY_C_CONTIGUOUS { ffi!(Py_DECREF(capsule)); Err(PyArrayError::NotContiguous) } else if unsafe { (*array).flags } & NPY_ARRAY_NOTSWAPPED != NPY_ARRAY_NOTSWAPPED { ffi!(Py_DECREF(capsule)); Err(PyArrayError::NotNativeEndian) } else { debug_assert!(unsafe { (*array).nd >= 0 }); #[allow(clippy::cast_sign_loss)] let num_dimensions = unsafe { (*array).nd as usize }; if num_dimensions == 0 { ffi!(Py_DECREF(capsule)); return Err(PyArrayError::UnsupportedDataType); } match ItemType::find(array, ptr) { None => { ffi!(Py_DECREF(capsule)); Err(PyArrayError::UnsupportedDataType) } Some(kind) => { let mut pyarray = NumpyArray { array: array, position: vec![0; num_dimensions], children: Vec::with_capacity(num_dimensions), depth: 0, capsule: capsule.cast::(), kind: kind, opts, }; if pyarray.dimensions() > 1 { pyarray.build(); } Ok(pyarray) } } } } #[cfg_attr(feature = "optimize", optimize(size))] fn child_from_parent(&self, position: Vec, num_children: usize) -> Self { let mut arr = NumpyArray { array: self.array, position: position, children: Vec::with_capacity(num_children), depth: self.depth + 1, capsule: self.capsule, kind: self.kind, opts: self.opts, }; arr.build(); arr } #[cfg_attr(feature = "optimize", optimize(size))] fn build(&mut self) { if self.depth < self.dimensions() - 1 { for i in 0..self.shape()[self.depth] { let mut position: Vec = self.position.clone(); position[self.depth] = i; let num_children: usize = if self.depth < self.dimensions() - 2 { isize_to_usize(self.shape()[self.depth + 1]) } else { 0 }; self.children .push(self.child_from_parent(position, num_children)); } } } #[inline(always)] fn data(&self) -> *const c_void { let offset = self .strides() .iter() .zip(self.position.iter().copied()) .take(self.depth) .map(|(a, b)| a * b) .sum::(); unsafe { (*self.array).data.offset(offset) } } fn num_items(&self) -> usize { isize_to_usize(self.shape()[self.shape().len() - 1]) } fn dimensions(&self) -> usize { #[allow(clippy::cast_sign_loss)] unsafe { (*self.array).nd as usize } } fn shape(&self) -> &[isize] { slice!((*self.array).shape.cast_const(), self.dimensions()) } fn strides(&self) -> &[isize] { slice!((*self.array).strides.cast_const(), self.dimensions()) } } impl Drop for NumpyArray { fn drop(&mut self) { if self.depth == 0 { ffi!(Py_DECREF(self.array.cast::())); ffi!(Py_DECREF(self.capsule.cast::())); } } } impl Serialize for NumpyArray { #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] fn serialize(&self, serializer: S) -> Result where S: Serializer, { if unlikely!(!(self.depth >= self.dimensions() || self.shape()[self.depth] != 0)) { ZeroListSerializer::new().serialize(serializer) } else if !self.children.is_empty() { let mut seq = serializer.serialize_seq(None).unwrap(); for child in &self.children { seq.serialize_element(child).unwrap(); } seq.end() } else { match self.kind { ItemType::F64 => { NumpyF64Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::F32 => { NumpyF32Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::F16 => { NumpyF16Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::U64 => { NumpyU64Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::U32 => { NumpyU32Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::U16 => { NumpyU16Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::U8 => { NumpyU8Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::I64 => { NumpyI64Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::I32 => { NumpyI32Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::I16 => { NumpyI16Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::I8 => { NumpyI8Array::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::BOOL => { NumpyBoolArray::new(slice!(self.data().cast::(), self.num_items())) .serialize(serializer) } ItemType::DATETIME64(unit) => NumpyDatetime64Array::new( slice!(self.data().cast::(), self.num_items()), unit, self.opts, ) .serialize(serializer), } } } } #[repr(transparent)] struct NumpyF64Array<'a> { data: &'a [f64], } impl<'a> NumpyF64Array<'a> { fn new(data: &'a [f64]) -> Self { Self { data } } } impl Serialize for NumpyF64Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeF64 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeF64 { obj: f64, } impl Serialize for DataTypeF64 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_f64(self.obj) } } #[repr(transparent)] struct NumpyF32Array<'a> { data: &'a [f32], } impl<'a> NumpyF32Array<'a> { fn new(data: &'a [f32]) -> Self { Self { data } } } impl Serialize for NumpyF32Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeF32 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] struct DataTypeF32 { obj: f32, } impl Serialize for DataTypeF32 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_f32(self.obj) } } #[repr(transparent)] struct NumpyF16Array<'a> { data: &'a [u16], } impl<'a> NumpyF16Array<'a> { fn new(data: &'a [u16]) -> Self { Self { data } } } impl Serialize for NumpyF16Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeF16 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] struct DataTypeF16 { obj: u16, } impl Serialize for DataTypeF16 { #[cold] #[cfg_attr(feature = "optimize", optimize(size))] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let as_f16 = half::f16::from_bits(self.obj); serializer.serialize_f32(as_f16.to_f32()) } } #[repr(transparent)] struct NumpyU64Array<'a> { data: &'a [u64], } impl<'a> NumpyU64Array<'a> { fn new(data: &'a [u64]) -> Self { Self { data } } } impl Serialize for NumpyU64Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeU64 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeU64 { obj: u64, } impl Serialize for DataTypeU64 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_u64(self.obj) } } #[repr(transparent)] struct NumpyU32Array<'a> { data: &'a [u32], } impl<'a> NumpyU32Array<'a> { fn new(data: &'a [u32]) -> Self { Self { data } } } impl Serialize for NumpyU32Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeU32 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeU32 { obj: u32, } impl Serialize for DataTypeU32 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_u32(self.obj) } } #[repr(transparent)] struct NumpyU16Array<'a> { data: &'a [u16], } impl<'a> NumpyU16Array<'a> { fn new(data: &'a [u16]) -> Self { Self { data } } } impl Serialize for NumpyU16Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeU16 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeU16 { obj: u16, } impl Serialize for DataTypeU16 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_u32(u32::from(self.obj)) } } #[repr(transparent)] struct NumpyI64Array<'a> { data: &'a [i64], } impl<'a> NumpyI64Array<'a> { fn new(data: &'a [i64]) -> Self { Self { data } } } impl Serialize for NumpyI64Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeI64 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeI64 { obj: i64, } impl Serialize for DataTypeI64 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_i64(self.obj) } } #[repr(transparent)] struct NumpyI32Array<'a> { data: &'a [i32], } impl<'a> NumpyI32Array<'a> { fn new(data: &'a [i32]) -> Self { Self { data } } } impl Serialize for NumpyI32Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeI32 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeI32 { obj: i32, } impl Serialize for DataTypeI32 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_i32(self.obj) } } #[repr(transparent)] struct NumpyI16Array<'a> { data: &'a [i16], } impl<'a> NumpyI16Array<'a> { fn new(data: &'a [i16]) -> Self { Self { data } } } impl Serialize for NumpyI16Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeI16 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeI16 { obj: i16, } impl Serialize for DataTypeI16 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_i32(i32::from(self.obj)) } } #[repr(transparent)] struct NumpyI8Array<'a> { data: &'a [i8], } impl<'a> NumpyI8Array<'a> { fn new(data: &'a [i8]) -> Self { Self { data } } } impl Serialize for NumpyI8Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeI8 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeI8 { obj: i8, } impl Serialize for DataTypeI8 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_i32(i32::from(self.obj)) } } #[repr(transparent)] struct NumpyU8Array<'a> { data: &'a [u8], } impl<'a> NumpyU8Array<'a> { fn new(data: &'a [u8]) -> Self { Self { data } } } impl Serialize for NumpyU8Array<'_> { #[cold] #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeU8 { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeU8 { obj: u8, } impl Serialize for DataTypeU8 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_u32(u32::from(self.obj)) } } #[repr(transparent)] struct NumpyBoolArray<'a> { data: &'a [u8], } impl<'a> NumpyBoolArray<'a> { fn new(data: &'a [u8]) -> Self { Self { data } } } impl Serialize for NumpyBoolArray<'_> { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { seq.serialize_element(&DataTypeBool { obj: each }).unwrap(); } seq.end() } } #[repr(transparent)] pub(crate) struct DataTypeBool { obj: u8, } impl Serialize for DataTypeBool { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_bool(self.obj == 1) } } pub(crate) struct NumpyScalar { ptr: *mut pyo3_ffi::PyObject, opts: Opt, } impl NumpyScalar { pub fn new(ptr: *mut PyObject, opts: Opt) -> Self { NumpyScalar { ptr, opts } } } impl Serialize for NumpyScalar { #[cold] #[inline(never)] #[cfg_attr(feature = "optimize", optimize(size))] fn serialize(&self, serializer: S) -> Result where S: Serializer, { unsafe { let ob_type = ob_type!(self.ptr); let scalar_types = unsafe { NUMPY_TYPES.get_or_init(load_numpy_types).unwrap().as_ref() }; if core::ptr::eq(ob_type, scalar_types.float64) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.float32) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.float16) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.int64) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.int32) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.int16) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.int8) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.uint64) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.uint32) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.uint16) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.uint8) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.bool_) { (*(self.ptr.cast::())).serialize(serializer) } else if core::ptr::eq(ob_type, scalar_types.datetime64) { let unit = NumpyDatetimeUnit::from_pyobject(self.ptr); let obj = &*self.ptr.cast::(); let dt = unit .datetime(obj.value, self.opts) .map_err(NumpyDateTimeError::into_serde_err)?; dt.serialize(serializer) } else { unreachable!() } } } } #[repr(C)] pub(crate) struct NumpyInt8 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: i8, } impl Serialize for NumpyInt8 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_i32(i32::from(self.value)) } } #[repr(C)] pub(crate) struct NumpyInt16 { pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, pub value: i16, } impl Serialize for NumpyInt16 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_i32(i32::from(self.value)) } } #[repr(C)] pub(crate) struct NumpyInt32 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: i32, } impl Serialize for NumpyInt32 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_i32(self.value) } } #[repr(C)] pub(crate) struct NumpyInt64 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: i64, } impl Serialize for NumpyInt64 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_i64(self.value) } } #[repr(C)] pub(crate) struct NumpyUint8 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: u8, } impl Serialize for NumpyUint8 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_u32(u32::from(self.value)) } } #[repr(C)] pub(crate) struct NumpyUint16 { pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, pub value: u16, } impl Serialize for NumpyUint16 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_u32(u32::from(self.value)) } } #[repr(C)] pub(crate) struct NumpyUint32 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: u32, } impl Serialize for NumpyUint32 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_u32(self.value) } } #[repr(C)] pub(crate) struct NumpyUint64 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: u64, } impl Serialize for NumpyUint64 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_u64(self.value) } } #[repr(C)] pub(crate) struct NumpyFloat16 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: u16, } impl Serialize for NumpyFloat16 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let as_f16 = half::f16::from_bits(self.value); serializer.serialize_f32(as_f16.to_f32()) } } #[repr(C)] pub(crate) struct NumpyFloat32 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: f32, } impl Serialize for NumpyFloat32 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_f32(self.value) } } #[repr(C)] pub(crate) struct NumpyFloat64 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: f64, } impl Serialize for NumpyFloat64 { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_f64(self.value) } } #[repr(C)] pub(crate) struct NumpyBool { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: bool, } impl Serialize for NumpyBool { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_bool(self.value) } } /// This mimicks the units supported by numpy's datetime64 type. /// /// See /// https://github.com/numpy/numpy/blob/fc8e3bbe419748ac5c6b7f3d0845e4bafa74644b/numpy/core/include/numpy/ndarraytypes.h#L268-L282. #[derive(Clone, Copy)] pub(crate) enum NumpyDatetimeUnit { NaT, Years, Months, Weeks, Days, Hours, Minutes, Seconds, Milliseconds, Microseconds, Nanoseconds, Picoseconds, Femtoseconds, Attoseconds, Generic, } impl fmt::Display for NumpyDatetimeUnit { #[cold] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let unit = match self { Self::NaT => "NaT", Self::Years => "years", Self::Months => "months", Self::Weeks => "weeks", Self::Days => "days", Self::Hours => "hours", Self::Minutes => "minutes", Self::Seconds => "seconds", Self::Milliseconds => "milliseconds", Self::Microseconds => "microseconds", Self::Nanoseconds => "nanoseconds", Self::Picoseconds => "picoseconds", Self::Femtoseconds => "femtoseconds", Self::Attoseconds => "attoseconds", Self::Generic => "generic", }; write!(f, "{unit}") } } #[derive(Clone, Copy)] enum NumpyDateTimeError { UnsupportedUnit(NumpyDatetimeUnit), Unrepresentable { unit: NumpyDatetimeUnit, val: i64 }, } impl NumpyDateTimeError { #[cold] fn into_serde_err(self) -> T { let err = match self { Self::UnsupportedUnit(unit) => format!("unsupported numpy.datetime64 unit: {unit}"), Self::Unrepresentable { unit, val } => { format!("unrepresentable numpy.datetime64: {val} {unit}") } }; ser::Error::custom(err) } } macro_rules! to_jiff_datetime { ($timestamp:expr, $self:expr, $val:expr) => { Ok( ($timestamp.map_err(|_| NumpyDateTimeError::Unrepresentable { unit: $self, val: $val, })?) .to_zoned(jiff::tz::TimeZone::UTC) .datetime(), ) }; } impl NumpyDatetimeUnit { /// Create a `NumpyDatetimeUnit` from a pointer to a Python object holding a /// numpy array. /// /// This function must only be called with pointers to numpy arrays. /// /// We need to look inside the `obj.dtype.descr` attribute of the Python /// object rather than using the `descr` field of the `__array_struct__` /// because that field isn't populated for datetime64 arrays; see /// https://github.com/numpy/numpy/issues/5350. #[cold] #[cfg_attr(feature = "optimize", optimize(size))] fn from_pyobject(ptr: *mut PyObject) -> Self { let dtype = ffi!(PyObject_GetAttr(ptr, DTYPE_STR)); let descr = ffi!(PyObject_GetAttr(dtype, DESCR_STR)); let el0 = ffi!(PyList_GET_ITEM(descr, 0)); let descr_str = unsafe { crate::ffi::PyTuple_GET_ITEM(el0, 1) }; let uni = unsafe { PyStr::from_ptr_unchecked(descr_str).to_str().unwrap() }; if uni.len() < 5 { return Self::NaT; } // unit descriptions are found at // https://github.com/numpy/numpy/blob/b235f9e701e14ed6f6f6dcba885f7986a833743f/numpy/core/src/multiarray/datetime.c#L79-L96. let ret = match &uni[4..uni.len() - 1] { "Y" => Self::Years, "M" => Self::Months, "W" => Self::Weeks, "D" => Self::Days, "h" => Self::Hours, "m" => Self::Minutes, "s" => Self::Seconds, "ms" => Self::Milliseconds, "us" => Self::Microseconds, "ns" => Self::Nanoseconds, "ps" => Self::Picoseconds, "fs" => Self::Femtoseconds, "as" => Self::Attoseconds, "generic" => Self::Generic, _ => unreachable!(), }; ffi!(Py_DECREF(dtype)); ffi!(Py_DECREF(descr)); ret } /// Return a `NumpyDatetime64Repr` for a value in array with this unit. /// /// Returns an `Err(NumpyDateTimeError)` if the value is invalid for this unit. #[cold] #[cfg_attr(feature = "optimize", optimize(size))] fn datetime(self, val: i64, opts: Opt) -> Result { match self { Self::Years => Ok(DateTime::new( (val + 1970) .try_into() .map_err(|_| NumpyDateTimeError::Unrepresentable { unit: self, val })?, 1, 1, 0, 0, 0, 0, ) .unwrap()), Self::Months => Ok(DateTime::new( (val / 12 + 1970) .try_into() .map_err(|_| NumpyDateTimeError::Unrepresentable { unit: self, val })?, (val % 12 + 1) .try_into() .map_err(|_| NumpyDateTimeError::Unrepresentable { unit: self, val })?, 1, 0, 0, 0, 0, ) .unwrap()), Self::Weeks => { to_jiff_datetime!(Timestamp::from_second(val * 7 * 24 * 60 * 60), self, val) } Self::Days => to_jiff_datetime!(Timestamp::from_second(val * 24 * 60 * 60), self, val), Self::Hours => to_jiff_datetime!(Timestamp::from_second(val * 60 * 60), self, val), Self::Minutes => to_jiff_datetime!(Timestamp::from_second(val * 60), self, val), Self::Seconds => to_jiff_datetime!(Timestamp::from_second(val), self, val), Self::Milliseconds => to_jiff_datetime!(Timestamp::from_millisecond(val), self, val), Self::Microseconds => to_jiff_datetime!(Timestamp::from_microsecond(val), self, val), Self::Nanoseconds => { to_jiff_datetime!(Timestamp::from_nanosecond(i128::from(val)), self, val) } _ => Err(NumpyDateTimeError::UnsupportedUnit(self)), } .map(|dt| NumpyDatetime64Repr { dt, opts }) } } struct NumpyDatetime64Array<'a> { data: &'a [i64], unit: NumpyDatetimeUnit, opts: Opt, } impl<'a> NumpyDatetime64Array<'a> { fn new(data: &'a [i64], unit: NumpyDatetimeUnit, opts: Opt) -> Self { Self { data, unit, opts } } } impl Serialize for NumpyDatetime64Array<'_> { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(None).unwrap(); for &each in self.data.iter() { let dt = self .unit .datetime(each, self.opts) .map_err(NumpyDateTimeError::into_serde_err)?; seq.serialize_element(&dt).unwrap(); } seq.end() } } #[repr(C)] pub(crate) struct NumpyDatetime64 { ob_refcnt: Py_ssize_t, ob_type: *mut PyTypeObject, value: i64, } macro_rules! forward_inner { ($meth: ident, $ty: ident) => { fn $meth(&self) -> $ty { debug_assert!(self.dt.$meth() >= 0); #[allow(clippy::cast_sign_loss)] let ret = self.dt.$meth() as $ty; // stmt_expr_attributes ret } }; } struct NumpyDatetime64Repr { dt: DateTime, opts: Opt, } impl DateTimeLike for NumpyDatetime64Repr { forward_inner!(year, i32); forward_inner!(month, u8); forward_inner!(day, u8); forward_inner!(hour, u8); forward_inner!(minute, u8); forward_inner!(second, u8); fn nanosecond(&self) -> u32 { debug_assert!(self.dt.subsec_nanosecond() >= 0); #[allow(clippy::cast_sign_loss)] let ret = self.dt.subsec_nanosecond() as u32; // stmt_expr_attributes ret } fn microsecond(&self) -> u32 { self.nanosecond() / 1_000 } fn has_tz(&self) -> bool { false } fn slow_offset(&self) -> Result { unreachable!() } fn offset(&self) -> Result { Ok(Offset::default()) } } impl Serialize for NumpyDatetime64Repr { #[cold] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut buf = SmallFixedBuffer::new(); let _ = self.write_buf(&mut buf, self.opts); serializer.collect_str(str_from_slice!(buf.as_ptr(), buf.len())) } } ijl-orjson-aa8c946/src/serialize/per_type/pybool.rs000066400000000000000000000010641505336676500225210ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use serde::ser::{Serialize, Serializer}; #[repr(transparent)] pub(crate) struct BoolSerializer { ptr: *mut pyo3_ffi::PyObject, } impl BoolSerializer { pub fn new(ptr: *mut pyo3_ffi::PyObject) -> Self { BoolSerializer { ptr: ptr } } } impl Serialize for BoolSerializer { #[inline] fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_bool(unsafe { core::ptr::eq(self.ptr, crate::typeref::TRUE) }) } } ijl-orjson-aa8c946/src/serialize/per_type/pyenum.rs000066400000000000000000000015671505336676500225420ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::serialize::serializer::PyObjectSerializer; use crate::typeref::VALUE_STR; use serde::ser::{Serialize, Serializer}; #[repr(transparent)] pub(crate) struct EnumSerializer<'a> { previous: &'a PyObjectSerializer, } impl<'a> EnumSerializer<'a> { pub fn new(previous: &'a PyObjectSerializer) -> Self { Self { previous: previous } } } impl Serialize for EnumSerializer<'_> { #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let value = ffi!(PyObject_GetAttr(self.previous.ptr, VALUE_STR)); debug_assert!(ffi!(Py_REFCNT(value)) >= 2); let ret = PyObjectSerializer::new(value, self.previous.state, self.previous.default) .serialize(serializer); ffi!(Py_DECREF(value)); ret } } ijl-orjson-aa8c946/src/serialize/per_type/unicode.rs000066400000000000000000000025331505336676500226450ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::serialize::error::SerializeError; use crate::str::{PyStr, PyStrSubclass}; use serde::ser::{Serialize, Serializer}; #[repr(transparent)] pub(crate) struct StrSerializer { ptr: *mut pyo3_ffi::PyObject, } impl StrSerializer { pub fn new(ptr: *mut pyo3_ffi::PyObject) -> Self { StrSerializer { ptr: ptr } } } impl Serialize for StrSerializer { #[inline(always)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { match unsafe { PyStr::from_ptr_unchecked(self.ptr).to_str() } { Some(uni) => serializer.serialize_str(uni), None => err!(SerializeError::InvalidStr), } } } #[repr(transparent)] pub(crate) struct StrSubclassSerializer { ptr: *mut pyo3_ffi::PyObject, } impl StrSubclassSerializer { pub fn new(ptr: *mut pyo3_ffi::PyObject) -> Self { StrSubclassSerializer { ptr: ptr } } } impl Serialize for StrSubclassSerializer { #[inline(never)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { match unsafe { PyStrSubclass::from_ptr_unchecked(self.ptr).to_str() } { Some(uni) => serializer.serialize_str(uni), None => err!(SerializeError::InvalidStr), } } } ijl-orjson-aa8c946/src/serialize/per_type/uuid.rs000066400000000000000000000043451505336676500221700ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::serialize::buffer::SmallFixedBuffer; use crate::typeref::INT_ATTR_STR; use core::ffi::c_uchar; use serde::ser::{Serialize, Serializer}; #[repr(transparent)] pub(crate) struct UUID { ptr: *mut pyo3_ffi::PyObject, } impl UUID { pub fn new(ptr: *mut pyo3_ffi::PyObject) -> Self { UUID { ptr: ptr } } #[inline(never)] pub fn write_buf(&self, buf: &mut B) where B: bytes::BufMut, { let value: u128; { // test_uuid_immutable, test_uuid_int let py_int = ffi!(PyObject_GetAttr(self.ptr, INT_ATTR_STR)); ffi!(Py_DECREF(py_int)); let mut buffer: [c_uchar; 16] = [0; 16]; unsafe { // test_uuid_overflow #[cfg(not(Py_3_13))] crate::ffi::_PyLong_AsByteArray( py_int.cast::(), buffer.as_mut_ptr(), 16, 1, // little_endian 0, // is_signed ); #[cfg(Py_3_13)] crate::ffi::_PyLong_AsByteArray( py_int.cast::(), buffer.as_mut_ptr(), 16, 1, // little_endian 0, // is_signed 0, ); }; value = u128::from_le_bytes(buffer); } unsafe { let buffer_length: usize = 40; debug_assert!(buf.remaining_mut() >= buffer_length); let len = uuid::Uuid::from_u128(value) .hyphenated() .encode_lower(core::slice::from_raw_parts_mut( buf.chunk_mut().as_mut_ptr(), buffer_length, )) .len(); buf.advance_mut(len); } } } impl Serialize for UUID { #[inline(always)] fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut buf = SmallFixedBuffer::new(); self.write_buf(&mut buf); serializer.serialize_unit_struct(str_from_slice!(buf.as_ptr(), buf.len())) } } ijl-orjson-aa8c946/src/serialize/serializer.rs000066400000000000000000000103031505336676500215330ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::opt::{Opt, APPEND_NEWLINE, INDENT_2}; use crate::serialize::obtype::{pyobject_to_obtype, ObType}; use crate::serialize::per_type::{ BoolSerializer, DataclassGenericSerializer, Date, DateTime, DefaultSerializer, DictGenericSerializer, EnumSerializer, FloatSerializer, FragmentSerializer, IntSerializer, ListTupleSerializer, NoneSerializer, NumpyScalar, NumpySerializer, StrSerializer, StrSubclassSerializer, Time, ZeroListSerializer, UUID, }; use crate::serialize::state::SerializerState; use crate::serialize::writer::{to_writer, to_writer_pretty, BytesWriter}; use core::ptr::NonNull; use serde::ser::{Serialize, Serializer}; pub(crate) fn serialize( ptr: *mut pyo3_ffi::PyObject, default: Option>, opts: Opt, ) -> Result, String> { let mut buf = BytesWriter::default(); let obj = PyObjectSerializer::new(ptr, SerializerState::new(opts), default); let res = if opt_disabled!(opts, INDENT_2) { to_writer(&mut buf, &obj) } else { to_writer_pretty(&mut buf, &obj) }; match res { Ok(()) => Ok(buf.finish(opt_enabled!(opts, APPEND_NEWLINE))), Err(err) => { ffi!(Py_DECREF(buf.bytes_ptr().as_ptr())); Err(err.to_string()) } } } pub(crate) struct PyObjectSerializer { pub ptr: *mut pyo3_ffi::PyObject, pub state: SerializerState, pub default: Option>, } impl PyObjectSerializer { pub fn new( ptr: *mut pyo3_ffi::PyObject, state: SerializerState, default: Option>, ) -> Self { PyObjectSerializer { ptr: ptr, state: state, default: default, } } } impl Serialize for PyObjectSerializer { fn serialize(&self, serializer: S) -> Result where S: Serializer, { match pyobject_to_obtype(self.ptr, self.state.opts()) { ObType::Str => StrSerializer::new(self.ptr).serialize(serializer), ObType::StrSubclass => StrSubclassSerializer::new(self.ptr).serialize(serializer), ObType::Int => IntSerializer::new(self.ptr, self.state.opts()).serialize(serializer), ObType::None => NoneSerializer::new().serialize(serializer), ObType::Float => FloatSerializer::new(self.ptr).serialize(serializer), ObType::Bool => BoolSerializer::new(self.ptr).serialize(serializer), ObType::Datetime => DateTime::new(self.ptr, self.state.opts()).serialize(serializer), ObType::Date => Date::new(self.ptr).serialize(serializer), ObType::Time => Time::new(self.ptr, self.state.opts()).serialize(serializer), ObType::Uuid => UUID::new(self.ptr).serialize(serializer), ObType::Dict => { DictGenericSerializer::new(self.ptr, self.state, self.default).serialize(serializer) } ObType::List => { if ffi!(Py_SIZE(self.ptr)) == 0 { ZeroListSerializer::new().serialize(serializer) } else { ListTupleSerializer::from_list(self.ptr, self.state, self.default) .serialize(serializer) } } ObType::Tuple => { if ffi!(Py_SIZE(self.ptr)) == 0 { ZeroListSerializer::new().serialize(serializer) } else { ListTupleSerializer::from_tuple(self.ptr, self.state, self.default) .serialize(serializer) } } ObType::Dataclass => DataclassGenericSerializer::new(self).serialize(serializer), ObType::Enum => EnumSerializer::new(self).serialize(serializer), ObType::NumpyArray => NumpySerializer::new(self).serialize(serializer), ObType::NumpyScalar => { NumpyScalar::new(self.ptr, self.state.opts()).serialize(serializer) } ObType::Fragment => FragmentSerializer::new(self.ptr).serialize(serializer), ObType::Unknown => DefaultSerializer::new(self).serialize(serializer), } } } ijl-orjson-aa8c946/src/serialize/state.rs000066400000000000000000000027141505336676500205110ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::opt::Opt; const RECURSION_SHIFT: usize = 24; const RECURSION_MASK: u32 = 255 << RECURSION_SHIFT; const DEFAULT_SHIFT: usize = 16; const DEFAULT_MASK: u32 = 255 << DEFAULT_SHIFT; #[repr(transparent)] #[derive(Copy, Clone)] pub(crate) struct SerializerState { // recursion: u8, // default_calls: u8, // opts: u16, state: u32, } impl SerializerState { #[inline(always)] pub fn new(opts: Opt) -> Self { debug_assert!(opts < u32::from(u16::MAX)); Self { state: opts } } #[inline(always)] pub fn opts(self) -> u32 { self.state } #[inline(always)] pub fn recursion_limit(self) -> bool { self.state & RECURSION_MASK == RECURSION_MASK } #[inline(always)] pub fn default_calls_limit(self) -> bool { self.state & DEFAULT_MASK == DEFAULT_MASK } #[inline(always)] pub fn copy_for_recursive_call(self) -> Self { let opt = self.state & !RECURSION_MASK; let recursion = (((self.state & RECURSION_MASK) >> RECURSION_SHIFT) + 1) << RECURSION_SHIFT; Self { state: opt | recursion, } } #[inline(always)] pub fn copy_for_default_call(self) -> Self { let opt = self.state & !DEFAULT_MASK; let default_calls = (((self.state & DEFAULT_MASK) >> DEFAULT_SHIFT) + 1) << DEFAULT_SHIFT; Self { state: opt | default_calls, } } } ijl-orjson-aa8c946/src/serialize/writer/000077500000000000000000000000001505336676500203335ustar00rootroot00000000000000ijl-orjson-aa8c946/src/serialize/writer/byteswriter.rs000066400000000000000000000074051505336676500232720ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::util::usize_to_isize; use bytes::{buf::UninitSlice, BufMut}; use core::mem::MaybeUninit; use core::ptr::NonNull; use pyo3_ffi::{PyBytesObject, PyBytes_FromStringAndSize, PyObject, PyVarObject, _PyBytes_Resize}; const BUFFER_LENGTH: usize = 1024; pub(crate) struct BytesWriter { cap: usize, len: usize, bytes: *mut PyBytesObject, } impl BytesWriter { #[inline] pub fn default() -> Self { BytesWriter { cap: BUFFER_LENGTH, len: 0, bytes: unsafe { PyBytes_FromStringAndSize(core::ptr::null_mut(), usize_to_isize(BUFFER_LENGTH)) .cast::() }, } } #[inline] pub fn bytes_ptr(&mut self) -> NonNull { unsafe { NonNull::new_unchecked(self.bytes.cast::()) } } #[inline] pub fn finish(&mut self, append: bool) -> NonNull { unsafe { if append { core::ptr::write(self.buffer_ptr(), b'\n'); self.len += 1; } core::ptr::write(self.buffer_ptr(), 0); crate::ffi::Py_SET_SIZE(self.bytes.cast::(), usize_to_isize(self.len)); self.resize(self.len); self.bytes_ptr() } } #[inline] fn buffer_ptr(&self) -> *mut u8 { unsafe { (&raw mut (*self.bytes).ob_sval).cast::().add(self.len) } } #[inline] pub fn resize(&mut self, len: usize) { self.cap = len; unsafe { _PyBytes_Resize( (&raw mut self.bytes).cast::<*mut PyObject>(), usize_to_isize(len), ); } } #[cold] #[inline(never)] fn grow(&mut self, len: usize) { let mut cap = self.cap; while len >= cap { cap *= 2; } self.resize(cap); } } unsafe impl BufMut for BytesWriter { #[inline] unsafe fn advance_mut(&mut self, cnt: usize) { self.len += cnt; } #[inline] fn chunk_mut(&mut self) -> &mut UninitSlice { unsafe { UninitSlice::uninit(core::slice::from_raw_parts_mut( self.buffer_ptr().cast::>(), self.remaining_mut(), )) } } #[inline] fn remaining_mut(&self) -> usize { self.cap - self.len } #[inline] fn put_u8(&mut self, value: u8) { debug_assert!(self.remaining_mut() > 1); unsafe { core::ptr::write(self.buffer_ptr(), value); self.advance_mut(1); } } #[inline] fn put_bytes(&mut self, val: u8, cnt: usize) { debug_assert!(self.remaining_mut() > cnt); unsafe { core::ptr::write_bytes(self.buffer_ptr(), val, cnt); self.advance_mut(cnt); }; } #[inline] fn put_slice(&mut self, src: &[u8]) { debug_assert!(self.remaining_mut() > src.len()); unsafe { core::ptr::copy_nonoverlapping(src.as_ptr(), self.buffer_ptr(), src.len()); self.advance_mut(src.len()); } } } // hack based on saethlin's research and patch in https://github.com/serde-rs/json/issues/766 pub(crate) trait WriteExt { #[inline] fn as_mut_buffer_ptr(&mut self) -> *mut u8 { core::ptr::null_mut() } #[inline] fn reserve(&mut self, len: usize) { let _ = len; } } impl WriteExt for &mut BytesWriter { #[inline(always)] fn as_mut_buffer_ptr(&mut self) -> *mut u8 { self.buffer_ptr() } #[inline(always)] fn reserve(&mut self, len: usize) { let end_length = self.len + len; if unlikely!(end_length >= self.cap) { self.grow(end_length); } } } ijl-orjson-aa8c946/src/serialize/writer/formatter.rs000066400000000000000000000213371505336676500227120ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) // This is an adaptation of `src/value/ser.rs` from serde-json. use crate::serialize::writer::WriteExt; use std::io; macro_rules! debug_assert_has_capacity { ($writer:expr) => { debug_assert!($writer.remaining_mut() > 4) }; } pub(crate) trait Formatter { #[inline] fn write_null(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_minimum!(writer); writer.put_slice(b"null"); Ok(()) } } #[inline] fn write_bool(&mut self, writer: &mut W, value: bool) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { reserve_minimum!(writer); unsafe { writer.put_slice(if value { b"true" } else { b"false" }); } Ok(()) } #[inline] fn write_i32(&mut self, writer: &mut W, value: i32) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_minimum!(writer); let len = itoap::write_to_ptr(writer.as_mut_buffer_ptr(), value); writer.advance_mut(len); } Ok(()) } #[inline] fn write_i64(&mut self, writer: &mut W, value: i64) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_minimum!(writer); let len = itoap::write_to_ptr(writer.as_mut_buffer_ptr(), value); writer.advance_mut(len); } Ok(()) } #[inline] fn write_u32(&mut self, writer: &mut W, value: u32) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_minimum!(writer); let len = itoap::write_to_ptr(writer.as_mut_buffer_ptr(), value); writer.advance_mut(len); } Ok(()) } #[inline] fn write_u64(&mut self, writer: &mut W, value: u64) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_minimum!(writer); let len = itoap::write_to_ptr(writer.as_mut_buffer_ptr(), value); writer.advance_mut(len); } Ok(()) } #[inline] fn write_f32(&mut self, writer: &mut W, value: f32) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_minimum!(writer); let len = ryu::raw::format32(value, writer.as_mut_buffer_ptr()); writer.advance_mut(len); } Ok(()) } #[inline] fn write_f64(&mut self, writer: &mut W, value: f64) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_minimum!(writer); let len = ryu::raw::format64(value, writer.as_mut_buffer_ptr()); writer.advance_mut(len); } Ok(()) } #[inline] fn begin_array(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { reserve_minimum!(writer); unsafe { writer.put_u8(b'['); } Ok(()) } #[inline] fn end_array(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { debug_assert_has_capacity!(writer); unsafe { writer.put_u8(b']'); } Ok(()) } #[inline] fn begin_array_value(&mut self, writer: &mut W, first: bool) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { debug_assert_has_capacity!(writer); if !first { unsafe { writer.put_u8(b',') } } Ok(()) } #[inline] fn end_array_value(&mut self, _writer: &mut W) -> io::Result<()> where W: ?Sized, { Ok(()) } #[inline] fn begin_object(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { reserve_minimum!(writer); unsafe { writer.put_u8(b'{'); } Ok(()) } #[inline] fn end_object(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { debug_assert_has_capacity!(writer); unsafe { writer.put_u8(b'}'); } Ok(()) } #[inline] fn begin_object_key(&mut self, writer: &mut W, first: bool) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { debug_assert_has_capacity!(writer); if !first { unsafe { writer.put_u8(b','); } } Ok(()) } #[inline] fn end_object_key(&mut self, _writer: &mut W) -> io::Result<()> where W: ?Sized, { Ok(()) } #[inline] fn begin_object_value(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { debug_assert_has_capacity!(writer); unsafe { writer.put_u8(b':'); } Ok(()) } #[inline] fn end_object_value(&mut self, _writer: &mut W) -> io::Result<()> where W: ?Sized, { Ok(()) } } pub(crate) struct CompactFormatter; impl Formatter for CompactFormatter {} pub(crate) struct PrettyFormatter { current_indent: usize, has_value: bool, } impl PrettyFormatter { #[allow(clippy::new_without_default)] pub const fn new() -> Self { PrettyFormatter { current_indent: 0, has_value: false, } } } impl Formatter for PrettyFormatter { #[inline] fn begin_array(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { self.current_indent += 1; self.has_value = false; reserve_minimum!(writer); unsafe { writer.put_u8(b'['); } Ok(()) } #[inline] fn end_array(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { self.current_indent -= 1; let num_spaces = self.current_indent * 2; reserve_pretty!(writer, num_spaces); unsafe { if self.has_value { writer.put_u8(b'\n'); writer.put_bytes(b' ', num_spaces); } writer.put_u8(b']'); Ok(()) } } #[inline] fn begin_array_value(&mut self, writer: &mut W, first: bool) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { let num_spaces = self.current_indent * 2; reserve_pretty!(writer, num_spaces); unsafe { writer.put_slice(if first { b"\n" } else { b",\n" }); writer.put_bytes(b' ', num_spaces); }; Ok(()) } #[inline] fn end_array_value(&mut self, _writer: &mut W) -> io::Result<()> where W: ?Sized, { self.has_value = true; Ok(()) } #[inline] fn begin_object(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { self.current_indent += 1; self.has_value = false; reserve_minimum!(writer); unsafe { writer.put_u8(b'{'); } Ok(()) } #[inline] fn end_object(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { self.current_indent -= 1; let num_spaces = self.current_indent * 2; reserve_pretty!(writer, num_spaces); unsafe { if self.has_value { writer.put_u8(b'\n'); writer.put_bytes(b' ', num_spaces); } writer.put_u8(b'}'); Ok(()) } } #[inline] fn begin_object_key(&mut self, writer: &mut W, first: bool) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { let num_spaces = self.current_indent * 2; reserve_pretty!(writer, num_spaces); unsafe { writer.put_slice(if first { b"\n" } else { b",\n" }); writer.put_bytes(b' ', num_spaces); } Ok(()) } #[inline] fn begin_object_value(&mut self, writer: &mut W) -> io::Result<()> where W: ?Sized + WriteExt + bytes::BufMut, { reserve_minimum!(writer); unsafe { writer.put_slice(b": "); } Ok(()) } #[inline] fn end_object_value(&mut self, _writer: &mut W) -> io::Result<()> where W: ?Sized, { self.has_value = true; Ok(()) } } ijl-orjson-aa8c946/src/serialize/writer/json.rs000066400000000000000000000402151505336676500216540ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) // This is an adaptation of `src/value/ser.rs` from serde-json. use crate::serialize::writer::formatter::{CompactFormatter, Formatter, PrettyFormatter}; use crate::serialize::writer::WriteExt; use serde::ser::{self, Impossible, Serialize}; use serde_json::error::{Error, Result}; pub(crate) struct Serializer { writer: W, formatter: F, } impl Serializer where W: WriteExt + bytes::BufMut, { #[inline] pub fn new(writer: W) -> Self { Serializer::with_formatter(writer, CompactFormatter) } } impl Serializer where W: WriteExt + bytes::BufMut, { #[inline] pub fn pretty(writer: W) -> Self { Serializer::with_formatter(writer, PrettyFormatter::new()) } } impl Serializer where W: WriteExt + bytes::BufMut, F: Formatter, { #[inline] pub fn with_formatter(writer: W, formatter: F) -> Self { Serializer { writer, formatter } } } impl<'a, W, F> ser::Serializer for &'a mut Serializer where W: WriteExt + bytes::BufMut, F: Formatter, { type Ok = (); type Error = Error; type SerializeSeq = Compound<'a, W, F>; type SerializeTuple = Impossible<(), Error>; type SerializeTupleStruct = Impossible<(), Error>; type SerializeTupleVariant = Impossible<(), Error>; type SerializeMap = Compound<'a, W, F>; type SerializeStruct = Impossible<(), Error>; type SerializeStructVariant = Impossible<(), Error>; #[inline] fn serialize_bool(self, value: bool) -> Result<()> { self.formatter .write_bool(&mut self.writer, value) .map_err(Error::io) } fn serialize_i8(self, _value: i8) -> Result<()> { unreachable!(); } fn serialize_i16(self, _value: i16) -> Result<()> { unreachable!(); } #[inline] fn serialize_i32(self, value: i32) -> Result<()> { self.formatter .write_i32(&mut self.writer, value) .map_err(Error::io) } #[inline] fn serialize_i64(self, value: i64) -> Result<()> { self.formatter .write_i64(&mut self.writer, value) .map_err(Error::io) } fn serialize_i128(self, _value: i128) -> Result<()> { unreachable!(); } fn serialize_u8(self, _value: u8) -> Result<()> { unreachable!(); } fn serialize_u16(self, _value: u16) -> Result<()> { unreachable!(); } #[inline] fn serialize_u32(self, value: u32) -> Result<()> { self.formatter .write_u32(&mut self.writer, value) .map_err(Error::io) } #[inline] fn serialize_u64(self, value: u64) -> Result<()> { self.formatter .write_u64(&mut self.writer, value) .map_err(Error::io) } fn serialize_u128(self, _value: u128) -> Result<()> { unreachable!(); } #[inline] fn serialize_f32(self, value: f32) -> Result<()> { if unlikely!(value.is_infinite() || value.is_nan()) { self.serialize_unit() } else { self.formatter .write_f32(&mut self.writer, value) .map_err(Error::io) } } #[inline] fn serialize_f64(self, value: f64) -> Result<()> { if unlikely!(value.is_infinite() || value.is_nan()) { self.serialize_unit() } else { self.formatter .write_f64(&mut self.writer, value) .map_err(Error::io) } } fn serialize_char(self, _value: char) -> Result<()> { unreachable!(); } #[inline(always)] fn serialize_str(self, value: &str) -> Result<()> { format_escaped_str(&mut self.writer, value); Ok(()) } #[inline(always)] fn serialize_bytes(self, value: &[u8]) -> Result<()> { self.writer.reserve(value.len() + 32); unsafe { self.writer.put_slice(value); } Ok(()) } #[inline] fn serialize_unit(self) -> Result<()> { self.formatter .write_null(&mut self.writer) .map_err(Error::io) } #[inline(always)] fn serialize_unit_struct(self, name: &'static str) -> Result<()> { debug_assert!(name.len() <= 36); reserve_minimum!(self.writer); unsafe { self.writer.put_u8(b'"'); self.writer.put_slice(name.as_bytes()); self.writer.put_u8(b'"'); } Ok(()) } fn serialize_unit_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, ) -> Result<()> { unreachable!(); } fn serialize_newtype_struct(self, _name: &'static str, _value: &T) -> Result<()> where T: ?Sized + Serialize, { unreachable!(); } fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _value: &T, ) -> Result<()> where T: ?Sized + Serialize, { unreachable!(); } #[inline] fn serialize_none(self) -> Result<()> { self.serialize_unit() } #[inline] fn serialize_some(self, value: &T) -> Result<()> where T: ?Sized + Serialize, { value.serialize(self) } #[inline(always)] fn serialize_seq(self, _len: Option) -> Result { self.formatter .begin_array(&mut self.writer) .map_err(Error::io)?; Ok(Compound { ser: self, state: State::First, }) } fn serialize_tuple(self, _len: usize) -> Result { unreachable!(); } fn serialize_tuple_struct( self, _name: &'static str, _len: usize, ) -> Result { unreachable!(); } fn serialize_tuple_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize, ) -> Result { unreachable!(); } #[inline(always)] fn serialize_map(self, _len: Option) -> Result { self.formatter .begin_object(&mut self.writer) .map_err(Error::io)?; Ok(Compound { ser: self, state: State::First, }) } fn serialize_struct(self, _name: &'static str, _len: usize) -> Result { unreachable!(); } fn serialize_struct_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize, ) -> Result { unreachable!(); } } #[derive(Eq, PartialEq)] pub(crate) enum State { First, Rest, } pub(crate) struct Compound<'a, W: 'a, F: 'a> { ser: &'a mut Serializer, state: State, } impl ser::SerializeSeq for Compound<'_, W, F> where W: WriteExt + bytes::BufMut, F: Formatter, { type Ok = (); type Error = Error; #[inline] fn serialize_element(&mut self, value: &T) -> Result<()> where T: ?Sized + Serialize, { self.ser .formatter .begin_array_value(&mut self.ser.writer, self.state == State::First) .unwrap(); self.state = State::Rest; value.serialize(&mut *self.ser)?; self.ser .formatter .end_array_value(&mut self.ser.writer) .map_err(Error::io) .unwrap(); Ok(()) } #[inline] fn end(self) -> Result<()> { self.ser.formatter.end_array(&mut self.ser.writer).unwrap(); Ok(()) } } impl ser::SerializeMap for Compound<'_, W, F> where W: WriteExt + bytes::BufMut, F: Formatter, { type Ok = (); type Error = Error; fn serialize_entry(&mut self, _key: &K, _value: &V) -> Result<()> where K: ?Sized + Serialize, V: ?Sized + Serialize, { unreachable!() } #[inline] fn serialize_key(&mut self, key: &T) -> Result<()> where T: ?Sized + Serialize, { self.ser .formatter .begin_object_key(&mut self.ser.writer, self.state == State::First) .unwrap(); self.state = State::Rest; key.serialize(MapKeySerializer { ser: self.ser })?; self.ser .formatter .end_object_key(&mut self.ser.writer) .unwrap(); Ok(()) } #[inline] fn serialize_value(&mut self, value: &T) -> Result<()> where T: ?Sized + Serialize, { self.ser .formatter .begin_object_value(&mut self.ser.writer) .unwrap(); value.serialize(&mut *self.ser)?; self.ser .formatter .end_object_value(&mut self.ser.writer) .unwrap(); Ok(()) } #[inline] fn end(self) -> Result<()> { self.ser.formatter.end_object(&mut self.ser.writer).unwrap(); Ok(()) } } #[repr(transparent)] struct MapKeySerializer<'a, W: 'a, F: 'a> { ser: &'a mut Serializer, } impl ser::Serializer for MapKeySerializer<'_, W, F> where W: WriteExt + bytes::BufMut, F: Formatter, { type Ok = (); type Error = Error; type SerializeSeq = Impossible<(), Error>; type SerializeTuple = Impossible<(), Error>; type SerializeTupleStruct = Impossible<(), Error>; type SerializeTupleVariant = Impossible<(), Error>; type SerializeMap = Impossible<(), Error>; type SerializeStruct = Impossible<(), Error>; type SerializeStructVariant = Impossible<(), Error>; #[inline(always)] fn serialize_str(self, value: &str) -> Result<()> { self.ser.serialize_str(value) } fn serialize_unit_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, ) -> Result<()> { unreachable!(); } fn serialize_newtype_struct(self, _name: &'static str, _value: &T) -> Result<()> where T: ?Sized + Serialize, { unreachable!(); } fn serialize_bool(self, _value: bool) -> Result<()> { unreachable!(); } fn serialize_i8(self, _value: i8) -> Result<()> { unreachable!(); } fn serialize_i16(self, _value: i16) -> Result<()> { unreachable!(); } fn serialize_i32(self, _value: i32) -> Result<()> { unreachable!(); } fn serialize_i64(self, _value: i64) -> Result<()> { unreachable!(); } fn serialize_i128(self, _value: i128) -> Result<()> { unreachable!(); } fn serialize_u8(self, _value: u8) -> Result<()> { unreachable!(); } fn serialize_u16(self, _value: u16) -> Result<()> { unreachable!(); } fn serialize_u32(self, _value: u32) -> Result<()> { unreachable!(); } fn serialize_u64(self, _value: u64) -> Result<()> { unreachable!(); } fn serialize_u128(self, _value: u128) -> Result<()> { unreachable!(); } fn serialize_f32(self, _value: f32) -> Result<()> { unreachable!(); } fn serialize_f64(self, _value: f64) -> Result<()> { unreachable!(); } fn serialize_char(self, _value: char) -> Result<()> { unreachable!(); } fn serialize_bytes(self, _value: &[u8]) -> Result<()> { unreachable!(); } fn serialize_unit(self) -> Result<()> { unreachable!(); } fn serialize_unit_struct(self, _name: &'static str) -> Result<()> { unreachable!(); } fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _value: &T, ) -> Result<()> where T: ?Sized + Serialize, { unreachable!(); } fn serialize_none(self) -> Result<()> { unreachable!(); } fn serialize_some(self, _value: &T) -> Result<()> where T: ?Sized + Serialize, { unreachable!(); } fn serialize_seq(self, _len: Option) -> Result { unreachable!(); } fn serialize_tuple(self, _len: usize) -> Result { unreachable!(); } fn serialize_tuple_struct( self, _name: &'static str, _len: usize, ) -> Result { unreachable!(); } fn serialize_tuple_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize, ) -> Result { unreachable!(); } fn serialize_map(self, _len: Option) -> Result { unreachable!(); } fn serialize_struct(self, _name: &'static str, _len: usize) -> Result { unreachable!(); } fn serialize_struct_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize, ) -> Result { unreachable!(); } } macro_rules! reserve_str { ($writer:expr, $value:expr) => { $writer.reserve($value.len() * 8 + 32); }; } #[cfg(all(target_arch = "x86_64", feature = "avx512"))] type StrFormatter = unsafe fn(*mut u8, *const u8, usize) -> usize; #[cfg(all(target_arch = "x86_64", feature = "avx512"))] static mut STR_FORMATTER_FN: StrFormatter = crate::serialize::writer::str::format_escaped_str_impl_sse2_128; pub(crate) fn set_str_formatter_fn() { unsafe { #[cfg(all(target_arch = "x86_64", feature = "avx512"))] if std::is_x86_feature_detected!("avx512vl") { STR_FORMATTER_FN = crate::serialize::writer::str::format_escaped_str_impl_512vl; } } } #[cfg(all(target_arch = "x86_64", not(feature = "avx512")))] #[inline(always)] fn format_escaped_str(writer: &mut W, value: &str) where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_str!(writer, value); let written = crate::serialize::writer::str::format_escaped_str_impl_sse2_128( writer.as_mut_buffer_ptr(), value.as_bytes().as_ptr(), value.len(), ); writer.advance_mut(written); } } #[cfg(all(target_arch = "x86_64", feature = "avx512"))] #[inline(always)] fn format_escaped_str(writer: &mut W, value: &str) where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_str!(writer, value); let written = STR_FORMATTER_FN( writer.as_mut_buffer_ptr(), value.as_bytes().as_ptr(), value.len(), ); writer.advance_mut(written); } } #[cfg(all( not(target_arch = "x86_64"), not(feature = "avx512"), feature = "generic_simd" ))] #[inline(always)] fn format_escaped_str(writer: &mut W, value: &str) where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_str!(writer, value); let written = crate::serialize::writer::str::format_escaped_str_impl_generic_128( writer.as_mut_buffer_ptr(), value.as_bytes().as_ptr(), value.len(), ); writer.advance_mut(written); } } #[cfg(all(not(target_arch = "x86_64"), not(feature = "generic_simd")))] #[inline(always)] fn format_escaped_str(writer: &mut W, value: &str) where W: ?Sized + WriteExt + bytes::BufMut, { unsafe { reserve_str!(writer, value); let written = crate::serialize::writer::str::format_escaped_str_scalar( writer.as_mut_buffer_ptr(), value.as_bytes().as_ptr(), value.len(), ); writer.advance_mut(written); } } #[inline] pub(crate) fn to_writer(writer: W, value: &T) -> Result<()> where W: WriteExt + bytes::BufMut, T: ?Sized + Serialize, { let mut ser = Serializer::new(writer); value.serialize(&mut ser) } #[inline] pub(crate) fn to_writer_pretty(writer: W, value: &T) -> Result<()> where W: WriteExt + bytes::BufMut, T: ?Sized + Serialize, { let mut ser = Serializer::pretty(writer); value.serialize(&mut ser) } ijl-orjson-aa8c946/src/serialize/writer/mod.rs000066400000000000000000000003441505336676500214610ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) mod byteswriter; mod formatter; mod json; mod str; pub(crate) use byteswriter::{BytesWriter, WriteExt}; pub(crate) use json::{set_str_formatter_fn, to_writer, to_writer_pretty}; ijl-orjson-aa8c946/src/serialize/writer/str/000077500000000000000000000000001505336676500211435ustar00rootroot00000000000000ijl-orjson-aa8c946/src/serialize/writer/str/avx512.rs000066400000000000000000000042721505336676500225440ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use core::arch::x86_64::{ _mm256_cmpeq_epu8_mask, _mm256_cmplt_epu8_mask, _mm256_loadu_epi8, _mm256_maskz_loadu_epi8, _mm256_set1_epi8, _mm256_storeu_epi8, }; #[inline(never)] #[target_feature(enable = "avx512f,avx512bw,avx512vl,bmi2")] pub(crate) unsafe fn format_escaped_str_impl_512vl( odst: *mut u8, value_ptr: *const u8, value_len: usize, ) -> usize { const STRIDE: usize = 32; let mut dst = odst; let mut src = value_ptr; let mut nb: usize = value_len; let blash = _mm256_set1_epi8(0b01011100i8); let quote = _mm256_set1_epi8(0b00100010i8); let x20 = _mm256_set1_epi8(0b00100000i8); core::ptr::write(dst, b'"'); dst = dst.add(1); while nb >= STRIDE { let str_vec = _mm256_loadu_epi8(src.cast::()); _mm256_storeu_epi8(dst.cast::(), str_vec); let mask = _mm256_cmpeq_epu8_mask(str_vec, blash) | _mm256_cmpeq_epu8_mask(str_vec, quote) | _mm256_cmplt_epu8_mask(str_vec, x20); if mask != 0 { let cn = trailing_zeros!(mask); src = src.add(cn); dst = dst.add(cn); nb -= cn; nb -= 1; write_escape!(*(src), dst); src = src.add(1); } else { nb -= STRIDE; dst = dst.add(STRIDE); src = src.add(STRIDE); } } loop { let remainder_mask = !(u32::MAX << nb); let str_vec = _mm256_maskz_loadu_epi8(remainder_mask, src.cast::()); _mm256_storeu_epi8(dst.cast::(), str_vec); let mask = (_mm256_cmpeq_epu8_mask(str_vec, blash) | _mm256_cmpeq_epu8_mask(str_vec, quote) | _mm256_cmplt_epu8_mask(str_vec, x20)) & remainder_mask; if mask != 0 { let cn = trailing_zeros!(mask); src = src.add(cn); dst = dst.add(cn); nb -= cn; nb -= 1; write_escape!(*(src), dst); src = src.add(1); } else { dst = dst.add(nb); break; } } core::ptr::write(dst, b'"'); dst = dst.add(1); dst as usize - odst as usize } ijl-orjson-aa8c946/src/serialize/writer/str/escape.rs000066400000000000000000000101051505336676500227460ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) // the constants and SIMD approach are adapted from cloudwego's sonic-rs #[cfg(feature = "inline_int")] macro_rules! write_escape { ($byte:expr, $dst:expr) => { debug_assert!($byte < 96); let escape = u64::from_ne_bytes( *crate::serialize::writer::str::escape::QUOTE_TAB.get_unchecked($byte as usize), ); core::ptr::write($dst.cast::(), escape); $dst = $dst.add((escape as usize) >> 56); }; } #[cfg(not(feature = "inline_int"))] macro_rules! write_escape { ($byte:expr, $dst:expr) => { debug_assert!($byte < 96); let escape = crate::serialize::writer::str::escape::QUOTE_TAB.get_unchecked($byte as usize); core::ptr::copy_nonoverlapping(escape.as_ptr(), $dst, 8); $dst = $dst.add(((*escape.as_ptr().add(7)) as usize)); }; } pub(crate) const NEED_ESCAPED: [u8; 256] = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; pub(crate) const QUOTE_TAB: [[u8; 8]; 96] = [ [b'\\', b'u', b'0', b'0', b'0', b'0', 0, 6], [b'\\', b'u', b'0', b'0', b'0', b'1', 0, 6], [b'\\', b'u', b'0', b'0', b'0', b'2', 0, 6], [b'\\', b'u', b'0', b'0', b'0', b'3', 0, 6], [b'\\', b'u', b'0', b'0', b'0', b'4', 0, 6], [b'\\', b'u', b'0', b'0', b'0', b'5', 0, 6], [b'\\', b'u', b'0', b'0', b'0', b'6', 0, 6], [b'\\', b'u', b'0', b'0', b'0', b'7', 0, 6], [b'\\', b'b', b'0', b'0', b'0', b'0', 0, 2], [b'\\', b't', b'0', b'0', b'0', b'0', 0, 2], [b'\\', b'n', b'0', b'0', b'0', b'0', 0, 2], [b'\\', b'u', b'0', b'0', b'0', b'b', 0, 6], [b'\\', b'f', b'0', b'0', b'0', b'0', 0, 2], [b'\\', b'r', b'0', b'0', b'0', b'0', 0, 2], [b'\\', b'u', b'0', b'0', b'0', b'e', 0, 6], [b'\\', b'u', b'0', b'0', b'0', b'f', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'0', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'1', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'2', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'3', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'4', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'5', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'6', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'7', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'8', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'9', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'a', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'b', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'c', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'd', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'e', 0, 6], [b'\\', b'u', b'0', b'0', b'1', b'f', 0, 6], [0; 8], [0; 8], [b'\\', b'"', 0, 0, 0, 0, 0, 2], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [0; 8], [b'\\', b'\\', 0, 0, 0, 0, 0, 2], [0; 8], [0; 8], [0; 8], ]; ijl-orjson-aa8c946/src/serialize/writer/str/generic.rs000066400000000000000000000060541505336676500231320ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use core::simd::cmp::{SimdPartialEq, SimdPartialOrd}; use core::simd::u8x16; #[inline(never)] #[cfg_attr(target_arch = "aarch64", target_feature(enable = "neon"))] pub(crate) unsafe fn format_escaped_str_impl_generic_128( odst: *mut u8, value_ptr: *const u8, value_len: usize, ) -> usize { const STRIDE: usize = 16; let mut dst = odst; let mut src = value_ptr; core::ptr::write(dst, b'"'); dst = dst.add(1); if value_len < STRIDE { impl_format_scalar!(dst, src, value_len); } else { let blash = u8x16::splat(b'\\'); let quote = u8x16::splat(b'"'); let x20 = u8x16::splat(32); let last_stride_src = src.add(value_len).sub(STRIDE); let mut nb: usize = value_len; unsafe { { while nb >= STRIDE { let v = u8x16::from_slice(core::slice::from_raw_parts(src, STRIDE)); let mask = (v.simd_eq(blash) | v.simd_eq(quote) | v.simd_lt(x20)).to_bitmask() as u32; v.copy_to_slice(core::slice::from_raw_parts_mut(dst, STRIDE)); if mask != 0 { let cn = trailing_zeros!(mask) as usize; nb -= cn; dst = dst.add(cn); src = src.add(cn); nb -= 1; write_escape!(*(src), dst); src = src.add(1); } else { nb -= STRIDE; dst = dst.add(STRIDE); src = src.add(STRIDE); } } } let mut scratch: [u8; 32] = [b'a'; 32]; let mut v = u8x16::from_slice(core::slice::from_raw_parts(last_stride_src, STRIDE)); v.copy_to_slice(core::slice::from_raw_parts_mut( scratch.as_mut_ptr(), STRIDE, )); let mut scratch_ptr = scratch.as_mut_ptr().add(16 - nb); v = u8x16::from_slice(core::slice::from_raw_parts(scratch_ptr, STRIDE)); let mut mask = (v.simd_eq(blash) | v.simd_eq(quote) | v.simd_lt(x20)).to_bitmask() as u32; loop { v.copy_to_slice(core::slice::from_raw_parts_mut(dst, STRIDE)); if mask != 0 { let cn = trailing_zeros!(mask) as usize; nb -= cn; dst = dst.add(cn); scratch_ptr = scratch_ptr.add(cn); nb -= 1; mask >>= cn + 1; write_escape!(*(scratch_ptr), dst); scratch_ptr = scratch_ptr.add(1); v = u8x16::from_slice(core::slice::from_raw_parts(scratch_ptr, STRIDE)); } else { dst = dst.add(nb); break; } } } } core::ptr::write(dst, b'"'); dst = dst.add(1); dst as usize - odst as usize } ijl-orjson-aa8c946/src/serialize/writer/str/mod.rs000066400000000000000000000013651505336676500222750ustar00rootroot00000000000000// SPDX-License-Identifier: Apache-2.0 #[macro_use] mod escape; #[macro_use] mod scalar; #[cfg(all(feature = "generic_simd", not(target_arch = "x86_64")))] mod generic; #[cfg(target_arch = "x86_64")] mod sse2; #[cfg(all(target_arch = "x86_64", feature = "avx512"))] mod avx512; #[cfg(all(not(target_arch = "x86_64"), not(feature = "generic_simd")))] pub(crate) use scalar::format_escaped_str_scalar; #[cfg(all(target_arch = "x86_64", feature = "avx512"))] pub(crate) use avx512::format_escaped_str_impl_512vl; #[allow(unused_imports)] #[cfg(target_arch = "x86_64")] pub(crate) use sse2::format_escaped_str_impl_sse2_128; #[cfg(all(feature = "generic_simd", not(target_arch = "x86_64")))] pub(crate) use generic::format_escaped_str_impl_generic_128; ijl-orjson-aa8c946/src/serialize/writer/str/scalar.rs000066400000000000000000000017671505336676500227710ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) macro_rules! impl_format_scalar { ($dst:expr, $src:expr, $value_len:expr) => { unsafe { for _ in 0..$value_len { core::ptr::write($dst, *($src)); $src = $src.add(1); $dst = $dst.add(1); if *super::escape::NEED_ESCAPED.get_unchecked(*($src.sub(1)) as usize) != 0 { $dst = $dst.sub(1); write_escape!(*($src.sub(1)), $dst); } } } }; } #[inline(never)] #[cfg(all(not(target_arch = "x86_64"), not(feature = "generic_simd")))] pub(crate) unsafe fn format_escaped_str_scalar( odst: *mut u8, value_ptr: *const u8, value_len: usize, ) -> usize { let mut dst = odst; let mut src = value_ptr; core::ptr::write(dst, b'"'); dst = dst.add(1); impl_format_scalar!(dst, src, value_len); core::ptr::write(dst, b'"'); dst = dst.add(1); dst as usize - odst as usize } ijl-orjson-aa8c946/src/serialize/writer/str/sse2.rs000066400000000000000000000071551505336676500223750ustar00rootroot00000000000000// SPDX-License-Identifier: Apache-2.0 use core::arch::x86_64::{ __m128i, _mm_cmpeq_epi8, _mm_loadu_si128, _mm_movemask_epi8, _mm_or_si128, _mm_set1_epi8, _mm_setzero_si128, _mm_storeu_si128, _mm_subs_epu8, }; #[allow(dead_code)] #[expect(clippy::cast_ptr_alignment)] #[inline(never)] pub(crate) unsafe fn format_escaped_str_impl_sse2_128( odst: *mut u8, value_ptr: *const u8, value_len: usize, ) -> usize { unsafe { const STRIDE: usize = 16; let mut dst = odst; let mut src = value_ptr; core::ptr::write(dst, b'"'); dst = dst.add(1); if value_len < STRIDE { impl_format_scalar!(dst, src, value_len); } else { let blash = _mm_set1_epi8(0b01011100i8); let quote = _mm_set1_epi8(0b00100010i8); let x20 = _mm_set1_epi8(0b00011111i8); let v0 = _mm_setzero_si128(); let last_stride_src = src.add(value_len).sub(STRIDE); let mut nb: usize = value_len; unsafe { while nb >= STRIDE { let str_vec = _mm_loadu_si128(src.cast::<__m128i>()); let mask = _mm_movemask_epi8(_mm_or_si128( _mm_or_si128( _mm_cmpeq_epi8(str_vec, blash), _mm_cmpeq_epi8(str_vec, quote), ), _mm_cmpeq_epi8(_mm_subs_epu8(str_vec, x20), v0), )); _mm_storeu_si128(dst.cast::<__m128i>(), str_vec); if mask != 0 { let cn = trailing_zeros!(mask) as usize; nb -= cn; dst = dst.add(cn); src = src.add(cn); nb -= 1; write_escape!(*(src), dst); src = src.add(1); } else { nb -= STRIDE; dst = dst.add(STRIDE); src = src.add(STRIDE); } } let mut scratch: [u8; 32] = [b'a'; 32]; let mut str_vec = _mm_loadu_si128(last_stride_src.cast::<__m128i>()); _mm_storeu_si128(scratch.as_mut_ptr().cast::<__m128i>(), str_vec); let mut scratch_ptr = scratch.as_mut_ptr().add(16 - nb); str_vec = _mm_loadu_si128(scratch_ptr as *const __m128i); let mut mask = _mm_movemask_epi8(_mm_or_si128( _mm_or_si128( _mm_cmpeq_epi8(str_vec, blash), _mm_cmpeq_epi8(str_vec, quote), ), _mm_cmpeq_epi8(_mm_subs_epu8(str_vec, x20), v0), )); loop { _mm_storeu_si128(dst.cast::<__m128i>(), str_vec); if mask != 0 { let cn = trailing_zeros!(mask) as usize; nb -= cn; dst = dst.add(cn); scratch_ptr = scratch_ptr.add(cn); nb -= 1; mask >>= cn + 1; write_escape!(*(scratch_ptr), dst); scratch_ptr = scratch_ptr.add(1); str_vec = _mm_loadu_si128(scratch_ptr as *const __m128i); } else { dst = dst.add(nb); break; } } } } core::ptr::write(dst, b'"'); dst = dst.add(1); dst as usize - odst as usize } } ijl-orjson-aa8c946/src/str/000077500000000000000000000000001505336676500156405ustar00rootroot00000000000000ijl-orjson-aa8c946/src/str/avx512.rs000066400000000000000000000045061505336676500172410ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::str::pyunicode_new::*; use core::arch::x86_64::{ _mm512_and_si512, _mm512_cmpgt_epu8_mask, _mm512_cmpneq_epi8_mask, _mm512_loadu_epi8, _mm512_mask_cmpneq_epi8_mask, _mm512_maskz_loadu_epi8, _mm512_max_epu8, _mm512_set1_epi8, }; #[inline(never)] #[target_feature(enable = "avx512f,avx512bw,avx512vl,bmi2")] pub(crate) unsafe fn create_str_impl_avx512vl(buf: &str) -> *mut pyo3_ffi::PyObject { const STRIDE: usize = 64; let buf_ptr = buf.as_bytes().as_ptr().cast::(); let buf_len = buf.len(); assume!(buf_len > 0); let num_loops = buf_len / STRIDE; let remainder = buf_len % STRIDE; let remainder_mask: u64 = !(u64::MAX << remainder); let mut str_vec = _mm512_maskz_loadu_epi8(remainder_mask, buf_ptr); let sptr = buf_ptr.add(remainder); for i in 0..num_loops { str_vec = _mm512_max_epu8( str_vec, _mm512_loadu_epi8(sptr.add(STRIDE * i).cast::()), ); } #[allow(overflowing_literals)] let vec_128 = _mm512_set1_epi8(0b10000000i8); if _mm512_cmpgt_epu8_mask(str_vec, vec_128) == 0 { pyunicode_ascii(buf.as_bytes().as_ptr(), buf_len) } else { #[allow(overflowing_literals)] let is_four = _mm512_cmpgt_epu8_mask(str_vec, _mm512_set1_epi8(239i8)) != 0; #[allow(overflowing_literals)] let is_not_latin = _mm512_cmpgt_epu8_mask(str_vec, _mm512_set1_epi8(195i8)) != 0; #[allow(overflowing_literals)] let multibyte = _mm512_set1_epi8(0b11000000i8); let mut num_chars = _mm512_mask_cmpneq_epi8_mask( remainder_mask, _mm512_and_si512(_mm512_maskz_loadu_epi8(remainder_mask, buf_ptr), multibyte), vec_128, ) .count_ones() as usize; for i in 0..num_loops { num_chars += _mm512_cmpneq_epi8_mask( _mm512_and_si512( _mm512_loadu_epi8(sptr.add(STRIDE * i).cast::()), multibyte, ), vec_128, ) .count_ones() as usize; } if is_four { pyunicode_fourbyte(buf, num_chars) } else if is_not_latin { pyunicode_twobyte(buf, num_chars) } else { pyunicode_onebyte(buf, num_chars) } } } ijl-orjson-aa8c946/src/str/mod.rs000066400000000000000000000003041505336676500167620ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) #[cfg(feature = "avx512")] mod avx512; mod pystr; mod pyunicode_new; mod scalar; pub(crate) use pystr::{set_str_create_fn, PyStr, PyStrSubclass}; ijl-orjson-aa8c946/src/str/pystr.rs000066400000000000000000000142011505336676500173650ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::typeref::{EMPTY_UNICODE, STR_TYPE}; #[cfg(target_endian = "little")] use crate::util::isize_to_usize; #[cfg(target_endian = "little")] use core::ffi::c_void; use core::ptr::NonNull; #[cfg(target_endian = "little")] use pyo3_ffi::PyCompactUnicodeObject; use pyo3_ffi::{PyASCIIObject, PyObject}; fn to_str_via_ffi(op: *mut PyObject) -> Option<&'static str> { let mut str_size: pyo3_ffi::Py_ssize_t = 0; let ptr = ffi!(PyUnicode_AsUTF8AndSize(op, &mut str_size)).cast::(); if unlikely!(ptr.is_null()) { None } else { Some(str_from_slice!(ptr, str_size as usize)) } } #[cfg(feature = "avx512")] pub type StrDeserializer = unsafe fn(&str) -> *mut pyo3_ffi::PyObject; #[cfg(feature = "avx512")] static mut STR_CREATE_FN: StrDeserializer = super::scalar::str_impl_kind_scalar; pub fn set_str_create_fn() { unsafe { #[cfg(feature = "avx512")] if std::is_x86_feature_detected!("avx512vl") { STR_CREATE_FN = crate::str::avx512::create_str_impl_avx512vl; } } } #[cfg(all(target_endian = "little", Py_3_14, Py_GIL_DISABLED))] const STATE_KIND_SHIFT: usize = 8; #[cfg(all(target_endian = "little", not(all(Py_3_14, Py_GIL_DISABLED))))] const STATE_KIND_SHIFT: usize = 2; #[cfg(target_endian = "little")] const STATE_KIND_MASK: u32 = 7 << STATE_KIND_SHIFT; #[cfg(target_endian = "little")] const STATE_COMPACT_ASCII: u32 = 1 << STATE_KIND_SHIFT | 1 << (STATE_KIND_SHIFT + 3) | 1 << (STATE_KIND_SHIFT + 4); #[cfg(target_endian = "little")] const STATE_COMPACT: u32 = 1 << (STATE_KIND_SHIFT + 3); #[repr(transparent)] #[derive(Copy, Clone)] pub(crate) struct PyStr { ptr: NonNull, } unsafe impl Send for PyStr {} unsafe impl Sync for PyStr {} impl PyStr { pub unsafe fn from_ptr_unchecked(ptr: *mut PyObject) -> PyStr { debug_assert!(!ptr.is_null()); debug_assert!(is_class_by_type!(ob_type!(ptr), STR_TYPE)); PyStr { ptr: nonnull!(ptr) } } #[inline(always)] pub fn from_str_with_hash(buf: &str) -> PyStr { let mut obj = PyStr::from_str(buf); obj.hash(); obj } #[inline(always)] pub fn from_str(buf: &str) -> PyStr { if unlikely!(buf.is_empty()) { return PyStr { ptr: nonnull!(use_immortal!(EMPTY_UNICODE)), }; } #[cfg(not(feature = "avx512"))] let str_ptr = unsafe { super::scalar::str_impl_kind_scalar(buf) }; #[cfg(feature = "avx512")] let str_ptr = unsafe { STR_CREATE_FN(buf) }; debug_assert!(!str_ptr.is_null()); PyStr { ptr: nonnull!(str_ptr), } } #[cfg(target_endian = "little")] pub fn hash(&mut self) { unsafe { let ptr = self.ptr.as_ptr().cast::(); let data_ptr: *mut c_void = if (*ptr).state & STATE_COMPACT_ASCII == STATE_COMPACT_ASCII { ptr.offset(1).cast::() } else { ptr.cast::() .offset(1) .cast::() }; let num_bytes = (*ptr).length * (((*ptr).state & STATE_KIND_MASK) >> STATE_KIND_SHIFT) as isize; #[cfg(Py_3_14)] let hash = pyo3_ffi::Py_HashBuffer(data_ptr, num_bytes); #[cfg(not(Py_3_14))] let hash = pyo3_ffi::_Py_HashBytes(data_ptr, num_bytes); (*ptr).hash = hash; debug_assert!((*ptr).hash != -1); } } #[cfg(not(target_endian = "little"))] pub fn hash(&mut self) { unsafe { let data_ptr = ffi!(PyUnicode_DATA(self.ptr.as_ptr())); #[allow(clippy::cast_possible_wrap)] let num_bytes = ffi!(PyUnicode_KIND(self.ptr.as_ptr())) as isize * ffi!(Py_SIZE(self.ptr.as_ptr())); #[cfg(Py_3_14)] let hash = pyo3_ffi::Py_HashBuffer(data_ptr, num_bytes); #[cfg(not(Py_3_14))] let hash = pyo3_ffi::_Py_HashBytes(data_ptr, num_bytes); (*self.ptr.as_ptr().cast::()).hash = hash; debug_assert!((*self.ptr.as_ptr().cast::()).hash != -1); } } #[inline(always)] #[cfg(target_endian = "little")] pub fn to_str(self) -> Option<&'static str> { unsafe { let op = self.ptr.as_ptr(); if unlikely!((*op.cast::()).state & STATE_COMPACT == 0) { to_str_via_ffi(op) } else if (*op.cast::()).state & STATE_COMPACT_ASCII == STATE_COMPACT_ASCII { let ptr = op.cast::().offset(1).cast::(); let len = isize_to_usize((*op.cast::()).length); Some(str_from_slice!(ptr, len)) } else if (*op.cast::()).utf8_length > 0 { let ptr = ((*op.cast::()).utf8).cast::(); let len = isize_to_usize((*op.cast::()).utf8_length); Some(str_from_slice!(ptr, len)) } else { to_str_via_ffi(op) } } } #[inline(always)] #[cfg(not(target_endian = "little"))] pub fn to_str(self) -> Option<&'static str> { to_str_via_ffi(self.ptr.as_ptr()) } pub fn as_ptr(self) -> *mut PyObject { self.ptr.as_ptr() } pub fn as_non_null_ptr(self) -> NonNull { self.ptr } } #[repr(transparent)] pub(crate) struct PyStrSubclass { ptr: NonNull, } impl PyStrSubclass { pub unsafe fn from_ptr_unchecked(ptr: *mut PyObject) -> PyStrSubclass { let ob_type = ob_type!(ptr); let tp_flags = tp_flags!(ob_type); debug_assert!(!ptr.is_null()); debug_assert!(!is_class_by_type!(ob_type, STR_TYPE)); debug_assert!(is_subclass_by_flag!(tp_flags, Py_TPFLAGS_UNICODE_SUBCLASS)); PyStrSubclass { ptr: nonnull!(ptr) } } #[inline(always)] pub fn to_str(&self) -> Option<&'static str> { to_str_via_ffi(self.ptr.as_ptr()) } } ijl-orjson-aa8c946/src/str/pyunicode_new.rs000066400000000000000000000045311505336676500210610ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::util::usize_to_isize; use pyo3_ffi::{PyASCIIObject, PyCompactUnicodeObject, PyObject}; macro_rules! validate_str { ($ptr:expr) => { #[cfg(CPython)] debug_assert!(ffi!(_PyUnicode_CheckConsistency($ptr.cast::(), 1)) == 1); }; } #[inline(never)] pub(crate) fn pyunicode_ascii(buf: *const u8, num_chars: usize) -> *mut pyo3_ffi::PyObject { unsafe { let ptr = ffi!(PyUnicode_New(usize_to_isize(num_chars), 127)); let data_ptr = ptr.cast::().offset(1).cast::(); core::ptr::copy_nonoverlapping(buf, data_ptr, num_chars); core::ptr::write(data_ptr.add(num_chars), 0); validate_str!(ptr); ptr.cast::() } } #[cold] #[inline(never)] pub(crate) fn pyunicode_onebyte(buf: &str, num_chars: usize) -> *mut pyo3_ffi::PyObject { unsafe { let ptr = ffi!(PyUnicode_New(usize_to_isize(num_chars), 255)); let mut data_ptr = ptr.cast::().offset(1).cast::(); for each in buf.chars().fuse() { core::ptr::write(data_ptr, each as u8); data_ptr = data_ptr.offset(1); } core::ptr::write(data_ptr, 0); validate_str!(ptr); ptr.cast::() } } #[inline(never)] pub(crate) fn pyunicode_twobyte(buf: &str, num_chars: usize) -> *mut pyo3_ffi::PyObject { unsafe { let ptr = ffi!(PyUnicode_New(usize_to_isize(num_chars), 65535)); let mut data_ptr = ptr.cast::().offset(1).cast::(); for each in buf.chars().fuse() { core::ptr::write(data_ptr, each as u16); data_ptr = data_ptr.offset(1); } core::ptr::write(data_ptr, 0); validate_str!(ptr); ptr.cast::() } } #[inline(never)] pub(crate) fn pyunicode_fourbyte(buf: &str, num_chars: usize) -> *mut pyo3_ffi::PyObject { unsafe { let ptr = ffi!(PyUnicode_New(usize_to_isize(num_chars), 1114111)); let mut data_ptr = ptr.cast::().offset(1).cast::(); for each in buf.chars().fuse() { core::ptr::write(data_ptr, each as u32); data_ptr = data_ptr.offset(1); } core::ptr::write(data_ptr, 0); validate_str!(ptr); ptr.cast::() } } ijl-orjson-aa8c946/src/str/scalar.rs000066400000000000000000000020571505336676500174570ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::str::pyunicode_new::{ pyunicode_ascii, pyunicode_fourbyte, pyunicode_onebyte, pyunicode_twobyte, }; #[inline(never)] pub(crate) unsafe fn str_impl_kind_scalar(buf: &str) -> *mut pyo3_ffi::PyObject { let num_chars = bytecount::num_chars(buf.as_bytes()); if buf.len() == num_chars { return pyunicode_ascii(buf.as_ptr(), num_chars); } unsafe { let len = buf.len(); assume!(len > 0); if unlikely!(*(buf.as_bytes().as_ptr()) > 239) { return pyunicode_fourbyte(buf, num_chars); } let sptr = buf.as_bytes().as_ptr(); let mut is_four = false; let mut not_latin = false; for i in 0..len { is_four |= *sptr.add(i) > 239; not_latin |= *sptr.add(i) > 195; } if is_four { pyunicode_fourbyte(buf, num_chars) } else if not_latin { pyunicode_twobyte(buf, num_chars) } else { pyunicode_onebyte(buf, num_chars) } } } ijl-orjson-aa8c946/src/typeref.rs000066400000000000000000000216001505336676500170530ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) use crate::ffi::orjson_fragmenttype_new; use core::ffi::CStr; use core::ptr::{null_mut, NonNull}; use once_cell::race::{OnceBool, OnceBox}; use pyo3_ffi::*; pub(crate) static mut DEFAULT: *mut PyObject = null_mut(); pub(crate) static mut OPTION: *mut PyObject = null_mut(); pub(crate) static mut NONE: *mut PyObject = null_mut(); pub(crate) static mut TRUE: *mut PyObject = null_mut(); pub(crate) static mut FALSE: *mut PyObject = null_mut(); pub(crate) static mut EMPTY_UNICODE: *mut PyObject = null_mut(); pub(crate) static mut BYTES_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut BYTEARRAY_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut MEMORYVIEW_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut STR_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut INT_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut BOOL_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut NONE_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut FLOAT_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut LIST_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut DICT_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut DATETIME_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut DATE_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut TIME_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut TUPLE_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut UUID_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut ENUM_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut FIELD_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut FRAGMENT_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut ZONEINFO_TYPE: *mut PyTypeObject = null_mut(); pub(crate) static mut UTCOFFSET_METHOD_STR: *mut PyObject = null_mut(); pub(crate) static mut NORMALIZE_METHOD_STR: *mut PyObject = null_mut(); pub(crate) static mut CONVERT_METHOD_STR: *mut PyObject = null_mut(); pub(crate) static mut DST_STR: *mut PyObject = null_mut(); pub(crate) static mut DICT_STR: *mut PyObject = null_mut(); pub(crate) static mut DATACLASS_FIELDS_STR: *mut PyObject = null_mut(); pub(crate) static mut SLOTS_STR: *mut PyObject = null_mut(); pub(crate) static mut FIELD_TYPE_STR: *mut PyObject = null_mut(); pub(crate) static mut ARRAY_STRUCT_STR: *mut PyObject = null_mut(); pub(crate) static mut DTYPE_STR: *mut PyObject = null_mut(); pub(crate) static mut DESCR_STR: *mut PyObject = null_mut(); pub(crate) static mut VALUE_STR: *mut PyObject = null_mut(); pub(crate) static mut INT_ATTR_STR: *mut PyObject = null_mut(); #[allow(non_upper_case_globals)] pub(crate) static mut JsonEncodeError: *mut PyObject = null_mut(); #[allow(non_upper_case_globals)] pub(crate) static mut JsonDecodeError: *mut PyObject = null_mut(); unsafe fn look_up_type_object(module_name: &CStr, member_name: &CStr) -> *mut PyTypeObject { unsafe { let module = PyImport_ImportModule(module_name.as_ptr()); let module_dict = PyObject_GenericGetDict(module, null_mut()); let ptr = PyMapping_GetItemString(module_dict, member_name.as_ptr()).cast::(); Py_DECREF(module_dict); Py_DECREF(module); ptr } } static INIT: OnceBool = OnceBool::new(); pub(crate) fn init_typerefs() { INIT.get_or_init(_init_typerefs_impl); } #[cold] #[cfg_attr(feature = "optimize", optimize(size))] fn _init_typerefs_impl() -> bool { unsafe { debug_assert!(crate::opt::MAX_OPT < i32::from(u16::MAX)); #[cfg(not(Py_GIL_DISABLED))] assert!(crate::deserialize::KEY_MAP .set(crate::deserialize::KeyMap::default()) .is_ok()); crate::serialize::writer::set_str_formatter_fn(); crate::str::set_str_create_fn(); NONE = Py_None(); TRUE = Py_True(); FALSE = Py_False(); EMPTY_UNICODE = PyUnicode_New(0, 255); STR_TYPE = &raw mut PyUnicode_Type; BYTES_TYPE = &raw mut PyBytes_Type; DICT_TYPE = &raw mut PyDict_Type; LIST_TYPE = &raw mut PyList_Type; TUPLE_TYPE = &raw mut PyTuple_Type; NONE_TYPE = (*NONE).ob_type; BOOL_TYPE = &raw mut PyBool_Type; INT_TYPE = &raw mut PyLong_Type; FLOAT_TYPE = &raw mut PyFloat_Type; BYTEARRAY_TYPE = &raw mut PyByteArray_Type; MEMORYVIEW_TYPE = &raw mut PyMemoryView_Type; PyDateTime_IMPORT(); let datetime_capsule = pyo3_ffi::PyCapsule_Import(c"datetime.datetime_CAPI".as_ptr(), 1) .cast::(); DATETIME_TYPE = (*datetime_capsule).DateTimeType; DATE_TYPE = (*datetime_capsule).DateType; TIME_TYPE = (*datetime_capsule).TimeType; ZONEINFO_TYPE = (*datetime_capsule).TZInfoType; UUID_TYPE = look_up_type_object(c"uuid", c"UUID"); ENUM_TYPE = look_up_type_object(c"enum", c"EnumMeta"); FIELD_TYPE = look_up_type_object(c"dataclasses", c"_FIELD"); FRAGMENT_TYPE = orjson_fragmenttype_new(); INT_ATTR_STR = PyUnicode_InternFromString(c"int".as_ptr()); UTCOFFSET_METHOD_STR = PyUnicode_InternFromString(c"utcoffset".as_ptr()); NORMALIZE_METHOD_STR = PyUnicode_InternFromString(c"normalize".as_ptr()); CONVERT_METHOD_STR = PyUnicode_InternFromString(c"convert".as_ptr()); DST_STR = PyUnicode_InternFromString(c"dst".as_ptr()); DICT_STR = PyUnicode_InternFromString(c"__dict__".as_ptr()); DATACLASS_FIELDS_STR = PyUnicode_InternFromString(c"__dataclass_fields__".as_ptr()); SLOTS_STR = PyUnicode_InternFromString(c"__slots__".as_ptr()); FIELD_TYPE_STR = PyUnicode_InternFromString(c"_field_type".as_ptr()); ARRAY_STRUCT_STR = PyUnicode_InternFromString(c"__array_struct__".as_ptr()); DTYPE_STR = PyUnicode_InternFromString(c"dtype".as_ptr()); DESCR_STR = PyUnicode_InternFromString(c"descr".as_ptr()); VALUE_STR = PyUnicode_InternFromString(c"value".as_ptr()); DEFAULT = PyUnicode_InternFromString(c"default".as_ptr()); OPTION = PyUnicode_InternFromString(c"option".as_ptr()); JsonEncodeError = pyo3_ffi::PyExc_TypeError; Py_INCREF(JsonEncodeError); let json_jsondecodeerror = look_up_type_object(c"json", c"JSONDecodeError").cast::(); JsonDecodeError = pyo3_ffi::PyErr_NewException( c"orjson.JSONDecodeError".as_ptr(), json_jsondecodeerror, null_mut(), ); Py_XDECREF(json_jsondecodeerror); }; true } pub(crate) struct NumpyTypes { pub array: *mut PyTypeObject, pub float64: *mut PyTypeObject, pub float32: *mut PyTypeObject, pub float16: *mut PyTypeObject, pub int64: *mut PyTypeObject, pub int32: *mut PyTypeObject, pub int16: *mut PyTypeObject, pub int8: *mut PyTypeObject, pub uint64: *mut PyTypeObject, pub uint32: *mut PyTypeObject, pub uint16: *mut PyTypeObject, pub uint8: *mut PyTypeObject, pub bool_: *mut PyTypeObject, pub datetime64: *mut PyTypeObject, } pub(crate) static mut NUMPY_TYPES: OnceBox>> = OnceBox::new(); unsafe fn look_up_numpy_type( numpy_module_dict: *mut PyObject, np_type: &CStr, ) -> *mut PyTypeObject { unsafe { let ptr = PyMapping_GetItemString(numpy_module_dict, np_type.as_ptr()); Py_XDECREF(ptr); ptr.cast::() } } #[cold] #[cfg_attr(feature = "optimize", optimize(size))] pub(crate) fn load_numpy_types() -> Box>> { unsafe { let numpy = PyImport_ImportModule(c"numpy".as_ptr()); if numpy.is_null() { PyErr_Clear(); return Box::new(None); } let numpy_module_dict = PyObject_GenericGetDict(numpy, null_mut()); let types = Box::new(NumpyTypes { array: look_up_numpy_type(numpy_module_dict, c"ndarray"), float16: look_up_numpy_type(numpy_module_dict, c"half"), float32: look_up_numpy_type(numpy_module_dict, c"float32"), float64: look_up_numpy_type(numpy_module_dict, c"float64"), int8: look_up_numpy_type(numpy_module_dict, c"int8"), int16: look_up_numpy_type(numpy_module_dict, c"int16"), int32: look_up_numpy_type(numpy_module_dict, c"int32"), int64: look_up_numpy_type(numpy_module_dict, c"int64"), uint16: look_up_numpy_type(numpy_module_dict, c"uint16"), uint32: look_up_numpy_type(numpy_module_dict, c"uint32"), uint64: look_up_numpy_type(numpy_module_dict, c"uint64"), uint8: look_up_numpy_type(numpy_module_dict, c"uint8"), bool_: look_up_numpy_type(numpy_module_dict, c"bool_"), datetime64: look_up_numpy_type(numpy_module_dict, c"datetime64"), }); Py_XDECREF(numpy_module_dict); Py_XDECREF(numpy); Box::new(Some(nonnull!(Box::::into_raw(types)))) } } ijl-orjson-aa8c946/src/util.rs000066400000000000000000000164321505336676500163610ustar00rootroot00000000000000// SPDX-License-Identifier: (Apache-2.0 OR MIT) pub(crate) const INVALID_STR: &str = "str is not valid UTF-8: surrogates not allowed"; macro_rules! is_type { ($obj_ptr:expr, $type_ptr:expr) => { unsafe { $obj_ptr == $type_ptr } }; } macro_rules! ob_type { ($obj:expr) => { unsafe { (*$obj).ob_type } }; } macro_rules! is_class_by_type { ($ob_type:expr, $type_ptr:ident) => { unsafe { $ob_type == $type_ptr } }; } #[cfg(not(Py_GIL_DISABLED))] macro_rules! tp_flags { ($ob_type:expr) => { unsafe { (*$ob_type).tp_flags } }; } #[cfg(Py_GIL_DISABLED)] macro_rules! tp_flags { ($ob_type:expr) => { unsafe { (*$ob_type) .tp_flags .load(std::sync::atomic::Ordering::Relaxed) } }; } macro_rules! is_subclass_by_flag { ($tp_flags:expr, $flag:ident) => { unsafe { (($tp_flags & pyo3_ffi::$flag) != 0) } }; } macro_rules! is_subclass_by_type { ($ob_type:expr, $type:ident) => { unsafe { (*($ob_type.cast::())) .ob_base .ob_base .ob_type == $type } }; } macro_rules! err { ($msg:expr) => { return Err(serde::ser::Error::custom($msg)) }; } macro_rules! opt_enabled { ($var:expr, $flag:expr) => { $var & $flag != 0 }; } macro_rules! opt_disabled { ($var:expr, $flag:expr) => { $var & $flag == 0 }; } #[cfg(feature = "intrinsics")] macro_rules! unlikely { ($exp:expr) => { core::intrinsics::unlikely($exp) }; } #[cfg(not(feature = "intrinsics"))] macro_rules! unlikely { ($exp:expr) => { $exp }; } #[allow(unused_macros)] #[cfg(feature = "intrinsics")] macro_rules! likely { ($exp:expr) => { core::intrinsics::likely($exp) }; } #[allow(unused_macros)] #[cfg(not(feature = "intrinsics"))] macro_rules! likely { ($exp:expr) => { $exp }; } macro_rules! nonnull { ($exp:expr) => { unsafe { core::ptr::NonNull::new_unchecked($exp) } }; } macro_rules! str_from_slice { ($ptr:expr, $size:expr) => { unsafe { core::str::from_utf8_unchecked(core::slice::from_raw_parts($ptr, $size as usize)) } }; } #[cfg(all(Py_3_12, not(Py_GIL_DISABLED)))] macro_rules! reverse_pydict_incref { ($op:expr) => { unsafe { if crate::ffi::_Py_IsImmortal($op) == 0 { debug_assert!(ffi!(Py_REFCNT($op)) >= 2); (*$op).ob_refcnt.ob_refcnt -= 1; } } }; } #[cfg(Py_GIL_DISABLED)] macro_rules! reverse_pydict_incref { ($op:expr) => { debug_assert!(ffi!(Py_REFCNT($op)) >= 2); ffi!(Py_DECREF($op)) }; } #[cfg(not(Py_3_12))] macro_rules! reverse_pydict_incref { ($op:expr) => { unsafe { debug_assert!(ffi!(Py_REFCNT($op)) >= 2); (*$op).ob_refcnt -= 1; } }; } macro_rules! ffi { ($fn:ident()) => { unsafe { pyo3_ffi::$fn() } }; ($fn:ident($obj1:expr)) => { unsafe { pyo3_ffi::$fn($obj1) } }; ($fn:ident($obj1:expr, $obj2:expr)) => { unsafe { pyo3_ffi::$fn($obj1, $obj2) } }; ($fn:ident($obj1:expr, $obj2:expr, $obj3:expr)) => { unsafe { pyo3_ffi::$fn($obj1, $obj2, $obj3) } }; ($fn:ident($obj1:expr, $obj2:expr, $obj3:expr, $obj4:expr)) => { unsafe { pyo3_ffi::$fn($obj1, $obj2, $obj3, $obj4) } }; } macro_rules! call_method { ($obj1:expr, $obj2:expr) => { unsafe { pyo3_ffi::PyObject_CallMethodNoArgs($obj1, $obj2) } }; ($obj1:expr, $obj2:expr, $obj3:expr) => { unsafe { pyo3_ffi::PyObject_CallMethodOneArg($obj1, $obj2, $obj3) } }; } macro_rules! str_hash { ($op:expr) => { unsafe { (*$op.cast::()).hash } }; } #[cfg(Py_3_13)] macro_rules! pydict_contains { ($obj1:expr, $obj2:expr) => { unsafe { pyo3_ffi::PyDict_Contains(pyo3_ffi::PyType_GetDict($obj1), $obj2) == 1 } }; } #[cfg(all(Py_3_12, not(Py_3_13)))] macro_rules! pydict_contains { ($obj1:expr, $obj2:expr) => { unsafe { crate::ffi::_PyDict_Contains_KnownHash( pyo3_ffi::PyType_GetDict($obj1), $obj2, (*$obj2.cast::()).hash, ) == 1 } }; } #[cfg(all(Py_3_10, not(Py_3_12)))] macro_rules! pydict_contains { ($obj1:expr, $obj2:expr) => { unsafe { crate::ffi::_PyDict_Contains_KnownHash( (*$obj1).tp_dict, $obj2, (*$obj2.cast::()).hash, ) == 1 } }; } #[cfg(not(Py_3_10))] macro_rules! pydict_contains { ($obj1:expr, $obj2:expr) => { unsafe { pyo3_ffi::PyDict_Contains((*$obj1).tp_dict, $obj2) == 1 } }; } #[cfg(Py_3_12)] macro_rules! use_immortal { ($op:expr) => { unsafe { $op } }; } #[cfg(not(Py_3_12))] macro_rules! use_immortal { ($op:expr) => { unsafe { ffi!(Py_INCREF($op)); $op } }; } #[cfg(not(Py_3_13))] macro_rules! pydict_next { ($obj1:expr, $obj2:expr, $obj3:expr, $obj4:expr) => { unsafe { crate::ffi::_PyDict_Next($obj1, $obj2, $obj3, $obj4, core::ptr::null_mut()) } }; } #[cfg(Py_3_13)] macro_rules! pydict_next { ($obj1:expr, $obj2:expr, $obj3:expr, $obj4:expr) => { unsafe { pyo3_ffi::PyDict_Next($obj1, $obj2, $obj3, $obj4) } }; } macro_rules! pydict_setitem { ($dict:expr, $pykey:expr, $pyval:expr) => { debug_assert!(ffi!(Py_REFCNT($dict)) == 1); debug_assert!(str_hash!($pykey) != -1); #[cfg(not(Py_3_13))] unsafe { let _ = crate::ffi::_PyDict_SetItem_KnownHash($dict, $pykey, $pyval, str_hash!($pykey)); } #[cfg(Py_3_13)] unsafe { let _ = crate::ffi::_PyDict_SetItem_KnownHash_LockHeld( $dict.cast::(), $pykey, $pyval, str_hash!($pykey), ); } #[cfg(not(Py_GIL_DISABLED))] reverse_pydict_incref!($pykey); reverse_pydict_incref!($pyval); }; } macro_rules! reserve_minimum { ($writer:expr) => { $writer.reserve(64); }; } macro_rules! reserve_pretty { ($writer:expr, $val:expr) => { $writer.reserve($val + 16); }; } macro_rules! assume { ($expr:expr) => { debug_assert!($expr); unsafe { core::hint::assert_unchecked($expr); }; }; } #[allow(unused_macros)] #[cfg(feature = "intrinsics")] macro_rules! trailing_zeros { ($val:expr) => { core::intrinsics::cttz_nonzero($val) as usize }; } #[allow(unused_macros)] #[cfg(not(feature = "intrinsics"))] macro_rules! trailing_zeros { ($val:expr) => { $val.trailing_zeros() as usize }; } macro_rules! unreachable_unchecked { () => { unsafe { core::hint::unreachable_unchecked() } }; } #[inline(always)] #[allow(clippy::cast_possible_wrap)] pub(crate) fn usize_to_isize(val: usize) -> isize { debug_assert!(val < (isize::MAX as usize)); val as isize } #[inline(always)] #[allow(clippy::cast_sign_loss)] pub(crate) fn isize_to_usize(val: isize) -> usize { debug_assert!(val >= 0); val as usize } ijl-orjson-aa8c946/test/000077500000000000000000000000001505336676500152205ustar00rootroot00000000000000ijl-orjson-aa8c946/test/__init__.py000066400000000000000000000000001505336676500173170ustar00rootroot00000000000000ijl-orjson-aa8c946/test/requirements.txt000066400000000000000000000006041505336676500205040ustar00rootroot00000000000000faker numpy;(platform_machine=="x86_64" or (platform_machine=="aarch64" and sys_platform == "linux")) and python_version<"3.13" pendulum;sys_platform=="linux" and platform_machine=="x86_64" and python_version<"3.14" psutil;(sys_platform=="linux" or sys_platform == "macos") and platform_machine=="x86_64" and python_version<"3.13" pytest python-dateutil >=2,<3;python_version<"3.14" pytz ijl-orjson-aa8c946/test/test_api.py000066400000000000000000000205761505336676500174140ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import datetime import inspect import json import re import pytest import orjson SIMPLE_TYPES = (1, 1.0, -1, None, "str", True, False) LOADS_RECURSION_LIMIT = 1024 def default(obj): return str(obj) class TestApi: def test_loads_trailing(self): """ loads() handles trailing whitespace """ assert orjson.loads("{}\n\t ") == {} def test_loads_trailing_invalid(self): """ loads() handles trailing invalid """ pytest.raises(orjson.JSONDecodeError, orjson.loads, "{}\n\t a") def test_simple_json(self): """ dumps() equivalent to json on simple types """ for obj in SIMPLE_TYPES: assert orjson.dumps(obj) == json.dumps(obj).encode("utf-8") def test_simple_round_trip(self): """ dumps(), loads() round trip on simple types """ for obj in SIMPLE_TYPES: assert orjson.loads(orjson.dumps(obj)) == obj def test_loads_type(self): """ loads() invalid type """ for val in (1, 3.14, [], {}, None): # type: ignore pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_loads_recursion_partial(self): """ loads() recursion limit partial """ pytest.raises(orjson.JSONDecodeError, orjson.loads, "[" * (1024 * 1024)) def test_loads_recursion_valid_limit_array(self): """ loads() recursion limit at limit array """ n = LOADS_RECURSION_LIMIT + 1 value = b"[" * n + b"]" * n pytest.raises(orjson.JSONDecodeError, orjson.loads, value) def test_loads_recursion_valid_limit_object(self): """ loads() recursion limit at limit object """ n = LOADS_RECURSION_LIMIT value = b'{"key":' * n + b'{"key":true}' + b"}" * n pytest.raises(orjson.JSONDecodeError, orjson.loads, value) def test_loads_recursion_valid_limit_mixed(self): """ loads() recursion limit at limit mixed """ n = LOADS_RECURSION_LIMIT value = b"".join((b"[", b'{"key":' * n, b'{"key":true}' + b"}" * n, b"]")) pytest.raises(orjson.JSONDecodeError, orjson.loads, value) def test_loads_recursion_valid_excessive_array(self): """ loads() recursion limit excessively high value """ n = 10000000 value = b"[" * n + b"]" * n pytest.raises(orjson.JSONDecodeError, orjson.loads, value) def test_loads_recursion_valid_limit_array_pretty(self): """ loads() recursion limit at limit array pretty """ n = LOADS_RECURSION_LIMIT + 1 value = b"[\n " * n + b"]" * n pytest.raises(orjson.JSONDecodeError, orjson.loads, value) def test_loads_recursion_valid_limit_object_pretty(self): """ loads() recursion limit at limit object pretty """ n = LOADS_RECURSION_LIMIT value = b'{\n "key":' * n + b'{"key":true}' + b"}" * n pytest.raises(orjson.JSONDecodeError, orjson.loads, value) def test_loads_recursion_valid_limit_mixed_pretty(self): """ loads() recursion limit at limit mixed pretty """ n = LOADS_RECURSION_LIMIT value = b'[\n {"key":' * n + b'{"key":true}' + b"}" * n + b"]" pytest.raises(orjson.JSONDecodeError, orjson.loads, value) def test_loads_recursion_valid_excessive_array_pretty(self): """ loads() recursion limit excessively high value pretty """ n = 10000000 value = b"[\n " * n + b"]" * n pytest.raises(orjson.JSONDecodeError, orjson.loads, value) def test_version(self): """ __version__ """ assert re.match(r"^\d+\.\d+(\.\d+)?$", orjson.__version__) def test_valueerror(self): """ orjson.JSONDecodeError is a subclass of ValueError """ pytest.raises(orjson.JSONDecodeError, orjson.loads, "{") pytest.raises(ValueError, orjson.loads, "{") def test_optional_none(self): """ dumps() option, default None """ assert orjson.dumps([], option=None) == b"[]" assert orjson.dumps([], default=None) == b"[]" assert orjson.dumps([], option=None, default=None) == b"[]" assert orjson.dumps([], None, None) == b"[]" def test_option_not_int(self): """ dumps() option not int or None """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps(True, option=True) def test_option_invalid_int(self): """ dumps() option invalid 64-bit number """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps(True, option=9223372036854775809) def test_option_range_low(self): """ dumps() option out of range low """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps(True, option=-1) def test_option_range_high(self): """ dumps() option out of range high """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps(True, option=1 << 12) def test_opts_multiple(self): """ dumps() multiple option """ assert ( orjson.dumps( [1, datetime.datetime(2000, 1, 1, 2, 3, 4)], option=orjson.OPT_STRICT_INTEGER | orjson.OPT_NAIVE_UTC, ) == b'[1,"2000-01-01T02:03:04+00:00"]' ) def test_default_positional(self): """ dumps() positional arg """ with pytest.raises(TypeError): orjson.dumps(__obj={}) # type: ignore with pytest.raises(TypeError): orjson.dumps(zxc={}) # type: ignore def test_default_unknown_kwarg(self): """ dumps() unknown kwarg """ with pytest.raises(TypeError): orjson.dumps({}, zxc=default) # type: ignore def test_default_empty_kwarg(self): """ dumps() empty kwarg """ assert orjson.dumps(None) == b"null" def test_default_twice(self): """ dumps() default twice """ with pytest.raises(TypeError): orjson.dumps({}, default, default=default) # type: ignore def test_option_twice(self): """ dumps() option twice """ with pytest.raises(TypeError): orjson.dumps({}, None, orjson.OPT_NAIVE_UTC, option=orjson.OPT_NAIVE_UTC) # type: ignore def test_option_mixed(self): """ dumps() option one arg, one kwarg """ class Custom: def __str__(self): return "zxc" assert ( orjson.dumps( [Custom(), datetime.datetime(2000, 1, 1, 2, 3, 4)], default, option=orjson.OPT_NAIVE_UTC, ) == b'["zxc","2000-01-01T02:03:04+00:00"]' ) def test_dumps_signature(self): """ dumps() valid __text_signature__ """ assert ( str(inspect.signature(orjson.dumps)) == "(obj, /, default=None, option=None)" ) inspect.signature(orjson.dumps).bind("str") inspect.signature(orjson.dumps).bind("str", default=default, option=1) inspect.signature(orjson.dumps).bind("str", default=None, option=None) def test_loads_signature(self): """ loads() valid __text_signature__ """ assert str(inspect.signature(orjson.loads)), "(obj == /)" inspect.signature(orjson.loads).bind("[]") def test_dumps_module_str(self): """ orjson.dumps.__module__ is a str """ assert orjson.dumps.__module__ == "orjson" def test_loads_module_str(self): """ orjson.loads.__module__ is a str """ assert orjson.loads.__module__ == "orjson" def test_bytes_buffer(self): """ dumps() trigger buffer growing where length is greater than growth """ a = "a" * 900 b = "b" * 4096 c = "c" * 4096 * 4096 assert orjson.dumps([a, b, c]) == f'["{a}","{b}","{c}"]'.encode("utf-8") def test_bytes_null_terminated(self): """ dumps() PyBytesObject buffer is null-terminated """ # would raise ValueError: invalid literal for int() with base 10: b'1596728892' int(orjson.dumps(1596728892)) ijl-orjson-aa8c946/test/test_append_newline.py000066400000000000000000000025631505336676500216270ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import orjson from .util import needs_data, read_fixture_obj class TestAppendNewline: def test_dumps_newline(self): """ dumps() OPT_APPEND_NEWLINE """ assert orjson.dumps([], option=orjson.OPT_APPEND_NEWLINE) == b"[]\n" @needs_data def test_twitter_newline(self): """ loads(),dumps() twitter.json OPT_APPEND_NEWLINE """ val = read_fixture_obj("twitter.json.xz") assert orjson.loads(orjson.dumps(val, option=orjson.OPT_APPEND_NEWLINE)) == val @needs_data def test_canada(self): """ loads(), dumps() canada.json OPT_APPEND_NEWLINE """ val = read_fixture_obj("canada.json.xz") assert orjson.loads(orjson.dumps(val, option=orjson.OPT_APPEND_NEWLINE)) == val @needs_data def test_citm_catalog_newline(self): """ loads(), dumps() citm_catalog.json OPT_APPEND_NEWLINE """ val = read_fixture_obj("citm_catalog.json.xz") assert orjson.loads(orjson.dumps(val, option=orjson.OPT_APPEND_NEWLINE)) == val @needs_data def test_github_newline(self): """ loads(), dumps() github.json OPT_APPEND_NEWLINE """ val = read_fixture_obj("github.json.xz") assert orjson.loads(orjson.dumps(val, option=orjson.OPT_APPEND_NEWLINE)) == val ijl-orjson-aa8c946/test/test_buffer.py000066400000000000000000000014371505336676500201070ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import os import pytest import orjson ORJSON_RUNNER_MEMORY_GIB = os.getenv("ORJSON_RUNNER_MEMORY_GIB", "") @pytest.mark.skipif( not ORJSON_RUNNER_MEMORY_GIB, reason="ORJSON_RUNNER_MEMORY_GIB not defined", ) def test_memory_loads(): buffer_factor = 12 segment = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" size = ( (int(ORJSON_RUNNER_MEMORY_GIB) * 1024 * 1024 * 1024) // buffer_factor // len(segment) ) doc = "".join(segment for _ in range(size)) with pytest.raises(orjson.JSONDecodeError) as exc_info: _ = orjson.loads(doc) assert ( str(exc_info.value) == "Not enough memory to allocate buffer for parsing: line 1 column 1 (char 0)" ) ijl-orjson-aa8c946/test/test_canonical.py000066400000000000000000000012501505336676500205560ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import orjson class TestCanonicalTests: def test_dumps_ctrl_escape(self): """ dumps() ctrl characters """ assert orjson.dumps("text\u0003\r\n") == b'"text\\u0003\\r\\n"' def test_dumps_escape_quote_backslash(self): """ dumps() quote, backslash escape """ assert orjson.dumps(r'"\ test') == b'"\\"\\\\ test"' def test_dumps_escape_line_separator(self): """ dumps() U+2028, U+2029 escape """ assert ( orjson.dumps({"spaces": "\u2028 \u2029"}) == b'{"spaces":"\xe2\x80\xa8 \xe2\x80\xa9"}' ) ijl-orjson-aa8c946/test/test_circular.py000066400000000000000000000040611505336676500204360ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest import orjson class TestCircular: def test_circular_dict(self): """ dumps() circular reference dict """ obj = {} # type: ignore obj["obj"] = obj with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj) def test_circular_dict_sort_keys(self): """ dumps() circular reference dict OPT_SORT_KEYS """ obj = {} # type: ignore obj["obj"] = obj with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) def test_circular_dict_non_str_keys(self): """ dumps() circular reference dict OPT_NON_STR_KEYS """ obj = {} # type: ignore obj["obj"] = obj with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS) def test_circular_list(self): """ dumps() circular reference list """ obj = [] # type: ignore obj.append(obj) # type: ignore with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj) def test_circular_nested(self): """ dumps() circular reference nested dict, list """ obj = {} # type: ignore obj["list"] = [{"obj": obj}] with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj) def test_circular_nested_sort_keys(self): """ dumps() circular reference nested dict, list OPT_SORT_KEYS """ obj = {} # type: ignore obj["list"] = [{"obj": obj}] with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) def test_circular_nested_non_str_keys(self): """ dumps() circular reference nested dict, list OPT_NON_STR_KEYS """ obj = {} # type: ignore obj["list"] = [{"obj": obj}] with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS) ijl-orjson-aa8c946/test/test_dataclass.py000066400000000000000000000162201505336676500205710ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import abc import uuid from dataclasses import InitVar, asdict, dataclass, field from enum import Enum from typing import ClassVar, Optional import pytest import orjson class AnEnum(Enum): ONE = 1 TWO = 2 @dataclass class EmptyDataclass: pass @dataclass class EmptyDataclassSlots: __slots__ = () @dataclass class Dataclass1: name: str number: int sub: Optional["Dataclass1"] @dataclass class Dataclass2: name: Optional[str] = field(default="?") @dataclass class Dataclass3: a: str b: int c: dict d: bool e: float f: list g: tuple @dataclass class Dataclass4: a: str = field() b: int = field(metadata={"unrelated": False}) c: float = 1.1 @dataclass class Datasubclass(Dataclass1): additional: bool @dataclass class Slotsdataclass: __slots__ = ("_c", "a", "b", "d") a: str b: int _c: str d: InitVar[str] cls_var: ClassVar[str] = "cls" @dataclass class Defaultdataclass: a: uuid.UUID b: AnEnum @dataclass class UnsortedDataclass: c: int b: int a: int d: Optional[dict] @dataclass class InitDataclass: a: InitVar[str] b: InitVar[str] cls_var: ClassVar[str] = "cls" ab: str = "" def __post_init__(self, a: str, b: str): self._other = 1 self.ab = f"{a} {b}" class AbstractBase(abc.ABC): @abc.abstractmethod def key(self): raise NotImplementedError @dataclass(frozen=True) class ConcreteAbc(AbstractBase): __slots__ = ("attr",) attr: float def key(self): return "dkjf" class TestDataclass: def test_dataclass(self): """ dumps() dataclass """ obj = Dataclass1("a", 1, None) assert orjson.dumps(obj) == b'{"name":"a","number":1,"sub":null}' def test_dataclass_recursive(self): """ dumps() dataclass recursive """ obj = Dataclass1("a", 1, Dataclass1("b", 2, None)) assert ( orjson.dumps(obj) == b'{"name":"a","number":1,"sub":{"name":"b","number":2,"sub":null}}' ) def test_dataclass_circular(self): """ dumps() dataclass circular """ obj1 = Dataclass1("a", 1, None) obj2 = Dataclass1("b", 2, obj1) obj1.sub = obj2 with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj1) def test_dataclass_empty(self): """ dumps() no attributes """ assert orjson.dumps(EmptyDataclass()) == b"{}" def test_dataclass_empty_slots(self): """ dumps() no attributes slots """ assert orjson.dumps(EmptyDataclassSlots()) == b"{}" def test_dataclass_default_arg(self): """ dumps() dataclass default arg """ obj = Dataclass2() assert orjson.dumps(obj) == b'{"name":"?"}' def test_dataclass_types(self): """ dumps() dataclass types """ obj = Dataclass3("a", 1, {"a": "b"}, True, 1.1, [1, 2], (3, 4)) assert ( orjson.dumps(obj) == b'{"a":"a","b":1,"c":{"a":"b"},"d":true,"e":1.1,"f":[1,2],"g":[3,4]}' ) def test_dataclass_metadata(self): """ dumps() dataclass metadata """ obj = Dataclass4("a", 1, 2.1) assert orjson.dumps(obj) == b'{"a":"a","b":1,"c":2.1}' def test_dataclass_classvar(self): """ dumps() dataclass class variable """ obj = Dataclass4("a", 1) assert orjson.dumps(obj) == b'{"a":"a","b":1,"c":1.1}' def test_dataclass_subclass(self): """ dumps() dataclass subclass """ obj = Datasubclass("a", 1, None, False) assert ( orjson.dumps(obj) == b'{"name":"a","number":1,"sub":null,"additional":false}' ) def test_dataclass_slots(self): """ dumps() dataclass with __slots__ does not include under attributes, InitVar, or ClassVar """ obj = Slotsdataclass("a", 1, "c", "d") assert "__dict__" not in dir(obj) assert orjson.dumps(obj) == b'{"a":"a","b":1}' def test_dataclass_default(self): """ dumps() dataclass with default """ def default(__obj): if isinstance(__obj, uuid.UUID): return str(__obj) elif isinstance(__obj, Enum): return __obj.value obj = Defaultdataclass( uuid.UUID("808989c0-00d5-48a8-b5c4-c804bf9032f2"), AnEnum.ONE, ) assert ( orjson.dumps(obj, default=default) == b'{"a":"808989c0-00d5-48a8-b5c4-c804bf9032f2","b":1}' ) def test_dataclass_sort(self): """ OPT_SORT_KEYS has no effect on dataclasses """ obj = UnsortedDataclass(1, 2, 3, None) assert ( orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) == b'{"c":1,"b":2,"a":3,"d":null}' ) def test_dataclass_sort_sub(self): """ dataclass fast path does not prevent OPT_SORT_KEYS from cascading """ obj = UnsortedDataclass(1, 2, 3, {"f": 2, "e": 1}) assert ( orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) == b'{"c":1,"b":2,"a":3,"d":{"e":1,"f":2}}' ) def test_dataclass_under(self): """ dumps() does not include under attributes, InitVar, or ClassVar """ obj = InitDataclass("zxc", "vbn") assert orjson.dumps(obj) == b'{"ab":"zxc vbn"}' def test_dataclass_option(self): """ dumps() accepts deprecated OPT_SERIALIZE_DATACLASS """ obj = Dataclass1("a", 1, None) assert ( orjson.dumps(obj, option=orjson.OPT_SERIALIZE_DATACLASS) == b'{"name":"a","number":1,"sub":null}' ) class TestDataclassPassthrough: def test_dataclass_passthrough_raise(self): """ dumps() dataclass passes to default with OPT_PASSTHROUGH_DATACLASS """ obj = Dataclass1("a", 1, None) with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj, option=orjson.OPT_PASSTHROUGH_DATACLASS) with pytest.raises(orjson.JSONEncodeError): orjson.dumps( InitDataclass("zxc", "vbn"), option=orjson.OPT_PASSTHROUGH_DATACLASS, ) def test_dataclass_passthrough_default(self): """ dumps() dataclass passes to default with OPT_PASSTHROUGH_DATACLASS """ obj = Dataclass1("a", 1, None) assert ( orjson.dumps(obj, option=orjson.OPT_PASSTHROUGH_DATACLASS, default=asdict) == b'{"name":"a","number":1,"sub":null}' ) def default(obj): if isinstance(obj, Dataclass1): return {"name": obj.name, "number": obj.number} raise TypeError assert ( orjson.dumps(obj, option=orjson.OPT_PASSTHROUGH_DATACLASS, default=default) == b'{"name":"a","number":1}' ) class TestAbstractDataclass: def test_dataclass_abc(self): obj = ConcreteAbc(1.0) assert orjson.dumps(obj) == b'{"attr":1.0}' ijl-orjson-aa8c946/test/test_datetime.py000066400000000000000000000576141505336676500204420ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import datetime import pytest import orjson try: import zoneinfo _ = zoneinfo.ZoneInfo("Europe/Amsterdam") except Exception: # ImportError,ZoneInfoNotFoundError zoneinfo = None # type: ignore try: import pytz except ImportError: pytz = None # type: ignore try: import pendulum except ImportError: pendulum = None # type: ignore try: from dateutil import tz except ImportError: tz = None # type: ignore AMSTERDAM_1937_DATETIMES = ( b'["1937-01-01T12:00:27.000087+00:20"]', # tzinfo<2022b and an example in RFC 3339 b'["1937-01-01T12:00:27.000087+00:00"]', # tzinfo>=2022b ) AMSTERDAM_1937_DATETIMES_WITH_Z = ( b'["1937-01-01T12:00:27.000087+00:20"]', b'["1937-01-01T12:00:27.000087Z"]', ) class TestDatetime: def test_datetime_naive(self): """ datetime.datetime naive prints without offset """ assert ( orjson.dumps([datetime.datetime(2000, 1, 1, 2, 3, 4, 123)]) == b'["2000-01-01T02:03:04.000123"]' ) def test_datetime_naive_utc(self): """ datetime.datetime naive with opt assumes UTC """ assert ( orjson.dumps( [datetime.datetime(2000, 1, 1, 2, 3, 4, 123)], option=orjson.OPT_NAIVE_UTC, ) == b'["2000-01-01T02:03:04.000123+00:00"]' ) def test_datetime_min(self): """ datetime.datetime min range """ assert ( orjson.dumps( [datetime.datetime(datetime.MINYEAR, 1, 1, 0, 0, 0, 0)], option=orjson.OPT_NAIVE_UTC, ) == b'["0001-01-01T00:00:00+00:00"]' ) def test_datetime_max(self): """ datetime.datetime max range """ assert ( orjson.dumps( [datetime.datetime(datetime.MAXYEAR, 12, 31, 23, 59, 50, 999999)], option=orjson.OPT_NAIVE_UTC, ) == b'["9999-12-31T23:59:50.999999+00:00"]' ) def test_datetime_three_digits(self): """ datetime.datetime three digit year """ assert ( orjson.dumps( [datetime.datetime(312, 1, 1)], option=orjson.OPT_NAIVE_UTC, ) == b'["0312-01-01T00:00:00+00:00"]' ) def test_datetime_two_digits(self): """ datetime.datetime two digit year """ assert ( orjson.dumps( [datetime.datetime(46, 1, 1)], option=orjson.OPT_NAIVE_UTC, ) == b'["0046-01-01T00:00:00+00:00"]' ) @pytest.mark.skipif(tz is None, reason="dateutil optional") def test_datetime_tz_assume(self): """ datetime.datetime tz with assume UTC uses tz """ assert ( orjson.dumps( [ datetime.datetime( 2018, 1, 1, 2, 3, 4, 0, tzinfo=tz.gettz("Asia/Shanghai"), ), ], option=orjson.OPT_NAIVE_UTC, ) == b'["2018-01-01T02:03:04+08:00"]' ) def test_datetime_timezone_utc(self): """ datetime.datetime.utc """ assert ( orjson.dumps( [ datetime.datetime( 2018, 6, 1, 2, 3, 4, 0, tzinfo=datetime.timezone.utc, ), ], ) == b'["2018-06-01T02:03:04+00:00"]' ) @pytest.mark.skipif(pytz is None, reason="pytz optional") def test_datetime_pytz_utc(self): """ pytz.UTC """ assert ( orjson.dumps([datetime.datetime(2018, 6, 1, 2, 3, 4, 0, tzinfo=pytz.UTC)]) == b'["2018-06-01T02:03:04+00:00"]' ) @pytest.mark.skipif(zoneinfo is None, reason="zoneinfo not available") def test_datetime_zoneinfo_utc(self): """ zoneinfo.ZoneInfo("UTC") """ assert ( orjson.dumps( [ datetime.datetime( 2018, 6, 1, 2, 3, 4, 0, tzinfo=zoneinfo.ZoneInfo("UTC"), ), ], ) == b'["2018-06-01T02:03:04+00:00"]' ) @pytest.mark.skipif(zoneinfo is None, reason="zoneinfo not available") def test_datetime_zoneinfo_positive(self): assert ( orjson.dumps( [ datetime.datetime( 2018, 1, 1, 2, 3, 4, 0, tzinfo=zoneinfo.ZoneInfo("Asia/Shanghai"), ), ], ) == b'["2018-01-01T02:03:04+08:00"]' ) @pytest.mark.skipif(zoneinfo is None, reason="zoneinfo not available") def test_datetime_zoneinfo_negative(self): assert ( orjson.dumps( [ datetime.datetime( 2018, 6, 1, 2, 3, 4, 0, tzinfo=zoneinfo.ZoneInfo("America/New_York"), ), ], ) == b'["2018-06-01T02:03:04-04:00"]' ) @pytest.mark.skipif(pendulum is None, reason="pendulum not installed") def test_datetime_pendulum_utc(self): """ datetime.datetime UTC """ assert ( orjson.dumps( [datetime.datetime(2018, 6, 1, 2, 3, 4, 0, tzinfo=pendulum.UTC)], ) == b'["2018-06-01T02:03:04+00:00"]' ) @pytest.mark.skipif(tz is None, reason="dateutil optional") def test_datetime_arrow_positive(self): """ datetime.datetime positive UTC """ assert ( orjson.dumps( [ datetime.datetime( 2018, 1, 1, 2, 3, 4, 0, tzinfo=tz.gettz("Asia/Shanghai"), ), ], ) == b'["2018-01-01T02:03:04+08:00"]' ) @pytest.mark.skipif(pytz is None, reason="pytz optional") def test_datetime_pytz_positive(self): """ datetime.datetime positive UTC """ assert ( orjson.dumps( [ datetime.datetime( 2018, 1, 1, 2, 3, 4, 0, tzinfo=pytz.timezone("Asia/Shanghai"), ), ], ) == b'["2018-01-01T02:03:04+08:00"]' ) @pytest.mark.skipif(pendulum is None, reason="pendulum not installed") def test_datetime_pendulum_positive(self): """ datetime.datetime positive UTC """ assert ( orjson.dumps( [ datetime.datetime( 2018, 1, 1, 2, 3, 4, 0, tzinfo=pendulum.timezone("Asia/Shanghai"), # type: ignore ), ], ) == b'["2018-01-01T02:03:04+08:00"]' ) @pytest.mark.skipif(pytz is None, reason="pytz optional") def test_datetime_pytz_negative_dst(self): """ datetime.datetime negative UTC DST """ assert ( orjson.dumps( [ datetime.datetime( 2018, 6, 1, 2, 3, 4, 0, tzinfo=pytz.timezone("America/New_York"), ), ], ) == b'["2018-06-01T02:03:04-04:00"]' ) @pytest.mark.skipif(pendulum is None, reason="pendulum not installed") def test_datetime_pendulum_negative_dst(self): """ datetime.datetime negative UTC DST """ assert ( orjson.dumps( [ datetime.datetime( 2018, 6, 1, 2, 3, 4, 0, tzinfo=pendulum.timezone("America/New_York"), # type: ignore ), ], ) == b'["2018-06-01T02:03:04-04:00"]' ) @pytest.mark.skipif(zoneinfo is None, reason="zoneinfo not available") def test_datetime_zoneinfo_negative_non_dst(self): """ datetime.datetime negative UTC non-DST """ assert ( orjson.dumps( [ datetime.datetime( 2018, 12, 1, 2, 3, 4, 0, tzinfo=zoneinfo.ZoneInfo("America/New_York"), ), ], ) == b'["2018-12-01T02:03:04-05:00"]' ) @pytest.mark.skipif(pytz is None, reason="pytz optional") def test_datetime_pytz_negative_non_dst(self): """ datetime.datetime negative UTC non-DST """ assert ( orjson.dumps( [ datetime.datetime( 2018, 12, 1, 2, 3, 4, 0, tzinfo=pytz.timezone("America/New_York"), ), ], ) == b'["2018-12-01T02:03:04-05:00"]' ) @pytest.mark.skipif(pendulum is None, reason="pendulum not installed") def test_datetime_pendulum_negative_non_dst(self): """ datetime.datetime negative UTC non-DST """ assert ( orjson.dumps( [ datetime.datetime( 2018, 12, 1, 2, 3, 4, 0, tzinfo=pendulum.timezone("America/New_York"), # type: ignore ), ], ) == b'["2018-12-01T02:03:04-05:00"]' ) @pytest.mark.skipif(zoneinfo is None, reason="zoneinfo not available") def test_datetime_zoneinfo_partial_hour(self): """ datetime.datetime UTC offset partial hour """ assert ( orjson.dumps( [ datetime.datetime( 2018, 12, 1, 2, 3, 4, 0, tzinfo=zoneinfo.ZoneInfo("Australia/Adelaide"), ), ], ) == b'["2018-12-01T02:03:04+10:30"]' ) @pytest.mark.skipif(pytz is None, reason="pytz optional") def test_datetime_pytz_partial_hour(self): """ datetime.datetime UTC offset partial hour """ assert ( orjson.dumps( [ datetime.datetime( 2018, 12, 1, 2, 3, 4, 0, tzinfo=pytz.timezone("Australia/Adelaide"), ), ], ) == b'["2018-12-01T02:03:04+10:30"]' ) @pytest.mark.skipif(pendulum is None, reason="pendulum not installed") def test_datetime_pendulum_partial_hour(self): """ datetime.datetime UTC offset partial hour """ assert ( orjson.dumps( [ datetime.datetime( 2018, 12, 1, 2, 3, 4, 0, tzinfo=pendulum.timezone("Australia/Adelaide"), # type: ignore ), ], ) == b'["2018-12-01T02:03:04+10:30"]' ) @pytest.mark.skipif(pendulum is None, reason="pendulum not installed") def test_datetime_partial_second_pendulum_supported(self): """ datetime.datetime UTC offset round seconds https://tools.ietf.org/html/rfc3339#section-5.8 """ assert ( orjson.dumps( [ datetime.datetime( 1937, 1, 1, 12, 0, 27, 87, tzinfo=pendulum.timezone("Europe/Amsterdam"), # type: ignore ), ], ) in AMSTERDAM_1937_DATETIMES ) @pytest.mark.skipif(zoneinfo is None, reason="zoneinfo not available") def test_datetime_partial_second_zoneinfo(self): """ datetime.datetime UTC offset round seconds https://tools.ietf.org/html/rfc3339#section-5.8 """ assert ( orjson.dumps( [ datetime.datetime( 1937, 1, 1, 12, 0, 27, 87, tzinfo=zoneinfo.ZoneInfo("Europe/Amsterdam"), ), ], ) in AMSTERDAM_1937_DATETIMES ) @pytest.mark.skipif(pytz is None, reason="pytz optional") def test_datetime_partial_second_pytz(self): """ datetime.datetime UTC offset round seconds https://tools.ietf.org/html/rfc3339#section-5.8 """ assert ( orjson.dumps( [ datetime.datetime( 1937, 1, 1, 12, 0, 27, 87, tzinfo=pytz.timezone("Europe/Amsterdam"), ), ], ) in AMSTERDAM_1937_DATETIMES ) @pytest.mark.skipif(tz is None, reason="dateutil optional") def test_datetime_partial_second_dateutil(self): """ datetime.datetime UTC offset round seconds https://tools.ietf.org/html/rfc3339#section-5.8 """ assert ( orjson.dumps( [ datetime.datetime( 1937, 1, 1, 12, 0, 27, 87, tzinfo=tz.gettz("Europe/Amsterdam"), ), ], ) in AMSTERDAM_1937_DATETIMES ) def test_datetime_microsecond_max(self): """ datetime.datetime microsecond max """ assert ( orjson.dumps(datetime.datetime(2000, 1, 1, 0, 0, 0, 999999)) == b'"2000-01-01T00:00:00.999999"' ) def test_datetime_microsecond_min(self): """ datetime.datetime microsecond min """ assert ( orjson.dumps(datetime.datetime(2000, 1, 1, 0, 0, 0, 1)) == b'"2000-01-01T00:00:00.000001"' ) def test_datetime_omit_microseconds(self): """ datetime.datetime OPT_OMIT_MICROSECONDS """ assert ( orjson.dumps( [datetime.datetime(2000, 1, 1, 2, 3, 4, 123)], option=orjson.OPT_OMIT_MICROSECONDS, ) == b'["2000-01-01T02:03:04"]' ) def test_datetime_omit_microseconds_naive(self): """ datetime.datetime naive OPT_OMIT_MICROSECONDS """ assert ( orjson.dumps( [datetime.datetime(2000, 1, 1, 2, 3, 4, 123)], option=orjson.OPT_NAIVE_UTC | orjson.OPT_OMIT_MICROSECONDS, ) == b'["2000-01-01T02:03:04+00:00"]' ) def test_time_omit_microseconds(self): """ datetime.time OPT_OMIT_MICROSECONDS """ assert ( orjson.dumps( [datetime.time(2, 3, 4, 123)], option=orjson.OPT_OMIT_MICROSECONDS, ) == b'["02:03:04"]' ) def test_datetime_utc_z_naive_omit(self): """ datetime.datetime naive OPT_UTC_Z """ assert ( orjson.dumps( [datetime.datetime(2000, 1, 1, 2, 3, 4, 123)], option=orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z | orjson.OPT_OMIT_MICROSECONDS, ) == b'["2000-01-01T02:03:04Z"]' ) def test_datetime_utc_z_naive(self): """ datetime.datetime naive OPT_UTC_Z """ assert ( orjson.dumps( [datetime.datetime(2000, 1, 1, 2, 3, 4, 123)], option=orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'["2000-01-01T02:03:04.000123Z"]' ) def test_datetime_utc_z_without_tz(self): """ datetime.datetime naive OPT_UTC_Z """ assert ( orjson.dumps( [datetime.datetime(2000, 1, 1, 2, 3, 4, 123)], option=orjson.OPT_UTC_Z, ) == b'["2000-01-01T02:03:04.000123"]' ) @pytest.mark.skipif(tz is None, reason="dateutil optional") def test_datetime_utc_z_with_tz(self): """ datetime.datetime naive OPT_UTC_Z """ assert ( orjson.dumps( [ datetime.datetime( 2000, 1, 1, 0, 0, 0, 1, tzinfo=datetime.timezone.utc, ), ], option=orjson.OPT_UTC_Z, ) == b'["2000-01-01T00:00:00.000001Z"]' ) assert ( orjson.dumps( [ datetime.datetime( 1937, 1, 1, 12, 0, 27, 87, tzinfo=tz.gettz("Europe/Amsterdam"), ), ], option=orjson.OPT_UTC_Z, ) in AMSTERDAM_1937_DATETIMES_WITH_Z ) @pytest.mark.skipif(pendulum is None, reason="pendulum not installed") def test_datetime_roundtrip(self): """ datetime.datetime parsed by pendulum """ obj = datetime.datetime(2000, 1, 1, 0, 0, 0, 1, tzinfo=datetime.timezone.utc) serialized = orjson.dumps(obj).decode("utf-8").replace('"', "") parsed = pendulum.parse(serialized) for attr in ("year", "month", "day", "hour", "minute", "second", "microsecond"): assert getattr(obj, attr) == getattr(parsed, attr) class TestDate: def test_date(self): """ datetime.date """ assert orjson.dumps([datetime.date(2000, 1, 13)]) == b'["2000-01-13"]' def test_date_min(self): """ datetime.date MINYEAR """ assert ( orjson.dumps([datetime.date(datetime.MINYEAR, 1, 1)]) == b'["0001-01-01"]' ) def test_date_max(self): """ datetime.date MAXYEAR """ assert ( orjson.dumps([datetime.date(datetime.MAXYEAR, 12, 31)]) == b'["9999-12-31"]' ) def test_date_three_digits(self): """ datetime.date three digit year """ assert ( orjson.dumps( [datetime.date(312, 1, 1)], ) == b'["0312-01-01"]' ) def test_date_two_digits(self): """ datetime.date two digit year """ assert ( orjson.dumps( [datetime.date(46, 1, 1)], ) == b'["0046-01-01"]' ) class TestTime: def test_time(self): """ datetime.time """ assert orjson.dumps([datetime.time(12, 15, 59, 111)]) == b'["12:15:59.000111"]' assert orjson.dumps([datetime.time(12, 15, 59)]) == b'["12:15:59"]' @pytest.mark.skipif(zoneinfo is None, reason="zoneinfo not available") def test_time_tz(self): """ datetime.time with tzinfo error """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps( [ datetime.time( 12, 15, 59, 111, tzinfo=zoneinfo.ZoneInfo("Asia/Shanghai"), ), ], ) def test_time_microsecond_max(self): """ datetime.time microsecond max """ assert orjson.dumps(datetime.time(0, 0, 0, 999999)) == b'"00:00:00.999999"' def test_time_microsecond_min(self): """ datetime.time microsecond min """ assert orjson.dumps(datetime.time(0, 0, 0, 1)) == b'"00:00:00.000001"' class TestDateclassPassthrough: def test_passthrough_datetime(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps( datetime.datetime(1970, 1, 1), option=orjson.OPT_PASSTHROUGH_DATETIME, ) def test_passthrough_date(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps( datetime.date(1970, 1, 1), option=orjson.OPT_PASSTHROUGH_DATETIME, ) def test_passthrough_time(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps( datetime.time(12, 0, 0), option=orjson.OPT_PASSTHROUGH_DATETIME, ) def test_passthrough_datetime_default(self): def default(obj): return obj.strftime("%a, %d %b %Y %H:%M:%S GMT") assert ( orjson.dumps( datetime.datetime(1970, 1, 1), option=orjson.OPT_PASSTHROUGH_DATETIME, default=default, ) == b'"Thu, 01 Jan 1970 00:00:00 GMT"' ) ijl-orjson-aa8c946/test/test_default.py000066400000000000000000000215541505336676500202640ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import datetime import sys import uuid import pytest import orjson from .util import numpy class Custom: def __init__(self): self.name = uuid.uuid4().hex def __str__(self): return f"{self.__class__.__name__}({self.name})" class Recursive: def __init__(self, cur): self.cur = cur def default_recursive(obj): if obj.cur != 0: obj.cur -= 1 return obj return obj.cur def default_raises(obj): raise TypeError class TestType: def test_default_not_callable(self): """ dumps() default not callable """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps(Custom(), default=NotImplementedError) ran = False try: orjson.dumps(Custom(), default=NotImplementedError) except Exception as err: assert isinstance(err, orjson.JSONEncodeError) assert str(err) == "default serializer exceeds recursion limit" ran = True assert ran def test_default_func(self): """ dumps() default function """ ref = Custom() def default(obj): return str(obj) assert orjson.dumps(ref, default=default) == b'"%s"' % str(ref).encode("utf-8") def test_default_func_none(self): """ dumps() default function None ok """ assert orjson.dumps(Custom(), default=lambda x: None) == b"null" def test_default_func_empty(self): """ dumps() default function no explicit return """ ref = Custom() def default(obj): if isinstance(obj, set): return list(obj) assert orjson.dumps(ref, default=default) == b"null" assert orjson.dumps({ref}, default=default) == b"[null]" def test_default_func_exc(self): """ dumps() default function raises exception """ def default(obj): raise NotImplementedError with pytest.raises(orjson.JSONEncodeError): orjson.dumps(Custom(), default=default) ran = False try: orjson.dumps(Custom(), default=default) except Exception as err: assert isinstance(err, orjson.JSONEncodeError) assert str(err) == "Type is not JSON serializable: Custom" ran = True assert ran def test_default_exception_type(self): """ dumps() TypeError in default() raises orjson.JSONEncodeError """ ref = Custom() with pytest.raises(orjson.JSONEncodeError): orjson.dumps(ref, default=default_raises) def test_default_vectorcall_str(self): """ dumps() default function vectorcall str """ class SubStr(str): pass obj = SubStr("saasa") ref = b'"%s"' % str(obj).encode("utf-8") assert ( orjson.dumps(obj, option=orjson.OPT_PASSTHROUGH_SUBCLASS, default=str) == ref ) def test_default_vectorcall_list(self): """ dumps() default function vectorcall list """ obj = {1, 2} ref = b"[1,2]" assert orjson.dumps(obj, default=list) == ref def test_default_func_nested_str(self): """ dumps() default function nested str """ ref = Custom() def default(obj): return str(obj) assert orjson.dumps({"a": ref}, default=default) == b'{"a":"%s"}' % str( ref, ).encode("utf-8") def test_default_func_list(self): """ dumps() default function nested list """ ref = Custom() def default(obj): if isinstance(obj, Custom): return [str(obj)] assert orjson.dumps({"a": ref}, default=default) == b'{"a":["%s"]}' % str( ref, ).encode("utf-8") def test_default_func_nested_list(self): """ dumps() default function list """ ref = Custom() def default(obj): return str(obj) assert orjson.dumps([ref] * 100, default=default) == b"[%s]" % b",".join( b'"%s"' % str(ref).encode("utf-8") for _ in range(100) ) def test_default_func_bytes(self): """ dumps() default function errors on non-str """ ref = Custom() def default(obj): return bytes(obj) with pytest.raises(orjson.JSONEncodeError): orjson.dumps(ref, default=default) ran = False try: orjson.dumps(ref, default=default) except Exception as err: assert isinstance(err, orjson.JSONEncodeError) assert str(err) == "Type is not JSON serializable: Custom" ran = True assert ran def test_default_func_invalid_str(self): """ dumps() default function errors on invalid str """ ref = Custom() def default(obj): return "\ud800" with pytest.raises(orjson.JSONEncodeError): orjson.dumps(ref, default=default) def test_default_lambda_ok(self): """ dumps() default lambda """ ref = Custom() assert orjson.dumps(ref, default=lambda x: str(x)) == b'"%s"' % str(ref).encode( "utf-8", ) def test_default_callable_ok(self): """ dumps() default callable """ class CustomSerializer: def __init__(self): self._cache = {} def __call__(self, obj): if obj not in self._cache: self._cache[obj] = str(obj) return self._cache[obj] ref_obj = Custom() ref_bytes = b'"%s"' % str(ref_obj).encode("utf-8") for obj in [ref_obj] * 100: assert orjson.dumps(obj, default=CustomSerializer()) == ref_bytes def test_default_recursion(self): """ dumps() default recursion limit """ assert orjson.dumps(Recursive(254), default=default_recursive) == b"0" def test_default_recursion_reset(self): """ dumps() default recursion limit reset """ assert ( orjson.dumps( [Recursive(254), {"a": "b"}, Recursive(254), Recursive(254)], default=default_recursive, ) == b'[0,{"a":"b"},0,0]' ) def test_default_recursion_infinite(self): """ dumps() default infinite recursion """ ref = Custom() def default(obj): return obj refcount = sys.getrefcount(ref) with pytest.raises(orjson.JSONEncodeError): orjson.dumps(ref, default=default) assert sys.getrefcount(ref) == refcount def test_reference_cleanup_default_custom_pass(self): ref = Custom() def default(obj): if isinstance(ref, Custom): return str(ref) raise TypeError refcount = sys.getrefcount(ref) orjson.dumps(ref, default=default) assert sys.getrefcount(ref) == refcount def test_reference_cleanup_default_custom_error(self): """ references to encoded objects are cleaned up """ ref = Custom() def default(obj): raise TypeError refcount = sys.getrefcount(ref) with pytest.raises(orjson.JSONEncodeError): orjson.dumps(ref, default=default) assert sys.getrefcount(ref) == refcount def test_reference_cleanup_default_subclass(self): ref = datetime.datetime(1970, 1, 1, 0, 0, 0) def default(obj): if isinstance(ref, datetime.datetime): return repr(ref) raise TypeError refcount = sys.getrefcount(ref) orjson.dumps(ref, option=orjson.OPT_PASSTHROUGH_DATETIME, default=default) assert sys.getrefcount(ref) == refcount def test_reference_cleanup_default_subclass_lambda(self): ref = uuid.uuid4() refcount = sys.getrefcount(ref) orjson.dumps( ref, option=orjson.OPT_PASSTHROUGH_DATETIME, default=lambda val: str(val), ) assert sys.getrefcount(ref) == refcount @pytest.mark.skipif(numpy is None, reason="numpy is not installed") def test_default_numpy(self): ref = numpy.array([""] * 100) # type: ignore refcount = sys.getrefcount(ref) orjson.dumps( ref, option=orjson.OPT_SERIALIZE_NUMPY, default=lambda val: val.tolist(), ) assert sys.getrefcount(ref) == refcount def test_default_set(self): """ dumps() default function with set """ def default(obj): if isinstance(obj, set): return list(obj) raise TypeError assert orjson.dumps({1, 2}, default=default) == b"[1,2]" ijl-orjson-aa8c946/test/test_dict.py000066400000000000000000000125021505336676500175540ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest import orjson class TestDict: def test_dict(self): """ dict """ obj = {"key": "value"} ref = '{"key":"value"}' assert orjson.dumps(obj) == ref.encode("utf-8") assert orjson.loads(ref) == obj def test_dict_duplicate_loads(self): assert orjson.loads(b'{"1":true,"1":false}') == {"1": False} def test_dict_empty(self): obj = [{"key": [{}] * 4096}] * 4096 # type:ignore assert orjson.loads(orjson.dumps(obj)) == obj def test_dict_large_dict(self): """ dict with >512 keys """ obj = {f"key_{idx}": [{}, {"a": [{}, {}, {}]}, {}] for idx in range(513)} # type: ignore assert len(obj) == 513 assert orjson.loads(orjson.dumps(obj)) == obj def test_dict_large_4096(self): """ dict with >4096 keys """ obj = {f"key_{idx}": f"value_{idx}" for idx in range(4097)} assert len(obj) == 4097 assert orjson.loads(orjson.dumps(obj)) == obj def test_dict_large_65536(self): """ dict with >65536 keys """ obj = {f"key_{idx}": f"value_{idx}" for idx in range(65537)} assert len(obj) == 65537 assert orjson.loads(orjson.dumps(obj)) == obj def test_dict_large_keys(self): """ dict with keys too large to cache """ obj = { "keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey": "value", } ref = '{"keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey":"value"}' assert orjson.dumps(obj) == ref.encode("utf-8") assert orjson.loads(ref) == obj def test_dict_unicode(self): """ dict unicode keys """ obj = {"🐈": "value"} ref = b'{"\xf0\x9f\x90\x88":"value"}' assert orjson.dumps(obj) == ref assert orjson.loads(ref) == obj assert orjson.loads(ref)["🐈"] == "value" def test_dict_invalid_key_dumps(self): """ dict invalid key dumps() """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps({1: "value"}) with pytest.raises(orjson.JSONEncodeError): orjson.dumps({b"key": "value"}) def test_dict_invalid_key_loads(self): """ dict invalid key loads() """ with pytest.raises(orjson.JSONDecodeError): orjson.loads('{1:"value"}') with pytest.raises(orjson.JSONDecodeError): orjson.loads('{{"a":true}:true}') def test_dict_similar_keys(self): """ loads() similar keys This was a regression in 3.4.2 caused by using the implementation in wy instead of wyhash. """ assert orjson.loads( '{"cf_status_firefox67": "---", "cf_status_firefox57": "verified"}', ) == {"cf_status_firefox57": "verified", "cf_status_firefox67": "---"} def test_dict_pop_replace_first(self): "Test pop and replace a first key in a dict with other keys." data = {"id": "any", "other": "any"} data.pop("id") assert orjson.dumps(data) == b'{"other":"any"}' data["id"] = "new" assert orjson.dumps(data) == b'{"other":"any","id":"new"}' def test_dict_pop_replace_last(self): "Test pop and replace a last key in a dict with other keys." data = {"other": "any", "id": "any"} data.pop("id") assert orjson.dumps(data) == b'{"other":"any"}' data["id"] = "new" assert orjson.dumps(data) == b'{"other":"any","id":"new"}' def test_dict_pop(self): "Test pop and replace a key in a dict with no other keys." data = {"id": "any"} data.pop("id") assert orjson.dumps(data) == b"{}" data["id"] = "new" assert orjson.dumps(data) == b'{"id":"new"}' def test_in_place(self): "Mutate dict in-place" data = {"id": "any", "static": "msg"} data["id"] = "new" assert orjson.dumps(data) == b'{"id":"new","static":"msg"}' def test_dict_0xff(self): "dk_size <= 0xff" data = {str(idx): idx for idx in range(0xFF)} data.pop("112") data["112"] = 1 data["113"] = 2 assert orjson.loads(orjson.dumps(data)) == data def test_dict_0xff_repeated(self): "dk_size <= 0xff repeated" for _ in range(100): data = {str(idx): idx for idx in range(0xFF)} data.pop("112") data["112"] = 1 data["113"] = 2 assert orjson.loads(orjson.dumps(data)) == data def test_dict_0xffff(self): "dk_size <= 0xffff" data = {str(idx): idx for idx in range(0xFFFF)} data.pop("112") data["112"] = 1 data["113"] = 2 assert orjson.loads(orjson.dumps(data)) == data def test_dict_0xffff_repeated(self): "dk_size <= 0xffff repeated" for _ in range(100): data = {str(idx): idx for idx in range(0xFFFF)} data.pop("112") data["112"] = 1 data["113"] = 2 assert orjson.loads(orjson.dumps(data)) == data def test_dict_dict(self): class C: def __init__(self): self.a = 0 self.b = 1 assert orjson.dumps(C().__dict__) == b'{"a":0,"b":1}' ijl-orjson-aa8c946/test/test_enum.py000066400000000000000000000051261505336676500176010ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import datetime import enum import pytest import orjson class StrEnum(str, enum.Enum): AAA = "aaa" class IntEnum(int, enum.Enum): ONE = 1 class IntEnumEnum(enum.IntEnum): ONE = 1 class IntFlagEnum(enum.IntFlag): ONE = 1 class FlagEnum(enum.Flag): ONE = 1 class AutoEnum(enum.auto): A = "a" class FloatEnum(float, enum.Enum): ONE = 1.1 class Custom: def __init__(self, val): self.val = val def default(obj): if isinstance(obj, Custom): return obj.val raise TypeError class UnspecifiedEnum(enum.Enum): A = "a" B = 1 C = FloatEnum.ONE D = {"d": IntEnum.ONE} # noqa: RUF012 E = Custom("c") F = datetime.datetime(1970, 1, 1) class TestEnum: def test_cannot_subclass(self): """ enum.Enum cannot be subclassed obj->ob_type->ob_base will always be enum.EnumMeta """ with pytest.raises(TypeError): class Subclass(StrEnum): # type: ignore B = "b" def test_arbitrary_enum(self): assert orjson.dumps(UnspecifiedEnum.A) == b'"a"' assert orjson.dumps(UnspecifiedEnum.B) == b"1" assert orjson.dumps(UnspecifiedEnum.C) == b"1.1" assert orjson.dumps(UnspecifiedEnum.D) == b'{"d":1}' def test_custom_enum(self): assert orjson.dumps(UnspecifiedEnum.E, default=default) == b'"c"' def test_enum_options(self): assert ( orjson.dumps(UnspecifiedEnum.F, option=orjson.OPT_NAIVE_UTC) == b'"1970-01-01T00:00:00+00:00"' ) def test_int_enum(self): assert orjson.dumps(IntEnum.ONE) == b"1" def test_intenum_enum(self): assert orjson.dumps(IntEnumEnum.ONE) == b"1" def test_intflag_enum(self): assert orjson.dumps(IntFlagEnum.ONE) == b"1" def test_flag_enum(self): assert orjson.dumps(FlagEnum.ONE) == b"1" def test_auto_enum(self): assert orjson.dumps(AutoEnum.A) == b'"a"' def test_float_enum(self): assert orjson.dumps(FloatEnum.ONE) == b"1.1" def test_str_enum(self): assert orjson.dumps(StrEnum.AAA) == b'"aaa"' def test_bool_enum(self): with pytest.raises(TypeError): class BoolEnum(bool, enum.Enum): # type: ignore TRUE = True def test_non_str_keys_enum(self): assert ( orjson.dumps({StrEnum.AAA: 1}, option=orjson.OPT_NON_STR_KEYS) == b'{"aaa":1}' ) assert ( orjson.dumps({IntEnum.ONE: 1}, option=orjson.OPT_NON_STR_KEYS) == b'{"1":1}' ) ijl-orjson-aa8c946/test/test_error.py000066400000000000000000000124571505336676500177730ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import json import pytest import orjson from .util import needs_data, read_fixture_str ASCII_TEST = b"""\ { "a": "qwe", "b": "qweqwe", "c": "qweq", "d: "qwe" } """ MULTILINE_EMOJI = """[ "😊", "a" """ class TestJsonDecodeError: def _get_error_infos(self, json_decode_error_exc_info): return { k: v for k, v in json_decode_error_exc_info.value.__dict__.items() if k in ("pos", "lineno", "colno") } def _test(self, data, expected_err_infos): with pytest.raises(json.decoder.JSONDecodeError) as json_exc_info: json.loads(data) with pytest.raises(json.decoder.JSONDecodeError) as orjson_exc_info: orjson.loads(data) assert ( self._get_error_infos(json_exc_info) == self._get_error_infos(orjson_exc_info) == expected_err_infos ) def test_empty(self): with pytest.raises(orjson.JSONDecodeError) as json_exc_info: orjson.loads("") assert str(json_exc_info.value).startswith( "Input is a zero-length, empty document:", ) def test_ascii(self): self._test( ASCII_TEST, {"pos": 55, "lineno": 5, "colno": 8}, ) def test_latin1(self): self._test( """["üýþÿ", "a" """, {"pos": 13, "lineno": 1, "colno": 14}, ) def test_two_byte_str(self): self._test( """["東京", "a" """, {"pos": 11, "lineno": 1, "colno": 12}, ) def test_two_byte_bytes(self): self._test( b'["\xe6\x9d\xb1\xe4\xba\xac", "a" ', {"pos": 11, "lineno": 1, "colno": 12}, ) def test_four_byte(self): self._test( MULTILINE_EMOJI, {"pos": 19, "lineno": 4, "colno": 1}, ) @needs_data def test_tab(self): data = read_fixture_str("fail26.json", "jsonchecker") with pytest.raises(json.decoder.JSONDecodeError) as json_exc_info: json.loads(data) assert self._get_error_infos(json_exc_info) == { "pos": 5, "lineno": 1, "colno": 6, } with pytest.raises(json.decoder.JSONDecodeError) as json_exc_info: orjson.loads(data) assert self._get_error_infos(json_exc_info) == { "pos": 6, "lineno": 1, "colno": 7, } class Custom: pass class CustomException(Exception): pass def default_typeerror(obj): raise TypeError def default_notimplementederror(obj): raise NotImplementedError def default_systemerror(obj): raise SystemError def default_importerror(obj): import doesnotexist # noqa: PLC0415 assert doesnotexist CUSTOM_ERROR_MESSAGE = "zxc" def default_customerror(obj): raise CustomException(CUSTOM_ERROR_MESSAGE) class TestJsonEncodeError: def test_dumps_arg(self): with pytest.raises(orjson.JSONEncodeError) as exc_info: orjson.dumps() # type: ignore assert exc_info.type == orjson.JSONEncodeError assert ( str(exc_info.value) == "dumps() missing 1 required positional argument: 'obj'" ) assert exc_info.value.__cause__ is None def test_dumps_chain_none(self): with pytest.raises(orjson.JSONEncodeError) as exc_info: orjson.dumps(Custom()) assert exc_info.type == orjson.JSONEncodeError assert str(exc_info.value) == "Type is not JSON serializable: Custom" assert exc_info.value.__cause__ is None def test_dumps_chain_u64(self): with pytest.raises(orjson.JSONEncodeError) as exc_info: orjson.dumps([18446744073709551615, Custom()]) assert exc_info.type == orjson.JSONEncodeError assert exc_info.value.__cause__ is None def test_dumps_chain_default_typeerror(self): with pytest.raises(orjson.JSONEncodeError) as exc_info: orjson.dumps(Custom(), default=default_typeerror) assert exc_info.type == orjson.JSONEncodeError assert isinstance(exc_info.value.__cause__, TypeError) def test_dumps_chain_default_systemerror(self): with pytest.raises(orjson.JSONEncodeError) as exc_info: orjson.dumps(Custom(), default=default_systemerror) assert exc_info.type == orjson.JSONEncodeError assert isinstance(exc_info.value.__cause__, SystemError) def test_dumps_chain_default_importerror(self): with pytest.raises(orjson.JSONEncodeError) as exc_info: orjson.dumps(Custom(), default=default_importerror) assert exc_info.type == orjson.JSONEncodeError assert isinstance(exc_info.value.__cause__, ImportError) def test_dumps_chain_default_customerror(self): with pytest.raises(orjson.JSONEncodeError) as exc_info: orjson.dumps(Custom(), default=default_customerror) assert exc_info.type == orjson.JSONEncodeError assert isinstance(exc_info.value.__cause__, CustomException) assert str(exc_info.value.__cause__) == CUSTOM_ERROR_MESSAGE def test_dumps_normalize_exception(self): with pytest.raises(orjson.JSONEncodeError) as exc_info: orjson.dumps(10**60) assert exc_info.type == orjson.JSONEncodeError ijl-orjson-aa8c946/test/test_escape.py000066400000000000000000000042101505336676500200660ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import orjson def test_issue565(): assert ( orjson.dumps("\n\r\u000b\f\u001c\u001d\u001e") == b'"\\n\\r\\u000b\\f\\u001c\\u001d\\u001e"' ) def test_0x00(): assert orjson.dumps("\u0000") == b'"\\u0000"' def test_0x01(): assert orjson.dumps("\u0001") == b'"\\u0001"' def test_0x02(): assert orjson.dumps("\u0002") == b'"\\u0002"' def test_0x03(): assert orjson.dumps("\u0003") == b'"\\u0003"' def test_0x04(): assert orjson.dumps("\u0004") == b'"\\u0004"' def test_0x05(): assert orjson.dumps("\u0005") == b'"\\u0005"' def test_0x06(): assert orjson.dumps("\u0006") == b'"\\u0006"' def test_0x07(): assert orjson.dumps("\u0007") == b'"\\u0007"' def test_0x08(): assert orjson.dumps("\u0008") == b'"\\b"' def test_0x09(): assert orjson.dumps("\u0009") == b'"\\t"' def test_0x0a(): assert orjson.dumps("\u000a") == b'"\\n"' def test_0x0b(): assert orjson.dumps("\u000b") == b'"\\u000b"' def test_0x0c(): assert orjson.dumps("\u000c") == b'"\\f"' def test_0x0d(): assert orjson.dumps("\u000d") == b'"\\r"' def test_0x0e(): assert orjson.dumps("\u000e") == b'"\\u000e"' def test_0x0f(): assert orjson.dumps("\u000f") == b'"\\u000f"' def test_0x10(): assert orjson.dumps("\u0010") == b'"\\u0010"' def test_0x11(): assert orjson.dumps("\u0011") == b'"\\u0011"' def test_0x12(): assert orjson.dumps("\u0012") == b'"\\u0012"' def test_0x13(): assert orjson.dumps("\u0013") == b'"\\u0013"' def test_0x14(): assert orjson.dumps("\u0014") == b'"\\u0014"' def test_0x15(): assert orjson.dumps("\u0015") == b'"\\u0015"' def test_0x16(): assert orjson.dumps("\u0016") == b'"\\u0016"' def test_0x17(): assert orjson.dumps("\u0017") == b'"\\u0017"' def test_0x18(): assert orjson.dumps("\u0018") == b'"\\u0018"' def test_0x19(): assert orjson.dumps("\u0019") == b'"\\u0019"' def test_0x1a(): assert orjson.dumps("\u001a") == b'"\\u001a"' def test_backslash(): assert orjson.dumps("\\") == b'"\\\\"' def test_quote(): assert orjson.dumps('"') == b'"\\""' ijl-orjson-aa8c946/test/test_fake.py000066400000000000000000000021241505336676500175360ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import random import pytest import orjson try: from faker import Faker except ImportError: Faker = None # type: ignore NUM_LOOPS = 10 NUM_SHUFFLES = 10 NUM_ENTRIES = 250 FAKER_LOCALES = [ "ar_AA", "fi_FI", "fil_PH", "he_IL", "ja_JP", "th_TH", "tr_TR", "uk_UA", "vi_VN", ] class TestFaker: @pytest.mark.skipif(Faker is None, reason="faker not available") def test_faker(self): fake = Faker(FAKER_LOCALES) profile_keys = list( set(fake.profile().keys()) - {"birthdate", "current_location"}, ) for _ in range(NUM_LOOPS): data = [ { "person": fake.profile(profile_keys), "emoji": fake.emoji(), "text": fake.paragraphs(), } for _ in range(NUM_ENTRIES) ] for _ in range(NUM_SHUFFLES): random.shuffle(data) output = orjson.dumps(data) assert orjson.loads(output) == data ijl-orjson-aa8c946/test/test_fixture.py000066400000000000000000000027741505336676500203310ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest import orjson from .util import needs_data, read_fixture_bytes, read_fixture_str @needs_data class TestFixture: def test_twitter(self): """ loads(),dumps() twitter.json """ val = read_fixture_str("twitter.json.xz") read = orjson.loads(val) assert orjson.loads(orjson.dumps(read)) == read @needs_data def test_canada(self): """ loads(), dumps() canada.json """ val = read_fixture_str("canada.json.xz") read = orjson.loads(val) assert orjson.loads(orjson.dumps(read)) == read def test_citm_catalog(self): """ loads(), dumps() citm_catalog.json """ val = read_fixture_str("citm_catalog.json.xz") read = orjson.loads(val) assert orjson.loads(orjson.dumps(read)) == read def test_github(self): """ loads(), dumps() github.json """ val = read_fixture_str("github.json.xz") read = orjson.loads(val) assert orjson.loads(orjson.dumps(read)) == read def test_blns(self): """ loads() blns.json JSONDecodeError https://github.com/minimaxir/big-list-of-naughty-strings """ val = read_fixture_bytes("blns.txt.xz") for line in val.split(b"\n"): if line and not line.startswith(b"#"): with pytest.raises(orjson.JSONDecodeError): _ = orjson.loads(b'"' + val + b'"') ijl-orjson-aa8c946/test/test_fragment.py000066400000000000000000001170141505336676500204400ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest import orjson try: import pandas as pd except ImportError: pd = None # type: ignore from .util import needs_data, read_fixture_bytes class TestFragment: def test_fragment_fragment_eq(self): assert orjson.Fragment(b"{}") != orjson.Fragment(b"{}") def test_fragment_fragment_not_mut(self): fragment = orjson.Fragment(b"{}") with pytest.raises(AttributeError): fragment.contents = b"[]" assert orjson.dumps(fragment) == b"{}" def test_fragment_repr(self): assert repr(orjson.Fragment(b"{}")).startswith("?","hex":"ģ䕧覫췯ꯍ\uef4a","true":true,"false":false,"null":null,"array":[],"object":{},"address":"50 St. James Street","url":"http://www.JSON.org/","comment":"// /* */":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\\"object with 1 member\\":[\\"array with 1 element\\"]}","quotes":"" \\" %22 0x22 034 "","/\\\\\\"쫾몾ꮘﳞ볚\uef4a\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?":"A key can be any string"},0.5,98.6,99.44,1066,10.0,1.0,0.1,1.0,2.0,2.0,"rosebud"]'.encode() @needs_data class TestJsonChecker: def _run_fail_json(self, filename, exc=orjson.JSONDecodeError): data = read_fixture_str(filename, "jsonchecker") pytest.raises(exc, orjson.loads, data) def _run_pass_json(self, filename, match=""): data = read_fixture_str(filename, "jsonchecker") assert orjson.dumps(orjson.loads(data)) == match def test_fail01(self): """ fail01.json """ self._run_pass_json( "fail01.json", b'"A JSON payload should be an object or array, not a string."', ) def test_fail02(self): """ fail02.json """ self._run_fail_json("fail02.json", orjson.JSONDecodeError) # EOF def test_fail03(self): """ fail03.json """ self._run_fail_json("fail03.json") def test_fail04(self): """ fail04.json """ self._run_fail_json("fail04.json") def test_fail05(self): """ fail05.json """ self._run_fail_json("fail05.json") def test_fail06(self): """ fail06.json """ self._run_fail_json("fail06.json") def test_fail07(self): """ fail07.json """ self._run_fail_json("fail07.json") def test_fail08(self): """ fail08.json """ self._run_fail_json("fail08.json") def test_fail09(self): """ fail09.json """ self._run_fail_json("fail09.json") def test_fail10(self): """ fail10.json """ self._run_fail_json("fail10.json") def test_fail11(self): """ fail11.json """ self._run_fail_json("fail11.json") def test_fail12(self): """ fail12.json """ self._run_fail_json("fail12.json") def test_fail13(self): """ fail13.json """ self._run_fail_json("fail13.json") def test_fail14(self): """ fail14.json """ self._run_fail_json("fail14.json") def test_fail15(self): """ fail15.json """ self._run_fail_json("fail15.json") def test_fail16(self): """ fail16.json """ self._run_fail_json("fail16.json") def test_fail17(self): """ fail17.json """ self._run_fail_json("fail17.json") def test_fail18(self): """ fail18.json """ self._run_pass_json( "fail18.json", b'[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]', ) def test_fail19(self): """ fail19.json """ self._run_fail_json("fail19.json") def test_fail20(self): """ fail20.json """ self._run_fail_json("fail20.json") def test_fail21(self): """ fail21.json """ self._run_fail_json("fail21.json") def test_fail22(self): """ fail22.json """ self._run_fail_json("fail22.json") def test_fail23(self): """ fail23.json """ self._run_fail_json("fail23.json") def test_fail24(self): """ fail24.json """ self._run_fail_json("fail24.json") def test_fail25(self): """ fail25.json """ self._run_fail_json("fail25.json") def test_fail26(self): """ fail26.json """ self._run_fail_json("fail26.json") def test_fail27(self): """ fail27.json """ self._run_fail_json("fail27.json") def test_fail28(self): """ fail28.json """ self._run_fail_json("fail28.json") def test_fail29(self): """ fail29.json """ self._run_fail_json("fail29.json") def test_fail30(self): """ fail30.json """ self._run_fail_json("fail30.json") def test_fail31(self): """ fail31.json """ self._run_fail_json("fail31.json") def test_fail32(self): """ fail32.json """ self._run_fail_json("fail32.json", orjson.JSONDecodeError) # EOF def test_fail33(self): """ fail33.json """ self._run_fail_json("fail33.json") def test_pass01(self): """ pass01.json """ self._run_pass_json("pass01.json", PATTERN_1) def test_pass02(self): """ pass02.json """ self._run_pass_json( "pass02.json", b'[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]', ) def test_pass03(self): """ pass03.json """ self._run_pass_json( "pass03.json", b'{"JSON Test Pattern pass3":{"The outermost value":"must be ' b'an object or array.","In this test":"It is an object."}}', ) ijl-orjson-aa8c946/test/test_memory.py000066400000000000000000000200771505336676500201470ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import dataclasses import datetime import gc import random from .util import numpy, pandas try: import pytz except ImportError: pytz = None # type: ignore try: import psutil except ImportError: psutil = None # type: ignore import pytest import orjson FIXTURE = '{"a":[81891289, 8919812.190129012], "b": false, "c": null, "d": "東京"}' def default(obj): return str(obj) @dataclasses.dataclass class Member: id: int active: bool @dataclasses.dataclass class Object: id: int updated_at: datetime.datetime name: str members: list[Member] DATACLASS_FIXTURE = [ Object( i, datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=random.randint(0, 10000)), str(i) * 3, [Member(j, True) for j in range(10)], ) for i in range(100000, 101000) ] MAX_INCREASE = 4194304 # 4MiB class Unsupported: pass class TestMemory: @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_loads(self): """ loads() memory leak """ proc = psutil.Process() gc.collect() val = orjson.loads(FIXTURE) assert val mem = proc.memory_info().rss for _ in range(10000): val = orjson.loads(FIXTURE) assert val gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_loads_memoryview(self): """ loads() memory leak using memoryview """ proc = psutil.Process() gc.collect() fixture = FIXTURE.encode("utf-8") val = orjson.loads(fixture) assert val mem = proc.memory_info().rss for _ in range(10000): val = orjson.loads(memoryview(fixture)) assert val gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_dumps(self): """ dumps() memory leak """ proc = psutil.Process() gc.collect() fixture = orjson.loads(FIXTURE) val = orjson.dumps(fixture) assert val mem = proc.memory_info().rss for _ in range(10000): val = orjson.dumps(fixture) assert val gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_loads_exc(self): """ loads() memory leak exception without a GC pause """ proc = psutil.Process() gc.disable() mem = proc.memory_info().rss n = 10000 i = 0 for _ in range(n): try: orjson.loads("") except orjson.JSONDecodeError: i += 1 assert n == i assert proc.memory_info().rss <= mem + MAX_INCREASE gc.enable() @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_dumps_exc(self): """ dumps() memory leak exception without a GC pause """ proc = psutil.Process() gc.disable() data = Unsupported() mem = proc.memory_info().rss n = 10000 i = 0 for _ in range(n): try: orjson.dumps(data) except orjson.JSONEncodeError: i += 1 assert n == i assert proc.memory_info().rss <= mem + MAX_INCREASE gc.enable() @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_dumps_default(self): """ dumps() default memory leak """ proc = psutil.Process() gc.collect() fixture = orjson.loads(FIXTURE) class Custom: def __init__(self, name): self.name = name def __str__(self): return f"{self.__class__.__name__}({self.name})" fixture["custom"] = Custom("orjson") val = orjson.dumps(fixture, default=default) mem = proc.memory_info().rss for _ in range(10000): val = orjson.dumps(fixture, default=default) assert val gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_dumps_dataclass(self): """ dumps() dataclass memory leak """ proc = psutil.Process() gc.collect() val = orjson.dumps(DATACLASS_FIXTURE) assert val mem = proc.memory_info().rss for _ in range(100): val = orjson.dumps(DATACLASS_FIXTURE) assert val assert val gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif( psutil is None or pytz is None, reason="psutil not installed", ) def test_memory_dumps_pytz_tzinfo(self): """ dumps() pytz tzinfo memory leak """ proc = psutil.Process() gc.collect() dt = datetime.datetime.now() val = orjson.dumps(pytz.UTC.localize(dt)) assert val mem = proc.memory_info().rss for _ in range(50000): val = orjson.dumps(pytz.UTC.localize(dt)) assert val assert val gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_loads_keys(self): """ loads() memory leak with number of keys causing cache eviction """ proc = psutil.Process() gc.collect() fixture = {f"key_{idx}": "value" for idx in range(1024)} assert len(fixture) == 1024 val = orjson.dumps(fixture) loaded = orjson.loads(val) assert loaded mem = proc.memory_info().rss for _ in range(100): loaded = orjson.loads(val) assert loaded gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif(psutil is None, reason="psutil not installed") @pytest.mark.skipif(numpy is None, reason="numpy is not installed") def test_memory_dumps_numpy(self): """ dumps() numpy memory leak """ proc = psutil.Process() gc.collect() fixture = numpy.random.rand(4, 4, 4) # type: ignore val = orjson.dumps(fixture, option=orjson.OPT_SERIALIZE_NUMPY) assert val mem = proc.memory_info().rss for _ in range(100): val = orjson.dumps(fixture, option=orjson.OPT_SERIALIZE_NUMPY) assert val assert val gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif(psutil is None, reason="psutil not installed") @pytest.mark.skipif(pandas is None, reason="pandas is not installed") def test_memory_dumps_pandas(self): """ dumps() pandas memory leak """ proc = psutil.Process() gc.collect() numpy.random.rand(4, 4, 4) # type: ignore df = pandas.Series(numpy.random.rand(4, 4, 4).tolist()) # type: ignore val = df.map(orjson.dumps) assert not val.empty mem = proc.memory_info().rss for _ in range(100): val = df.map(orjson.dumps) assert not val.empty gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memory_dumps_fragment(self): """ dumps() Fragment memory leak """ proc = psutil.Process() gc.collect() orjson.dumps(orjson.Fragment(str(0))) mem = proc.memory_info().rss for i in range(10000): orjson.dumps(orjson.Fragment(str(i))) gc.collect() assert proc.memory_info().rss <= mem + MAX_INCREASE ijl-orjson-aa8c946/test/test_non_str_keys.py000066400000000000000000000217251505336676500213550ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import dataclasses import datetime import uuid import pytest import orjson try: import pytz except ImportError: pytz = None # type: ignore from .util import numpy class SubStr(str): pass class TestNonStrKeyTests: def test_dict_keys_duplicate(self): """ OPT_NON_STR_KEYS serializes duplicate keys """ assert ( orjson.dumps({"1": True, 1: False}, option=orjson.OPT_NON_STR_KEYS) == b'{"1":true,"1":false}' ) def test_dict_keys_int(self): assert ( orjson.dumps({1: True, 2: False}, option=orjson.OPT_NON_STR_KEYS) == b'{"1":true,"2":false}' ) def test_dict_keys_substr(self): assert ( orjson.dumps({SubStr("aaa"): True}, option=orjson.OPT_NON_STR_KEYS) == b'{"aaa":true}' ) def test_dict_keys_substr_passthrough(self): """ OPT_PASSTHROUGH_SUBCLASS does not affect OPT_NON_STR_KEYS """ assert ( orjson.dumps( {SubStr("aaa"): True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_PASSTHROUGH_SUBCLASS, ) == b'{"aaa":true}' ) def test_dict_keys_substr_invalid(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps({SubStr("\ud800"): True}, option=orjson.OPT_NON_STR_KEYS) def test_dict_keys_strict(self): """ OPT_NON_STR_KEYS does not respect OPT_STRICT_INTEGER """ assert ( orjson.dumps( {9223372036854775807: True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_STRICT_INTEGER, ) == b'{"9223372036854775807":true}' ) def test_dict_keys_int_range_valid_i64(self): """ OPT_NON_STR_KEYS has a i64 range for int, valid """ assert ( orjson.dumps( {9223372036854775807: True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_STRICT_INTEGER, ) == b'{"9223372036854775807":true}' ) assert ( orjson.dumps( {-9223372036854775807: True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_STRICT_INTEGER, ) == b'{"-9223372036854775807":true}' ) assert ( orjson.dumps( {9223372036854775809: True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_STRICT_INTEGER, ) == b'{"9223372036854775809":true}' ) def test_dict_keys_int_range_valid_u64(self): """ OPT_NON_STR_KEYS has a u64 range for int, valid """ assert ( orjson.dumps( {0: True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_STRICT_INTEGER, ) == b'{"0":true}' ) assert ( orjson.dumps( {18446744073709551615: True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_STRICT_INTEGER, ) == b'{"18446744073709551615":true}' ) def test_dict_keys_int_range_invalid(self): """ OPT_NON_STR_KEYS has a range of i64::MIN to u64::MAX """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps({-9223372036854775809: True}, option=orjson.OPT_NON_STR_KEYS) with pytest.raises(orjson.JSONEncodeError): orjson.dumps({18446744073709551616: True}, option=orjson.OPT_NON_STR_KEYS) def test_dict_keys_float(self): assert ( orjson.dumps({1.1: True, 2.2: False}, option=orjson.OPT_NON_STR_KEYS) == b'{"1.1":true,"2.2":false}' ) def test_dict_keys_inf(self): assert ( orjson.dumps({float("Infinity"): True}, option=orjson.OPT_NON_STR_KEYS) == b'{"null":true}' ) assert ( orjson.dumps({float("-Infinity"): True}, option=orjson.OPT_NON_STR_KEYS) == b'{"null":true}' ) def test_dict_keys_nan(self): assert ( orjson.dumps({float("NaN"): True}, option=orjson.OPT_NON_STR_KEYS) == b'{"null":true}' ) def test_dict_keys_bool(self): assert ( orjson.dumps({True: True, False: False}, option=orjson.OPT_NON_STR_KEYS) == b'{"true":true,"false":false}' ) def test_dict_keys_datetime(self): assert ( orjson.dumps( {datetime.datetime(2000, 1, 1, 2, 3, 4, 123): True}, option=orjson.OPT_NON_STR_KEYS, ) == b'{"2000-01-01T02:03:04.000123":true}' ) def test_dict_keys_datetime_opt(self): assert ( orjson.dumps( {datetime.datetime(2000, 1, 1, 2, 3, 4, 123): True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_OMIT_MICROSECONDS | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'{"2000-01-01T02:03:04Z":true}' ) def test_dict_keys_datetime_passthrough(self): """ OPT_PASSTHROUGH_DATETIME does not affect OPT_NON_STR_KEYS """ assert ( orjson.dumps( {datetime.datetime(2000, 1, 1, 2, 3, 4, 123): True}, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_PASSTHROUGH_DATETIME, ) == b'{"2000-01-01T02:03:04.000123":true}' ) def test_dict_keys_uuid(self): """ OPT_NON_STR_KEYS always serializes UUID as keys """ assert ( orjson.dumps( {uuid.UUID("7202d115-7ff3-4c81-a7c1-2a1f067b1ece"): True}, option=orjson.OPT_NON_STR_KEYS, ) == b'{"7202d115-7ff3-4c81-a7c1-2a1f067b1ece":true}' ) def test_dict_keys_date(self): assert ( orjson.dumps( {datetime.date(1970, 1, 1): True}, option=orjson.OPT_NON_STR_KEYS, ) == b'{"1970-01-01":true}' ) def test_dict_keys_time(self): assert ( orjson.dumps( {datetime.time(12, 15, 59, 111): True}, option=orjson.OPT_NON_STR_KEYS, ) == b'{"12:15:59.000111":true}' ) def test_dict_non_str_and_sort_keys(self): assert ( orjson.dumps( { "other": 1, datetime.date(1970, 1, 5): 2, datetime.date(1970, 1, 3): 3, }, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS, ) == b'{"1970-01-03":3,"1970-01-05":2,"other":1}' ) @pytest.mark.skipif(pytz is None, reason="pytz optional") def test_dict_keys_time_err(self): """ OPT_NON_STR_KEYS propagates errors in types """ val = datetime.time(12, 15, 59, 111, tzinfo=pytz.timezone("Asia/Shanghai")) with pytest.raises(orjson.JSONEncodeError): orjson.dumps({val: True}, option=orjson.OPT_NON_STR_KEYS) def test_dict_keys_str(self): assert ( orjson.dumps({"1": True}, option=orjson.OPT_NON_STR_KEYS) == b'{"1":true}' ) def test_dict_keys_type(self): class Obj: a: str val = Obj() with pytest.raises(orjson.JSONEncodeError): orjson.dumps({val: True}, option=orjson.OPT_NON_STR_KEYS) @pytest.mark.skipif(numpy is None, reason="numpy is not installed") def test_dict_keys_array(self): with pytest.raises(TypeError): _ = {numpy.array([1, 2]): True} # type: ignore def test_dict_keys_dataclass(self): @dataclasses.dataclass class Dataclass: a: str with pytest.raises(TypeError): _ = {Dataclass("a"): True} def test_dict_keys_dataclass_hash(self): @dataclasses.dataclass class Dataclass: a: str def __hash__(self): return 1 obj = {Dataclass("a"): True} with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS) def test_dict_keys_list(self): with pytest.raises(TypeError): _ = {[]: True} def test_dict_keys_dict(self): with pytest.raises(TypeError): _ = {{}: True} def test_dict_keys_tuple(self): obj = {(): True} with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS) def test_dict_keys_unknown(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps({frozenset(): True}, option=orjson.OPT_NON_STR_KEYS) def test_dict_keys_no_str_call(self): class Obj: a: str def __str__(self): return "Obj" val = Obj() with pytest.raises(orjson.JSONEncodeError): orjson.dumps({val: True}, option=orjson.OPT_NON_STR_KEYS) ijl-orjson-aa8c946/test/test_numpy.py000066400000000000000000001061431505336676500200060ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) # mypy: ignore-errors import sys import pytest import orjson from .util import numpy def numpy_default(obj): if isinstance(obj, numpy.ndarray): return obj.tolist() raise TypeError @pytest.mark.skipif(numpy is None, reason="numpy is not installed") class TestNumpy: def test_numpy_array_d1_uintp(self): low = numpy.iinfo(numpy.uintp).min high = numpy.iinfo(numpy.uintp).max assert orjson.dumps( numpy.array([low, high], numpy.uintp), option=orjson.OPT_SERIALIZE_NUMPY, ) == f"[{low},{high}]".encode("ascii") def test_numpy_array_d1_intp(self): low = numpy.iinfo(numpy.intp).min high = numpy.iinfo(numpy.intp).max assert orjson.dumps( numpy.array([low, high], numpy.intp), option=orjson.OPT_SERIALIZE_NUMPY, ) == f"[{low},{high}]".encode("ascii") def test_numpy_array_d1_i64(self): assert ( orjson.dumps( numpy.array([-9223372036854775807, 9223372036854775807], numpy.int64), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[-9223372036854775807,9223372036854775807]" ) def test_numpy_array_d1_u64(self): assert ( orjson.dumps( numpy.array([0, 18446744073709551615], numpy.uint64), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[0,18446744073709551615]" ) def test_numpy_array_d1_i8(self): assert ( orjson.dumps( numpy.array([-128, 127], numpy.int8), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[-128,127]" ) def test_numpy_array_d1_u8(self): assert ( orjson.dumps( numpy.array([0, 255], numpy.uint8), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[0,255]" ) def test_numpy_array_d1_i32(self): assert ( orjson.dumps( numpy.array([-2147483647, 2147483647], numpy.int32), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[-2147483647,2147483647]" ) def test_numpy_array_d1_i16(self): assert ( orjson.dumps( numpy.array([-32768, 32767], numpy.int16), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[-32768,32767]" ) def test_numpy_array_d1_u16(self): assert ( orjson.dumps( numpy.array([0, 65535], numpy.uint16), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[0,65535]" ) def test_numpy_array_d1_u32(self): assert ( orjson.dumps( numpy.array([0, 4294967295], numpy.uint32), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[0,4294967295]" ) def test_numpy_array_d1_f32(self): assert ( orjson.dumps( numpy.array([1.0, 3.4028235e38], numpy.float32), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[1.0,3.4028235e38]" ) def test_numpy_array_d1_f16(self): assert ( orjson.dumps( numpy.array([-1.0, 0.0009765625, 1.0, 65504.0], numpy.float16), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[-1.0,0.0009765625,1.0,65504.0]" ) def test_numpy_array_f16_roundtrip(self): ref = [ -1.0, -2.0, 0.000000059604645, 0.000060975552, 0.00006103515625, 0.0009765625, 0.33325195, 0.99951172, 1.0, 1.00097656, 65504.0, ] obj = numpy.array(ref, numpy.float16) # type: ignore serialized = orjson.dumps( obj, option=orjson.OPT_SERIALIZE_NUMPY, ) deserialized = numpy.array(orjson.loads(serialized), numpy.float16) # type: ignore assert numpy.array_equal(obj, deserialized) def test_numpy_array_f16_edge(self): assert ( orjson.dumps( numpy.array( [ numpy.inf, -numpy.inf, numpy.nan, -0.0, 0.0, numpy.pi, ], numpy.float16, ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[null,null,null,-0.0,0.0,3.140625]" ) def test_numpy_array_f32_edge(self): assert ( orjson.dumps( numpy.array( [ numpy.inf, -numpy.inf, numpy.nan, -0.0, 0.0, numpy.pi, ], numpy.float32, ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[null,null,null,-0.0,0.0,3.1415927]" ) def test_numpy_array_f64_edge(self): assert ( orjson.dumps( numpy.array( [ numpy.inf, -numpy.inf, numpy.nan, -0.0, 0.0, numpy.pi, ], numpy.float64, ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[null,null,null,-0.0,0.0,3.141592653589793]" ) def test_numpy_array_d1_f64(self): assert ( orjson.dumps( numpy.array([1.0, 1.7976931348623157e308], numpy.float64), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[1.0,1.7976931348623157e308]" ) def test_numpy_array_d1_bool(self): assert ( orjson.dumps( numpy.array([True, False, False, True]), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[true,false,false,true]" ) def test_numpy_array_d1_datetime64_years(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("1"), numpy.datetime64("970"), numpy.datetime64("1920"), numpy.datetime64("1971"), numpy.datetime64("2021"), numpy.datetime64("2022"), numpy.datetime64("2023"), numpy.datetime64("9999"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["0001-01-01T00:00:00","0970-01-01T00:00:00","1920-01-01T00:00:00","1971-01-01T00:00:00","2021-01-01T00:00:00","2022-01-01T00:00:00","2023-01-01T00:00:00","9999-01-01T00:00:00"]' ) def test_numpy_array_d1_datetime64_months(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("2021-01"), numpy.datetime64("2022-01"), numpy.datetime64("2023-01"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["2021-01-01T00:00:00","2022-01-01T00:00:00","2023-01-01T00:00:00"]' ) def test_numpy_array_d1_datetime64_days(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("2021-01-01"), numpy.datetime64("2021-01-01"), numpy.datetime64("2021-01-01"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["2021-01-01T00:00:00","2021-01-01T00:00:00","2021-01-01T00:00:00"]' ) def test_numpy_array_d1_datetime64_hours(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("2021-01-01T00"), numpy.datetime64("2021-01-01T01"), numpy.datetime64("2021-01-01T02"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["2021-01-01T00:00:00","2021-01-01T01:00:00","2021-01-01T02:00:00"]' ) def test_numpy_array_d1_datetime64_minutes(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("2021-01-01T00:00"), numpy.datetime64("2021-01-01T00:01"), numpy.datetime64("2021-01-01T00:02"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["2021-01-01T00:00:00","2021-01-01T00:01:00","2021-01-01T00:02:00"]' ) def test_numpy_array_d1_datetime64_seconds(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("2021-01-01T00:00:00"), numpy.datetime64("2021-01-01T00:00:01"), numpy.datetime64("2021-01-01T00:00:02"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["2021-01-01T00:00:00","2021-01-01T00:00:01","2021-01-01T00:00:02"]' ) def test_numpy_array_d1_datetime64_milliseconds(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("2021-01-01T00:00:00"), numpy.datetime64("2021-01-01T00:00:00.172"), numpy.datetime64("2021-01-01T00:00:00.567"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["2021-01-01T00:00:00","2021-01-01T00:00:00.172000","2021-01-01T00:00:00.567000"]' ) def test_numpy_array_d1_datetime64_microseconds(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("2021-01-01T00:00:00"), numpy.datetime64("2021-01-01T00:00:00.172"), numpy.datetime64("2021-01-01T00:00:00.567891"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["2021-01-01T00:00:00","2021-01-01T00:00:00.172000","2021-01-01T00:00:00.567891"]' ) def test_numpy_array_d1_datetime64_nanoseconds(self): assert ( orjson.dumps( numpy.array( [ numpy.datetime64("2021-01-01T00:00:00"), numpy.datetime64("2021-01-01T00:00:00.172"), numpy.datetime64("2021-01-01T00:00:00.567891234"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'["2021-01-01T00:00:00","2021-01-01T00:00:00.172000","2021-01-01T00:00:00.567891"]' ) def test_numpy_array_d1_datetime64_picoseconds(self): try: orjson.dumps( numpy.array( [ numpy.datetime64("2021-01-01T00:00:00"), numpy.datetime64("2021-01-01T00:00:00.172"), numpy.datetime64("2021-01-01T00:00:00.567891234567"), ], ), option=orjson.OPT_SERIALIZE_NUMPY, ) raise AssertionError() except TypeError as exc: assert str(exc) == "unsupported numpy.datetime64 unit: picoseconds" def test_numpy_array_d2_i64(self): assert ( orjson.dumps( numpy.array([[1, 2, 3], [4, 5, 6]], numpy.int64), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[[1,2,3],[4,5,6]]" ) def test_numpy_array_d2_f64(self): assert ( orjson.dumps( numpy.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], numpy.float64), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[[1.0,2.0,3.0],[4.0,5.0,6.0]]" ) def test_numpy_array_d3_i8(self): assert ( orjson.dumps( numpy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], numpy.int8), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[[[1,2],[3,4]],[[5,6],[7,8]]]" ) def test_numpy_array_d3_u8(self): assert ( orjson.dumps( numpy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], numpy.uint8), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[[[1,2],[3,4]],[[5,6],[7,8]]]" ) def test_numpy_array_d3_i32(self): assert ( orjson.dumps( numpy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], numpy.int32), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[[[1,2],[3,4]],[[5,6],[7,8]]]" ) def test_numpy_array_d3_i64(self): assert ( orjson.dumps( numpy.array([[[1, 2], [3, 4], [5, 6], [7, 8]]], numpy.int64), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[[[1,2],[3,4],[5,6],[7,8]]]" ) def test_numpy_array_d3_f64(self): assert ( orjson.dumps( numpy.array( [[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]], numpy.float64, ), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[[[1.0,2.0],[3.0,4.0]],[[5.0,6.0],[7.0,8.0]]]" ) def test_numpy_array_fortran(self): array = numpy.array([[1, 2], [3, 4]], order="F") assert array.flags["F_CONTIGUOUS"] is True with pytest.raises(orjson.JSONEncodeError): orjson.dumps(array, option=orjson.OPT_SERIALIZE_NUMPY) assert orjson.dumps( array, default=numpy_default, option=orjson.OPT_SERIALIZE_NUMPY, ) == orjson.dumps(array.tolist()) def test_numpy_array_non_contiguous_message(self): array = numpy.array([[1, 2], [3, 4]], order="F") assert array.flags["F_CONTIGUOUS"] is True try: orjson.dumps(array, option=orjson.OPT_SERIALIZE_NUMPY) raise AssertionError() except TypeError as exc: assert ( str(exc) == "numpy array is not C contiguous; use ndarray.tolist() in default" ) def test_numpy_array_unsupported_dtype(self): array = numpy.array([[1, 2], [3, 4]], numpy.csingle) # type: ignore with pytest.raises(orjson.JSONEncodeError) as cm: orjson.dumps(array, option=orjson.OPT_SERIALIZE_NUMPY) assert "unsupported datatype in numpy array" in str(cm) def test_numpy_array_d1(self): array = numpy.array([1]) assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) def test_numpy_array_d2(self): array = numpy.array([[1]]) assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) def test_numpy_array_d3(self): array = numpy.array([[[1]]]) assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) def test_numpy_array_d4(self): array = numpy.array([[[[1]]]]) assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) def test_numpy_array_4_stride(self): array = numpy.random.rand(4, 4, 4, 4) assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) def test_numpy_array_dimension_zero(self): array = numpy.array(0) assert array.ndim == 0 with pytest.raises(orjson.JSONEncodeError): orjson.dumps(array, option=orjson.OPT_SERIALIZE_NUMPY) array = numpy.empty((0, 4, 2)) assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) array = numpy.empty((4, 0, 2)) assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) array = numpy.empty((2, 4, 0)) assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) def test_numpy_array_dimension_max(self): array = numpy.random.rand( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ) assert array.ndim == 32 assert ( orjson.loads( orjson.dumps( array, option=orjson.OPT_SERIALIZE_NUMPY, ), ) == array.tolist() ) def test_numpy_scalar_int8(self): assert orjson.dumps(numpy.int8(0), option=orjson.OPT_SERIALIZE_NUMPY) == b"0" assert ( orjson.dumps(numpy.int8(127), option=orjson.OPT_SERIALIZE_NUMPY) == b"127" ) assert ( orjson.dumps(numpy.int8(-128), option=orjson.OPT_SERIALIZE_NUMPY) == b"-128" ) def test_numpy_scalar_int16(self): assert orjson.dumps(numpy.int16(0), option=orjson.OPT_SERIALIZE_NUMPY) == b"0" assert ( orjson.dumps(numpy.int16(32767), option=orjson.OPT_SERIALIZE_NUMPY) == b"32767" ) assert ( orjson.dumps(numpy.int16(-32768), option=orjson.OPT_SERIALIZE_NUMPY) == b"-32768" ) def test_numpy_scalar_int32(self): assert orjson.dumps(numpy.int32(1), option=orjson.OPT_SERIALIZE_NUMPY) == b"1" assert ( orjson.dumps(numpy.int32(2147483647), option=orjson.OPT_SERIALIZE_NUMPY) == b"2147483647" ) assert ( orjson.dumps(numpy.int32(-2147483648), option=orjson.OPT_SERIALIZE_NUMPY) == b"-2147483648" ) def test_numpy_scalar_int64(self): assert ( orjson.dumps( numpy.int64(-9223372036854775808), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"-9223372036854775808" ) assert ( orjson.dumps( numpy.int64(9223372036854775807), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"9223372036854775807" ) def test_numpy_scalar_uint8(self): assert orjson.dumps(numpy.uint8(0), option=orjson.OPT_SERIALIZE_NUMPY) == b"0" assert ( orjson.dumps(numpy.uint8(255), option=orjson.OPT_SERIALIZE_NUMPY) == b"255" ) def test_numpy_scalar_uint16(self): assert orjson.dumps(numpy.uint16(0), option=orjson.OPT_SERIALIZE_NUMPY) == b"0" assert ( orjson.dumps(numpy.uint16(65535), option=orjson.OPT_SERIALIZE_NUMPY) == b"65535" ) def test_numpy_scalar_uint32(self): assert orjson.dumps(numpy.uint32(0), option=orjson.OPT_SERIALIZE_NUMPY) == b"0" assert ( orjson.dumps(numpy.uint32(4294967295), option=orjson.OPT_SERIALIZE_NUMPY) == b"4294967295" ) def test_numpy_scalar_uint64(self): assert orjson.dumps(numpy.uint64(0), option=orjson.OPT_SERIALIZE_NUMPY) == b"0" assert ( orjson.dumps( numpy.uint64(18446744073709551615), option=orjson.OPT_SERIALIZE_NUMPY, ) == b"18446744073709551615" ) def test_numpy_scalar_float16(self): assert ( orjson.dumps(numpy.float16(1.0), option=orjson.OPT_SERIALIZE_NUMPY) == b"1.0" ) def test_numpy_scalar_float32(self): assert ( orjson.dumps(numpy.float32(1.0), option=orjson.OPT_SERIALIZE_NUMPY) == b"1.0" ) def test_numpy_scalar_float64(self): assert ( orjson.dumps(numpy.float64(123.123), option=orjson.OPT_SERIALIZE_NUMPY) == b"123.123" ) def test_numpy_bool(self): assert ( orjson.dumps( {"a": numpy.bool_(True), "b": numpy.bool_(False)}, option=orjson.OPT_SERIALIZE_NUMPY, ) == b'{"a":true,"b":false}' ) def test_numpy_datetime_year(self): assert ( orjson.dumps(numpy.datetime64("2021"), option=orjson.OPT_SERIALIZE_NUMPY) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_month(self): assert ( orjson.dumps(numpy.datetime64("2021-01"), option=orjson.OPT_SERIALIZE_NUMPY) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_day(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01"), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_hour(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00"), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_minute(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00"), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_second(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00"), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_milli(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172"), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'"2021-01-01T00:00:00.172000"' ) def test_numpy_datetime_micro(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172576"), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'"2021-01-01T00:00:00.172576"' ) def test_numpy_datetime_nano(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172576789"), option=orjson.OPT_SERIALIZE_NUMPY, ) == b'"2021-01-01T00:00:00.172576"' ) def test_numpy_datetime_naive_utc_year(self): assert ( orjson.dumps( numpy.datetime64("2021"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00+00:00"' ) def test_numpy_datetime_naive_utc_month(self): assert ( orjson.dumps( numpy.datetime64("2021-01"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00+00:00"' ) def test_numpy_datetime_naive_utc_day(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00+00:00"' ) def test_numpy_datetime_naive_utc_hour(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00+00:00"' ) def test_numpy_datetime_naive_utc_minute(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00+00:00"' ) def test_numpy_datetime_naive_utc_second(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00+00:00"' ) def test_numpy_datetime_naive_utc_milli(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00.172000+00:00"' ) def test_numpy_datetime_naive_utc_micro(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172576"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00.172576+00:00"' ) def test_numpy_datetime_naive_utc_nano(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172576789"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC, ) == b'"2021-01-01T00:00:00.172576+00:00"' ) def test_numpy_datetime_naive_utc_utc_z_year(self): assert ( orjson.dumps( numpy.datetime64("2021"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00Z"' ) def test_numpy_datetime_naive_utc_utc_z_month(self): assert ( orjson.dumps( numpy.datetime64("2021-01"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00Z"' ) def test_numpy_datetime_naive_utc_utc_z_day(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00Z"' ) def test_numpy_datetime_naive_utc_utc_z_hour(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00Z"' ) def test_numpy_datetime_naive_utc_utc_z_minute(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00Z"' ) def test_numpy_datetime_naive_utc_utc_z_second(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00Z"' ) def test_numpy_datetime_naive_utc_utc_z_milli(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00.172000Z"' ) def test_numpy_datetime_naive_utc_utc_z_micro(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172576"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00.172576Z"' ) def test_numpy_datetime_naive_utc_utc_z_nano(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172576789"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, ) == b'"2021-01-01T00:00:00.172576Z"' ) def test_numpy_datetime_omit_microseconds_year(self): assert ( orjson.dumps( numpy.datetime64("2021"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_omit_microseconds_month(self): assert ( orjson.dumps( numpy.datetime64("2021-01"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_omit_microseconds_day(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_omit_microseconds_hour(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_omit_microseconds_minute(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_omit_microseconds_second(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_omit_microseconds_milli(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_omit_microseconds_micro(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172576"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_omit_microseconds_nano(self): assert ( orjson.dumps( numpy.datetime64("2021-01-01T00:00:00.172576789"), option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_OMIT_MICROSECONDS, ) == b'"2021-01-01T00:00:00"' ) def test_numpy_datetime_nat(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(numpy.datetime64("NaT"), option=orjson.OPT_SERIALIZE_NUMPY) with pytest.raises(orjson.JSONEncodeError): orjson.dumps([numpy.datetime64("NaT")], option=orjson.OPT_SERIALIZE_NUMPY) def test_numpy_repeated(self): data = numpy.array([[[1, 2], [3, 4], [5, 6], [7, 8]]], numpy.int64) # type: ignore for _ in range(3): assert ( orjson.dumps( data, option=orjson.OPT_SERIALIZE_NUMPY, ) == b"[[[1,2],[3,4],[5,6],[7,8]]]" ) @pytest.mark.skipif(numpy is None, reason="numpy is not installed") class TestNumpyEquivalence: def _test(self, obj): assert orjson.dumps(obj, option=orjson.OPT_SERIALIZE_NUMPY) == orjson.dumps( obj.tolist(), ) def test_numpy_uint8(self): self._test(numpy.array([0, 255], numpy.uint8)) def test_numpy_uint16(self): self._test(numpy.array([0, 65535], numpy.uint16)) def test_numpy_uint32(self): self._test(numpy.array([0, 4294967295], numpy.uint32)) def test_numpy_uint64(self): self._test(numpy.array([0, 18446744073709551615], numpy.uint64)) def test_numpy_int8(self): self._test(numpy.array([-128, 127], numpy.int8)) def test_numpy_int16(self): self._test(numpy.array([-32768, 32767], numpy.int16)) def test_numpy_int32(self): self._test(numpy.array([-2147483647, 2147483647], numpy.int32)) def test_numpy_int64(self): self._test( numpy.array([-9223372036854775807, 9223372036854775807], numpy.int64), ) @pytest.mark.skip(reason="tolist() conversion results in 3.4028234663852886e38") def test_numpy_float32(self): self._test( numpy.array( [ -340282346638528859811704183484516925440.0000000000000000, 340282346638528859811704183484516925440.0000000000000000, ], numpy.float32, ), ) self._test(numpy.array([-3.4028235e38, 3.4028235e38], numpy.float32)) def test_numpy_float64(self): self._test( numpy.array( [-1.7976931348623157e308, 1.7976931348623157e308], numpy.float64, ), ) @pytest.mark.skipif(numpy is None, reason="numpy is not installed") class NumpyEndianness: def test_numpy_array_dimension_zero(self): wrong_endianness = ">" if sys.byteorder == "little" else "<" array = numpy.array([0, 1, 0.4, 5.7], dtype=f"{wrong_endianness}f8") with pytest.raises(orjson.JSONEncodeError): orjson.dumps(array, option=orjson.OPT_SERIALIZE_NUMPY) ijl-orjson-aa8c946/test/test_parsing.py000066400000000000000000001572611505336676500203100ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest import orjson from .util import needs_data, read_fixture_bytes @needs_data class TestJSONTestSuiteParsing: def _run_fail_json(self, filename, exc=orjson.JSONDecodeError): data = read_fixture_bytes(filename, "parsing") with pytest.raises(exc): orjson.loads(data) with pytest.raises(exc): orjson.loads(bytearray(data)) with pytest.raises(exc): orjson.loads(memoryview(data)) try: decoded = data.decode("utf-8") except UnicodeDecodeError: pass else: with pytest.raises(exc): orjson.loads(decoded) def _run_pass_json(self, filename, match=""): data = read_fixture_bytes(filename, "parsing") orjson.loads(data) orjson.loads(bytearray(data)) orjson.loads(memoryview(data)) orjson.loads(data.decode("utf-8")) def test_y_array_arraysWithSpace(self): """ y_array_arraysWithSpaces.json """ self._run_pass_json("y_array_arraysWithSpaces.json") def test_y_array_empty_string(self): """ y_array_empty-string.json """ self._run_pass_json("y_array_empty-string.json") def test_y_array_empty(self): """ y_array_empty.json """ self._run_pass_json("y_array_empty.json") def test_y_array_ending_with_newline(self): """ y_array_ending_with_newline.json """ self._run_pass_json("y_array_ending_with_newline.json") def test_y_array_false(self): """ y_array_false.json """ self._run_pass_json("y_array_false.json") def test_y_array_heterogeneou(self): """ y_array_heterogeneous.json """ self._run_pass_json("y_array_heterogeneous.json") def test_y_array_null(self): """ y_array_null.json """ self._run_pass_json("y_array_null.json") def test_y_array_with_1_and_newline(self): """ y_array_with_1_and_newline.json """ self._run_pass_json("y_array_with_1_and_newline.json") def test_y_array_with_leading_space(self): """ y_array_with_leading_space.json """ self._run_pass_json("y_array_with_leading_space.json") def test_y_array_with_several_null(self): """ y_array_with_several_null.json """ self._run_pass_json("y_array_with_several_null.json") def test_y_array_with_trailing_space(self): """ y_array_with_trailing_space.json """ self._run_pass_json("y_array_with_trailing_space.json") def test_y_number(self): """ y_number.json """ self._run_pass_json("y_number.json") def test_y_number_0e_1(self): """ y_number_0e+1.json """ self._run_pass_json("y_number_0e+1.json") def test_y_number_0e1(self): """ y_number_0e1.json """ self._run_pass_json("y_number_0e1.json") def test_y_number_after_space(self): """ y_number_after_space.json """ self._run_pass_json("y_number_after_space.json") def test_y_number_double_close_to_zer(self): """ y_number_double_close_to_zero.json """ self._run_pass_json("y_number_double_close_to_zero.json") def test_y_number_int_with_exp(self): """ y_number_int_with_exp.json """ self._run_pass_json("y_number_int_with_exp.json") def test_y_number_minus_zer(self): """ y_number_minus_zero.json """ self._run_pass_json("y_number_minus_zero.json") def test_y_number_negative_int(self): """ y_number_negative_int.json """ self._run_pass_json("y_number_negative_int.json") def test_y_number_negative_one(self): """ y_number_negative_one.json """ self._run_pass_json("y_number_negative_one.json") def test_y_number_negative_zer(self): """ y_number_negative_zero.json """ self._run_pass_json("y_number_negative_zero.json") def test_y_number_real_capital_e(self): """ y_number_real_capital_e.json """ self._run_pass_json("y_number_real_capital_e.json") def test_y_number_real_capital_e_neg_exp(self): """ y_number_real_capital_e_neg_exp.json """ self._run_pass_json("y_number_real_capital_e_neg_exp.json") def test_y_number_real_capital_e_pos_exp(self): """ y_number_real_capital_e_pos_exp.json """ self._run_pass_json("y_number_real_capital_e_pos_exp.json") def test_y_number_real_exponent(self): """ y_number_real_exponent.json """ self._run_pass_json("y_number_real_exponent.json") def test_y_number_real_fraction_exponent(self): """ y_number_real_fraction_exponent.json """ self._run_pass_json("y_number_real_fraction_exponent.json") def test_y_number_real_neg_exp(self): """ y_number_real_neg_exp.json """ self._run_pass_json("y_number_real_neg_exp.json") def test_y_number_real_pos_exponent(self): """ y_number_real_pos_exponent.json """ self._run_pass_json("y_number_real_pos_exponent.json") def test_y_number_simple_int(self): """ y_number_simple_int.json """ self._run_pass_json("y_number_simple_int.json") def test_y_number_simple_real(self): """ y_number_simple_real.json """ self._run_pass_json("y_number_simple_real.json") def test_y_object(self): """ y_object.json """ self._run_pass_json("y_object.json") def test_y_object_basic(self): """ y_object_basic.json """ self._run_pass_json("y_object_basic.json") def test_y_object_duplicated_key(self): """ y_object_duplicated_key.json """ self._run_pass_json("y_object_duplicated_key.json") def test_y_object_duplicated_key_and_value(self): """ y_object_duplicated_key_and_value.json """ self._run_pass_json("y_object_duplicated_key_and_value.json") def test_y_object_empty(self): """ y_object_empty.json """ self._run_pass_json("y_object_empty.json") def test_y_object_empty_key(self): """ y_object_empty_key.json """ self._run_pass_json("y_object_empty_key.json") def test_y_object_escaped_null_in_key(self): """ y_object_escaped_null_in_key.json """ self._run_pass_json("y_object_escaped_null_in_key.json") def test_y_object_extreme_number(self): """ y_object_extreme_numbers.json """ self._run_pass_json("y_object_extreme_numbers.json") def test_y_object_long_string(self): """ y_object_long_strings.json """ self._run_pass_json("y_object_long_strings.json") def test_y_object_simple(self): """ y_object_simple.json """ self._run_pass_json("y_object_simple.json") def test_y_object_string_unicode(self): """ y_object_string_unicode.json """ self._run_pass_json("y_object_string_unicode.json") def test_y_object_with_newline(self): """ y_object_with_newlines.json """ self._run_pass_json("y_object_with_newlines.json") def test_y_string_1_2_3_bytes_UTF_8_sequence(self): """ y_string_1_2_3_bytes_UTF-8_sequences.json """ self._run_pass_json("y_string_1_2_3_bytes_UTF-8_sequences.json") def test_y_string_accepted_surrogate_pair(self): """ y_string_accepted_surrogate_pair.json """ self._run_pass_json("y_string_accepted_surrogate_pair.json") def test_y_string_accepted_surrogate_pairs(self): """ y_string_accepted_surrogate_pairs.json """ self._run_pass_json("y_string_accepted_surrogate_pairs.json") def test_y_string_allowed_escape(self): """ y_string_allowed_escapes.json """ self._run_pass_json("y_string_allowed_escapes.json") def test_y_string_backslash_and_u_escaped_zer(self): """ y_string_backslash_and_u_escaped_zero.json """ self._run_pass_json("y_string_backslash_and_u_escaped_zero.json") def test_y_string_backslash_doublequote(self): """ y_string_backslash_doublequotes.json """ self._run_pass_json("y_string_backslash_doublequotes.json") def test_y_string_comment(self): """ y_string_comments.json """ self._run_pass_json("y_string_comments.json") def test_y_string_double_escape_a(self): """ y_string_double_escape_a.json """ self._run_pass_json("y_string_double_escape_a.json") def test_y_string_double_escape_(self): """ y_string_double_escape_n.json """ self._run_pass_json("y_string_double_escape_n.json") def test_y_string_escaped_control_character(self): """ y_string_escaped_control_character.json """ self._run_pass_json("y_string_escaped_control_character.json") def test_y_string_escaped_noncharacter(self): """ y_string_escaped_noncharacter.json """ self._run_pass_json("y_string_escaped_noncharacter.json") def test_y_string_in_array(self): """ y_string_in_array.json """ self._run_pass_json("y_string_in_array.json") def test_y_string_in_array_with_leading_space(self): """ y_string_in_array_with_leading_space.json """ self._run_pass_json("y_string_in_array_with_leading_space.json") def test_y_string_last_surrogates_1_and_2(self): """ y_string_last_surrogates_1_and_2.json """ self._run_pass_json("y_string_last_surrogates_1_and_2.json") def test_y_string_nbsp_uescaped(self): """ y_string_nbsp_uescaped.json """ self._run_pass_json("y_string_nbsp_uescaped.json") def test_y_string_nonCharacterInUTF_8_U_10FFFF(self): """ y_string_nonCharacterInUTF-8_U+10FFFF.json """ self._run_pass_json("y_string_nonCharacterInUTF-8_U+10FFFF.json") def test_y_string_nonCharacterInUTF_8_U_FFFF(self): """ y_string_nonCharacterInUTF-8_U+FFFF.json """ self._run_pass_json("y_string_nonCharacterInUTF-8_U+FFFF.json") def test_y_string_null_escape(self): """ y_string_null_escape.json """ self._run_pass_json("y_string_null_escape.json") def test_y_string_one_byte_utf_8(self): """ y_string_one-byte-utf-8.json """ self._run_pass_json("y_string_one-byte-utf-8.json") def test_y_string_pi(self): """ y_string_pi.json """ self._run_pass_json("y_string_pi.json") def test_y_string_reservedCharacterInUTF_8_U_1BFFF(self): """ y_string_reservedCharacterInUTF-8_U+1BFFF.json """ self._run_pass_json("y_string_reservedCharacterInUTF-8_U+1BFFF.json") def test_y_string_simple_ascii(self): """ y_string_simple_ascii.json """ self._run_pass_json("y_string_simple_ascii.json") def test_y_string_space(self): """ y_string_space.json """ self._run_pass_json("y_string_space.json") def test_y_string_surrogates_U_1D11E_MUSICAL_SYMBOL_G_CLEF(self): """ y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json """ self._run_pass_json("y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json") def test_y_string_three_byte_utf_8(self): """ y_string_three-byte-utf-8.json """ self._run_pass_json("y_string_three-byte-utf-8.json") def test_y_string_two_byte_utf_8(self): """ y_string_two-byte-utf-8.json """ self._run_pass_json("y_string_two-byte-utf-8.json") def test_y_string_u_2028_line_sep(self): """ y_string_u+2028_line_sep.json """ self._run_pass_json("y_string_u+2028_line_sep.json") def test_y_string_u_2029_par_sep(self): """ y_string_u+2029_par_sep.json """ self._run_pass_json("y_string_u+2029_par_sep.json") def test_y_string_uEscape(self): """ y_string_uEscape.json """ self._run_pass_json("y_string_uEscape.json") def test_y_string_uescaped_newline(self): """ y_string_uescaped_newline.json """ self._run_pass_json("y_string_uescaped_newline.json") def test_y_string_unescaped_char_delete(self): """ y_string_unescaped_char_delete.json """ self._run_pass_json("y_string_unescaped_char_delete.json") def test_y_string_unicode(self): """ y_string_unicode.json """ self._run_pass_json("y_string_unicode.json") def test_y_string_unicodeEscapedBackslash(self): """ y_string_unicodeEscapedBackslash.json """ self._run_pass_json("y_string_unicodeEscapedBackslash.json") def test_y_string_unicode_2(self): """ y_string_unicode_2.json """ self._run_pass_json("y_string_unicode_2.json") def test_y_string_unicode_U_10FFFE_nonchar(self): """ y_string_unicode_U+10FFFE_nonchar.json """ self._run_pass_json("y_string_unicode_U+10FFFE_nonchar.json") def test_y_string_unicode_U_1FFFE_nonchar(self): """ y_string_unicode_U+1FFFE_nonchar.json """ self._run_pass_json("y_string_unicode_U+1FFFE_nonchar.json") def test_y_string_unicode_U_200B_ZERO_WIDTH_SPACE(self): """ y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json """ self._run_pass_json("y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json") def test_y_string_unicode_U_2064_invisible_plu(self): """ y_string_unicode_U+2064_invisible_plus.json """ self._run_pass_json("y_string_unicode_U+2064_invisible_plus.json") def test_y_string_unicode_U_FDD0_nonchar(self): """ y_string_unicode_U+FDD0_nonchar.json """ self._run_pass_json("y_string_unicode_U+FDD0_nonchar.json") def test_y_string_unicode_U_FFFE_nonchar(self): """ y_string_unicode_U+FFFE_nonchar.json """ self._run_pass_json("y_string_unicode_U+FFFE_nonchar.json") def test_y_string_unicode_escaped_double_quote(self): """ y_string_unicode_escaped_double_quote.json """ self._run_pass_json("y_string_unicode_escaped_double_quote.json") def test_y_string_utf8(self): """ y_string_utf8.json """ self._run_pass_json("y_string_utf8.json") def test_y_string_with_del_character(self): """ y_string_with_del_character.json """ self._run_pass_json("y_string_with_del_character.json") def test_y_structure_lonely_false(self): """ y_structure_lonely_false.json """ self._run_pass_json("y_structure_lonely_false.json") def test_y_structure_lonely_int(self): """ y_structure_lonely_int.json """ self._run_pass_json("y_structure_lonely_int.json") def test_y_structure_lonely_negative_real(self): """ y_structure_lonely_negative_real.json """ self._run_pass_json("y_structure_lonely_negative_real.json") def test_y_structure_lonely_null(self): """ y_structure_lonely_null.json """ self._run_pass_json("y_structure_lonely_null.json") def test_y_structure_lonely_string(self): """ y_structure_lonely_string.json """ self._run_pass_json("y_structure_lonely_string.json") def test_y_structure_lonely_true(self): """ y_structure_lonely_true.json """ self._run_pass_json("y_structure_lonely_true.json") def test_y_structure_string_empty(self): """ y_structure_string_empty.json """ self._run_pass_json("y_structure_string_empty.json") def test_y_structure_trailing_newline(self): """ y_structure_trailing_newline.json """ self._run_pass_json("y_structure_trailing_newline.json") def test_y_structure_true_in_array(self): """ y_structure_true_in_array.json """ self._run_pass_json("y_structure_true_in_array.json") def test_y_structure_whitespace_array(self): """ y_structure_whitespace_array.json """ self._run_pass_json("y_structure_whitespace_array.json") def test_n_array_1_true_without_comma(self): """ n_array_1_true_without_comma.json """ self._run_fail_json("n_array_1_true_without_comma.json") def test_n_array_a_invalid_utf8(self): """ n_array_a_invalid_utf8.json """ self._run_fail_json("n_array_a_invalid_utf8.json") def test_n_array_colon_instead_of_comma(self): """ n_array_colon_instead_of_comma.json """ self._run_fail_json("n_array_colon_instead_of_comma.json") def test_n_array_comma_after_close(self): """ n_array_comma_after_close.json """ self._run_fail_json("n_array_comma_after_close.json") def test_n_array_comma_and_number(self): """ n_array_comma_and_number.json """ self._run_fail_json("n_array_comma_and_number.json") def test_n_array_double_comma(self): """ n_array_double_comma.json """ self._run_fail_json("n_array_double_comma.json") def test_n_array_double_extra_comma(self): """ n_array_double_extra_comma.json """ self._run_fail_json("n_array_double_extra_comma.json") def test_n_array_extra_close(self): """ n_array_extra_close.json """ self._run_fail_json("n_array_extra_close.json") def test_n_array_extra_comma(self): """ n_array_extra_comma.json """ self._run_fail_json("n_array_extra_comma.json") def test_n_array_incomplete(self): """ n_array_incomplete.json """ self._run_fail_json("n_array_incomplete.json") def test_n_array_incomplete_invalid_value(self): """ n_array_incomplete_invalid_value.json """ self._run_fail_json("n_array_incomplete_invalid_value.json") def test_n_array_inner_array_no_comma(self): """ n_array_inner_array_no_comma.json """ self._run_fail_json("n_array_inner_array_no_comma.json") def test_n_array_invalid_utf8(self): """ n_array_invalid_utf8.json """ self._run_fail_json("n_array_invalid_utf8.json") def test_n_array_items_separated_by_semicol(self): """ n_array_items_separated_by_semicolon.json """ self._run_fail_json("n_array_items_separated_by_semicolon.json") def test_n_array_just_comma(self): """ n_array_just_comma.json """ self._run_fail_json("n_array_just_comma.json") def test_n_array_just_minu(self): """ n_array_just_minus.json """ self._run_fail_json("n_array_just_minus.json") def test_n_array_missing_value(self): """ n_array_missing_value.json """ self._run_fail_json("n_array_missing_value.json") def test_n_array_newlines_unclosed(self): """ n_array_newlines_unclosed.json """ self._run_fail_json("n_array_newlines_unclosed.json") def test_n_array_number_and_comma(self): """ n_array_number_and_comma.json """ self._run_fail_json("n_array_number_and_comma.json") def test_n_array_number_and_several_comma(self): """ n_array_number_and_several_commas.json """ self._run_fail_json("n_array_number_and_several_commas.json") def test_n_array_spaces_vertical_tab_formfeed(self): """ n_array_spaces_vertical_tab_formfeed.json """ self._run_fail_json("n_array_spaces_vertical_tab_formfeed.json") def test_n_array_star_inside(self): """ n_array_star_inside.json """ self._run_fail_json("n_array_star_inside.json") def test_n_array_unclosed(self): """ n_array_unclosed.json """ self._run_fail_json("n_array_unclosed.json") def test_n_array_unclosed_trailing_comma(self): """ n_array_unclosed_trailing_comma.json """ self._run_fail_json("n_array_unclosed_trailing_comma.json") def test_n_array_unclosed_with_new_line(self): """ n_array_unclosed_with_new_lines.json """ self._run_fail_json("n_array_unclosed_with_new_lines.json") def test_n_array_unclosed_with_object_inside(self): """ n_array_unclosed_with_object_inside.json """ self._run_fail_json("n_array_unclosed_with_object_inside.json") def test_n_incomplete_false(self): """ n_incomplete_false.json """ self._run_fail_json("n_incomplete_false.json") def test_n_incomplete_null(self): """ n_incomplete_null.json """ self._run_fail_json("n_incomplete_null.json") def test_n_incomplete_true(self): """ n_incomplete_true.json """ self._run_fail_json("n_incomplete_true.json") def test_n_multidigit_number_then_00(self): """ n_multidigit_number_then_00.json """ self._run_fail_json("n_multidigit_number_then_00.json") def test_n_number__(self): """ n_number_++.json """ self._run_fail_json("n_number_++.json") def test_n_number_1(self): """ n_number_+1.json """ self._run_fail_json("n_number_+1.json") def test_n_number_Inf(self): """ n_number_+Inf.json """ self._run_fail_json("n_number_+Inf.json") def test_n_number_01(self): """ n_number_-01.json """ self._run_fail_json("n_number_-01.json") def test_n_number_1_0(self): """ n_number_-1.0..json """ self._run_fail_json("n_number_-1.0..json") def test_n_number_2(self): """ n_number_-2..json """ self._run_fail_json("n_number_-2..json") def test_n_number_negative_NaN(self): """ n_number_-NaN.json """ self._run_fail_json("n_number_-NaN.json") def test_n_number_negative_1(self): """ n_number_.-1.json """ self._run_fail_json("n_number_.-1.json") def test_n_number_2e_3(self): """ n_number_.2e-3.json """ self._run_fail_json("n_number_.2e-3.json") def test_n_number_0_1_2(self): """ n_number_0.1.2.json """ self._run_fail_json("n_number_0.1.2.json") def test_n_number_0_3e_(self): """ n_number_0.3e+.json """ self._run_fail_json("n_number_0.3e+.json") def test_n_number_0_3e(self): """ n_number_0.3e.json """ self._run_fail_json("n_number_0.3e.json") def test_n_number_0_e1(self): """ n_number_0.e1.json """ self._run_fail_json("n_number_0.e1.json") def test_n_number_0_capital_E_(self): """ n_number_0_capital_E+.json """ self._run_fail_json("n_number_0_capital_E+.json") def test_n_number_0_capital_E(self): """ n_number_0_capital_E.json """ self._run_fail_json("n_number_0_capital_E.json") def test_n_number_0e_(self): """ n_number_0e+.json """ self._run_fail_json("n_number_0e+.json") def test_n_number_0e(self): """ n_number_0e.json """ self._run_fail_json("n_number_0e.json") def test_n_number_1_0e_(self): """ n_number_1.0e+.json """ self._run_fail_json("n_number_1.0e+.json") def test_n_number_1_0e_2(self): """ n_number_1.0e-.json """ self._run_fail_json("n_number_1.0e-.json") def test_n_number_1_0e(self): """ n_number_1.0e.json """ self._run_fail_json("n_number_1.0e.json") def test_n_number_1_000(self): """ n_number_1_000.json """ self._run_fail_json("n_number_1_000.json") def test_n_number_1eE2(self): """ n_number_1eE2.json """ self._run_fail_json("n_number_1eE2.json") def test_n_number_2_e_3(self): """ n_number_2.e+3.json """ self._run_fail_json("n_number_2.e+3.json") def test_n_number_2_e_3_2(self): """ n_number_2.e-3.json """ self._run_fail_json("n_number_2.e-3.json") def test_n_number_2_e3_3(self): """ n_number_2.e3.json """ self._run_fail_json("n_number_2.e3.json") def test_n_number_9_e_(self): """ n_number_9.e+.json """ self._run_fail_json("n_number_9.e+.json") def test_n_number_negative_Inf(self): """ n_number_Inf.json """ self._run_fail_json("n_number_Inf.json") def test_n_number_NaN(self): """ n_number_NaN.json """ self._run_fail_json("n_number_NaN.json") def test_n_number_U_FF11_fullwidth_digit_one(self): """ n_number_U+FF11_fullwidth_digit_one.json """ self._run_fail_json("n_number_U+FF11_fullwidth_digit_one.json") def test_n_number_expressi(self): """ n_number_expression.json """ self._run_fail_json("n_number_expression.json") def test_n_number_hex_1_digit(self): """ n_number_hex_1_digit.json """ self._run_fail_json("n_number_hex_1_digit.json") def test_n_number_hex_2_digit(self): """ n_number_hex_2_digits.json """ self._run_fail_json("n_number_hex_2_digits.json") def test_n_number_infinity(self): """ n_number_infinity.json """ self._run_fail_json("n_number_infinity.json") def test_n_number_invalid_(self): """ n_number_invalid+-.json """ self._run_fail_json("n_number_invalid+-.json") def test_n_number_invalid_negative_real(self): """ n_number_invalid-negative-real.json """ self._run_fail_json("n_number_invalid-negative-real.json") def test_n_number_invalid_utf_8_in_bigger_int(self): """ n_number_invalid-utf-8-in-bigger-int.json """ self._run_fail_json("n_number_invalid-utf-8-in-bigger-int.json") def test_n_number_invalid_utf_8_in_exponent(self): """ n_number_invalid-utf-8-in-exponent.json """ self._run_fail_json("n_number_invalid-utf-8-in-exponent.json") def test_n_number_invalid_utf_8_in_int(self): """ n_number_invalid-utf-8-in-int.json """ self._run_fail_json("n_number_invalid-utf-8-in-int.json") def test_n_number_minus_infinity(self): """ n_number_minus_infinity.json """ self._run_fail_json("n_number_minus_infinity.json") def test_n_number_minus_sign_with_trailing_garbage(self): """ n_number_minus_sign_with_trailing_garbage.json """ self._run_fail_json("n_number_minus_sign_with_trailing_garbage.json") def test_n_number_minus_space_1(self): """ n_number_minus_space_1.json """ self._run_fail_json("n_number_minus_space_1.json") def test_n_number_neg_int_starting_with_zer(self): """ n_number_neg_int_starting_with_zero.json """ self._run_fail_json("n_number_neg_int_starting_with_zero.json") def test_n_number_neg_real_without_int_part(self): """ n_number_neg_real_without_int_part.json """ self._run_fail_json("n_number_neg_real_without_int_part.json") def test_n_number_neg_with_garbage_at_end(self): """ n_number_neg_with_garbage_at_end.json """ self._run_fail_json("n_number_neg_with_garbage_at_end.json") def test_n_number_real_garbage_after_e(self): """ n_number_real_garbage_after_e.json """ self._run_fail_json("n_number_real_garbage_after_e.json") def test_n_number_real_with_invalid_utf8_after_e(self): """ n_number_real_with_invalid_utf8_after_e.json """ self._run_fail_json("n_number_real_with_invalid_utf8_after_e.json") def test_n_number_real_without_fractional_part(self): """ n_number_real_without_fractional_part.json """ self._run_fail_json("n_number_real_without_fractional_part.json") def test_n_number_starting_with_dot(self): """ n_number_starting_with_dot.json """ self._run_fail_json("n_number_starting_with_dot.json") def test_n_number_with_alpha(self): """ n_number_with_alpha.json """ self._run_fail_json("n_number_with_alpha.json") def test_n_number_with_alpha_char(self): """ n_number_with_alpha_char.json """ self._run_fail_json("n_number_with_alpha_char.json") def test_n_number_with_leading_zer(self): """ n_number_with_leading_zero.json """ self._run_fail_json("n_number_with_leading_zero.json") def test_n_object_bad_value(self): """ n_object_bad_value.json """ self._run_fail_json("n_object_bad_value.json") def test_n_object_bracket_key(self): """ n_object_bracket_key.json """ self._run_fail_json("n_object_bracket_key.json") def test_n_object_comma_instead_of_col(self): """ n_object_comma_instead_of_colon.json """ self._run_fail_json("n_object_comma_instead_of_colon.json") def test_n_object_double_col(self): """ n_object_double_colon.json """ self._run_fail_json("n_object_double_colon.json") def test_n_object_emoji(self): """ n_object_emoji.json """ self._run_fail_json("n_object_emoji.json") def test_n_object_garbage_at_end(self): """ n_object_garbage_at_end.json """ self._run_fail_json("n_object_garbage_at_end.json") def test_n_object_key_with_single_quote(self): """ n_object_key_with_single_quotes.json """ self._run_fail_json("n_object_key_with_single_quotes.json") def test_n_object_lone_continuation_byte_in_key_and_trailing_comma(self): """ n_object_lone_continuation_byte_in_key_and_trailing_comma.json """ self._run_fail_json( "n_object_lone_continuation_byte_in_key_and_trailing_comma.json", ) def test_n_object_missing_col(self): """ n_object_missing_colon.json """ self._run_fail_json("n_object_missing_colon.json") def test_n_object_missing_key(self): """ n_object_missing_key.json """ self._run_fail_json("n_object_missing_key.json") def test_n_object_missing_semicol(self): """ n_object_missing_semicolon.json """ self._run_fail_json("n_object_missing_semicolon.json") def test_n_object_missing_value(self): """ n_object_missing_value.json """ self._run_fail_json("n_object_missing_value.json") def test_n_object_no_col(self): """ n_object_no-colon.json """ self._run_fail_json("n_object_no-colon.json") def test_n_object_non_string_key(self): """ n_object_non_string_key.json """ self._run_fail_json("n_object_non_string_key.json") def test_n_object_non_string_key_but_huge_number_instead(self): """ n_object_non_string_key_but_huge_number_instead.json """ self._run_fail_json("n_object_non_string_key_but_huge_number_instead.json") def test_n_object_repeated_null_null(self): """ n_object_repeated_null_null.json """ self._run_fail_json("n_object_repeated_null_null.json") def test_n_object_several_trailing_comma(self): """ n_object_several_trailing_commas.json """ self._run_fail_json("n_object_several_trailing_commas.json") def test_n_object_single_quote(self): """ n_object_single_quote.json """ self._run_fail_json("n_object_single_quote.json") def test_n_object_trailing_comma(self): """ n_object_trailing_comma.json """ self._run_fail_json("n_object_trailing_comma.json") def test_n_object_trailing_comment(self): """ n_object_trailing_comment.json """ self._run_fail_json("n_object_trailing_comment.json") def test_n_object_trailing_comment_ope(self): """ n_object_trailing_comment_open.json """ self._run_fail_json("n_object_trailing_comment_open.json") def test_n_object_trailing_comment_slash_ope(self): """ n_object_trailing_comment_slash_open.json """ self._run_fail_json("n_object_trailing_comment_slash_open.json") def test_n_object_trailing_comment_slash_open_incomplete(self): """ n_object_trailing_comment_slash_open_incomplete.json """ self._run_fail_json("n_object_trailing_comment_slash_open_incomplete.json") def test_n_object_two_commas_in_a_row(self): """ n_object_two_commas_in_a_row.json """ self._run_fail_json("n_object_two_commas_in_a_row.json") def test_n_object_unquoted_key(self): """ n_object_unquoted_key.json """ self._run_fail_json("n_object_unquoted_key.json") def test_n_object_unterminated_value(self): """ n_object_unterminated-value.json """ self._run_fail_json("n_object_unterminated-value.json") def test_n_object_with_single_string(self): """ n_object_with_single_string.json """ self._run_fail_json("n_object_with_single_string.json") def test_n_object_with_trailing_garbage(self): """ n_object_with_trailing_garbage.json """ self._run_fail_json("n_object_with_trailing_garbage.json") def test_n_single_space(self): """ n_single_space.json """ self._run_fail_json("n_single_space.json") def test_n_string_1_surrogate_then_escape(self): """ n_string_1_surrogate_then_escape.json """ self._run_fail_json("n_string_1_surrogate_then_escape.json") def test_n_string_1_surrogate_then_escape_u(self): """ n_string_1_surrogate_then_escape_u.json """ self._run_fail_json("n_string_1_surrogate_then_escape_u.json") def test_n_string_1_surrogate_then_escape_u1(self): """ n_string_1_surrogate_then_escape_u1.json """ self._run_fail_json("n_string_1_surrogate_then_escape_u1.json") def test_n_string_1_surrogate_then_escape_u1x(self): """ n_string_1_surrogate_then_escape_u1x.json """ self._run_fail_json("n_string_1_surrogate_then_escape_u1x.json") def test_n_string_accentuated_char_no_quote(self): """ n_string_accentuated_char_no_quotes.json """ self._run_fail_json("n_string_accentuated_char_no_quotes.json") def test_n_string_backslash_00(self): """ n_string_backslash_00.json """ self._run_fail_json("n_string_backslash_00.json") def test_n_string_escape_x(self): """ n_string_escape_x.json """ self._run_fail_json("n_string_escape_x.json") def test_n_string_escaped_backslash_bad(self): """ n_string_escaped_backslash_bad.json """ self._run_fail_json("n_string_escaped_backslash_bad.json") def test_n_string_escaped_ctrl_char_tab(self): """ n_string_escaped_ctrl_char_tab.json """ self._run_fail_json("n_string_escaped_ctrl_char_tab.json") def test_n_string_escaped_emoji(self): """ n_string_escaped_emoji.json """ self._run_fail_json("n_string_escaped_emoji.json") def test_n_string_incomplete_escape(self): """ n_string_incomplete_escape.json """ self._run_fail_json("n_string_incomplete_escape.json") def test_n_string_incomplete_escaped_character(self): """ n_string_incomplete_escaped_character.json """ self._run_fail_json("n_string_incomplete_escaped_character.json") def test_n_string_incomplete_surrogate(self): """ n_string_incomplete_surrogate.json """ self._run_fail_json("n_string_incomplete_surrogate.json") def test_n_string_incomplete_surrogate_escape_invalid(self): """ n_string_incomplete_surrogate_escape_invalid.json """ self._run_fail_json("n_string_incomplete_surrogate_escape_invalid.json") def test_n_string_invalid_utf_8_in_escape(self): """ n_string_invalid-utf-8-in-escape.json """ self._run_fail_json("n_string_invalid-utf-8-in-escape.json") def test_n_string_invalid_backslash_esc(self): """ n_string_invalid_backslash_esc.json """ self._run_fail_json("n_string_invalid_backslash_esc.json") def test_n_string_invalid_unicode_escape(self): """ n_string_invalid_unicode_escape.json """ self._run_fail_json("n_string_invalid_unicode_escape.json") def test_n_string_invalid_utf8_after_escape(self): """ n_string_invalid_utf8_after_escape.json """ self._run_fail_json("n_string_invalid_utf8_after_escape.json") def test_n_string_leading_uescaped_thinspace(self): """ n_string_leading_uescaped_thinspace.json """ self._run_fail_json("n_string_leading_uescaped_thinspace.json") def test_n_string_no_quotes_with_bad_escape(self): """ n_string_no_quotes_with_bad_escape.json """ self._run_fail_json("n_string_no_quotes_with_bad_escape.json") def test_n_string_single_doublequote(self): """ n_string_single_doublequote.json """ self._run_fail_json("n_string_single_doublequote.json") def test_n_string_single_quote(self): """ n_string_single_quote.json """ self._run_fail_json("n_string_single_quote.json") def test_n_string_single_string_no_double_quote(self): """ n_string_single_string_no_double_quotes.json """ self._run_fail_json("n_string_single_string_no_double_quotes.json") def test_n_string_start_escape_unclosed(self): """ n_string_start_escape_unclosed.json """ self._run_fail_json("n_string_start_escape_unclosed.json") def test_n_string_unescaped_crtl_char(self): """ n_string_unescaped_crtl_char.json """ self._run_fail_json("n_string_unescaped_crtl_char.json") def test_n_string_unescaped_newline(self): """ n_string_unescaped_newline.json """ self._run_fail_json("n_string_unescaped_newline.json") def test_n_string_unescaped_tab(self): """ n_string_unescaped_tab.json """ self._run_fail_json("n_string_unescaped_tab.json") def test_n_string_unicode_CapitalU(self): """ n_string_unicode_CapitalU.json """ self._run_fail_json("n_string_unicode_CapitalU.json") def test_n_string_with_trailing_garbage(self): """ n_string_with_trailing_garbage.json """ self._run_fail_json("n_string_with_trailing_garbage.json") def test_n_structure_100000_opening_array(self): """ n_structure_100000_opening_arrays.json """ self._run_fail_json("n_structure_100000_opening_arrays.json.xz") def test_n_structure_U_2060_word_joined(self): """ n_structure_U+2060_word_joined.json """ self._run_fail_json("n_structure_U+2060_word_joined.json") def test_n_structure_UTF8_BOM_no_data(self): """ n_structure_UTF8_BOM_no_data.json """ self._run_fail_json("n_structure_UTF8_BOM_no_data.json") def test_n_structure_angle_bracket_(self): """ n_structure_angle_bracket_..json """ self._run_fail_json("n_structure_angle_bracket_..json") def test_n_structure_angle_bracket_null(self): """ n_structure_angle_bracket_null.json """ self._run_fail_json("n_structure_angle_bracket_null.json") def test_n_structure_array_trailing_garbage(self): """ n_structure_array_trailing_garbage.json """ self._run_fail_json("n_structure_array_trailing_garbage.json") def test_n_structure_array_with_extra_array_close(self): """ n_structure_array_with_extra_array_close.json """ self._run_fail_json("n_structure_array_with_extra_array_close.json") def test_n_structure_array_with_unclosed_string(self): """ n_structure_array_with_unclosed_string.json """ self._run_fail_json("n_structure_array_with_unclosed_string.json") def test_n_structure_ascii_unicode_identifier(self): """ n_structure_ascii-unicode-identifier.json """ self._run_fail_json("n_structure_ascii-unicode-identifier.json") def test_n_structure_capitalized_True(self): """ n_structure_capitalized_True.json """ self._run_fail_json("n_structure_capitalized_True.json") def test_n_structure_close_unopened_array(self): """ n_structure_close_unopened_array.json """ self._run_fail_json("n_structure_close_unopened_array.json") def test_n_structure_comma_instead_of_closing_brace(self): """ n_structure_comma_instead_of_closing_brace.json """ self._run_fail_json("n_structure_comma_instead_of_closing_brace.json") def test_n_structure_double_array(self): """ n_structure_double_array.json """ self._run_fail_json("n_structure_double_array.json") def test_n_structure_end_array(self): """ n_structure_end_array.json """ self._run_fail_json("n_structure_end_array.json") def test_n_structure_incomplete_UTF8_BOM(self): """ n_structure_incomplete_UTF8_BOM.json """ self._run_fail_json("n_structure_incomplete_UTF8_BOM.json") def test_n_structure_lone_invalid_utf_8(self): """ n_structure_lone-invalid-utf-8.json """ self._run_fail_json("n_structure_lone-invalid-utf-8.json") def test_n_structure_lone_open_bracket(self): """ n_structure_lone-open-bracket.json """ self._run_fail_json("n_structure_lone-open-bracket.json") def test_n_structure_no_data(self): """ n_structure_no_data.json """ self._run_fail_json("n_structure_no_data.json") def test_n_structure_null_byte_outside_string(self): """ n_structure_null-byte-outside-string.json """ self._run_fail_json("n_structure_null-byte-outside-string.json") def test_n_structure_number_with_trailing_garbage(self): """ n_structure_number_with_trailing_garbage.json """ self._run_fail_json("n_structure_number_with_trailing_garbage.json") def test_n_structure_object_followed_by_closing_object(self): """ n_structure_object_followed_by_closing_object.json """ self._run_fail_json("n_structure_object_followed_by_closing_object.json") def test_n_structure_object_unclosed_no_value(self): """ n_structure_object_unclosed_no_value.json """ self._run_fail_json("n_structure_object_unclosed_no_value.json") def test_n_structure_object_with_comment(self): """ n_structure_object_with_comment.json """ self._run_fail_json("n_structure_object_with_comment.json") def test_n_structure_object_with_trailing_garbage(self): """ n_structure_object_with_trailing_garbage.json """ self._run_fail_json("n_structure_object_with_trailing_garbage.json") def test_n_structure_open_array_apostrophe(self): """ n_structure_open_array_apostrophe.json """ self._run_fail_json("n_structure_open_array_apostrophe.json") def test_n_structure_open_array_comma(self): """ n_structure_open_array_comma.json """ self._run_fail_json("n_structure_open_array_comma.json") def test_n_structure_open_array_object(self): """ n_structure_open_array_object.json """ self._run_fail_json("n_structure_open_array_object.json.xz") def test_n_structure_open_array_open_object(self): """ n_structure_open_array_open_object.json """ self._run_fail_json("n_structure_open_array_open_object.json") def test_n_structure_open_array_open_string(self): """ n_structure_open_array_open_string.json """ self._run_fail_json("n_structure_open_array_open_string.json") def test_n_structure_open_array_string(self): """ n_structure_open_array_string.json """ self._run_fail_json("n_structure_open_array_string.json") def test_n_structure_open_object(self): """ n_structure_open_object.json """ self._run_fail_json("n_structure_open_object.json") def test_n_structure_open_object_close_array(self): """ n_structure_open_object_close_array.json """ self._run_fail_json("n_structure_open_object_close_array.json") def test_n_structure_open_object_comma(self): """ n_structure_open_object_comma.json """ self._run_fail_json("n_structure_open_object_comma.json") def test_n_structure_open_object_open_array(self): """ n_structure_open_object_open_array.json """ self._run_fail_json("n_structure_open_object_open_array.json") def test_n_structure_open_object_open_string(self): """ n_structure_open_object_open_string.json """ self._run_fail_json("n_structure_open_object_open_string.json") def test_n_structure_open_object_string_with_apostrophe(self): """ n_structure_open_object_string_with_apostrophes.json """ self._run_fail_json("n_structure_open_object_string_with_apostrophes.json") def test_n_structure_open_ope(self): """ n_structure_open_open.json """ self._run_fail_json("n_structure_open_open.json") def test_n_structure_single_eacute(self): """ n_structure_single_eacute.json """ self._run_fail_json("n_structure_single_eacute.json") def test_n_structure_single_star(self): """ n_structure_single_star.json """ self._run_fail_json("n_structure_single_star.json") def test_n_structure_trailing_(self): """ n_structure_trailing_#.json """ self._run_fail_json("n_structure_trailing_#.json") def test_n_structure_uescaped_LF_before_string(self): """ n_structure_uescaped_LF_before_string.json """ self._run_fail_json("n_structure_uescaped_LF_before_string.json") def test_n_structure_unclosed_array(self): """ n_structure_unclosed_array.json """ self._run_fail_json("n_structure_unclosed_array.json") def test_n_structure_unclosed_array_partial_null(self): """ n_structure_unclosed_array_partial_null.json """ self._run_fail_json("n_structure_unclosed_array_partial_null.json") def test_n_structure_unclosed_array_unfinished_false(self): """ n_structure_unclosed_array_unfinished_false.json """ self._run_fail_json("n_structure_unclosed_array_unfinished_false.json") def test_n_structure_unclosed_array_unfinished_true(self): """ n_structure_unclosed_array_unfinished_true.json """ self._run_fail_json("n_structure_unclosed_array_unfinished_true.json") def test_n_structure_unclosed_object(self): """ n_structure_unclosed_object.json """ self._run_fail_json("n_structure_unclosed_object.json") def test_n_structure_unicode_identifier(self): """ n_structure_unicode-identifier.json """ self._run_fail_json("n_structure_unicode-identifier.json") def test_n_structure_whitespace_U_2060_word_joiner(self): """ n_structure_whitespace_U+2060_word_joiner.json """ self._run_fail_json("n_structure_whitespace_U+2060_word_joiner.json") def test_n_structure_whitespace_formfeed(self): """ n_structure_whitespace_formfeed.json """ self._run_fail_json("n_structure_whitespace_formfeed.json") def test_i_number_double_huge_neg_exp(self): """ i_number_double_huge_neg_exp.json """ self._run_pass_json("i_number_double_huge_neg_exp.json") def test_i_number_huge_exp(self): """ i_number_huge_exp.json """ self._run_fail_json("i_number_huge_exp.json") def test_i_number_neg_int_huge_exp(self): """ i_number_neg_int_huge_exp.json """ self._run_fail_json("i_number_neg_int_huge_exp.json") def test_i_number_pos_double_huge_exp(self): """ i_number_pos_double_huge_exp.json """ self._run_fail_json("i_number_pos_double_huge_exp.json") def test_i_number_real_neg_overflow(self): """ i_number_real_neg_overflow.json """ self._run_fail_json("i_number_real_neg_overflow.json") def test_i_number_real_pos_overflow(self): """ i_number_real_pos_overflow.json """ self._run_fail_json("i_number_real_pos_overflow.json") def test_i_number_real_underflow(self): """ i_number_real_underflow.json """ self._run_pass_json("i_number_real_underflow.json") def test_i_number_too_big_neg_int(self): """ i_number_too_big_neg_int.json """ self._run_pass_json("i_number_too_big_neg_int.json") def test_i_number_too_big_pos_int(self): """ i_number_too_big_pos_int.json """ self._run_pass_json("i_number_too_big_pos_int.json") def test_i_number_very_big_negative_int(self): """ i_number_very_big_negative_int.json """ self._run_pass_json("i_number_very_big_negative_int.json") def test_i_object_key_lone_2nd_surrogate(self): """ i_object_key_lone_2nd_surrogate.json """ self._run_fail_json("i_object_key_lone_2nd_surrogate.json") def test_i_string_1st_surrogate_but_2nd_missing(self): """ i_string_1st_surrogate_but_2nd_missing.json """ self._run_fail_json("i_string_1st_surrogate_but_2nd_missing.json") def test_i_string_1st_valid_surrogate_2nd_invalid(self): """ i_string_1st_valid_surrogate_2nd_invalid.json """ self._run_fail_json("i_string_1st_valid_surrogate_2nd_invalid.json") def test_i_string_UTF_16LE_with_BOM(self): """ i_string_UTF-16LE_with_BOM.json """ self._run_fail_json("i_string_UTF-16LE_with_BOM.json") def test_i_string_UTF_8_invalid_sequence(self): """ i_string_UTF-8_invalid_sequence.json """ self._run_fail_json("i_string_UTF-8_invalid_sequence.json") def test_i_string_UTF8_surrogate_U_D800(self): """ i_string_UTF8_surrogate_U+D800.json """ self._run_fail_json("i_string_UTF8_surrogate_U+D800.json") def test_i_string_incomplete_surrogate_and_escape_valid(self): """ i_string_incomplete_surrogate_and_escape_valid.json """ self._run_fail_json("i_string_incomplete_surrogate_and_escape_valid.json") def test_i_string_incomplete_surrogate_pair(self): """ i_string_incomplete_surrogate_pair.json """ self._run_fail_json("i_string_incomplete_surrogate_pair.json") def test_i_string_incomplete_surrogates_escape_valid(self): """ i_string_incomplete_surrogates_escape_valid.json """ self._run_fail_json("i_string_incomplete_surrogates_escape_valid.json") def test_i_string_invalid_lonely_surrogate(self): """ i_string_invalid_lonely_surrogate.json """ self._run_fail_json("i_string_invalid_lonely_surrogate.json") def test_i_string_invalid_surrogate(self): """ i_string_invalid_surrogate.json """ self._run_fail_json("i_string_invalid_surrogate.json") def test_i_string_invalid_utf_8(self): """ i_string_invalid_utf-8.json """ self._run_fail_json("i_string_invalid_utf-8.json") def test_i_string_inverted_surrogates_U_1D11E(self): """ i_string_inverted_surrogates_U+1D11E.json """ self._run_fail_json("i_string_inverted_surrogates_U+1D11E.json") def test_i_string_iso_latin_1(self): """ i_string_iso_latin_1.json """ self._run_fail_json("i_string_iso_latin_1.json") def test_i_string_lone_second_surrogate(self): """ i_string_lone_second_surrogate.json """ self._run_fail_json("i_string_lone_second_surrogate.json") def test_i_string_lone_utf8_continuation_byte(self): """ i_string_lone_utf8_continuation_byte.json """ self._run_fail_json("i_string_lone_utf8_continuation_byte.json") def test_i_string_not_in_unicode_range(self): """ i_string_not_in_unicode_range.json """ self._run_fail_json("i_string_not_in_unicode_range.json") def test_i_string_overlong_sequence_2_byte(self): """ i_string_overlong_sequence_2_bytes.json """ self._run_fail_json("i_string_overlong_sequence_2_bytes.json") def test_i_string_overlong_sequence_6_byte(self): """ i_string_overlong_sequence_6_bytes.json """ self._run_fail_json("i_string_overlong_sequence_6_bytes.json") def test_i_string_overlong_sequence_6_bytes_null(self): """ i_string_overlong_sequence_6_bytes_null.json """ self._run_fail_json("i_string_overlong_sequence_6_bytes_null.json") def test_i_string_truncated_utf_8(self): """ i_string_truncated-utf-8.json """ self._run_fail_json("i_string_truncated-utf-8.json") def test_i_string_utf16BE_no_BOM(self): """ i_string_utf16BE_no_BOM.json """ self._run_fail_json("i_string_utf16BE_no_BOM.json") def test_i_string_utf16LE_no_BOM(self): """ i_string_utf16LE_no_BOM.json """ self._run_fail_json("i_string_utf16LE_no_BOM.json") def test_i_structure_500_nested_array(self): """ i_structure_500_nested_arrays.json """ try: self._run_pass_json("i_structure_500_nested_arrays.json.xz") except orjson.JSONDecodeError: # fails on serde, passes on yyjson pass def test_i_structure_UTF_8_BOM_empty_object(self): """ i_structure_UTF-8_BOM_empty_object.json """ self._run_fail_json("i_structure_UTF-8_BOM_empty_object.json") ijl-orjson-aa8c946/test/test_reentrant.py000066400000000000000000000003221505336676500206300ustar00rootroot00000000000000import orjson class C: c: "C" def __del__(self): orjson.loads('"' + "a" * 10000 + '"') def test_reentrant(): c = C() c.c = c del c orjson.loads("[" + "[]," * 1000 + "[]]") ijl-orjson-aa8c946/test/test_roundtrip.py000066400000000000000000000076621505336676500206720ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import orjson from .util import needs_data, read_fixture_str @needs_data class TestJsonChecker: def _run_roundtrip_json(self, filename): data = read_fixture_str(filename, "roundtrip") assert orjson.dumps(orjson.loads(data)) == data.encode("utf-8") def test_roundtrip001(self): """ roundtrip001.json """ self._run_roundtrip_json("roundtrip01.json") def test_roundtrip002(self): """ roundtrip002.json """ self._run_roundtrip_json("roundtrip02.json") def test_roundtrip003(self): """ roundtrip003.json """ self._run_roundtrip_json("roundtrip03.json") def test_roundtrip004(self): """ roundtrip004.json """ self._run_roundtrip_json("roundtrip04.json") def test_roundtrip005(self): """ roundtrip005.json """ self._run_roundtrip_json("roundtrip05.json") def test_roundtrip006(self): """ roundtrip006.json """ self._run_roundtrip_json("roundtrip06.json") def test_roundtrip007(self): """ roundtrip007.json """ self._run_roundtrip_json("roundtrip07.json") def test_roundtrip008(self): """ roundtrip008.json """ self._run_roundtrip_json("roundtrip08.json") def test_roundtrip009(self): """ roundtrip009.json """ self._run_roundtrip_json("roundtrip09.json") def test_roundtrip010(self): """ roundtrip010.json """ self._run_roundtrip_json("roundtrip10.json") def test_roundtrip011(self): """ roundtrip011.json """ self._run_roundtrip_json("roundtrip11.json") def test_roundtrip012(self): """ roundtrip012.json """ self._run_roundtrip_json("roundtrip12.json") def test_roundtrip013(self): """ roundtrip013.json """ self._run_roundtrip_json("roundtrip13.json") def test_roundtrip014(self): """ roundtrip014.json """ self._run_roundtrip_json("roundtrip14.json") def test_roundtrip015(self): """ roundtrip015.json """ self._run_roundtrip_json("roundtrip15.json") def test_roundtrip016(self): """ roundtrip016.json """ self._run_roundtrip_json("roundtrip16.json") def test_roundtrip017(self): """ roundtrip017.json """ self._run_roundtrip_json("roundtrip17.json") def test_roundtrip018(self): """ roundtrip018.json """ self._run_roundtrip_json("roundtrip18.json") def test_roundtrip019(self): """ roundtrip019.json """ self._run_roundtrip_json("roundtrip19.json") def test_roundtrip020(self): """ roundtrip020.json """ self._run_roundtrip_json("roundtrip20.json") def test_roundtrip021(self): """ roundtrip021.json """ self._run_roundtrip_json("roundtrip21.json") def test_roundtrip022(self): """ roundtrip022.json """ self._run_roundtrip_json("roundtrip22.json") def test_roundtrip023(self): """ roundtrip023.json """ self._run_roundtrip_json("roundtrip23.json") def test_roundtrip024(self): """ roundtrip024.json """ self._run_roundtrip_json("roundtrip24.json") def test_roundtrip025(self): """ roundtrip025.json """ self._run_roundtrip_json("roundtrip25.json") def test_roundtrip026(self): """ roundtrip026.json """ self._run_roundtrip_json("roundtrip26.json") def test_roundtrip027(self): """ roundtrip027.json """ self._run_roundtrip_json("roundtrip27.json") ijl-orjson-aa8c946/test/test_sort_keys.py000066400000000000000000000032201505336676500206500ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import orjson from .util import needs_data, read_fixture_obj @needs_data class TestDictSortKeys: # citm_catalog is already sorted def test_twitter_sorted(self): """ twitter.json sorted """ obj = read_fixture_obj("twitter.json.xz") assert list(obj.keys()) != sorted(list(obj.keys())) serialized = orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) val = orjson.loads(serialized) assert list(val.keys()) == sorted(list(val.keys())) def test_canada_sorted(self): """ canada.json sorted """ obj = read_fixture_obj("canada.json.xz") assert list(obj.keys()) != sorted(list(obj.keys())) serialized = orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) val = orjson.loads(serialized) assert list(val.keys()) == sorted(list(val.keys())) def test_github_sorted(self): """ github.json sorted """ obj = read_fixture_obj("github.json.xz") for each in obj: assert list(each.keys()) != sorted(list(each.keys())) serialized = orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) val = orjson.loads(serialized) for each in val: assert list(each.keys()) == sorted(list(each.keys())) def test_utf8_sorted(self): """ UTF-8 sorted """ obj = {"a": 1, "ä": 2, "A": 3} assert list(obj.keys()) != sorted(list(obj.keys())) serialized = orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) val = orjson.loads(serialized) assert list(val.keys()) == sorted(list(val.keys())) ijl-orjson-aa8c946/test/test_subclass.py000066400000000000000000000060661505336676500204600ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import collections import json import pytest import orjson class SubStr(str): pass class SubInt(int): pass class SubDict(dict): pass class SubList(list): pass class SubFloat(float): pass class SubTuple(tuple): pass class TestSubclass: def test_subclass_str(self): assert orjson.dumps(SubStr("zxc")) == b'"zxc"' def test_subclass_str_invalid(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(SubStr("\ud800")) def test_subclass_int(self): assert orjson.dumps(SubInt(1)) == b"1" def test_subclass_int_64(self): for val in (9223372036854775807, -9223372036854775807): assert orjson.dumps(SubInt(val)) == str(val).encode("utf-8") def test_subclass_int_53(self): for val in (9007199254740992, -9007199254740992): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(SubInt(val), option=orjson.OPT_STRICT_INTEGER) def test_subclass_dict(self): assert orjson.dumps(SubDict({"a": "b"})) == b'{"a":"b"}' def test_subclass_list(self): assert orjson.dumps(SubList(["a", "b"])) == b'["a","b"]' ref = [True] * 512 assert orjson.loads(orjson.dumps(SubList(ref))) == ref def test_subclass_float(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(SubFloat(1.1)) assert json.dumps(SubFloat(1.1)) == "1.1" def test_subclass_tuple(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(SubTuple((1, 2))) assert json.dumps(SubTuple((1, 2))) == "[1, 2]" def test_namedtuple(self): Point = collections.namedtuple("Point", ["x", "y"]) with pytest.raises(orjson.JSONEncodeError): orjson.dumps(Point(1, 2)) def test_subclass_circular_dict(self): obj = SubDict({}) obj["obj"] = obj with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj) def test_subclass_circular_list(self): obj = SubList([]) obj.append(obj) with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj) def test_subclass_circular_nested(self): obj = SubDict({}) obj["list"] = SubList([{"obj": obj}]) with pytest.raises(orjson.JSONEncodeError): orjson.dumps(obj) class TestSubclassPassthrough: def test_subclass_str(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(SubStr("zxc"), option=orjson.OPT_PASSTHROUGH_SUBCLASS) def test_subclass_int(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(SubInt(1), option=orjson.OPT_PASSTHROUGH_SUBCLASS) def test_subclass_dict(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(SubDict({"a": "b"}), option=orjson.OPT_PASSTHROUGH_SUBCLASS) def test_subclass_list(self): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(SubList(["a", "b"]), option=orjson.OPT_PASSTHROUGH_SUBCLASS) ijl-orjson-aa8c946/test/test_transform.py000066400000000000000000000072461505336676500206550ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import pytest import orjson from .util import needs_data, read_fixture_bytes def _read_file(filename): return read_fixture_bytes(filename, "transform").strip(b"\n").strip(b"\r") @needs_data class TestJSONTestSuiteTransform: def _pass_transform(self, filename, reference=None): data = _read_file(filename) assert orjson.dumps(orjson.loads(data)) == (reference or data) def _fail_transform(self, filename): data = _read_file(filename) with pytest.raises(orjson.JSONDecodeError): orjson.loads(data) def test_number_1(self): """ number_1.0.json """ self._pass_transform("number_1.0.json") def test_number_1e6(self): """ number_1e6.json """ self._pass_transform("number_1e6.json", b"[1000000.0]") def test_number_1e_999(self): """ number_1e-999.json """ self._pass_transform("number_1e-999.json", b"[0.0]") def test_number_10000000000000000999(self): """ number_10000000000000000999.json """ # cannot serialize due to range assert orjson.loads(_read_file("number_10000000000000000999.json")) == [ 10000000000000000999, ] def test_number_1000000000000000(self): """ number_1000000000000000.json """ self._pass_transform("number_1000000000000000.json") def test_object_key_nfc_nfd(self): """ object_key_nfc_nfd.json """ self._pass_transform("object_key_nfc_nfd.json") def test_object_key_nfd_nfc(self): """ object_key_nfd_nfc.json """ self._pass_transform("object_key_nfd_nfc.json") def test_object_same_key_different_values(self): """ object_same_key_different_values.json """ self._pass_transform("object_same_key_different_values.json", b'{"a":2}') def test_object_same_key_same_value(self): """ object_same_key_same_value.json """ self._pass_transform("object_same_key_same_value.json", b'{"a":1}') def test_object_same_key_unclear_values(self): """ object_same_key_unclear_values.json """ data = _read_file("object_same_key_unclear_values.json") # varies by backend assert data in (b'{"a":-0.0}', b'{"a":0, "a":-0}') def test_string_1_escaped_invalid_codepoint(self): """ string_1_escaped_invalid_codepoint.json """ self._fail_transform("string_1_escaped_invalid_codepoint.json") def test_string_1_invalid_codepoint(self): """ string_1_invalid_codepoint.json """ self._fail_transform("string_1_invalid_codepoint.json") def test_string_2_escaped_invalid_codepoints(self): """ string_2_escaped_invalid_codepoints.json """ self._fail_transform("string_2_escaped_invalid_codepoints.json") def test_string_2_invalid_codepoints(self): """ string_2_invalid_codepoints.json """ self._fail_transform("string_2_invalid_codepoints.json") def test_string_3_escaped_invalid_codepoints(self): """ string_3_escaped_invalid_codepoints.json """ self._fail_transform("string_3_escaped_invalid_codepoints.json") def test_string_3_invalid_codepoints(self): """ string_3_invalid_codepoints.json """ self._fail_transform("string_3_invalid_codepoints.json") def test_string_with_escaped_NULL(self): """ string_with_escaped_NULL.json """ self._pass_transform("string_with_escaped_NULL.json") ijl-orjson-aa8c946/test/test_type.py000066400000000000000000000420051505336676500176130ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import io import sys import pytest import orjson class TestType: def test_fragment(self): """ orjson.JSONDecodeError on fragments """ for val in ("n", "{", "[", "t"): pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_invalid(self): """ orjson.JSONDecodeError on invalid """ for val in ('{"age", 44}', "[31337,]", "[,31337]", "[]]", "[,]"): pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_str(self): """ str """ for obj, ref in (("blah", b'"blah"'), ("東京", b'"\xe6\x9d\xb1\xe4\xba\xac"')): assert orjson.dumps(obj) == ref assert orjson.loads(ref) == obj def test_str_latin1(self): """ str latin1 """ assert orjson.loads(orjson.dumps("üýþÿ")) == "üýþÿ" def test_str_long(self): """ str long """ for obj in ("aaaa" * 1024, "üýþÿ" * 1024, "好" * 1024, "�" * 1024): assert orjson.loads(orjson.dumps(obj)) == obj def test_str_2mib(self): ref = '🐈🐈🐈🐈🐈"üýa0s9999🐈🐈🐈🐈🐈9\0999\\9999' * 1024 * 50 assert orjson.loads(orjson.dumps(ref)) == ref def test_str_very_long(self): """ str long enough to trigger overflow in bytecount """ for obj in ("aaaa" * 20000, "üýþÿ" * 20000, "好" * 20000, "�" * 20000): assert orjson.loads(orjson.dumps(obj)) == obj def test_str_replacement(self): """ str roundtrip � """ assert orjson.dumps("�") == b'"\xef\xbf\xbd"' assert orjson.loads(b'"\xef\xbf\xbd"') == "�" def test_str_trailing_4_byte(self): ref = "うぞ〜😏🙌" assert orjson.loads(orjson.dumps(ref)) == ref def test_str_ascii_control(self): """ worst case format_escaped_str_with_escapes() allocation """ ref = "\x01\x1f" * 1024 * 16 assert orjson.loads(orjson.dumps(ref)) == ref assert orjson.loads(orjson.dumps(ref, option=orjson.OPT_INDENT_2)) == ref def test_str_escape_quote_0(self): assert orjson.dumps('"aaaaaaabb') == b'"\\"aaaaaaabb"' def test_str_escape_quote_1(self): assert orjson.dumps('a"aaaaaabb') == b'"a\\"aaaaaabb"' def test_str_escape_quote_2(self): assert orjson.dumps('aa"aaaaabb') == b'"aa\\"aaaaabb"' def test_str_escape_quote_3(self): assert orjson.dumps('aaa"aaaabb') == b'"aaa\\"aaaabb"' def test_str_escape_quote_4(self): assert orjson.dumps('aaaa"aaabb') == b'"aaaa\\"aaabb"' def test_str_escape_quote_5(self): assert orjson.dumps('aaaaa"aabb') == b'"aaaaa\\"aabb"' def test_str_escape_quote_6(self): assert orjson.dumps('aaaaaa"abb') == b'"aaaaaa\\"abb"' def test_str_escape_quote_7(self): assert orjson.dumps('aaaaaaa"bb') == b'"aaaaaaa\\"bb"' def test_str_escape_quote_8(self): assert orjson.dumps('aaaaaaaab"') == b'"aaaaaaaab\\""' def test_str_escape_quote_multi(self): assert ( orjson.dumps('aa"aaaaabbbbbbbbbbbbbbbbbbbb"bb') == b'"aa\\"aaaaabbbbbbbbbbbbbbbbbbbb\\"bb"' ) def test_str_escape_quote_buffer(self): orjson.dumps(['"' * 4096] * 1024) def test_str_escape_backslash_0(self): assert orjson.dumps("\\aaaaaaabb") == b'"\\\\aaaaaaabb"' def test_str_escape_backslash_1(self): assert orjson.dumps("a\\aaaaaabb") == b'"a\\\\aaaaaabb"' def test_str_escape_backslash_2(self): assert orjson.dumps("aa\\aaaaabb") == b'"aa\\\\aaaaabb"' def test_str_escape_backslash_3(self): assert orjson.dumps("aaa\\aaaabb") == b'"aaa\\\\aaaabb"' def test_str_escape_backslash_4(self): assert orjson.dumps("aaaa\\aaabb") == b'"aaaa\\\\aaabb"' def test_str_escape_backslash_5(self): assert orjson.dumps("aaaaa\\aabb") == b'"aaaaa\\\\aabb"' def test_str_escape_backslash_6(self): assert orjson.dumps("aaaaaa\\abb") == b'"aaaaaa\\\\abb"' def test_str_escape_backslash_7(self): assert orjson.dumps("aaaaaaa\\bb") == b'"aaaaaaa\\\\bb"' def test_str_escape_backslash_8(self): assert orjson.dumps("aaaaaaaab\\") == b'"aaaaaaaab\\\\"' def test_str_escape_backslash_multi(self): assert ( orjson.dumps("aa\\aaaaabbbbbbbbbbbbbbbbbbbb\\bb") == b'"aa\\\\aaaaabbbbbbbbbbbbbbbbbbbb\\\\bb"' ) def test_str_escape_backslash_buffer(self): orjson.dumps(["\\" * 4096] * 1024) def test_str_escape_x32_0(self): assert orjson.dumps("\taaaaaaabb") == b'"\\taaaaaaabb"' def test_str_escape_x32_1(self): assert orjson.dumps("a\taaaaaabb") == b'"a\\taaaaaabb"' def test_str_escape_x32_2(self): assert orjson.dumps("aa\taaaaabb") == b'"aa\\taaaaabb"' def test_str_escape_x32_3(self): assert orjson.dumps("aaa\taaaabb") == b'"aaa\\taaaabb"' def test_str_escape_x32_4(self): assert orjson.dumps("aaaa\taaabb") == b'"aaaa\\taaabb"' def test_str_escape_x32_5(self): assert orjson.dumps("aaaaa\taabb") == b'"aaaaa\\taabb"' def test_str_escape_x32_6(self): assert orjson.dumps("aaaaaa\tabb") == b'"aaaaaa\\tabb"' def test_str_escape_x32_7(self): assert orjson.dumps("aaaaaaa\tbb") == b'"aaaaaaa\\tbb"' def test_str_escape_x32_8(self): assert orjson.dumps("aaaaaaaab\t") == b'"aaaaaaaab\\t"' def test_str_escape_x32_multi(self): assert ( orjson.dumps("aa\taaaaabbbbbbbbbbbbbbbbbbbb\tbb") == b'"aa\\taaaaabbbbbbbbbbbbbbbbbbbb\\tbb"' ) def test_str_escape_x32_buffer(self): orjson.dumps(["\t" * 4096] * 1024) def test_str_emoji(self): ref = "®️" assert orjson.loads(orjson.dumps(ref)) == ref def test_str_emoji_escape(self): ref = '/"®️/"' assert orjson.loads(orjson.dumps(ref)) == ref def test_very_long_list(self): orjson.dumps([[]] * 1024 * 16) def test_very_long_list_pretty(self): orjson.dumps([[]] * 1024 * 16, option=orjson.OPT_INDENT_2) def test_very_long_dict(self): orjson.dumps([{}] * 1024 * 16) def test_very_long_dict_pretty(self): orjson.dumps([{}] * 1024 * 16, option=orjson.OPT_INDENT_2) def test_very_long_str_empty(self): orjson.dumps([""] * 1024 * 16) def test_very_long_str_empty_pretty(self): orjson.dumps([""] * 1024 * 16, option=orjson.OPT_INDENT_2) def test_very_long_str_not_empty(self): orjson.dumps(["a"] * 1024 * 16) def test_very_long_str_not_empty_pretty(self): orjson.dumps(["a"] * 1024 * 16, option=orjson.OPT_INDENT_2) def test_very_long_bool(self): orjson.dumps([True] * 1024 * 16) def test_very_long_bool_pretty(self): orjson.dumps([True] * 1024 * 16, option=orjson.OPT_INDENT_2) def test_very_long_int(self): orjson.dumps([(2**64) - 1] * 1024 * 16) def test_very_long_int_pretty(self): orjson.dumps([(2**64) - 1] * 1024 * 16, option=orjson.OPT_INDENT_2) def test_very_long_float(self): orjson.dumps([sys.float_info.max] * 1024 * 16) def test_very_long_float_pretty(self): orjson.dumps([sys.float_info.max] * 1024 * 16, option=orjson.OPT_INDENT_2) def test_str_surrogates_loads(self): """ str unicode surrogates loads() """ pytest.raises(orjson.JSONDecodeError, orjson.loads, '"\ud800"') pytest.raises(orjson.JSONDecodeError, orjson.loads, '"\ud83d\ude80"') pytest.raises(orjson.JSONDecodeError, orjson.loads, '"\udcff"') pytest.raises( orjson.JSONDecodeError, orjson.loads, b'"\xed\xa0\xbd\xed\xba\x80"', ) # \ud83d\ude80 def test_str_surrogates_dumps(self): """ str unicode surrogates dumps() """ pytest.raises(orjson.JSONEncodeError, orjson.dumps, "\ud800") pytest.raises(orjson.JSONEncodeError, orjson.dumps, "\ud83d\ude80") pytest.raises(orjson.JSONEncodeError, orjson.dumps, "\udcff") pytest.raises(orjson.JSONEncodeError, orjson.dumps, {"\ud83d\ude80": None}) pytest.raises( orjson.JSONEncodeError, orjson.dumps, b"\xed\xa0\xbd\xed\xba\x80", ) # \ud83d\ude80 def test_bytes_dumps(self): """ bytes dumps not supported """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps([b"a"]) def test_bytes_loads(self): """ bytes loads """ assert orjson.loads(b"[]") == [] def test_bytearray_loads(self): """ bytearray loads """ arr = bytearray() arr.extend(b"[]") assert orjson.loads(arr) == [] def test_memoryview_loads(self): """ memoryview loads """ arr = bytearray() arr.extend(b"[]") assert orjson.loads(memoryview(arr)) == [] def test_bytesio_loads(self): """ memoryview loads """ arr = io.BytesIO(b"[]") assert orjson.loads(arr.getbuffer()) == [] def test_bool(self): """ bool """ for obj, ref in ((True, "true"), (False, "false")): assert orjson.dumps(obj) == ref.encode("utf-8") assert orjson.loads(ref) == obj def test_bool_true_array(self): """ bool true array """ obj = [True] * 256 ref = ("[" + ("true," * 255) + "true]").encode("utf-8") assert orjson.dumps(obj) == ref assert orjson.loads(ref) == obj def test_bool_false_array(self): """ bool false array """ obj = [False] * 256 ref = ("[" + ("false," * 255) + "false]").encode("utf-8") assert orjson.dumps(obj) == ref assert orjson.loads(ref) == obj def test_none(self): """ null """ obj = None ref = "null" assert orjson.dumps(obj) == ref.encode("utf-8") assert orjson.loads(ref) == obj def test_int(self): """ int compact and non-compact """ obj = [-5000, -1000, -10, -5, -2, -1, 0, 1, 2, 5, 10, 1000, 50000] ref = b"[-5000,-1000,-10,-5,-2,-1,0,1,2,5,10,1000,50000]" assert orjson.dumps(obj) == ref assert orjson.loads(ref) == obj def test_null_array(self): """ null array """ obj = [None] * 256 ref = ("[" + ("null," * 255) + "null]").encode("utf-8") assert orjson.dumps(obj) == ref assert orjson.loads(ref) == obj def test_nan_dumps(self): """ NaN serializes to null """ assert orjson.dumps(float("NaN")) == b"null" def test_nan_loads(self): """ NaN is not valid JSON """ with pytest.raises(orjson.JSONDecodeError): orjson.loads("[NaN]") with pytest.raises(orjson.JSONDecodeError): orjson.loads("[nan]") def test_infinity_dumps(self): """ Infinity serializes to null """ assert orjson.dumps(float("Infinity")) == b"null" def test_infinity_loads(self): """ Infinity, -Infinity is not valid JSON """ with pytest.raises(orjson.JSONDecodeError): orjson.loads("[infinity]") with pytest.raises(orjson.JSONDecodeError): orjson.loads("[Infinity]") with pytest.raises(orjson.JSONDecodeError): orjson.loads("[-Infinity]") with pytest.raises(orjson.JSONDecodeError): orjson.loads("[-infinity]") def test_int_53(self): """ int 53-bit """ for val in (9007199254740991, -9007199254740991): assert orjson.loads(str(val)) == val assert orjson.dumps(val, option=orjson.OPT_STRICT_INTEGER) == str( val, ).encode("utf-8") def test_int_53_exc(self): """ int 53-bit exception on 64-bit """ for val in (9007199254740992, -9007199254740992): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(val, option=orjson.OPT_STRICT_INTEGER) def test_int_53_exc_usize(self): """ int 53-bit exception on 64-bit usize """ for val in (9223372036854775808, 18446744073709551615): with pytest.raises(orjson.JSONEncodeError): orjson.dumps(val, option=orjson.OPT_STRICT_INTEGER) def test_int_53_exc_128(self): """ int 53-bit exception on 128-bit """ val = 2**65 with pytest.raises(orjson.JSONEncodeError): orjson.dumps(val, option=orjson.OPT_STRICT_INTEGER) def test_int_64(self): """ int 64-bit """ for val in (9223372036854775807, -9223372036854775807): assert orjson.loads(str(val)) == val assert orjson.dumps(val) == str(val).encode("utf-8") def test_uint_64(self): """ uint 64-bit """ for val in (0, 9223372036854775808, 18446744073709551615): assert orjson.loads(str(val)) == val assert orjson.dumps(val) == str(val).encode("utf-8") def test_int_128(self): """ int 128-bit """ for val in (18446744073709551616, -9223372036854775809): pytest.raises(orjson.JSONEncodeError, orjson.dumps, val) def test_float(self): """ float """ assert -1.1234567893 == orjson.loads("-1.1234567893") assert -1.234567893 == orjson.loads("-1.234567893") assert -1.34567893 == orjson.loads("-1.34567893") assert -1.4567893 == orjson.loads("-1.4567893") assert -1.567893 == orjson.loads("-1.567893") assert -1.67893 == orjson.loads("-1.67893") assert -1.7893 == orjson.loads("-1.7893") assert -1.893 == orjson.loads("-1.893") assert -1.3 == orjson.loads("-1.3") assert 1.1234567893 == orjson.loads("1.1234567893") assert 1.234567893 == orjson.loads("1.234567893") assert 1.34567893 == orjson.loads("1.34567893") assert 1.4567893 == orjson.loads("1.4567893") assert 1.567893 == orjson.loads("1.567893") assert 1.67893 == orjson.loads("1.67893") assert 1.7893 == orjson.loads("1.7893") assert 1.893 == orjson.loads("1.893") assert 1.3 == orjson.loads("1.3") def test_float_precision_loads(self): """ float precision loads() """ assert orjson.loads("31.245270191439438") == 31.245270191439438 assert orjson.loads("-31.245270191439438") == -31.245270191439438 assert orjson.loads("121.48791951161945") == 121.48791951161945 assert orjson.loads("-121.48791951161945") == -121.48791951161945 assert orjson.loads("100.78399658203125") == 100.78399658203125 assert orjson.loads("-100.78399658203125") == -100.78399658203125 def test_float_precision_dumps(self): """ float precision dumps() """ assert orjson.dumps(31.245270191439438) == b"31.245270191439438" assert orjson.dumps(-31.245270191439438) == b"-31.245270191439438" assert orjson.dumps(121.48791951161945) == b"121.48791951161945" assert orjson.dumps(-121.48791951161945) == b"-121.48791951161945" assert orjson.dumps(100.78399658203125) == b"100.78399658203125" assert orjson.dumps(-100.78399658203125) == b"-100.78399658203125" def test_float_edge(self): """ float edge cases """ assert orjson.dumps(0.8701) == b"0.8701" assert orjson.loads("0.8701") == 0.8701 assert ( orjson.loads("0.0000000000000000000000000000000000000000000000000123e50") == 1.23 ) assert orjson.loads("0.4e5") == 40000.0 assert orjson.loads("0.00e-00") == 0.0 assert orjson.loads("0.4e-001") == 0.04 assert orjson.loads("0.123456789e-12") == 1.23456789e-13 assert orjson.loads("1.234567890E+34") == 1.23456789e34 assert orjson.loads("23456789012E66") == 2.3456789012e76 def test_float_notation(self): """ float notation """ for val in ("1.337E40", "1.337e+40", "1337e40", "1.337E-4"): obj = orjson.loads(val) assert obj == float(val) assert orjson.dumps(val) == (f'"{val}"').encode("utf-8") def test_list(self): """ list """ obj = ["a", "😊", True, {"b": 1.1}, 2] ref = '["a","😊",true,{"b":1.1},2]' assert orjson.dumps(obj) == ref.encode("utf-8") assert orjson.loads(ref) == obj def test_tuple(self): """ tuple """ obj = ("a", "😊", True, {"b": 1.1}, 2) ref = '["a","😊",true,{"b":1.1},2]' assert orjson.dumps(obj) == ref.encode("utf-8") assert orjson.loads(ref) == list(obj) def test_object(self): """ object() dumps() """ with pytest.raises(orjson.JSONEncodeError): orjson.dumps(object()) ijl-orjson-aa8c946/test/test_typeddict.py000066400000000000000000000007051505336676500206240ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import orjson try: from typing import TypedDict # type: ignore except ImportError: from typing_extensions import TypedDict class TestTypedDict: def test_typeddict(self): """ dumps() TypedDict """ class TypedDict1(TypedDict): a: str b: int obj = TypedDict1(a="a", b=1) assert orjson.dumps(obj) == b'{"a":"a","b":1}' ijl-orjson-aa8c946/test/test_ujson.py000066400000000000000000000250431505336676500177730ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import json import pytest import orjson class TestUltraJSON: def test_doubleLongIssue(self): sut = {"a": -4342969734183514} encoded = orjson.dumps(sut) decoded = orjson.loads(encoded) assert sut == decoded encoded = orjson.dumps(sut) decoded = orjson.loads(encoded) assert sut == decoded def test_doubleLongDecimalIssue(self): sut = {"a": -12345678901234.56789012} encoded = orjson.dumps(sut) decoded = orjson.loads(encoded) assert sut == decoded encoded = orjson.dumps(sut) decoded = orjson.loads(encoded) assert sut == decoded def test_encodeDecodeLongDecimal(self): sut = {"a": -528656961.4399388} encoded = orjson.dumps(sut) orjson.loads(encoded) def test_decimalDecodeTest(self): sut = {"a": 4.56} encoded = orjson.dumps(sut) decoded = orjson.loads(encoded) pytest.approx(sut["a"], decoded["a"]) def test_encodeDictWithUnicodeKeys(self): val = { "key1": "value1", "key1": "value1", "key1": "value1", "key1": "value1", "key1": "value1", "key1": "value1", } orjson.dumps(val) val = { "بن": "value1", "بن": "value1", "بن": "value1", "بن": "value1", "بن": "value1", "بن": "value1", "بن": "value1", } orjson.dumps(val) def test_encodeArrayOfNestedArrays(self): val = [[[[]]]] * 20 # type: ignore output = orjson.dumps(val) assert val == orjson.loads(output) assert val == orjson.loads(output) def test_encodeArrayOfDoubles(self): val = [31337.31337, 31337.31337, 31337.31337, 31337.31337] * 10 output = orjson.dumps(val) assert val == orjson.loads(output) assert val == orjson.loads(output) def test_encodeStringConversion2(self): val = "A string \\ / \b \f \n \r \t" output = orjson.dumps(val) assert val == orjson.loads(output) assert output == b'"A string \\\\ / \\b \\f \\n \\r \\t"' assert val == orjson.loads(output) def test_decodeUnicodeConversion(self): pass def test_encodeUnicodeConversion1(self): val = "Räksmörgås اسامة بن محمد بن عوض بن لادن" enc = orjson.dumps(val) dec = orjson.loads(enc) assert enc == orjson.dumps(val) assert dec == orjson.loads(enc) def test_encodeControlEscaping(self): val = "\x19" enc = orjson.dumps(val) dec = orjson.loads(enc) assert val == dec assert enc == orjson.dumps(val) def test_encodeUnicodeConversion2(self): val = "\xe6\x97\xa5\xd1\x88" enc = orjson.dumps(val) dec = orjson.loads(enc) assert enc == orjson.dumps(val) assert dec == orjson.loads(enc) def test_encodeUnicodeSurrogatePair(self): val = "\xf0\x90\x8d\x86" enc = orjson.dumps(val) dec = orjson.loads(enc) assert enc == orjson.dumps(val) assert dec == orjson.loads(enc) def test_encodeUnicode4BytesUTF8(self): val = "\xf0\x91\x80\xb0TRAILINGNORMAL" enc = orjson.dumps(val) dec = orjson.loads(enc) assert enc == orjson.dumps(val) assert dec == orjson.loads(enc) def test_encodeUnicode4BytesUTF8Highest(self): val = "\xf3\xbf\xbf\xbfTRAILINGNORMAL" enc = orjson.dumps(val) dec = orjson.loads(enc) assert enc == orjson.dumps(val) assert dec == orjson.loads(enc) def testEncodeUnicodeBMP(self): s = "\U0001f42e\U0001f42e\U0001f42d\U0001f42d" # 🐮🐮🐭🐭 orjson.dumps(s) json.dumps(s) assert json.loads(json.dumps(s)) == s assert orjson.loads(orjson.dumps(s)) == s def testEncodeSymbols(self): s = "\u273f\u2661\u273f" # ✿♡✿ encoded = orjson.dumps(s) encoded_json = json.dumps(s) decoded = orjson.loads(encoded) assert s == decoded encoded = orjson.dumps(s) # json outputs an unicode object encoded_json = json.dumps(s, ensure_ascii=False) assert encoded == encoded_json.encode("utf-8") decoded = orjson.loads(encoded) assert s == decoded def test_encodeArrayInArray(self): val = [[[[]]]] # type: ignore output = orjson.dumps(val) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) def test_encodeIntConversion(self): val = 31337 output = orjson.dumps(val) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) def test_encodeIntNegConversion(self): val = -31337 output = orjson.dumps(val) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) def test_encodeLongNegConversion(self): val = -9223372036854775808 output = orjson.dumps(val) orjson.loads(output) orjson.loads(output) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) def test_encodeListConversion(self): val = [1, 2, 3, 4] output = orjson.dumps(val) assert val == orjson.loads(output) assert val == orjson.loads(output) def test_encodeDictConversion(self): val = {"k1": 1, "k2": 2, "k3": 3, "k4": 4} output = orjson.dumps(val) assert val == orjson.loads(output) assert val == orjson.loads(output) assert val == orjson.loads(output) def test_encodeNoneConversion(self): val = None output = orjson.dumps(val) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) def test_encodeTrueConversion(self): val = True output = orjson.dumps(val) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) def test_encodeFalseConversion(self): val = False output = orjson.dumps(val) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) def test_encodeToUTF8(self): val = b"\xe6\x97\xa5\xd1\x88".decode("utf-8") enc = orjson.dumps(val) dec = orjson.loads(enc) assert enc == orjson.dumps(val) assert dec == orjson.loads(enc) def test_decodeFromUnicode(self): val = '{"obj": 31337}' dec1 = orjson.loads(val) dec2 = orjson.loads(str(val)) assert dec1 == dec2 def test_decodeJibberish(self): val = "fdsa sda v9sa fdsa" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeBrokenArrayStart(self): val = "[" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeBrokenObjectStart(self): val = "{" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeBrokenArrayEnd(self): val = "]" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeBrokenObjectEnd(self): val = "}" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeObjectDepthTooBig(self): val = "{" * (1024 * 1024) pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeStringUnterminated(self): val = '"TESTING' pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeStringUntermEscapeSequence(self): val = '"TESTING\\"' pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeStringBadEscape(self): val = '"TESTING\\"' pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeTrueBroken(self): val = "tru" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeFalseBroken(self): val = "fa" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeNullBroken(self): val = "n" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeBrokenDictKeyTypeLeakTest(self): val = '{{1337:""}}' for _ in range(1000): pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeBrokenDictLeakTest(self): val = '{{"key":"}' for _ in range(1000): pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeBrokenListLeakTest(self): val = "[[[true" for _ in range(1000): pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeDictWithNoKey(self): val = "{{{{31337}}}}" pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeDictWithNoColonOrValue(self): val = '{{{{"key"}}}}' pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeDictWithNoValue(self): val = '{{{{"key":}}}}' pytest.raises(orjson.JSONDecodeError, orjson.loads, val) def test_decodeNumericIntPos(self): val = "31337" assert 31337 == orjson.loads(val) def test_decodeNumericIntNeg(self): assert -31337 == orjson.loads("-31337") def test_encodeNullCharacter(self): val = "31337 \x00 1337" output = orjson.dumps(val) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) val = "\x00" output = orjson.dumps(val) assert val == orjson.loads(output) assert output == orjson.dumps(val) assert val == orjson.loads(output) assert b'" \\u0000\\r\\n "' == orjson.dumps(" \u0000\r\n ") def test_decodeNullCharacter(self): val = '"31337 \\u0000 31337"' assert orjson.loads(val) == json.loads(val) def test_decodeEscape(self): base = "\u00e5".encode("utf-8") quote = b'"' val = quote + base + quote assert json.loads(val) == orjson.loads(val) def test_decodeBigEscape(self): for _ in range(10): base = "\u00e5".encode("utf-8") quote = b'"' val = quote + (base * 1024 * 1024 * 2) + quote assert json.loads(val) == orjson.loads(val) ijl-orjson-aa8c946/test/test_uuid.py000066400000000000000000000065371505336676500176120ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import uuid import pytest import orjson class TestUUID: def test_uuid_immutable(self): """ UUID objects are immutable """ val = uuid.uuid4() with pytest.raises(TypeError): val.int = 1 # type: ignore with pytest.raises(TypeError): val.int = None # type: ignore def test_uuid_int(self): """ UUID.int is a 128-bit integer """ val = uuid.UUID("7202d115-7ff3-4c81-a7c1-2a1f067b1ece") assert isinstance(val.int, int) assert val.int >= 2**64 assert val.int < 2**128 assert val.int == 151546616840194781678008611711208857294 def test_uuid_overflow(self): """ UUID.int can't trigger errors in _PyLong_AsByteArray """ with pytest.raises(ValueError): uuid.UUID(int=2**128) with pytest.raises(ValueError): uuid.UUID(int=-1) def test_uuid_subclass(self): """ UUID subclasses are not serialized """ class AUUID(uuid.UUID): pass with pytest.raises(orjson.JSONEncodeError): orjson.dumps(AUUID("{12345678-1234-5678-1234-567812345678}")) def test_serializes_withopt(self): """ dumps() accepts deprecated OPT_SERIALIZE_UUID """ assert ( orjson.dumps( uuid.UUID("7202d115-7ff3-4c81-a7c1-2a1f067b1ece"), option=orjson.OPT_SERIALIZE_UUID, ) == b'"7202d115-7ff3-4c81-a7c1-2a1f067b1ece"' ) def test_nil_uuid(self): assert ( orjson.dumps(uuid.UUID("00000000-0000-0000-0000-000000000000")) == b'"00000000-0000-0000-0000-000000000000"' ) def test_all_ways_to_create_uuid_behave_equivalently(self): # Note that according to the docstring for the uuid.UUID class, all the # forms below are equivalent -- they end up with the same value for # `self.int`, which is all that really matters uuids = [ uuid.UUID("{12345678-1234-5678-1234-567812345678}"), uuid.UUID("12345678123456781234567812345678"), uuid.UUID("urn:uuid:12345678-1234-5678-1234-567812345678"), uuid.UUID(bytes=b"\x12\x34\x56\x78" * 4), uuid.UUID( bytes_le=b"\x78\x56\x34\x12\x34\x12\x78\x56\x12\x34\x56\x78\x12\x34\x56\x78", ), uuid.UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678)), uuid.UUID(int=0x12345678123456781234567812345678), ] result = orjson.dumps(uuids) canonical_uuids = [f'"{u!s}"' for u in uuids] serialized = ("[{}]".format(",".join(canonical_uuids))).encode("utf8") assert result == serialized def test_serializes_correctly_with_leading_zeroes(self): instance = uuid.UUID(int=0x00345678123456781234567812345678) assert orjson.dumps(instance) == (f'"{instance!s}"').encode("utf-8") def test_all_uuid_creation_functions_create_serializable_uuids(self): uuids = ( uuid.uuid1(), uuid.uuid3(uuid.NAMESPACE_DNS, "python.org"), uuid.uuid4(), uuid.uuid5(uuid.NAMESPACE_DNS, "python.org"), ) for val in uuids: assert orjson.dumps(val) == f'"{val}"'.encode("utf-8") ijl-orjson-aa8c946/test/util.py000066400000000000000000000027071505336676500165550ustar00rootroot00000000000000# SPDX-License-Identifier: (Apache-2.0 OR MIT) import lzma import os import sysconfig from pathlib import Path from typing import Any IS_FREETHREADING = sysconfig.get_config_var("Py_GIL_DISABLED") numpy = None # type: ignore if not IS_FREETHREADING: try: import numpy # type: ignore # noqa: F401 except ImportError: pass pandas = None # type: ignore if not IS_FREETHREADING: try: import pandas # type: ignore # noqa: F401 except ImportError: pass import pytest import orjson data_dir = os.path.join(os.path.dirname(__file__), "../data") STR_CACHE: dict[str, str] = {} OBJ_CACHE: dict[str, Any] = {} def read_fixture_bytes(filename, subdir=None): if subdir is None: path = Path(data_dir, filename) else: path = Path(data_dir, subdir, filename) if path.suffix == ".xz": contents = lzma.decompress(path.read_bytes()) else: contents = path.read_bytes() return contents def read_fixture_str(filename, subdir=None): if filename not in STR_CACHE: STR_CACHE[filename] = read_fixture_bytes(filename, subdir).decode("utf-8") return STR_CACHE[filename] def read_fixture_obj(filename): if filename not in OBJ_CACHE: OBJ_CACHE[filename] = orjson.loads(read_fixture_str(filename)) return OBJ_CACHE[filename] needs_data = pytest.mark.skipif( not Path(data_dir).exists(), reason="Test depends on ./data dir that contains fixtures", )