Add method to check PyCapsule name while getting pointer
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
PyCapsule::pointer() passes the name of the PyCapsule itself, instead of passing a user-provided name. This means users must perform the validation of the PyCapsule name themselves.
let capsule: PyCapsule = object.extract(py)?;
if capsule.name() != expected_name {
return PyValueError::new_err("Capsule does not have expected name");
}
let pointer = capsule.pointer() as *mut MyDataType;
if pointer.is_null() {
return PyValueError::new_err("Capsule pointer was null");
}
// do something with pointer.
It might be nice to instead have an API that is more strongly typed and convenient:
let capsule = unsafe { TypedPyCapsule::<MyDataType>::from_object(obj, expected_name)? }; // does name check
let pointer: NonNull<MyDataType> = capsule.get_pointer()?; // does null check
Contributor guide
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 by reading the existing PyCapsule::pointer() and name() APIs in the Rust bindings, then compare them with the proposed TypedPyCapsule and get_pointer() usage. Done means the API can validate a user-provided capsule name and reject null pointers while providing the proposed typed access pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100