Skip to content

Commit

Permalink
Merge branch 'serde-rs:master' into size-opt
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed May 30, 2024
2 parents e9ffa9c + 62839b7 commit 7a3f03c
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 122 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --exit-code 1
- run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "serde_json"
version = "1.0.111"
version = "1.0.117"
authors = ["Erick Tryzelaar <[email protected]>", "David Tolnay <[email protected]>"]
categories = ["encoding", "parser-implementations", "no-std"]
description = "A JSON serialization file format"
Expand All @@ -12,7 +12,7 @@ repository = "https://github.com/serde-rs/json"
rust-version = "1.56"

[dependencies]
indexmap = { version = "2", optional = true }
indexmap = { version = "2.2.1", optional = true }
itoa = "1.0"
ryu = "1.0"
serde = { version = "1.0.194", default-features = false }
Expand All @@ -32,9 +32,9 @@ trybuild = { version = "1.0.81", features = ["diff"] }
doc-scrape-examples = false

[package.metadata.docs.rs]
features = ["raw_value", "unbounded_depth"]
features = ["preserve_order", "raw_value", "unbounded_depth"]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
rustdoc-args = ["--generate-link-to-definition"]

[package.metadata.playground]
features = ["raw_value"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ enum Value {

A string of JSON data can be parsed into a `serde_json::Value` by the
[`serde_json::from_str`][from_str] function. There is also
[`from_slice`][from_slice] for parsing from a byte slice &\[u8\] and
[`from_slice`][from_slice] for parsing from a byte slice `&[u8]` and
[`from_reader`][from_reader] for parsing from any `io::Read` like a File or a
TCP stream.

Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::env;
fn main() {
println!("cargo:rerun-if-changed=build.rs");

println!("cargo:rustc-check-cfg=cfg(limb_width_32)");
println!("cargo:rustc-check-cfg=cfg(limb_width_64)");

// Decide ideal limb width for arithmetic in the float parser. Refer to
// src/lexical/math.rs for where this has an effect.
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
Expand Down
8 changes: 4 additions & 4 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
// try to keep the number as a `u64` until we grow
// too large. At that point, switch to parsing the
// value as a `f64`.
if overflow!(significand * 10 + digit, u64::max_value()) {
if overflow!(significand * 10 + digit, u64::MAX) {
return Ok(ParserNumber::F64(tri!(
self.parse_long_integer(positive, significand),
)));
Expand Down Expand Up @@ -562,7 +562,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
let digit = (c - b'0') as u64;

if overflow!(significand * 10 + digit, u64::max_value()) {
if overflow!(significand * 10 + digit, u64::MAX) {
let exponent = exponent_before_decimal_point + exponent_after_decimal_point;
return self.parse_decimal_overflow(positive, significand, exponent);
}
Expand Down Expand Up @@ -626,7 +626,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.eat_char();
let digit = (c - b'0') as i32;

if overflow!(exp * 10 + digit, i32::max_value()) {
if overflow!(exp * 10 + digit, i32::MAX) {
let zero_significand = significand == 0;
return self.parse_exponent_overflow(positive, zero_significand, positive_exp);
}
Expand Down Expand Up @@ -818,7 +818,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.eat_char();
let digit = (c - b'0') as i32;

if overflow!(exp * 10 + digit, i32::max_value()) {
if overflow!(exp * 10 + digit, i32::MAX) {
let zero_significand = self.scratch.iter().all(|&digit| digit == b'0');
return self.parse_exponent_overflow(positive, zero_significand, positive_exp);
}
Expand Down
35 changes: 30 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,20 @@ impl de::Error for Error {

#[cold]
fn invalid_type(unexp: de::Unexpected, exp: &dyn de::Expected) -> Self {
if let de::Unexpected::Unit = unexp {
Error::custom(format_args!("invalid type: null, expected {}", exp))
} else {
Error::custom(format_args!("invalid type: {}, expected {}", unexp, exp))
}
Error::custom(format_args!(
"invalid type: {}, expected {}",
JsonUnexpected(unexp),
exp,
))
}

#[cold]
fn invalid_value(unexp: de::Unexpected, exp: &dyn de::Expected) -> Self {
Error::custom(format_args!(
"invalid value: {}, expected {}",
JsonUnexpected(unexp),
exp,
))
}
}

Expand All @@ -450,6 +459,22 @@ impl ser::Error for Error {
}
}

struct JsonUnexpected<'a>(de::Unexpected<'a>);

impl<'a> Display for JsonUnexpected<'a> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self.0 {
de::Unexpected::Unit => formatter.write_str("null"),
de::Unexpected::Float(value) => write!(
formatter,
"floating point `{}`",
ryu::Buffer::new().format(value),
),
unexp => Display::fmt(&unexp, formatter),
}
}
}

// Parse our own error message that looks like "{} at line {} column {}" to work
// around erased-serde round-tripping the error through de::Error::custom.
fn make_error(mut msg: String) -> Error {
Expand Down
1 change: 0 additions & 1 deletion src/features_check/error.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/features_check/mod.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/lexical/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Big integer type definition.

use super::math::*;
#[allow(unused_imports)]
use alloc::vec::Vec;

/// Storage for a big integer type.
Expand Down
4 changes: 2 additions & 2 deletions src/lexical/exponent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
/// the mantissa we do not overflow for comically-long exponents.
#[inline]
fn into_i32(value: usize) -> i32 {
if value > i32::max_value() as usize {
i32::max_value()
if value > i32::MAX as usize {
i32::MAX
} else {
value as i32
}
Expand Down
2 changes: 1 addition & 1 deletion src/lexical/large_powers32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//! Precalculated large powers for 32-bit limbs.

/// Large powers (&[u32]) for base5 operations.
/// Large powers (`&[u32]`) for base5 operations.
const POW5_1: [u32; 1] = [5];
const POW5_2: [u32; 1] = [25];
const POW5_3: [u32; 1] = [625];
Expand Down
2 changes: 1 addition & 1 deletion src/lexical/large_powers64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//! Precalculated large powers for 64-bit limbs.

/// Large powers (&[u64]) for base5 operations.
/// Large powers (`&[u64]`) for base5 operations.
const POW5_1: [u64; 1] = [5];
const POW5_2: [u64; 1] = [25];
const POW5_3: [u64; 1] = [625];
Expand Down
13 changes: 1 addition & 12 deletions src/lexical/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub trait Float: Number {
const NEGATIVE_INFINITY_BITS: Self::Unsigned;
/// Size of the significand (mantissa) without hidden bit.
const MANTISSA_SIZE: i32;
/// Bias of the exponet
/// Bias of the exponent
const EXPONENT_BIAS: i32;
/// Exponent portion of a denormal float.
const DENORMAL_EXPONENT: i32;
Expand All @@ -248,7 +248,6 @@ pub trait Float: Number {
fn from_bits(u: Self::Unsigned) -> Self;
fn to_bits(self) -> Self::Unsigned;
fn is_sign_positive(self) -> bool;
fn is_sign_negative(self) -> bool;

/// Returns true if the float is a denormal.
#[inline]
Expand Down Expand Up @@ -368,11 +367,6 @@ impl Float for f32 {
fn is_sign_positive(self) -> bool {
f32::is_sign_positive(self)
}

#[inline]
fn is_sign_negative(self) -> bool {
f32::is_sign_negative(self)
}
}

impl Float for f64 {
Expand Down Expand Up @@ -432,9 +426,4 @@ impl Float for f64 {
fn is_sign_positive(self) -> bool {
f64::is_sign_positive(self)
}

#[inline]
fn is_sign_negative(self) -> bool {
f64::is_sign_negative(self)
}
}
2 changes: 1 addition & 1 deletion src/lexical/rounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) fn lower_n_mask(n: u64) -> u64 {
debug_assert!(n <= bits, "lower_n_mask() overflow in shl.");

if n == bits {
u64::max_value()
u64::MAX
} else {
(1 << n) - 1
}
Expand Down
17 changes: 12 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
//!
//! A string of JSON data can be parsed into a `serde_json::Value` by the
//! [`serde_json::from_str`][from_str] function. There is also [`from_slice`]
//! for parsing from a byte slice &\[u8\] and [`from_reader`] for parsing from
//! for parsing from a byte slice `&[u8]` and [`from_reader`] for parsing from
//! any `io::Read` like a File or a TCP stream.
//!
//! ```
Expand Down Expand Up @@ -299,7 +299,7 @@
//! [macro]: crate::json
//! [`serde-json-core`]: https://github.com/rust-embedded-community/serde-json-core

#![doc(html_root_url = "https://docs.rs/serde_json/1.0.111")]
#![doc(html_root_url = "https://docs.rs/serde_json/1.0.117")]
// Ignored clippy lints
#![allow(
clippy::collapsible_else_if,
Expand All @@ -316,6 +316,7 @@
clippy::needless_late_init,
clippy::return_self_not_must_use,
clippy::transmute_ptr_to_ptr,
clippy::unconditional_recursion, // https://github.com/rust-lang/rust-clippy/issues/12133
clippy::unnecessary_wraps
)]
// Ignored clippy_pedantic lints
Expand Down Expand Up @@ -359,11 +360,19 @@
#![deny(clippy::question_mark_used)]
#![allow(non_upper_case_globals)]
#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(not(any(feature = "std", feature = "alloc")))]
compile_error! {
"serde_json requires that either `std` (default) or `alloc` feature is enabled"
}

extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[doc(inline)]
Expand Down Expand Up @@ -405,8 +414,6 @@ pub mod ser;
mod ser;
pub mod value;

mod features_check;

mod io;
#[cfg(feature = "std")]
mod iter;
Expand Down
Loading

0 comments on commit 7a3f03c

Please sign in to comment.