Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context manager for AvailableData #122

Conversation

nclack
Copy link
Member

@nclack nclack commented Nov 29, 2023

closes #68

This is an alternative to #70.

This is in draft until I feel more confident about the tests and the napari plugin. But I think it's close.

@@ -72,7 +72,7 @@ fn main() {
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg(format!("-I{}/include", dst.display()))
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changed here? Something in bindgen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I beleive this means rerun_on_header_files is on by default

Comment on lines +82 to +96
fn map_read(&self, stream_id: u32) -> Result<(*mut capi::VideoFrame, *mut capi::VideoFrame)> {
let mut beg = null_mut();
let mut end = null_mut();
unsafe {
capi::acquire_map_read(self.inner.as_ptr(), stream_id, &mut beg, &mut end).ok()?;
}
Ok((beg, end))
}

fn unmap_read(&self, stream_id: u32, consumed_bytes: usize) -> Result<()> {
unsafe {
capi::acquire_unmap_read(self.inner.as_ptr(), stream_id, consumed_bytes).ok()?;
}
Ok(())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@aliddell
Copy link
Member

#132 strikes again.

@nclack nclack marked this pull request as ready for review December 12, 2023 16:56
@nclack
Copy link
Member Author

nclack commented Dec 12, 2023

I wonder if there's a way to avoid the if. null context manager? @andy-sweet

Copy link
Contributor

@andy-sweet andy-sweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks fine. We could consider adding support for an empty AvailableData, which might help clean up some of the Python examples and avoid the need for some of the checks in the with statements, but I think that can be done later too.

I think I found a few missed lines that could be deleted now. We could also consider removing the TODO at the end of __init__.py, though this only adds context manager for available data and not for runtime/start/stop.

tests/test_zarr.py Outdated Show resolved Hide resolved
tests/test_basic.py Outdated Show resolved Hide resolved
tests/test_basic.py Outdated Show resolved Hide resolved
@aliddell
Copy link
Member

Generally looks fine. We could consider adding support for an empty AvailableData, which might help clean up some of the Python examples and avoid the need for some of the checks in the with statements, but I think that can be done later too.

Yeah, I agree that empty AvailableData should be supported, but it should be a separate PR. I can make an issue of it after this is merged and hold off on cutting a 0.3.0 rc until after that makes it in.

I think I found a few missed lines that could be deleted now. We could also consider removing the TODO at the end of __init__.py, though this only adds context manager for available data and not for runtime/start/stop.

I've removed those del / = None statements, but I'm going to leave the TODO in for now.

@aliddell aliddell merged commit 1c80d86 into acquire-project:main Dec 13, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AvailableData relies on deletion for cleanup
3 participants