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

chore: Cleanup casters to avoid unnecessary ref counting #4269

Merged
merged 1 commit into from
Oct 21, 2022

Conversation

Skylion007
Copy link
Collaborator

Description

  • I noticed some style inconsistency where we inc_ref() 'None()' when returning them in casters. In reality, we should be calling release() on them to simply return the existing handle from the underlying object.
  • In other words, currently we call inc_ref() twice and dec_ref() once to increase the ref count by one (once in ctor, once manually, once in the dor). This change makes it so we only call it once in the ctor.
  • This also makes the style more consistent for when people write their own casters.

Suggested changelog entry:

* Optimize casting C++ object to None.

@Skylion007 Skylion007 changed the title chore: Cleanup casters to release none() to avoid ref counting chore: Cleanup casters to avoid unnecessary ref counting Oct 21, 2022
@Skylion007 Skylion007 merged commit 2ce76f7 into pybind:master Oct 21, 2022
@Skylion007 Skylion007 deleted the none-incref-cleanup branch October 21, 2022 16:51
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Oct 21, 2022
henryiii pushed a commit to henryiii/pybind11 that referenced this pull request Oct 21, 2022
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Oct 31, 2022
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