Deallocates an instance; via holder, if constructed; otherwise via operator delete.
| 1928 | |
| 1929 | /// Deallocates an instance; via holder, if constructed; otherwise via operator delete. |
| 1930 | static void dealloc(detail::value_and_holder &v_h) { |
| 1931 | // We could be deallocating because we are cleaning up after a Python exception. |
| 1932 | // If so, the Python error indicator will be set. We need to clear that before |
| 1933 | // running the destructor, in case the destructor code calls more Python. |
| 1934 | // If we don't, the Python API will exit with an exception, and pybind11 will |
| 1935 | // throw error_already_set from the C++ destructor which is forbidden and triggers |
| 1936 | // std::terminate(). |
| 1937 | error_scope scope; |
| 1938 | if (v_h.holder_constructed()) { |
| 1939 | v_h.holder<holder_type>().~holder_type(); |
| 1940 | v_h.set_holder_constructed(false); |
| 1941 | } else { |
| 1942 | detail::call_operator_delete( |
| 1943 | v_h.value_ptr<type>(), v_h.type->type_size, v_h.type->type_align); |
| 1944 | } |
| 1945 | v_h.value_ptr() = nullptr; |
| 1946 | } |
| 1947 | |
| 1948 | static detail::function_record *get_function_record(handle h) { |
| 1949 | h = detail::get_function(h); |
no test coverage detected