Skip to content

Commit 2c0c369

Browse files
committed
feat: support use_rawnumber and use_raw
1 parent f538413 commit 2c0c369

30 files changed

+442
-781
lines changed

scripts/sanitize.sh

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,10 @@ set -ex
44

55
export ASAN_OPTIONS="disable_coredump=0:unmap_shadow_on_exit=1:abort_on_error=1"
66

7-
testcase_lists() {
8-
cargo test -- -Zunstable-options --list --format json
9-
local result=$?
10-
if [ ${result} -ne 0 ]; then
11-
exit -1
12-
fi
13-
cargo test -- -Zunstable-options --list --format json | jq -c 'select(.type=="test") | .name' | awk -F'"' '{print $2}' | awk '{print ($2) ? $3 : $1}'
14-
return $?
15-
}
16-
17-
sanitize() {
18-
local san="$1"
19-
local target="$2"
20-
local testcase="$3"
21-
# use single thread to make error info more readable and accurate
22-
RUSTFLAGS="-Zsanitizer=${san}" RUSTDOCFLAGS="-Zsanitizer=${san}" cargo test --target ${target} ${testcase} -- --test-threads=1
23-
RUSTFLAGS="-Zsanitizer=${san}" RUSTDOCFLAGS="-Zsanitizer=${san}" cargo test --doc --package sonic-rs --target ${target} ${testcase} -- --show-output --test-threads=1
24-
}
25-
26-
sanitize_single() {
27-
local san="$1"
28-
local target="$2"
29-
local lists=$(testcase_lists)
30-
for case in ${lists}; do
31-
sanitize ${san} ${target} ${case}
32-
done
33-
}
34-
35-
main() {
36-
for san in address leak; do
37-
echo "Running tests with $san"
38-
sanitize_single $san "x86_64-unknown-linux-gnu"
39-
done
40-
}
41-
42-
main "$@"
7+
for san in address leak; do
8+
echo "Running tests with $san"
9+
RUSTFLAGS="-Zsanitizer=${san}" RUSTDOCFLAGS="-Zsanitizer=${san}" cargo test --target x86_64-unknown-linux-gnu -- --test-threads=1
10+
RUSTFLAGS="-Zsanitizer=${san}" RUSTDOCFLAGS="-Zsanitizer=${san}" cargo test --doc --package sonic-rs --target x86_64-unknown-linux-gnu -- --show-output --test-threads=1
11+
done
4312

4413

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[derive(Debug, Clone, Copy, Default)]
2+
pub(crate) struct DeserializeCfg {
3+
pub(crate) use_rawnumber: bool,
4+
pub(crate) use_raw: bool,
5+
}

src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ mod test {
504504

505505
#[test]
506506
fn test_serde_errors_display() {
507+
#[allow(unused)]
507508
#[derive(Debug, Deserialize)]
508509
struct Foo {
509510
a: Vec<i32>,

src/index.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{
22
util::{private::Sealed, reborrow::DormantMutRef},
3-
value::{object::DEFAULT_OBJ_CAP, shared::Shared},
43
JsonValueMutTrait, JsonValueTrait, PointerNode, Value,
54
};
65

src/lazyvalue/get.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ where
179179
let slice = json.to_u8_slice();
180180
let reader = Read::new(slice, false);
181181
let mut parser = Parser::new(reader);
182-
let (sub, status) = parser.get_from_with_iter(path)?;
182+
let (sub, status) = parser.get_from_with_iter_unchecked(path)?;
183183
LazyValue::new(json.from_subset(sub), status == ParseStatus::HasEscaped)
184184
}
185185

@@ -388,7 +388,7 @@ where
388388
let slice = json.to_u8_slice();
389389
let reader = Read::new(slice, false);
390390
let mut parser = Parser::new(reader);
391-
let (sub, status) = parser.get_from_with_iter_checked(path)?;
391+
let (sub, status) = parser.get_from_with_iter(path)?;
392392
let lv = LazyValue::new(json.from_subset(sub), status == ParseStatus::HasEscaped)?;
393393

394394
// validate the utf-8 if slice

src/lazyvalue/owned.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ impl JsonValueTrait for OwnedLazyValue {
9191
}
9292
}
9393

94-
#[cfg(feature = "arbitrary_precision")]
9594
fn as_raw_number(&self) -> Option<crate::RawNumber> {
9695
if let Ok(num) = from_str(self.as_raw_str()) {
9796
Some(num)

src/lazyvalue/value.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ use std::{
99

1010
use faststr::FastStr;
1111

12-
#[cfg(feature = "arbitrary_precision")]
13-
use crate::RawNumber;
1412
use crate::{
1513
from_str, get_unchecked, index::Index, input::JsonSlice, serde::Number, JsonType,
16-
JsonValueTrait, Result,
14+
JsonValueTrait, RawNumber, Result,
1715
};
1816

1917
/// LazyValue wrappers a unparsed raw JSON text. It is borrowed from the origin JSON text.
@@ -200,7 +198,6 @@ impl<'a> JsonValueTrait for LazyValue<'a> {
200198
}
201199
}
202200

203-
#[cfg(feature = "arbitrary_precision")]
204201
fn as_raw_number(&self) -> Option<RawNumber> {
205202
if let Ok(num) = from_str(self.as_raw_str()) {
206203
Some(num)

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(clippy::needless_lifetimes)]
33
#![doc(test(attr(warn(unused))))]
44

5+
mod config;
56
mod error;
67
mod index;
78
mod input;

0 commit comments

Comments
 (0)