Skip to content

Commit f4b3518

Browse files
committed
yyjson 0.5.1, build misc
1 parent edde952 commit f4b3518

9 files changed

Lines changed: 54 additions & 51 deletions

File tree

.github/workflows/manylinux_2_28.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- run: cargo fetch
3131
- run: maturin build --no-sdist --release --strip --cargo-extra-args="--features=unstable-simd,yyjson" --compatibility manylinux_2_28 --interpreter python${{ matrix.python.version }}
3232
env:
33+
CC: "clang"
34+
CFLAGS: "-O2 -fno-plt -flto=thin"
35+
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
3336
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
3437
- run: python3 -m pip install --user target/wheels/orjson*.whl
3538
- run: python3 -m pip install --user -r test/requirements.txt -r integration/requirements.txt

build.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
22

3-
#[cfg(feature = "yyjson")]
4-
extern crate cc;
5-
63
#[allow(dead_code)]
74
#[cfg(feature = "yyjson")]
85
fn build_yyjson() {
9-
// note -march is not automatically propagated by -C target-cpu
106
cc::Build::new()
11-
.file("include/yyjson.c")
12-
.include("include")
7+
.file("include/yyjson/yyjson.c")
8+
.include("include/yyjson")
139
.define("YYJSON_DISABLE_WRITER", "1")
1410
.define("YYJSON_DISABLE_NON_STANDARD", "1")
15-
.compiler("clang")
16-
.static_flag(true)
17-
.use_plt(false)
18-
.opt_level_str("2")
19-
.flag("-flto=thin")
2011
.compile("yyjson");
2112
}
2213

ci/azure-macos.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ steps:
1313
displayName: test dependencies
1414
- bash: PATH=$HOME/.cargo/bin:$PATH cargo fetch
1515
- bash: PATH=$HOME/.cargo/bin:$PATH maturin build --no-sdist --release --strip --cargo-extra-args="--features=unstable-simd,yyjson" --interpreter $(interpreter)
16+
env:
17+
CC: "clang"
18+
CFLAGS: "-O2 -fno-plt -flto=thin"
19+
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
1620
displayName: build
1721
- bash: pip install target/wheels/orjson*.whl
1822
displayName: install
@@ -29,6 +33,10 @@ steps:
2933
- bash: rustup target add aarch64-apple-darwin
3034
displayName: rustup target
3135
- bash: PATH=$HOME/.cargo/bin:$PATH PYO3_CROSS_LIB_DIR=$(python -c "import sysconfig;print(sysconfig.get_config_var('LIBDIR'))") maturin build --no-sdist --release --strip --cargo-extra-args="--features=unstable-simd" --interpreter $(interpreter) --universal2
36+
env:
37+
CC: "clang"
38+
CFLAGS: "-O2 -fno-plt -flto=thin"
39+
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld --as-needed,-z,relro,-z,now"
3240
displayName: build universal2
3341
- bash: pip install --force-reinstall target/wheels/orjson*universal2.whl
3442
displayName: install universal2

