Skip to content

Commit

Permalink
edition 2024 compatibility, MSRV 1.82
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed Dec 23, 2024
1 parent e5ddb0b commit 10180d5
Show file tree
Hide file tree
Showing 17 changed files with 419 additions and 369 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
fail-fast: false
matrix:
profile: [
{ rust: "1.72", features: "" },
{ rust: "1.72", features: "--features=yyjson" },
{ rust: "1.82", features: "" },
{ rust: "1.82", features: "--features=yyjson" },
{ rust: "nightly-2024-11-22", features: "--features=avx512,yyjson,unstable-simd" },
]
python: [
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["ijl <[email protected]>"]
description = "Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy"
edition = "2021"
resolver = "2"
rust-version = "1.72"
rust-version = "1.82"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/ijl/orjson"
homepage = "https://github.com/ijl/orjson"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ No, it supports RFC 8259.

## Packaging

To package orjson requires at least [Rust](https://www.rust-lang.org/) 1.72
To package orjson requires at least [Rust](https://www.rust-lang.org/) 1.82
and the [maturin](https://github.com/PyO3/maturin) build tool. The recommended
build command is:

Expand Down
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ fn main() {
}
Err(_) => {
if env::var("CARGO_FEATURE_YYJSON").is_ok() {
panic!("yyjson was enabled but the build failed. To build with a different backend do not specify the feature.")
panic!(
"yyjson was enabled but the build failed. To build with a different backend do not specify the feature."
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ffi/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ pub struct PyMemoryViewObject {
#[allow(non_snake_case)]
#[inline(always)]
pub unsafe fn PyMemoryView_GET_BUFFER(op: *mut PyObject) -> *const Py_buffer {
&(*op.cast::<PyMemoryViewObject>()).view
unsafe { &(*op.cast::<PyMemoryViewObject>()).view }
}
4 changes: 2 additions & 2 deletions src/ffi/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use pyo3_ffi::{PyBytesObject, PyObject, PyVarObject, Py_ssize_t};
#[allow(non_snake_case)]
#[inline(always)]
pub unsafe fn PyBytes_AS_STRING(op: *mut PyObject) -> *const c_char {
&(*op.cast::<PyBytesObject>()).ob_sval as *const c_char
unsafe { &(*op.cast::<PyBytesObject>()).ob_sval as *const c_char }
}

#[allow(non_snake_case)]
#[inline(always)]
pub unsafe fn PyBytes_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
(*op.cast::<PyVarObject>()).ob_size
unsafe { (*op.cast::<PyVarObject>()).ob_size }
}
174 changes: 90 additions & 84 deletions src/ffi/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,39 @@ fn raise_args_exception() -> *mut PyObject {
null_mut()
}

#[no_mangle]
#[unsafe(no_mangle)]
#[cold]
#[cfg_attr(feature = "optimize", optimize(size))]
pub unsafe extern "C" fn orjson_fragment_tp_new(
_subtype: *mut PyTypeObject,
args: *mut PyObject,
kwds: *mut PyObject,
) -> *mut PyObject {
if Py_SIZE(args) != 1 || !kwds.is_null() {
raise_args_exception();
null_mut()
} else {
let contents = PyTuple_GET_ITEM(args, 0);
Py_INCREF(contents);
let obj = Box::new(Fragment {
ob_refcnt: 1,
ob_type: crate::typeref::FRAGMENT_TYPE,
contents: contents,
});
Box::into_raw(obj) as *mut PyObject
unsafe {
if Py_SIZE(args) != 1 || !kwds.is_null() {
raise_args_exception();
null_mut()
} else {
let contents = PyTuple_GET_ITEM(args, 0);
Py_INCREF(contents);
let obj = Box::new(Fragment {
ob_refcnt: 1,
ob_type: crate::typeref::FRAGMENT_TYPE,
contents: contents,
});
Box::into_raw(obj) as *mut PyObject
}
}
}

#[no_mangle]
#[unsafe(no_mangle)]
#[cold]
#[cfg_attr(feature = "optimize", optimize(size))]
pub unsafe extern "C" fn orjson_fragment_dealloc(object: *mut PyObject) {
Py_DECREF((*(object as *mut Fragment)).contents);
std::alloc::dealloc(object as *mut u8, std::alloc::Layout::new::<Fragment>());
unsafe {
Py_DECREF((*(object as *mut Fragment)).contents);
std::alloc::dealloc(object as *mut u8, std::alloc::Layout::new::<Fragment>());
}
}

#[cfg(Py_3_10)]
Expand All @@ -64,76 +68,78 @@ const FRAGMENT_TP_FLAGS: c_ulong = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE
#[cfg(not(Py_3_10))]
const FRAGMENT_TP_FLAGS: c_ulong = Py_TPFLAGS_DEFAULT;

#[no_mangle]
#[unsafe(no_mangle)]
#[cold]
#[cfg_attr(feature = "optimize", optimize(size))]
pub unsafe extern "C" fn orjson_fragmenttype_new() -> *mut PyTypeObject {
let ob = Box::new(PyTypeObject {
ob_base: PyVarObject {
ob_base: PyObject {
#[cfg(Py_3_12)]
ob_refcnt: pyo3_ffi::PyObjectObRefcnt { ob_refcnt: 0 },
#[cfg(not(Py_3_12))]
ob_refcnt: 0,
ob_type: core::ptr::addr_of_mut!(PyType_Type),
unsafe {
let ob = Box::new(PyTypeObject {
ob_base: PyVarObject {
ob_base: PyObject {
#[cfg(Py_3_12)]
ob_refcnt: pyo3_ffi::PyObjectObRefcnt { ob_refcnt: 0 },
#[cfg(not(Py_3_12))]
ob_refcnt: 0,
ob_type: core::ptr::addr_of_mut!(PyType_Type),
},
ob_size: 0,
},
ob_size: 0,
},
tp_name: "orjson.Fragment\0".as_ptr() as *const c_char,
tp_basicsize: core::mem::size_of::<Fragment>() as isize,
tp_itemsize: 0,
tp_dealloc: Some(orjson_fragment_dealloc),
tp_init: None,
tp_new: Some(orjson_fragment_tp_new),
tp_flags: FRAGMENT_TP_FLAGS,
// ...
tp_bases: null_mut(),
tp_cache: null_mut(),
tp_del: None,
tp_finalize: None,
tp_free: None,
tp_is_gc: None,
tp_mro: null_mut(),
tp_subclasses: null_mut(),
tp_vectorcall: None,
tp_version_tag: 0,
tp_weaklist: null_mut(),
#[cfg(not(Py_3_9))]
tp_print: None,
tp_vectorcall_offset: 0,
tp_getattr: None,
tp_setattr: None,
tp_as_async: null_mut(),
tp_repr: None,
tp_as_number: null_mut(),
tp_as_sequence: null_mut(),
tp_as_mapping: null_mut(),
tp_hash: None,
tp_call: None,
tp_str: None,
tp_getattro: None,
tp_setattro: None,
tp_as_buffer: null_mut(),
tp_doc: core::ptr::null_mut(),
tp_traverse: None,
tp_clear: None,
tp_richcompare: None,
tp_weaklistoffset: 0,
tp_iter: None,
tp_iternext: None,
tp_methods: null_mut(),
tp_members: null_mut(),
tp_getset: null_mut(),
tp_base: null_mut(),
tp_dict: null_mut(),
tp_descr_get: None,
tp_descr_set: None,
tp_dictoffset: 0,
tp_alloc: None,
#[cfg(Py_3_12)]
tp_watched: 0,
});
let ob_ptr = Box::into_raw(ob);
PyType_Ready(ob_ptr);
ob_ptr
tp_name: "orjson.Fragment\0".as_ptr() as *const c_char,
tp_basicsize: core::mem::size_of::<Fragment>() as isize,
tp_itemsize: 0,
tp_dealloc: Some(orjson_fragment_dealloc),
tp_init: None,
tp_new: Some(orjson_fragment_tp_new),
tp_flags: FRAGMENT_TP_FLAGS,
// ...
tp_bases: null_mut(),
tp_cache: null_mut(),
tp_del: None,
tp_finalize: None,
tp_free: None,
tp_is_gc: None,
tp_mro: null_mut(),
tp_subclasses: null_mut(),
tp_vectorcall: None,
tp_version_tag: 0,
tp_weaklist: null_mut(),
#[cfg(not(Py_3_9))]
tp_print: None,
tp_vectorcall_offset: 0,
tp_getattr: None,
tp_setattr: None,
tp_as_async: null_mut(),
tp_repr: None,
tp_as_number: null_mut(),
tp_as_sequence: null_mut(),
tp_as_mapping: null_mut(),
tp_hash: None,
tp_call: None,
tp_str: None,
tp_getattro: None,
tp_setattro: None,
tp_as_buffer: null_mut(),
tp_doc: core::ptr::null_mut(),
tp_traverse: None,
tp_clear: None,
tp_richcompare: None,
tp_weaklistoffset: 0,
tp_iter: None,
tp_iternext: None,
tp_methods: null_mut(),
tp_members: null_mut(),
tp_getset: null_mut(),
tp_base: null_mut(),
tp_dict: null_mut(),
tp_descr_get: None,
tp_descr_set: None,
tp_dictoffset: 0,
tp_alloc: None,
#[cfg(Py_3_12)]
tp_watched: 0,
});
let ob_ptr = Box::into_raw(ob);
PyType_Ready(ob_ptr);
ob_ptr
}
}
2 changes: 1 addition & 1 deletion src/ffi/long.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn pylong_get_inline_value(ptr: *mut pyo3_ffi::PyObject) -> i64 {
if pylong_is_unsigned(ptr) {
(*(ptr as *mut PyLongObject)).long_value.ob_digit as i64
} else {
-1 * (*(ptr as *mut PyLongObject)).long_value.ob_digit as i64
-((*(ptr as *mut PyLongObject)).long_value.ob_digit as i64)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ffi/yyjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct yyjson_alc {
>,
pub ctx: *mut ::core::ffi::c_void,
}
extern "C" {
unsafe extern "C" {
pub fn yyjson_alc_pool_init(
alc: *mut yyjson_alc,
buf: *mut ::core::ffi::c_void,
Expand All @@ -33,15 +33,15 @@ pub struct yyjson_read_err {
pub msg: *const ::core::ffi::c_char,
pub pos: usize,
}
extern "C" {
unsafe extern "C" {
pub fn yyjson_read_opts(
dat: *mut ::core::ffi::c_char,
len: usize,
alc: *const yyjson_alc,
err: *mut yyjson_read_err,
) -> *mut yyjson_doc;
}
extern "C" {
unsafe extern "C" {
pub fn yyjson_doc_free(doc: *mut yyjson_doc);
}
#[repr(C)]
Expand Down
Loading

0 comments on commit 10180d5

Please sign in to comment.