[Mlir-commits] [mlir] [MLIR:Python] Fix race on PyOperations. (PR #139721)

Maksim Levental llvmlistbot at llvm.org
Tue May 13 06:55:27 PDT 2025


makslevental wrote:

`liveOperations` strikes again!

Regarding

> and it's probably good for the world that we don't end up with many copies of the fallback implementation

Is it "n00b" to propose that rathe than copy-pasting the impl from nbbind we just rely on the detail/impl via the same `extern`? I.e., couldn't we just copy-paste ([roughly](https://github.com/wjakob/nanobind/blob/62fc996018d9ea4d51af9c86cf008c2562b4eeab/src/nb_ft.h#L26-L38))

```c++
#if PY_VERSION_HEX >= 0x030E00A5
/// Sufficiently recent CPython versions provide an API for the following operations
inline void nb_enable_try_inc_ref(PyObject *obj) noexcept {
    PyUnstable_EnableTryIncRef(obj);
}
inline bool nb_try_inc_ref(PyObject *obj) noexcept {
    return PyUnstable_TryIncRef(obj);
}
#else
/// Otherwise, nanabind ships with a low-level implementation
extern void nb_enable_try_inc_ref(PyObject *) noexcept;
extern bool nb_try_inc_ref(PyObject *obj) noexcept;
#endif
```

https://github.com/llvm/llvm-project/pull/139721


More information about the Mlir-commits mailing list