wjakob / nanobind

nanobind: tiny and efficient C++/Python bindings
BSD 3-Clause "New" or "Revised" License
2.29k stars 191 forks source link

Fix support for None in unique_ptr caster #590

Closed oremanj closed 4 months ago

oremanj commented 4 months ago

Support passing None where a unique_ptr<T> is needed (subject to argument nullability rules), and producing None when a null unique_ptr<T> is returned to Python.

Previously from-python conversion would pass a None object to nb_type_relinquish_ownership which would try to reinterpret it as a nanobind instance. Similarly, in from-cpp conversion, nb_type_put_unique would call nb_type_put_unique_finalize which would try to modify some bits in Py_None.