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

implement PyCapsuleMethods #3770

Merged
merged 1 commit into from
Jan 29, 2024
Merged

implement PyCapsuleMethods #3770

merged 1 commit into from
Jan 29, 2024

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Jan 28, 2024

This ports PyCapsule to the new Bound API from #3684.

Copy link

codspeed-hq bot commented Jan 28, 2024

CodSpeed Performance Report

Merging #3770 will degrade performances by 16.93%

Comparing Icxolu:capsule (e323fcb) with main (0d421b1)

🎉 Hooray! pytest-codspeed just leveled up to 2.2.0!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

⚡ 1 improvements
❌ 2 regressions
✅ 77 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main Icxolu:capsule Change
extract_float_downcast_success 446.7 ns 530 ns -15.72%
not_a_list_via_downcast 242.8 ns 215 ns +12.92%
extract_float_extract_success 408.9 ns 492.2 ns -16.93%

@davidhewitt
Copy link
Member

Thank you so much for the continued help! I will do my best to find a moment to review this first thing in the morning tomorrow 🙏

Copy link
Member

@adamreichold adamreichold left a comment

Choose a reason for hiding this comment

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

One suggestion on readability, otherwise LGTM.

self.as_borrowed().name()
}

fn name_ptr_ignore_error(slf: &Bound<'_, Self>) -> *const c_char {
Copy link
Member

Choose a reason for hiding this comment

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

I think keeping this as an inherent method is a bit detrimental to readability. I would suggest making it a free function within this module and maybe putting it next to ensure_no_error.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Agree with @adamreichold, otherwise just some tiny comments from me!

Thanks again 👍

value: T,
name: Option<CString>,
) -> PyResult<&Self> {
Self::new_bound(py, value, name).map(|b| b.into_gil_ref())
Copy link
Member

Choose a reason for hiding this comment

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

I slightly prefer the following style for the map:

Suggested change
Self::new_bound(py, value, name).map(|b| b.into_gil_ref())
Self::new_bound(py, value, name).map(Bound::into_gil_ref)

name: Option<CString>,
destructor: F,
) -> PyResult<&'_ Self> {
Self::new_bound_with_destructor(py, value, name, destructor).map(|b| b.into_gil_ref())
Copy link
Member

Choose a reason for hiding this comment

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

Ditto here

Suggested change
Self::new_bound_with_destructor(py, value, name, destructor).map(|b| b.into_gil_ref())
Self::new_bound_with_destructor(py, value, name, destructor).map(Bound::into_gil_ref)

src/types/capsule.rs Show resolved Hide resolved
let cap_ptr = ffi::PyCapsule_New(
Box::into_raw(val) as *mut c_void,
ffi::PyCapsule_New(
Box::into_raw(val).cast(),
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Jan 29, 2024
@Icxolu
Copy link
Contributor Author

Icxolu commented Jan 29, 2024

Thanks for the review, I've adjusted the points.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks yet again, looks great!

@davidhewitt davidhewitt added this pull request to the merge queue Jan 29, 2024
Merged via the queue into PyO3:main with commit 718be9f Jan 29, 2024
36 of 38 checks passed
@Icxolu Icxolu deleted the capsule branch January 29, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants