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

vstinner commented Nov 5, 2025

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

colesbury and others added 2 commits November 5, 2025 16:44
Co-authored-by: Victor Stinner <vstinner@python.org>
@colesbury colesbury requested a review from vstinner November 5, 2025 21:46
static int MyObject_dealloc_called = 0;

static void
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?

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

vstinner commented Nov 5, 2025

Merged, thanks for your contribution.

@colesbury colesbury deleted the try_incref branch November 5, 2025 22:08
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