PyO3 / pyo3

Rust bindings for the Python interpreter
https://pyo3.rs
Apache License 2.0
12.12k stars 745 forks source link

Refcounting changes after PEP 683 #3357

Open davidhewitt opened 1 year ago

davidhewitt commented 1 year ago

PEP 683's "immortal objects" changed the meaning of reference counts; immortal objects have a fixed refcount value which never changes.

Further, the PEP states:

Py_REFCNT() - add “The refcounts 0 and 1 have specific meanings and all others only mean code somewhere is using the object, regardless of the value. 0 means the object is not used and will be cleaned up. 1 means code holds exactly a single reference.”

Does this mean that PyAny::get_refcnt should change, given that the upstream position is essentially that only 0 and 1 have meaning?

alex commented 1 year ago

What's the use case for PyAny::get_refcnt? Perhaps it should be deprecated in favor of methods with narrower semantics.

davidhewitt commented 1 year ago

I might even suggest it doesn't need a replacement added immediately, we can let users call pyo3::ffi::Py_REFCNT(obj.as_ptr()) to get the same functionality for now and if someone comes up with a desirable proposal for a safe API we could add that then?

davidhewitt commented 6 months ago

Labelling as "Good First Issue" as all that's really needed is to remove or deprecate .get_refcnt() methods.