Skip to content

Commit

Permalink
Fix compile bug
Browse files Browse the repository at this point in the history
  • Loading branch information
awolverp committed Jun 6, 2024
1 parent 665d046 commit 0b27c8a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "cachebox"
version = "3.1.0"
description = "The fastest memoizing and caching Python library written in Rust"
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.8"
license = {file = "LICENSE"}
keywords = ["caching", "cached", "cachebox", "cache", "in-memory-caching", "memoizing"]
authors = [
Expand Down
8 changes: 4 additions & 4 deletions src/basic/pickle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro_rules! pickle_check_state {
))
} else {
let tuple = $state.as_ptr();
if unsafe { pyo3::ffi::PyTuple_GET_SIZE(tuple) != $size } {
if unsafe { pyo3::ffi::PyTuple_Size(tuple) != $size } {
Err($crate::create_pyerr!(
pyo3::exceptions::PyTypeError,
"tuple length is invalid"
Expand All @@ -40,7 +40,7 @@ macro_rules! pickle_check_state {
macro_rules! pickle_get_first_objects {
($py:expr, $state:expr) => {{
let maxsize = {
let obj = pyo3::ffi::PyTuple_GET_ITEM($state, 0);
let obj = pyo3::ffi::PyTuple_GetItem($state, 0);
pyo3::ffi::PyLong_AsSize_t(obj)
};

Expand All @@ -49,7 +49,7 @@ macro_rules! pickle_get_first_objects {
}

let iterable = {
let obj = pyo3::ffi::PyTuple_GET_ITEM($state, 1);
let obj = pyo3::ffi::PyTuple_GetItem($state, 1);

if pyo3::ffi::PyDict_CheckExact(obj) != 1 {
return Err(create_pyerr!(
Expand All @@ -63,7 +63,7 @@ macro_rules! pickle_get_first_objects {
};

let capacity = {
let obj = pyo3::ffi::PyTuple_GET_ITEM($state, 2);
let obj = pyo3::ffi::PyTuple_GetItem($state, 2);
pyo3::ffi::PyLong_AsSize_t(obj)
};

Expand Down
6 changes: 3 additions & 3 deletions src/cache/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ impl PickleMethods for RawCache {
let capacity = pyo3::ffi::PyLong_FromSize_t(self.table.capacity());

let tuple = pyo3::ffi::PyTuple_New(Self::PICKLE_TUPLE_SIZE);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 1, dict);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 2, capacity);
pyo3::ffi::PyTuple_SetItem(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SetItem(tuple, 1, dict);
pyo3::ffi::PyTuple_SetItem(tuple, 2, capacity);

tuple
}
Expand Down
16 changes: 8 additions & 8 deletions src/fifocache/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ impl PickleMethods for RawFIFOCache {

let order = pyo3::ffi::PyTuple_New(self.order.len() as isize);
for (index, key) in self.order.iter().enumerate() {
pyo3::ffi::PyTuple_SET_ITEM(order, index as isize, key.object.as_ptr());
pyo3::ffi::PyTuple_SetItem(order, index as isize, key.object.as_ptr());
}

let maxsize = pyo3::ffi::PyLong_FromSize_t(self.maxsize.get());
let capacity = pyo3::ffi::PyLong_FromSize_t(self.table.capacity());

let tuple = pyo3::ffi::PyTuple_New(Self::PICKLE_TUPLE_SIZE);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 1, dict);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 2, capacity);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 3, order);
pyo3::ffi::PyTuple_SetItem(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SetItem(tuple, 1, dict);
pyo3::ffi::PyTuple_SetItem(tuple, 2, capacity);
pyo3::ffi::PyTuple_SetItem(tuple, 3, order);

tuple
}
Expand All @@ -254,7 +254,7 @@ impl PickleMethods for RawFIFOCache {
let (maxsize, iterable, capacity) = pickle_get_first_objects!(py, state);

let order = {
let obj = pyo3::ffi::PyTuple_GET_ITEM(state, 3);
let obj = pyo3::ffi::PyTuple_GetItem(state, 3);

if pyo3::ffi::PyTuple_CheckExact(obj) != 1 {
return Err(create_pyerr!(
Expand All @@ -273,7 +273,7 @@ impl PickleMethods for RawFIFOCache {
#[cfg(not(debug_assertions))]
let dict: &Bound<pyo3::types::PyDict> = iterable.downcast_bound(py).unwrap_unchecked();

let tuple_length = pyo3::ffi::PyTuple_GET_SIZE(order);
let tuple_length = pyo3::ffi::PyTuple_Size(order);

if tuple_length as usize != dict.len() {
return Err(create_pyerr!(
Expand All @@ -293,7 +293,7 @@ impl PickleMethods for RawFIFOCache {
}

for k in 0..tuple_length {
let key = pyo3::ffi::PyTuple_GET_ITEM(order, k);
let key = pyo3::ffi::PyTuple_GetItem(order, k);
let hashable =
HashablePyObject::try_from_pyobject(PyObject::from_borrowed_ptr(py, key), py)?;
new.order.push_back(hashable);
Expand Down
16 changes: 8 additions & 8 deletions src/lfucache/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ impl crate::basic::PickleMethods for RawLFUCache {

let val_tuple = pyo3::ffi::PyTuple_New(2);
let c = pyo3::ffi::PyLong_FromSize_t(*count);
pyo3::ffi::PyTuple_SET_ITEM(val_tuple, 0, val.as_ptr());
pyo3::ffi::PyTuple_SET_ITEM(val_tuple, 1, c);
pyo3::ffi::PyTuple_SetItem(val_tuple, 0, val.as_ptr());
pyo3::ffi::PyTuple_SetItem(val_tuple, 1, c);

pyo3::ffi::PyDict_SetItem(dict, key.object.as_ptr(), val_tuple);
pyo3::ffi::Py_XDECREF(val_tuple);
Expand All @@ -237,9 +237,9 @@ impl crate::basic::PickleMethods for RawLFUCache {
let capacity = pyo3::ffi::PyLong_FromSize_t(self.table.capacity());

let tuple = pyo3::ffi::PyTuple_New(Self::PICKLE_TUPLE_SIZE);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 1, dict);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 2, capacity);
pyo3::ffi::PyTuple_SetItem(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SetItem(tuple, 1, dict);
pyo3::ffi::PyTuple_SetItem(tuple, 2, capacity);

tuple
}
Expand All @@ -264,17 +264,17 @@ impl crate::basic::PickleMethods for RawLFUCache {

let op = value.as_ptr();

if pyo3::ffi::PyTuple_CheckExact(op) != 1 || pyo3::ffi::PyTuple_GET_SIZE(op) != 2 {
if pyo3::ffi::PyTuple_CheckExact(op) != 1 || pyo3::ffi::PyTuple_Size(op) != 2 {
return Err(create_pyerr!(
pyo3::exceptions::PyTypeError,
"expected tuple, found another type #op"
));
}

let val = pyo3::ffi::PyTuple_GET_ITEM(op, 0);
let val = pyo3::ffi::PyTuple_GetItem(op, 0);

let n = {
let obj = pyo3::ffi::PyTuple_GET_ITEM(op, 1);
let obj = pyo3::ffi::PyTuple_GetItem(op, 1);
pyo3::ffi::PyLong_AsSize_t(obj)
};

Expand Down
16 changes: 8 additions & 8 deletions src/lrucache/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,17 @@ impl PickleMethods for RawLRUCache {

let order = pyo3::ffi::PyTuple_New(self.order.len() as isize);
for (index, key) in self.order.iter().enumerate() {
pyo3::ffi::PyTuple_SET_ITEM(order, index as isize, key.object.as_ptr());
pyo3::ffi::PyTuple_SetItem(order, index as isize, key.object.as_ptr());
}

let maxsize = pyo3::ffi::PyLong_FromSize_t(self.maxsize.get());
let capacity = pyo3::ffi::PyLong_FromSize_t(self.table.capacity());

let tuple = pyo3::ffi::PyTuple_New(Self::PICKLE_TUPLE_SIZE);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 1, dict);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 2, capacity);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 3, order);
pyo3::ffi::PyTuple_SetItem(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SetItem(tuple, 1, dict);
pyo3::ffi::PyTuple_SetItem(tuple, 2, capacity);
pyo3::ffi::PyTuple_SetItem(tuple, 3, order);

tuple
}
Expand All @@ -271,7 +271,7 @@ impl PickleMethods for RawLRUCache {
let (maxsize, iterable, capacity) = pickle_get_first_objects!(py, state);

let order = {
let obj = pyo3::ffi::PyTuple_GET_ITEM(state, 3);
let obj = pyo3::ffi::PyTuple_GetItem(state, 3);

if pyo3::ffi::PyTuple_CheckExact(obj) != 1 {
return Err(create_pyerr!(
Expand All @@ -290,7 +290,7 @@ impl PickleMethods for RawLRUCache {
#[cfg(not(debug_assertions))]
let dict: &Bound<pyo3::types::PyDict> = iterable.downcast_bound(py).unwrap_unchecked();

let tuple_length = pyo3::ffi::PyTuple_GET_SIZE(order);
let tuple_length = pyo3::ffi::PyTuple_Size(order);

if tuple_length as usize != dict.len() {
return Err(create_pyerr!(
Expand All @@ -310,7 +310,7 @@ impl PickleMethods for RawLRUCache {
}

for k in 0..tuple_length {
let key = pyo3::ffi::PyTuple_GET_ITEM(order, k);
let key = pyo3::ffi::PyTuple_GetItem(order, k);
let hashable =
HashablePyObject::try_from_pyobject(PyObject::from_borrowed_ptr(py, key), py)?;
new.order.push_back(hashable);
Expand Down
30 changes: 15 additions & 15 deletions src/ttlcache/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,28 +319,28 @@ impl crate::basic::PickleMethods for RawTTLCache {
let val_tuple = pyo3::ffi::PyTuple_New(2);
let timestamp = pyo3::ffi::PyFloat_FromDouble(val.timestamp());

pyo3::ffi::PyTuple_SET_ITEM(val_tuple, 0, val.0.as_ptr());
pyo3::ffi::PyTuple_SET_ITEM(val_tuple, 1, timestamp);
pyo3::ffi::PyTuple_SetItem(val_tuple, 0, val.0.as_ptr());
pyo3::ffi::PyTuple_SetItem(val_tuple, 1, timestamp);

pyo3::ffi::PyDict_SetItem(dict, key.object.as_ptr(), val_tuple);
pyo3::ffi::Py_XDECREF(val_tuple);
}

let order = pyo3::ffi::PyTuple_New(self.order.len() as isize);
for (index, key) in self.order.iter().enumerate() {
pyo3::ffi::PyTuple_SET_ITEM(order, index as isize, key.object.as_ptr());
pyo3::ffi::PyTuple_SetItem(order, index as isize, key.object.as_ptr());
}

let maxsize = pyo3::ffi::PyLong_FromSize_t(self.maxsize.get());
let capacity = pyo3::ffi::PyLong_FromSize_t(self.table.capacity());
let ttl = pyo3::ffi::PyFloat_FromDouble(self.ttl as f64);

let tuple = pyo3::ffi::PyTuple_New(Self::PICKLE_TUPLE_SIZE);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 1, dict);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 2, capacity);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 3, order);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 4, ttl);
pyo3::ffi::PyTuple_SetItem(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SetItem(tuple, 1, dict);
pyo3::ffi::PyTuple_SetItem(tuple, 2, capacity);
pyo3::ffi::PyTuple_SetItem(tuple, 3, order);
pyo3::ffi::PyTuple_SetItem(tuple, 4, ttl);

tuple
}
Expand All @@ -353,7 +353,7 @@ impl crate::basic::PickleMethods for RawTTLCache {
let (maxsize, iterable, capacity) = pickle_get_first_objects!(py, state);

let order = {
let obj = pyo3::ffi::PyTuple_GET_ITEM(state, 3);
let obj = pyo3::ffi::PyTuple_GetItem(state, 3);

if pyo3::ffi::PyTuple_CheckExact(obj) != 1 {
return Err(create_pyerr!(
Expand All @@ -366,7 +366,7 @@ impl crate::basic::PickleMethods for RawTTLCache {
};

let ttl = {
let obj = pyo3::ffi::PyTuple_GET_ITEM(state, 4);
let obj = pyo3::ffi::PyTuple_GetItem(state, 4);
pyo3::ffi::PyFloat_AsDouble(obj) as f32
};

Expand All @@ -381,7 +381,7 @@ impl crate::basic::PickleMethods for RawTTLCache {
#[cfg(not(debug_assertions))]
let dict: &Bound<pyo3::types::PyDict> = iterable.downcast_bound(py).unwrap_unchecked();

let tuple_length = pyo3::ffi::PyTuple_GET_SIZE(order);
let tuple_length = pyo3::ffi::PyTuple_Size(order);

if tuple_length as usize != dict.len() {
return Err(create_pyerr!(
Expand All @@ -400,15 +400,15 @@ impl crate::basic::PickleMethods for RawTTLCache {
));
}

if pyo3::ffi::PyTuple_GET_SIZE(value_as_tuple) != 2 {
if pyo3::ffi::PyTuple_Size(value_as_tuple) != 2 {
return Err(create_pyerr!(
pyo3::exceptions::PyTypeError,
"a value in dictionary that's tuple, but its size isn't equal 2"
));
}

let value_0 = pyo3::ffi::PyTuple_GET_ITEM(value_as_tuple, 0);
let value_1 = pyo3::ffi::PyTuple_GET_ITEM(value_as_tuple, 1);
let value_0 = pyo3::ffi::PyTuple_GetItem(value_as_tuple, 0);
let value_1 = pyo3::ffi::PyTuple_GetItem(value_as_tuple, 1);
let timestamp = pyo3::ffi::PyFloat_AsDouble(value_1);

// SAFETY: key is hashable, so don't worry
Expand All @@ -425,7 +425,7 @@ impl crate::basic::PickleMethods for RawTTLCache {
}

for k in 0..tuple_length {
let key = pyo3::ffi::PyTuple_GET_ITEM(order, k);
let key = pyo3::ffi::PyTuple_GetItem(order, k);
let hashable =
HashablePyObject::try_from_pyobject(PyObject::from_borrowed_ptr(py, key), py)?;
new.order.push_back(hashable);
Expand Down
36 changes: 18 additions & 18 deletions src/vttlcache/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ impl crate::basic::PickleMethods for RawVTTLCache {
let key_tuple = pyo3::ffi::PyTuple_New(2);
let timestamp = pyo3::ffi::PyFloat_FromDouble(f);

pyo3::ffi::PyTuple_SET_ITEM(key_tuple, 0, key.key().object.as_ptr());
pyo3::ffi::PyTuple_SET_ITEM(key_tuple, 1, timestamp);
pyo3::ffi::PyTuple_SetItem(key_tuple, 0, key.key().object.as_ptr());
pyo3::ffi::PyTuple_SetItem(key_tuple, 1, timestamp);

pyo3::ffi::PyDict_SetItem(dict, key_tuple, val.as_ptr());
pyo3::ffi::Py_XDECREF(key_tuple);
Expand All @@ -446,13 +446,13 @@ impl crate::basic::PickleMethods for RawVTTLCache {
Some(f) => {
let key_tuple = pyo3::ffi::PyTuple_New(2);
let timestamp = pyo3::ffi::PyFloat_FromDouble(f);
pyo3::ffi::PyTuple_SET_ITEM(key_tuple, 0, key.key().object.as_ptr());
pyo3::ffi::PyTuple_SET_ITEM(key_tuple, 1, timestamp);
pyo3::ffi::PyTuple_SetItem(key_tuple, 0, key.key().object.as_ptr());
pyo3::ffi::PyTuple_SetItem(key_tuple, 1, timestamp);

pyo3::ffi::PyTuple_SET_ITEM(order, index as isize, key_tuple);
pyo3::ffi::PyTuple_SetItem(order, index as isize, key_tuple);
}
None => {
pyo3::ffi::PyTuple_SET_ITEM(order, index as isize, key.key().object.as_ptr());
pyo3::ffi::PyTuple_SetItem(order, index as isize, key.key().object.as_ptr());
}
}
}
Expand All @@ -461,10 +461,10 @@ impl crate::basic::PickleMethods for RawVTTLCache {
let capacity = pyo3::ffi::PyLong_FromSize_t(self.table.capacity());

let tuple = pyo3::ffi::PyTuple_New(Self::PICKLE_TUPLE_SIZE);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 1, dict);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 2, capacity);
pyo3::ffi::PyTuple_SET_ITEM(tuple, 3, order);
pyo3::ffi::PyTuple_SetItem(tuple, 0, maxsize);
pyo3::ffi::PyTuple_SetItem(tuple, 1, dict);
pyo3::ffi::PyTuple_SetItem(tuple, 2, capacity);
pyo3::ffi::PyTuple_SetItem(tuple, 3, order);

tuple
}
Expand All @@ -477,7 +477,7 @@ impl crate::basic::PickleMethods for RawVTTLCache {
let (maxsize, iterable, capacity) = pickle_get_first_objects!(py, state);

let order = {
let obj = pyo3::ffi::PyTuple_GET_ITEM(state, 3);
let obj = pyo3::ffi::PyTuple_GetItem(state, 3);

if pyo3::ffi::PyTuple_CheckExact(obj) != 1 {
return Err(create_pyerr!(
Expand Down Expand Up @@ -509,15 +509,15 @@ impl crate::basic::PickleMethods for RawVTTLCache {
let key_as_ptr = key.as_ptr();

if pyo3::ffi::PyTuple_CheckExact(key_as_ptr) == 1 {
if pyo3::ffi::PyTuple_GET_SIZE(key_as_ptr) != 2 {
if pyo3::ffi::PyTuple_Size(key_as_ptr) != 2 {
return Err(create_pyerr!(
pyo3::exceptions::PyTypeError,
"a value in dictionary that's tuple, but its size isn't equal 2"
));
}

let key_object = pyo3::ffi::PyTuple_GET_ITEM(key_as_ptr, 0);
let timestamp_object = pyo3::ffi::PyTuple_GET_ITEM(key_as_ptr, 1);
let key_object = pyo3::ffi::PyTuple_GetItem(key_as_ptr, 0);
let timestamp_object = pyo3::ffi::PyTuple_GetItem(key_as_ptr, 1);
let timestamp = pyo3::ffi::PyFloat_AsDouble(timestamp_object);

let hashable = HashablePyObject::try_from_pyobject(
Expand All @@ -541,18 +541,18 @@ impl crate::basic::PickleMethods for RawVTTLCache {
}

for k in 0..tuple_length {
let key_as_ptr = pyo3::ffi::PyTuple_GET_ITEM(order, k);
let key_as_ptr = pyo3::ffi::PyTuple_GetItem(order, k);

if pyo3::ffi::PyTuple_CheckExact(key_as_ptr) == 1 {
if pyo3::ffi::PyTuple_GET_SIZE(key_as_ptr) != 2 {
if pyo3::ffi::PyTuple_Size(key_as_ptr) != 2 {
return Err(create_pyerr!(
pyo3::exceptions::PyTypeError,
"a value in dictionary that's tuple, but its size isn't equal 2"
));
}

let key_object = pyo3::ffi::PyTuple_GET_ITEM(key_as_ptr, 0);
let timestamp_object = pyo3::ffi::PyTuple_GET_ITEM(key_as_ptr, 1);
let key_object = pyo3::ffi::PyTuple_GetItem(key_as_ptr, 0);
let timestamp_object = pyo3::ffi::PyTuple_GetItem(key_as_ptr, 1);
let timestamp = pyo3::ffi::PyFloat_AsDouble(timestamp_object);

let hashable = HashablePyObject::try_from_pyobject(
Expand Down

0 comments on commit 0b27c8a

Please sign in to comment.