Skip to content

Conversation

davidhewitt
Copy link
Member

Fixes #5127

This PR tweaks the internal machinery of #[pyfunction] slightly to avoid needing to leak ffi::PyMethodDef structures inside the macro-generated code.

This is done by:

  • Changing #[pyfunction] to store a static ffi::PyMethodDef (wrapped as a PyFunctionDef newtype to be Sync).
  • removing PyCFunction::internal_new and replacing it with pyo3::impl_::pyfunction::create_py_c_function

PyCFunction::new and PyCFunction::new_with_keywords still leak, we should probably open a follow-up issue to track that. I don't see a way to avoid other than replace those APIs with a better alternative.

@alex
Copy link
Contributor

alex commented Sep 20, 2025

Nice!

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.

Memory Leak in pyo3 used by cryptography
2 participants