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

pyproto: don't use inventory for methods #1446

Merged
merged 2 commits into from
Feb 26, 2021

Conversation

davidhewitt
Copy link
Member

This is the next step in making inventory optional, by changing #[pyproto] methods which use inventory to also use dtolnay specialization.

It works very similarly to #1328.

From a very basic benchmark, this doesn't appear to change performance of type object initialization at all. (Perf doesn't matter very much here anyway, as this is only something that runs once on library startup.)

The next (and final) PR in this series will make it so that inventory is optional. Without inventory, you will only be allowed one #[pymethods] for each #[pyclass]. However you will get faster compile times and support on platforms where inventory isn't available :)

Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

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

Thanks, I don't see any problem, but maybe it's better we have a comment on transmute.

@@ -210,7 +210,7 @@ pub fn add_fn_to_module(
pyo3::types::PyCFunction::internal_new(
name,
doc,
pyo3::class::PyMethodType::PyCFunctionWithKeywords(#wrapper_ident),
unsafe { std::mem::transmute(#wrapper_ident as *const std::os::raw::c_void) },
Copy link
Member

Choose a reason for hiding this comment

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

Transmuting to enum is safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a function-pointer-to-function-pointer cast (I changed the arguments to PyCFunction::internal_new).

Actually I think I can get rid of this by refactoring PyCFunction::internal_new a bit more. It will have a slight user-facing change (but a good one imo) so I'll do it in a follow-up PR.

@davidhewitt davidhewitt merged commit c4bd933 into PyO3:master Feb 26, 2021
@davidhewitt davidhewitt deleted the no-pyproto-inventory branch February 26, 2021 09:09
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.

2 participants