Skip to content

Commit 1ca01f7

Browse files
committed
zmij
1 parent 1716a22 commit 1ca01f7

File tree

9 files changed

+58
-41
lines changed

9 files changed

+58
-41
lines changed

.github/workflows/artifact.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,28 @@ jobs:
152152
{
153153
arch: 'i686',
154154
cflags: '-Os -fstrict-aliasing',
155-
features: '',
155+
features: 'no_panic',
156156
rustflags: '-Z unstable-options -C panic=immediate-abort -Z mir-opt-level=4 -D warnings',
157157
target: 'i686-unknown-linux-gnu',
158158
},
159159
{
160160
arch: 'armv7',
161161
cflags: '-Os -fstrict-aliasing',
162-
features: '',
162+
features: 'no_panic',
163163
rustflags: '-Z unstable-options -C panic=immediate-abort -Z mir-opt-level=4 -D warnings -C opt-level=s',
164164
target: 'armv7-unknown-linux-gnueabihf',
165165
},
166166
{
167167
arch: 'ppc64le',
168168
cflags: '-Os -fstrict-aliasing',
169-
features: 'generic_simd',
169+
features: 'generic_simd,no_panic',
170170
rustflags: '-Z unstable-options -C panic=immediate-abort -Z mir-opt-level=4 -D warnings',
171171
target: 'powerpc64le-unknown-linux-gnu',
172172
},
173173
{
174174
arch: 's390x',
175175
cflags: '-Os -fstrict-aliasing -march=z10',
176-
features: '',
176+
features: 'no_panic',
177177
rustflags: '-Z unstable-options -C panic=immediate-abort -Z mir-opt-level=4 -D warnings -C target-cpu=z10',
178178
target: 's390x-unknown-linux-gnu',
179179
},
@@ -332,11 +332,11 @@ jobs:
332332
- target: aarch64-unknown-linux-musl
333333
arch: aarch64
334334
platform: linux/arm64
335-
features: generic_simd,unwind
335+
features: generic_simd,no_panic,unwind
336336
- target: armv7-unknown-linux-musleabihf
337337
arch: armv7l
338338
platform: linux/arm/v7
339-
features: ''
339+
features: no_panic
340340
steps:
341341
- uses: actions/checkout@v6
342342

@@ -445,7 +445,7 @@ jobs:
445445
maturin build \
446446
--release \
447447
--strip \
448-
--features=generic_simd \
448+
--features=generic_simd,no_panic \
449449
--interpreter python${{ matrix.python.version }} \
450450
--target=aarch64-apple-darwin
451451
uv pip install target/wheels/orjson*.whl
@@ -530,7 +530,7 @@ jobs:
530530
maturin build \
531531
--release \
532532
--strip \
533-
--features=generic_simd \
533+
--features=generic_simd,no_panic \
534534
--interpreter python${{ matrix.python.version }} \
535535
--target=universal2-apple-darwin
536536
uv pip install target/wheels/orjson*.whl
@@ -568,8 +568,8 @@ jobs:
568568
{ version: '3.10', publish: true },
569569
]
570570
platform: [
571-
{ arch: "x64", target: "x86_64-pc-windows-msvc", features: "avx512" },
572-
{ arch: "x86", target: "i686-pc-windows-msvc", features: "" },
571+
{ arch: "x64", target: "x86_64-pc-windows-msvc", features: "avx512,no_panic" },
572+
{ arch: "x86", target: "i686-pc-windows-msvc", features: "no_panic" },
573573
]
574574
env:
575575
CFLAGS: "-O2"
@@ -677,7 +677,7 @@ jobs:
677677
678678
- name: maturin
679679
run: |
680-
maturin.exe build --release --strip --features=generic_simd --target="$env:TARGET"
680+
maturin.exe build --release --strip --features=generic_simd,no_panic --target="$env:TARGET"
681681
python.exe -m pip install orjson --no-index --find-links target\wheels
682682
683683
- run: python.exe -m pytest -s -rxX -v test

Cargo.lock

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ cold_path = []
3939
generic_simd = []
4040
inline_int = []
4141
inline_str = []
42+
no_panic = ["zmij/no-panic"]
4243
optimize = []
4344

4445
[dependencies]
@@ -52,14 +53,14 @@ itoap = { version = "1", default-features = false, features = ["std", "simd"] }
5253
jiff = { version = "^0.2", default-features = false }
5354
once_cell = { version = "1", default-features = false, features = ["alloc", "race"] }
5455
pyo3-ffi = { version = "0.28", default-features = false }
55-
ryu = { version = "1", default-features = false }
5656
serde = { version = "1", default-features = false }
5757
serde_json = { version = "1", default-features = false, features = ["std"] }
5858
simdutf8 = { version = "0.1", default-features = false, features = ["std", "public_imp", "aarch64_neon"] }
5959
smallvec = { version = "^1.11", default-features = false, features = ["union", "write"] }
6060
unwinding = { version = "=0.2.8", default-features = false, features = ["unwinder"], optional = true }
6161
uuid = { version = "1", default-features = false }
6262
xxhash-rust = { version = "^0.8", default-features = false, features = ["xxh3"] }
63+
zmij = { version = "1", default-features = false }
6364

6465
[build-dependencies]
6566
cc = { version = "1" }

script/develop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ export RUSTFLAGS="-Z unstable-options -C panic=immediate-abort -C linker=${CC} -
2222

2323
rm -f ${CARGO_TARGET_DIR}/wheels/*.whl
2424

25-
maturin build --target="${TARGET}" --compatibility="${ORJSON_COMPATIBILITY}" "$@"
25+
maturin build --target="${TARGET}" --features=no_panic --compatibility="${ORJSON_COMPATIBILITY}" "$@"
2626

2727
uv pip install --link-mode=copy ${CARGO_TARGET_DIR}/wheels/*.whl

src/serialize/per_type/dict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ fn non_str_float(key: *mut crate::ffi::PyObject) -> Result<String, SerializeErro
431431
if !val.is_finite() {
432432
Ok(String::from("null"))
433433
} else {
434-
Ok(String::from(ryu::Buffer::new().format_finite(val)))
434+
Ok(String::from(zmij::Buffer::new().format_finite(val)))
435435
}
436436
}
437437

src/serialize/writer/num.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ where
5757
cold_path!();
5858
buf.put_slice(b"null");
5959
} else {
60-
unsafe {
61-
debug_assert!(buf.remaining_mut() >= 40);
62-
let len = ryu::raw::format32(val, buf.as_mut_buffer_ptr());
63-
buf.advance_mut(len);
64-
}
60+
write_finite_float(buf, val)
6561
}
6662
}
6763

@@ -74,10 +70,19 @@ where
7470
cold_path!();
7571
buf.put_slice(b"null");
7672
} else {
77-
unsafe {
78-
debug_assert!(buf.remaining_mut() >= 40);
79-
let len = ryu::raw::format64(val, buf.as_mut_buffer_ptr());
80-
buf.advance_mut(len);
81-
}
73+
write_finite_float(buf, val)
74+
}
75+
}
76+
77+
fn write_finite_float<B, F: zmij::Float>(buf: &mut B, val: F)
78+
where
79+
B: ?Sized + WriteExt + BufMut,
80+
{
81+
unsafe {
82+
debug_assert!(buf.remaining_mut() >= 40);
83+
let buffer =
84+
unsafe { core::mem::transmute::<*mut u8, &mut zmij::Buffer>(buf.as_mut_buffer_ptr()) };
85+
let res = buffer.format_finite(val);
86+
buf.advance_mut(res.len());
8287
}
8388
}

test/test_jsonchecker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from .util import needs_data, read_fixture_str
1010

11-
PATTERN_1 = '["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e34,"":2.3456789012e76,"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":"ģ䕧覫췯ꯍ\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":"&#34; \\" %22 0x22 034 &#x22;","/\\\\\\"쫾몾ꮘﳞ볚\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()
11+
PATTERN_1 = '["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"":2.3456789012e+76,"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":"ģ䕧覫췯ꯍ\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":"&#34; \\" %22 0x22 034 &#x22;","/\\\\\\"쫾몾ꮘﳞ볚\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()
1212

1313

1414
@needs_data

test/test_numpy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
2-
# Copyright ijl (2020-2025), Ben Sully (2021), Nazar Kostetskyi (2022), Aviram Hassan (2020-2021), Marco Ribeiro (2020), Eric Jolibois (2021)
2+
# Copyright ijl (2020-2026), Ben Sully (2021), Nazar Kostetskyi (2022), Aviram Hassan (2020-2021), Marco Ribeiro (2020), Eric Jolibois (2021)
33
# mypy: ignore-errors
44

55
import sys
@@ -113,7 +113,7 @@ def test_numpy_array_d1_f32(self):
113113
numpy.array([1.0, 3.4028235e38], numpy.float32),
114114
option=orjson.OPT_SERIALIZE_NUMPY,
115115
)
116-
== b"[1.0,3.4028235e38]"
116+
== b"[1.0,3.4028235e+38]"
117117
)
118118

119119
def test_numpy_array_d1_f16(self):
@@ -210,7 +210,7 @@ def test_numpy_array_d1_f64(self):
210210
numpy.array([1.0, 1.7976931348623157e308], numpy.float64),
211211
option=orjson.OPT_SERIALIZE_NUMPY,
212212
)
213-
== b"[1.0,1.7976931348623157e308]"
213+
== b"[1.0,1.7976931348623157e+308]"
214214
)
215215

216216
def test_numpy_array_d1_bool(self):

test/test_roundtrip.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MPL-2.0
2-
# Copyright ijl (2018-2025)
2+
# Copyright ijl (2018-2026)
33

44
import orjson
55

@@ -8,9 +8,12 @@
88

99
@needs_data
1010
class TestJsonChecker:
11-
def _run_roundtrip_json(self, filename):
11+
def _run_roundtrip_json(self, filename, byte_exact=True):
1212
data = read_fixture_str(filename, "roundtrip")
13-
assert orjson.dumps(orjson.loads(data)) == data.encode("utf-8")
13+
if byte_exact:
14+
assert orjson.dumps(orjson.loads(data)) == data.encode("utf-8")
15+
else:
16+
assert orjson.loads(orjson.dumps(orjson.loads(data))) == orjson.loads(data)
1417

1518
def test_roundtrip001(self):
1619
"""
@@ -172,4 +175,4 @@ def test_roundtrip027(self):
172175
"""
173176
roundtrip027.json
174177
"""
175-
self._run_roundtrip_json("roundtrip27.json")
178+
self._run_roundtrip_json("roundtrip27.json", byte_exact=False)

0 commit comments

Comments
 (0)