Skip to content

Commit

Permalink
Update ref counting for 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored and ijl committed Aug 3, 2023
1 parent 5c8f93d commit fa2df4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ffi/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ 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: std::ptr::addr_of_mut!(PyType_Type),
},
Expand Down
10 changes: 10 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ macro_rules! str_from_slice {
};
}

#[cfg(Py_3_12)]
macro_rules! py_decref_without_destroy {
($op:expr) => {
unsafe {
(*$op).ob_refcnt.ob_refcnt -= 1;
}
};
}

#[cfg(not(Py_3_12))]
macro_rules! py_decref_without_destroy {
($op:expr) => {
unsafe {
Expand Down

0 comments on commit fa2df4d

Please sign in to comment.