Skip to content

remove AsPyPointer from FromPyObject impl for Py<T>`#3406

Closed
davidhewitt wants to merge 1 commit intoPyO3:mainfrom
davidhewitt:py-frompyobject
Closed

remove AsPyPointer from FromPyObject impl for Py<T>`#3406
davidhewitt wants to merge 1 commit intoPyO3:mainfrom
davidhewitt:py-frompyobject

Conversation

@davidhewitt
Copy link
Copy Markdown
Member

Related to #3358

This drops the AsPyPointer bound from the Py<T> conversion. I think the resulting implementation is more intuitive and almost certainly more performant.

@davidhewitt
Copy link
Copy Markdown
Member Author

I can't decide whether this one is CHANGELOG worthy. By removing bounds here I can't imagine it would affect user code?

ob.extract::<&T::AsRefTarget>()
.map(|val| Py::from_borrowed_ptr(ob.py(), val.as_ptr()))
if ob.is_instance_of::<T>() {
Ok(unsafe { Py::from_non_null(NonNull::new_unchecked(ob.into_ptr())) })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So this can assume that val will always point to the same object (i.e. not a sub-allocation) as ob?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, that's a good observation. I think I've always assumed that should be the case, and I'd quite like this to be true. But it is breaking. So if we like this property we could document this as a breaking change?

@davidhewitt
Copy link
Copy Markdown
Member Author

Closing as I think we'll release 0.20 without this change and then hopefully a rework in 0.21 will remove the need for this.

@davidhewitt davidhewitt closed this Sep 5, 2023
@davidhewitt davidhewitt deleted the py-frompyobject branch September 5, 2023 23:11
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.

3 participants