You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 {returnPyValueError::new_err("Capsule does not have expected name");}let pointer = capsule.pointer()as*mutMyDataType;if pointer.is_null(){returnPyValueError::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 checklet pointer:NonNull<MyDataType> = capsule.get_pointer()?;// does null check
The text was updated successfully, but these errors were encountered:
wjones127
changed the title
Add PyCapsule::import_mut as mutable parallel to PyCapsule::import
Add method to check PyCapsule name while getting pointer
Nov 18, 2023
I'll implement this as a utility wrapper in upstream projects and meanwhile I'll let the project maintainers here think about whether this is something that would make sense in PyO3.
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.It might be nice to instead have an API that is more strongly typed and convenient:
The text was updated successfully, but these errors were encountered: