Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: python-test

on:
push:
pull_request:

permissions:
contents: read
Expand All @@ -20,6 +21,7 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.14rc2'
- 'pypy3.9'
- 'pypy3.10'

Expand Down
34 changes: 16 additions & 18 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ features = ["inline-more", "raw"]
version = "2.3.0"

[dependencies.pyo3]
version = "0.24.1"
version = "0.26.0"
default-features = false
features = ["macros", "extension-module"]

[dependencies.cfg-if]
version = "1.0.0"
version = "1.0.3"

[dependencies.parking_lot_core]
version = "0.9.10"
version = "0.9.11"
default-features = false

[dependencies.lock_api]
version = "0.4.12"
version = "0.4.13"
default-features = false

[build-dependencies.pyo3-build-config]
version = "0.24.1"
version = "0.26.0"
features = ["resolve-config"]

[lints.clippy]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python",
"Programming Language :: Rust",
"Intended Audience :: Developers",
Expand Down
47 changes: 31 additions & 16 deletions src/bridge/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Cache {
#[pyo3::pyclass(module = "cachebox._core")]
pub struct cache_items {
pub ptr: ObservedIterator,
pub iter: crate::mutex::Mutex<hashbrown::raw::RawIter<(PreHashObject, pyo3::PyObject)>>,
pub iter: crate::mutex::Mutex<hashbrown::raw::RawIter<(PreHashObject, pyo3::Py<pyo3::PyAny>)>>,
}

#[pyo3::pymethods]
Expand Down Expand Up @@ -45,11 +45,14 @@ impl Cache {

fn __sizeof__(&self) -> usize {
let lock = self.raw.lock();
lock.capacity()
* (std::mem::size_of::<PreHashObject>() + std::mem::size_of::<pyo3::ffi::PyObject>())
lock.capacity() * (size_of::<PreHashObject>() + size_of::<pyo3::ffi::PyObject>())
}

fn __contains__(&self, py: pyo3::Python<'_>, key: pyo3::PyObject) -> pyo3::PyResult<bool> {
fn __contains__(
&self,
py: pyo3::Python<'_>,
key: pyo3::Py<pyo3::PyAny>,
) -> pyo3::PyResult<bool> {
let key = PreHashObject::from_pyobject(py, key)?;
let lock = self.raw.lock();

Expand All @@ -70,9 +73,9 @@ impl Cache {
fn insert(
&self,
py: pyo3::Python<'_>,
key: pyo3::PyObject,
value: pyo3::PyObject,
) -> pyo3::PyResult<Option<pyo3::PyObject>> {
key: pyo3::Py<pyo3::PyAny>,
value: pyo3::Py<pyo3::PyAny>,
) -> pyo3::PyResult<Option<pyo3::Py<pyo3::PyAny>>> {
let key = PreHashObject::from_pyobject(py, key)?;
let mut lock = self.raw.lock();

Expand All @@ -85,7 +88,11 @@ impl Cache {
}
}

fn get(&self, py: pyo3::Python<'_>, key: pyo3::PyObject) -> pyo3::PyResult<pyo3::PyObject> {
fn get(
&self,
py: pyo3::Python<'_>,
key: pyo3::Py<pyo3::PyAny>,
) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
let key = PreHashObject::from_pyobject(py, key)?;
let lock = self.raw.lock();

Expand All @@ -98,7 +105,7 @@ impl Cache {
fn update(
slf: pyo3::PyRef<'_, Self>,
py: pyo3::Python<'_>,
iterable: pyo3::PyObject,
iterable: pyo3::Py<pyo3::PyAny>,
) -> pyo3::PyResult<()> {
if slf.as_ptr() == iterable.as_ptr() {
return Ok(());
Expand All @@ -110,7 +117,7 @@ impl Cache {

fn __richcmp__(
slf: pyo3::PyRef<'_, Self>,
other: pyo3::PyObject,
other: pyo3::Py<pyo3::PyAny>,
op: pyo3::class::basic::CompareOp,
) -> pyo3::PyResult<bool> {
let other = other.extract::<pyo3::PyRef<'_, Self>>(slf.py())?;
Expand Down Expand Up @@ -139,7 +146,11 @@ impl Cache {
}
}

fn remove(&self, py: pyo3::Python<'_>, key: pyo3::PyObject) -> pyo3::PyResult<pyo3::PyObject> {
fn remove(
&self,
py: pyo3::Python<'_>,
key: pyo3::Py<pyo3::PyAny>,
) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
let key = PreHashObject::from_pyobject(py, key)?;
let mut lock = self.raw.lock();

Expand Down Expand Up @@ -169,9 +180,9 @@ impl Cache {
fn setdefault(
&self,
py: pyo3::Python<'_>,
key: pyo3::PyObject,
default: pyo3::PyObject,
) -> pyo3::PyResult<pyo3::PyObject> {
key: pyo3::Py<pyo3::PyAny>,
default: pyo3::Py<pyo3::PyAny>,
) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
let key = PreHashObject::from_pyobject(py, key)?;
let mut lock = self.raw.lock();

Expand Down Expand Up @@ -204,7 +215,7 @@ impl Cache {
(0,)
}

fn __getstate__(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<pyo3::PyObject> {
fn __getstate__(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
let lock = self.raw.lock();
unsafe {
let state = {
Expand Down Expand Up @@ -235,7 +246,11 @@ impl Cache {
}
}

pub fn __setstate__(&self, py: pyo3::Python<'_>, state: pyo3::PyObject) -> pyo3::PyResult<()> {
pub fn __setstate__(
&self,
py: pyo3::Python<'_>,
state: pyo3::Py<pyo3::PyAny>,
) -> pyo3::PyResult<()> {
let mut lock = self.raw.lock();
lock.from_pickle(py, state.as_ptr())
}
Expand Down
Loading