Skip to content

Commit

Permalink
cargo update, fix build cfg warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed May 14, 2024
1 parent 3c1f2a4 commit a71978d
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 54 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
jobs:

sdist:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
env:
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
retention-days: 1

manylinux_2_17_amd64:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
retention-days: 1

musllinux_1_2:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -204,7 +204,7 @@ jobs:
retention-days: 1

manylinux_2_17_non_amd64:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -432,7 +432,7 @@ jobs:

pypi:
name: PyPI
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
if: "startsWith(github.ref, 'refs/tags/')"
needs: [
sdist,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: push
jobs:

debug:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: lint
on: push
jobs:
lint:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/setup-python@v5
with:
Expand Down
56 changes: 28 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ unstable-simd = []
# Include runtime-detected functions that use AVX512VL. Requires unstable-simd and amd64.
avx512 = []

# 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 = []

no-panic = [
"itoa/no-panic",
"ryu/no-panic",
]

# 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.
intrinsics = []
optimize = []
strict_provenance = []

[dependencies]
ahash = { version = "^0.8.9", default-features = false, features = ["compile-time-rng"] }
Expand Down
9 changes: 9 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
use std::env;

fn main() {
println!("cargo:rustc-check-cfg=cfg(optimize)");
println!("cargo:rustc-check-cfg=cfg(intrinsics)");
println!("cargo:rustc-check-cfg=cfg(Py_3_8)");
println!("cargo:rustc-check-cfg=cfg(Py_3_9)");
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:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=include/yyjson/*");
println!("cargo:rerun-if-env-changed=CC");
Expand Down
3 changes: 2 additions & 1 deletion script/develop
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ export UNSAFE_PYO3_SKIP_VERSION_CHECK=1

export CC="${CC:-clang}"
export LD="${LD:-lld}"
export TARGET="${TARGET:-x86_64-unknown-linux-gnu}"

echo "CC: ${CC}, LD: ${LD}, LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}"

export CFLAGS="-Os -fstrict-aliasing -fno-plt -flto=full -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 virtual-function-elimination -Z threads=8"

maturin build "$@"
maturin build --target="${TARGET}" "$@"

uv pip install target/wheels/*.whl
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub unsafe extern "C" fn dumps(
if num_args & 3 == 3 {
optsptr = Some(NonNull::new_unchecked(*args.offset(2)));
}
if !kwnames.is_null() {
if unlikely!(!kwnames.is_null()) {
for i in 0..=Py_SIZE(kwnames).saturating_sub(1) {
let arg = PyTuple_GET_ITEM(kwnames, i as Py_ssize_t);
if arg == typeref::DEFAULT {
Expand All @@ -347,15 +347,15 @@ pub unsafe extern "C" fn dumps(
}

let mut optsbits: i32 = 0;
if let Some(opts) = optsptr {
if opts.as_ptr() == typeref::NONE {
} else if (*opts.as_ptr()).ob_type != typeref::INT_TYPE {
return raise_dumps_exception_fixed("Invalid opts");
} else {
if unlikely!(optsptr.is_some()) {
let opts = optsptr.unwrap();
if (*opts.as_ptr()).ob_type == typeref::INT_TYPE {
optsbits = PyLong_AsLong(optsptr.unwrap().as_ptr()) as i32;
if !(0..=opt::MAX_OPT).contains(&optsbits) {
if unlikely!(!(0..=opt::MAX_OPT).contains(&optsbits)) {
return raise_dumps_exception_fixed("Invalid opts");
}
} else if unlikely!(opts.as_ptr() != typeref::NONE) {
return raise_dumps_exception_fixed("Invalid opts");
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/serialize/per_type/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,24 @@ impl Serialize for FragmentSerializer {
where
S: Serializer,
{
let buffer: &[u8];
unsafe {
let fragment: *mut Fragment = self.ptr as *mut Fragment;
let ob_type = ob_type!((*fragment).contents);
if ob_type == BYTES_TYPE {
buffer = core::slice::from_raw_parts(
let buffer: &[u8] = if ob_type == BYTES_TYPE {
core::slice::from_raw_parts(
PyBytes_AS_STRING((*fragment).contents) as *const u8,
PyBytes_GET_SIZE((*fragment).contents) as usize,
);
)
} else if ob_type == STR_TYPE {
let uni = unicode_to_str((*fragment).contents);
if unlikely!(uni.is_none()) {
err!(SerializeError::InvalidStr)
}
buffer = uni.unwrap().as_bytes();
uni.unwrap().as_bytes()
} else {
err!(SerializeError::InvalidFragment)
}
};
serializer.serialize_bytes(buffer)
}
serializer.serialize_bytes(buffer)
}
}
30 changes: 29 additions & 1 deletion src/serialize/writer/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,35 @@ where
}
}

#[cfg(all(feature = "unstable-simd", target_arch = "x86_64", feature = "avx512"))]
#[cfg(all(
feature = "unstable-simd",
target_arch = "x86_64",
feature = "avx512",
target_feature = "avx512vl"
))]
#[inline(always)]
fn format_escaped_str<W>(writer: &mut W, value: &str)
where
W: ?Sized + io::Write + WriteExt,
{
unsafe {
reserve_str!(writer, value);

let written = format_escaped_str_impl_512vl(
writer.as_mut_buffer_ptr(),
value.as_bytes().as_ptr(),
value.len(),
);
writer.set_written(written);
}
}

#[cfg(all(
feature = "unstable-simd",
target_arch = "x86_64",
feature = "avx512",
not(target_feature = "avx512vl")
))]
#[inline(always)]
fn format_escaped_str<W>(writer: &mut W, value: &str)
where
Expand Down

0 comments on commit a71978d

Please sign in to comment.