Skip to content

chore: Cleanup casters to avoid unnecessary ref counting #4269

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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 requested review from rwgk and henryiii October 21, 2022 15:44
@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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants