From ca397ec1ca18706802ac155aab097563e5824a0e Mon Sep 17 00:00:00 2001 From: ijl Date: Thu, 12 Oct 2023 22:26:24 +0000 Subject: [PATCH] pyo3 0.20, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- README.md | 7 ++----- src/ffi/immortal.rs | 27 --------------------------- src/ffi/mod.rs | 4 ---- src/lib.rs | 12 +++++++++++- src/util.rs | 2 +- 7 files changed, 20 insertions(+), 44 deletions(-) delete mode 100644 src/ffi/immortal.rs diff --git a/Cargo.lock b/Cargo.lock index 7bb2c2fa..e5dd648c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -210,9 +210,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.19.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076c73d0bc438f7a4ef6fdd0c3bb4732149136abd952b110ac93e4edb13a6ba5" +checksum = "a96fe70b176a89cff78f2fa7b3c930081e163d5379b4dcdf993e3ae29ca662e5" dependencies = [ "once_cell", "target-lexicon", @@ -220,9 +220,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.19.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53cee42e77ebe256066ba8aa77eff722b3bb91f3419177cf4cd0f304d3284d9" +checksum = "214929900fd25e6604661ed9cf349727c8920d47deff196c4e28165a6ef2a96b" dependencies = [ "libc", "pyo3-build-config", diff --git a/Cargo.toml b/Cargo.toml index d4be7f86..48ced59e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ encoding_rs = { version = "0.8", default_features = false } itoa = { version = "1", default_features = false } itoap = { version = "1", features = ["std", "simd"] } once_cell = { version = "1", default_features = false, features = ["race"] } -pyo3-ffi = { version = "^0.19.2", default_features = false, features = ["extension-module"]} +pyo3-ffi = { version = "^0.20", default_features = false, features = ["extension-module"]} ryu = { version = "1", default_features = false } serde = { version = "1", default_features = false } serde_json = { version = "1", default_features = false, features = ["std", "float_roundtrip"] } @@ -68,7 +68,7 @@ smallvec = { version = "^1.11", default_features = false, features = ["union", " [build-dependencies] cc = { version = "1" } -pyo3-build-config = { version = "^0.19.2" } +pyo3-build-config = { version = "^0.20" } version_check = { version = "0.9" } [profile.dev] diff --git a/README.md b/README.md index 016e1891..532ca6d5 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ file-like objects orjson supports CPython 3.8, 3.9, 3.10, 3.11, and 3.12. It distributes amd64/x86_64, aarch64/armv8, arm7, POWER/ppc64le, and s390x wheels for Linux, amd64 and aarch64 wheels for macOS, and amd64 and i686/x86 wheels for Windows. -orjson does not support PyPy. Releases follow semantic versioning and +orjson does not and will not support PyPy. orjson does not and will not +support PEP 554 subinterpreters. Releases follow semantic versioning and serializing a new object type without an opt-in flag is considered a breaking change. @@ -1177,10 +1178,6 @@ level above this. No. `bytes` is the correct type for a serialized blob. -### Will it support PyPy? - -Probably not. - ## Packaging To package orjson requires at least [Rust](https://www.rust-lang.org/) 1.65 diff --git a/src/ffi/immortal.rs b/src/ffi/immortal.rs deleted file mode 100644 index 82dae962..00000000 --- a/src/ffi/immortal.rs +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: (Apache-2.0 OR MIT) -// copied from PyO3 when 0.19.2 was latest - -#[allow(non_snake_case)] -#[cfg(all(Py_3_12, target_pointer_width = "32"))] -pub const _Py_IMMORTAL_REFCNT: pyo3_ffi::Py_ssize_t = { - if cfg!(target_pointer_width = "64") { - std::os::raw::c_uint::MAX as pyo3_ffi::Py_ssize_t - } else { - // for 32-bit systems, use the lower 30 bits (see comment in CPython's object.h) - (std::os::raw::c_uint::MAX >> 2) as pyo3_ffi::Py_ssize_t - } -}; - -#[inline(always)] -#[allow(non_snake_case)] -#[cfg(all(Py_3_12, target_pointer_width = "64"))] -pub unsafe fn _Py_IsImmortal(op: *mut pyo3_ffi::PyObject) -> std::os::raw::c_int { - (((*op).ob_refcnt.ob_refcnt as i32) < 0) as std::os::raw::c_int -} - -#[inline(always)] -#[allow(non_snake_case)] -#[cfg(all(Py_3_12, target_pointer_width = "32"))] -pub unsafe fn _Py_IsImmortal(op: *mut pyo3_ffi::PyObject) -> std::os::raw::c_int { - ((*op).ob_refcnt.ob_refcnt == _Py_IMMORTAL_REFCNT) as std::os::raw::c_int -} diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 695323e6..afc7ef50 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -3,8 +3,6 @@ mod buffer; mod bytes; mod fragment; -#[cfg(Py_3_12)] -mod immortal; mod list; mod long; #[cfg(feature = "yyjson")] @@ -13,7 +11,5 @@ pub mod yyjson; pub use buffer::*; pub use bytes::*; pub use fragment::{orjson_fragmenttype_new, Fragment}; -#[cfg(Py_3_12)] -pub use immortal::_Py_IsImmortal; pub use list::PyListIter; pub use long::{pylong_is_unsigned, pylong_is_zero}; diff --git a/src/lib.rs b/src/lib.rs index c427586e..31763b54 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,16 +143,26 @@ pub unsafe extern "C" fn orjson_init_exec(mptr: *mut PyObject) -> c_int { 0 } +#[cfg(not(Py_3_12))] +const PYMODULEDEF_LEN: usize = 2; +#[cfg(Py_3_12)] +const PYMODULEDEF_LEN: usize = 3; + #[allow(non_snake_case)] #[no_mangle] #[cold] #[cfg_attr(feature = "optimize", optimize(size))] pub unsafe extern "C" fn PyInit_orjson() -> *mut PyModuleDef { - let mod_slots: Box<[PyModuleDef_Slot; 2]> = Box::new([ + let mod_slots: Box<[PyModuleDef_Slot; PYMODULEDEF_LEN]> = Box::new([ PyModuleDef_Slot { slot: Py_mod_exec, value: orjson_init_exec as *mut c_void, }, + #[cfg(Py_3_12)] + PyModuleDef_Slot { + slot: Py_mod_multiple_interpreters, + value: Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED, + }, PyModuleDef_Slot { slot: 0, value: null_mut(), diff --git a/src/util.rs b/src/util.rs index 3c17ddad..dd3b25bc 100644 --- a/src/util.rs +++ b/src/util.rs @@ -86,7 +86,7 @@ macro_rules! str_from_slice { macro_rules! reverse_pydict_incref { ($op:expr) => { unsafe { - if crate::ffi::_Py_IsImmortal($op) == 0 { + if pyo3_ffi::_Py_IsImmortal($op) == 0 { debug_assert!(ffi!(Py_REFCNT($op)) >= 2); (*$op).ob_refcnt.ob_refcnt -= 1; }