From 774a5570c572e120f2f942f7ae335b2e8b11f9f4 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 28 Jun 2026 23:15:05 -0400 Subject: [PATCH] revert: "add life support to handles cast to string_view (#6092)" This reverts commit 59d7cb28c1f5a014bb17ad4a8e80da2fb51a6159 (#6092). #6092 introduced regressions that are being addressed in #6096; reverting Assisted-by: ClaudeCode:claude-opus-4.8 --- include/pybind11/cast.h | 9 --------- tests/test_stl.cpp | 10 ---------- tests/test_stl.py | 12 ------------ 3 files changed, 31 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index fb67ff8d56..62ca45a09a 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -525,9 +525,6 @@ struct string_caster { return false; } value = StringType(buffer, static_cast(size)); - if (IsView) { - loader_life_support::add_patient(src); - } return true; } @@ -605,9 +602,6 @@ struct string_caster { pybind11_fail("Unexpected PYBIND11_BYTES_AS_STRING() failure."); } value = StringType(bytes, (size_t) PYBIND11_BYTES_SIZE(src.ptr())); - if (IsView) { - loader_life_support::add_patient(src); - } return true; } if (PyByteArray_Check(src.ptr())) { @@ -618,9 +612,6 @@ struct string_caster { pybind11_fail("Unexpected PyByteArray_AsString() failure."); } value = StringType(bytearray, (size_t) PyByteArray_Size(src.ptr())); - if (IsView) { - loader_life_support::add_patient(src); - } return true; } diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index 526c7643ac..8bddbb1f38 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -582,16 +582,6 @@ TEST_SUBMODULE(stl, m) { [](const std::list &) { return 2; }); m.def("func_with_string_or_vector_string_arg_overload", [](const std::string &) { return 3; }); -#ifdef PYBIND11_HAS_STRING_VIEW - m.def("func_with_string_views", [](const std::vector &svs) { - py::list l; - for (std::string_view sv : svs) { - l.append(sv); - } - return l; - }); -#endif - class Placeholder { public: Placeholder() { print_created(this); } diff --git a/tests/test_stl.py b/tests/test_stl.py index 8b97c76195..b04f55c9f8 100644 --- a/tests/test_stl.py +++ b/tests/test_stl.py @@ -28,18 +28,6 @@ def test_vector(doc): # Test regression caused by 936: pointers to stl containers weren't castable assert m.cast_ptr_vector() == ["lvalue", "lvalue"] - if hasattr(m, "func_with_string_views"): - - def gen(): - return ("a" + str(x) for x in range(10000, 10010)) - - expected = list(gen()) - assert m.func_with_string_views(gen()) == expected - assert m.func_with_string_views(x.encode() for x in gen()) == expected - assert ( - m.func_with_string_views(bytearray(x.encode()) for x in gen()) == expected - ) - def test_deque(): """std::deque <-> list"""