• Jason Rhinelander's avatar
    Support `take_ownership` for custom type casters given a pointer · 60526d46
    Jason Rhinelander authored
    This changes the pointer `cast()` in `PYBIND11_TYPE_CASTER` to recognize
    the `take_ownership` policy: if casting a pointer with take-ownership,
    the `cast()` now recalls `cast()` with a dereferenced rvalue (rather
    than the previous code, which was always calling it with a const lvalue
    reference), and deletes the pointer after the chained `cast()` is
    complete.
    
    This makes code like:
    
        m.def("f", []() { return new std::vector<int>(100, 1); },
            py::return_value_policy::take_ownership);
    
    do the expected thing by taking over ownership of the returned pointer
    (which is deleted once the chained cast completes).
    60526d46
test_methods_and_attributes.cpp 21 KB