You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could be implemented with a simple change to getptr. Would make the unsafe API a lot safer in most cases. In fact, much of the unsafe API could become a safe "mutable" API.
Alternatively, we could remove NULLs from the API entirely. We already recommend using const foo = Ref{Py}() rather than const foo = pynew() in top-level package code.
For example, unsafe_pynext() could be removed. Instead have a method pynext(x, d) which returns d when there are no more items. For example pynext(iter, nothing) would return nothing (rather than a python NULL).
Activity
cjdoris commentedon May 31, 2026
I quite like this idea - it seems good for safety.
pynew()should return None not NULL.pynew(ptr)just wraps the given pointer.pydel!work in all of this? It needs to eagerly free the python object. So it SHOULD set the ptr to null.[-]Treat all NULLs as None?[/-][+]Idea: Treat all NULLs as None[/+]cjdoris commentedon May 31, 2026
Alternatively, we could remove NULLs from the API entirely. We already recommend using
const foo = Ref{Py}()rather thanconst foo = pynew()in top-level package code.cjdoris commentedon May 31, 2026
For example,
unsafe_pynext()could be removed. Instead have a methodpynext(x, d)which returnsdwhen there are no more items. For examplepynext(iter, nothing)would returnnothing(rather than a python NULL).cjdoris commentedon May 31, 2026
#783 adds
pynext(x, d)so we can just deprecateunsafe_pynext.cjdoris commentedon Jun 4, 2026
Ok we've removed the unsafe API - Py objects are not NULL in the API. So this issue is irrelevant now.