Skip to content

Conversation

@colesbury
Copy link
Contributor

These would be useful in PyTorch, which uses pythoncapi-compat.h. They are also already used in pybind11, which doesn't use pythoncapi-compat.h.

return-1;
}
#endif
MyType.tp_name="MyType";
Copy link
Member

Choose a reason for hiding this comment

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

Can you please use a less generic name, such as TryIncrefType? (for the variable name and the type name)

@vstinner
Copy link
Member

I'm fine with adding these two functions. I just have some suggestions on the implementation.

colesburyand others added 2 commits November 5, 2025 16:44
Co-authored-by: Victor Stinner <vstinner@python.org>
staticintMyObject_dealloc_called=0;

staticvoid
MyObject_dealloc(PyObject*op)
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind to rename it to TryIncref_dealloc() and rename also MyObject_dealloc_called?

@vstinnervstinner merged commit c44469c into python:mainNov 5, 2025
36 checks passed
@vstinner
Copy link
Member

Merged, thanks for your contribution.

@colesburycolesbury deleted the try_incref branch November 5, 2025 22:08
Sign up for freeto 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

@colesbury@vstinner