`PyCFunction::new` and `PyCFunction::new_with_keywords` necessarily leak a `PyMethodDef`
Open
Nobody has claimed this yet.
needs-design
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Follow up to #5459
PyCFunction::new and PyCFunction::new_with_keywords both have to leak PyMethodDef because there is nowhere to store the one they create to produce Python functions.
I see possible solutions:
- replace these constructors with one which takes
&'static PyMethodDef. - expand
PyCFunction::new_closureinto a family of functions which work similarly for various function-like types (and Python call protocols, e.g.new_closureonly supports tuple & dict convention but "vectorcall" is more efficient)
Needs experimentation to see what feels good.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the PyCFunction::new, PyCFunction::new_with_keywords, and PyCFunction::new_closure entry points, then read the context from follow-up #5459. Compare the ownership of the created PyMethodDef and the supported tuple-and-dict versus vectorcall protocols; done means selecting and validating an API approach that avoids the reported leak.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api, backend-api-design
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100