ci/drone.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ steps:
1313
from_secret: twine_username
1414
MATURIN_PASSWORD:
1515
from_secret: twine_password
16+
CC: "clang"
17+
CFLAGS: "-O2 -fno-plt -flto=thin"
18+
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
1619
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
1720
commands:
1821
- yum update -y && yum install -y clang lld
@@ -40,6 +43,9 @@ steps:
4043
from_secret: twine_username
4144
MATURIN_PASSWORD:
4245
from_secret: twine_password
46+
CC: "clang"
47+
CFLAGS: "-O2 -fno-plt -flto=thin"
48+
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
4349
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
4450
commands:
4551
- yum update -y && yum install -y clang lld
@@ -67,6 +73,9 @@ steps:
6773
from_secret: twine_username
6874
MATURIN_PASSWORD:
6975
from_secret: twine_password
76+
CC: "clang"
77+
CFLAGS: "-O2 -fno-plt -flto=thin"
78+
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
7079
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
7180
commands:
7281
- yum update -y && yum install -y clang lld
@@ -94,6 +103,9 @@ steps:
94103
from_secret: twine_username
95104
MATURIN_PASSWORD:
96105
from_secret: twine_password
106+
CC: "clang"
107+
CFLAGS: "-O2 -fno-plt -flto=thin"
108+
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
97109
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
98110
commands:
99111
- yum update -y && yum install -y clang lld
Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ static_inline void u128_mul_add(u64 a, u64 b, u64 c, u64 *hi, u64 *lo) {
907907
u64 h, l, t;
908908
u128_mul(a, b, &h, &l);
909909
t = l + c;
910-
h += ((t < l) | (t < c));
910+
h += (u64)(((t < l) | (t < c)));
911911
*hi = h;
912912
*lo = t;
913913
#endif
@@ -1558,11 +1558,11 @@ static_inline void *pointer_read_arr(const char **ptr,
15581558
cur++;
15591559
idx = idx * 10 + add;
15601560
}
1561-
if (cur == hdr) return NULL;
1561+
if (cur == hdr || idx >= (u64)USIZE_MAX) return NULL;
15621562
*ptr = cur;
15631563
return mut
1564-
? (void *)yyjson_mut_arr_get(m_arr, idx)
1565-
: (void *)yyjson_arr_get(i_arr, idx);
1564+
? (void *)yyjson_mut_arr_get(m_arr, (usize)idx)
1565+
: (void *)yyjson_arr_get(i_arr, (usize)idx);
15661566
}
15671567

