Uh oh!
There was an error while loading. Please reload this page.
Add PyUnstable_TryIncref and PyUnstable_EnableTryIncRef. - #159
Conversation
Uh oh!
There was an error while loading. Please reload this page.
| return -1; | ||
| } | ||
| #endif | ||
| MyType.tp_name = "MyType"; |
There was a problem hiding this comment.
Can you please use a less generic name, such as TryIncrefType? (for the variable name and the type name)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Nov 5, 2025
I'm fine with adding these two functions. I just have some suggestions on the implementation. |
Co-authored-by: Victor Stinner <vstinner@python.org>
| static int MyObject_dealloc_called = 0; | ||
| static void | ||
| MyObject_dealloc(PyObject *op) |
There was a problem hiding this comment.
Would you mind to rename it to TryIncref_dealloc() and rename also MyObject_dealloc_called?
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Nov 5, 2025
Merged, thanks for your contribution. |
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.