Safely access data in PyUntypedArray
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 141
- Avg merge
- 16m
- Merged PRs (30d)
- 3
Description
PyUntypedArrayMethods::as_array_ptr doesn’t describe under which circumstances the returned pointer is convertible into a reference.
Since the requirements are rather hairy, it would be great to have a way to access the data safely without going through unsafe. Would it e.g. be possible to have this?
trait PyUntypedArrayMethods<'py> {
...
fn bytes<'a>(&'a self) -> &'a [u8] {
let ptr = self.as_array_ptr();
let n_bytes = self.len() * self.dtype().itemsize();
unsafe {
let p = (*ptr).data.cast();
slice::from_raw_parts(p, n_bytes)
}
}
}
Because we currently implement this ourselves, but without any of the aforementioned safety information, we can’t really be sure if it’s safe.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at PyUntypedArrayMethods::as_array_ptr and read the Rust pointer-to-reference conversion documentation cited in the issue. Determine the existing pointer’s safety guarantees and evaluate the proposed bytes accessor, including what documentation or tests are needed to show that callers can access the data safely without their own unsafe code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, rust
- Domain
- api, backend-api-design, data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100