15681568
/**
@@ -3402,23 +3402,16 @@ static_inline bool read_number(u8 **ptr,
34023402

34033403
/*
34043404
Read integral part, same as the following code.
3405-
For more explanation, see the comments under label `skip_ascii_begin`.
34063405
34073406
for (int i = 1; i <= 18; i++) {
34083407
num = cur[i] - '0';
34093408
if (num <= 9) sig = num + sig * 10;
34103409
else goto digi_sepr_i;
34113410
}
34123411
*/
3413-
#if YYJSON_IS_REAL_GCC
3414-
#define expr_intg(i) \
3415-
if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \
3416-
else { __asm volatile("":"=m"(cur[i])::); goto digi_sepr_##i; }
3417-
#else
34183412
#define expr_intg(i) \
34193413
if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \
34203414
else { goto digi_sepr_##i; }
3421-
#endif
34223415
repeat_in_1_18(expr_intg);
34233416
#undef expr_intg
34243417

@@ -3446,19 +3439,11 @@ static_inline bool read_number(u8 **ptr,
34463439

34473440

34483441
/* read fraction part */
3449-
#if YYJSON_IS_REAL_GCC
3450-
#define expr_frac(i) \
3451-
digi_frac_##i: \
3452-
if (likely((num = (u64)(cur[i + 1] - (u8)'0')) <= 9)) \
3453-
sig = num + sig * 10; \
3454-
else { __asm volatile("":"=m"(cur[i + 1])::); goto digi_stop_##i; }
3455-
#else
34563442
#define expr_frac(i) \
34573443
digi_frac_##i: \
34583444
if (likely((num = (u64)(cur[i + 1] - (u8)'0')) <= 9)) \
34593445
sig = num + sig * 10; \
34603446
else { goto digi_stop_##i; }
3461-
#endif
34623447
repeat_in_1_18(expr_frac)
34633448
#undef expr_frac
34643449

@@ -6020,8 +6005,8 @@ static_inline u64 round_to_odd(u64 hi, u64 lo, u64 cp) {
60206005
The output significand is shortest decimal but may have trailing zeros.
60216006
60226007
This function use the Schubfach algorithm:
6023-
Raffaello Giulietti, The Schubfach way to render doubles (4th version), 2021.
6024-
https://drive.google.com/file/d/1IEeATSVnEE6TkrHlCYNY2GjaraBjOT4f
6008+
Raffaello Giulietti, The Schubfach way to render doubles (5th version), 2022.
6009+
https://drive.google.com/file/d/1gp5xv4CAa78SVgCeWfGqqI4FfYYYuNFb
60256010
https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-November/083536.html
60266011
https://github.com/openjdk/jdk/pull/3402 (Java implementation)
60276012
https://github.com/abolz/Drachennest (C++ implementation)
@@ -6211,6 +6196,7 @@ static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) {
62116196
/* write with scientific notation */
62126197
/* such as 1.234e56 */
62136198
u8 *end = write_u64_len_15_to_17_trim(buf + 1, sig_dec);
6199+
end -= (end == buf + 2); /* remove '.0', e.g. 2.0e34 -> 2e134 */
62146200
exp_dec += sig_len - 1;
62156201
hdr[0] = hdr[1];
62166202
hdr[1] = '.';
@@ -7306,8 +7292,8 @@ static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
73067292
val_begin:
73077293
val_type = unsafe_yyjson_get_type(val);
73087294
if (val_type == YYJSON_TYPE_STR) {
7309-
is_key = ((u8)ctn_obj & (u8)~ctn_len);
7310-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7295+
is_key = (bool)((u8)ctn_obj & (u8)~ctn_len);
7296+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
73117297
str_len = unsafe_yyjson_get_len(val);
73127298
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
73137299
check_str_len(str_len);
@@ -7320,7 +7306,7 @@ static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
73207306
goto val_end;
73217307
}
73227308
if (val_type == YYJSON_TYPE_NUM) {
7323-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7309+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
73247310
incr_len(32 + (no_indent ? 0 : level * 4));
73257311
cur = write_indent(cur, no_indent ? 0 : level);
73267312
cur = write_number(cur, val, flg);
@@ -7331,7 +7317,7 @@ static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
73317317
}
73327318
if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) ==
73337319
(YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) {
7334-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7320+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
73357321
ctn_len_tmp = unsafe_yyjson_get_len(val);
73367322
ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ);
73377323
if (unlikely(ctn_len_tmp == 0)) {
@@ -7358,15 +7344,15 @@ static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
73587344
}
73597345
}
73607346
if (val_type == YYJSON_TYPE_BOOL) {
7361-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7347+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
73627348
incr_len(16 + (no_indent ? 0 : level * 4));
73637349
cur = write_indent(cur, no_indent ? 0 : level);
73647350
cur = write_bool(cur, unsafe_yyjson_get_bool(val));
73657351
cur += 2;
73667352
goto val_end;
73677353
}
73687354
if (val_type == YYJSON_TYPE_NULL) {
7369-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7355+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
73707356
incr_len(16 + (no_indent ? 0 : level * 4));
73717357
cur = write_indent(cur, no_indent ? 0 : level);
73727358
cur = write_null(cur);
@@ -7794,8 +7780,8 @@ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
77947780
val_begin:
77957781
val_type = unsafe_yyjson_get_type(val);
77967782
if (val_type == YYJSON_TYPE_STR) {
7797-
is_key = ((u8)ctn_obj & (u8)~ctn_len);
7798-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7783+
is_key = (bool)((u8)ctn_obj & (u8)~ctn_len);
7784+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
77997785
str_len = unsafe_yyjson_get_len(val);
78007786
str_ptr = (const u8 *)unsafe_yyjson_get_str(val);
78017787
check_str_len(str_len);
@@ -7808,7 +7794,7 @@ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
78087794
goto val_end;
78097795
}
78107796
if (val_type == YYJSON_TYPE_NUM) {
7811-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7797+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
78127798
incr_len(32 + (no_indent ? 0 : level * 4));
78137799
cur = write_indent(cur, no_indent ? 0 : level);
78147800
cur = write_number(cur, (yyjson_val *)val, flg);
@@ -7819,7 +7805,7 @@ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
78197805
}
78207806
if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) ==
78217807
(YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ)) {
7822-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7808+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
78237809
ctn_len_tmp = unsafe_yyjson_get_len(val);
78247810
ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ);
78257811
if (unlikely(ctn_len_tmp == 0)) {
@@ -7848,15 +7834,15 @@ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
78487834
}
78497835
}
78507836
if (val_type == YYJSON_TYPE_BOOL) {
7851-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7837+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
78527838
incr_len(16 + (no_indent ? 0 : level * 4));
78537839
cur = write_indent(cur, no_indent ? 0 : level);
78547840
cur = write_bool(cur, unsafe_yyjson_get_bool(val));
78557841
cur += 2;
78567842
goto val_end;
78577843
}
78587844
if (val_type == YYJSON_TYPE_NULL) {
7859-
no_indent = ((u8)ctn_obj & (u8)ctn_len);
7845+
no_indent = (bool)((u8)ctn_obj & (u8)ctn_len);
78607846
incr_len(16 + (no_indent ? 0 : level * 4));
78617847
cur = write_indent(cur, no_indent ? 0 : level);
78627848
cur = write_null(cur);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,13 @@ extern "C" {
409409
#define YYJSON_VERSION_MINOR 5
410410

411411
/** The patch version of yyjson. */
412-
#define YYJSON_VERSION_PATCH 0
412+
#define YYJSON_VERSION_PATCH 1
413413

414414
/** The version of yyjson in hex: (major << 16) | (minor << 8) | (patch). */
415-
#define YYJSON_VERSION_HEX 0x000500
415+
#define YYJSON_VERSION_HEX 0x000501
416416

417417
/** The version string of yyjson. */
418-
#define YYJSON_VERSION_STRING "0.5.0"
418+
#define YYJSON_VERSION_STRING "0.5.1"
419419

420420
/** The version of yyjson in hex, same as `YYJSON_VERSION_HEX`. */
421421
yyjson_api uint32_t yyjson_version(void);
@@ -779,7 +779,7 @@ yyjson_api_inline yyjson_doc *yyjson_read(const char *dat,
779779
@endcode
780780
@see yyjson_alc_pool_init()
781781
*/
782-
yyjson_api size_t yyjson_read_max_memory_usage(size_t len,
782+
yyjson_api_inline size_t yyjson_read_max_memory_usage(size_t len,
783783
yyjson_read_flag flg) {
784784
/*
785785
1. The max value count is (json_size / 2 + 1),

script/develop

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
rm -f target/wheels/*
44

5+
export CC="clang"
6+
export CFLAGS="-O2 -fno-plt -flto=thin"
7+
export LDFLAGS="-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
58
export RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=lld"
69

710
maturin build --no-sdist --compatibility off -i python3 --release "$@"

script/generate-yyjson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -eou pipefail
55
_repo="$(dirname "$(dirname "${BASH_SOURCE[0]}")")"
66

77
bindgen \
8-
"${_repo}/include/yyjson.h" \
8+
"${_repo}/include/yyjson/yyjson.h" \
99
--size_t-is-usize \
1010
--disable-header-comment \
1111
--no-derive-debug \

src/deserialize/yyjson.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn unsafe_yyjson_get_next(val: *mut yyjson_val) -> *mut yyjson_val {
6565
}
6666
}
6767

68-
fn yyjson_arr_iter_next(iter: *mut yyjson_arr_iter) -> *mut yyjson_val {
68+
fn yyjson_arr_iter_next(iter: &mut yyjson_arr_iter) -> *mut yyjson_val {
6969
unsafe {
7070
let val = (*iter).cur;
7171
(*iter).cur = unsafe_yyjson_get_next(val);
@@ -74,7 +74,7 @@ fn yyjson_arr_iter_next(iter: *mut yyjson_arr_iter) -> *mut yyjson_val {
7474
}
7575
}
7676

77-
fn yyjson_obj_iter_next(iter: *mut yyjson_obj_iter) -> *mut yyjson_val {
77+
fn yyjson_obj_iter_next(iter: &mut yyjson_obj_iter) -> *mut yyjson_val {
7878
unsafe {
7979
let key = (*iter).cur;
8080
(*iter).cur = unsafe_yyjson_get_next(key.add(1));

0 commit comments

Comments
 (0)