Skip to content

Commit db92ad9

Browse files
authored
revert: "add life support to handles cast to string_view (#6092)" (#6097)
This reverts commit 59d7cb2 (#6092). #6092 introduced regressions that are being addressed in #6096; reverting Assisted-by: ClaudeCode:claude-opus-4.8
1 parent 84da0e2 commit db92ad9

3 files changed

Lines changed: 0 additions & 31 deletions

File tree

include/pybind11/cast.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,6 @@ struct string_caster {
525525
return false;
526526
}
527527
value = StringType(buffer, static_cast<size_t>(size));
528-
if (IsView) {
529-
loader_life_support::add_patient(src);
530-
}
531528
return true;
532529
}
533530

@@ -605,9 +602,6 @@ struct string_caster {
605602
pybind11_fail("Unexpected PYBIND11_BYTES_AS_STRING() failure.");
606603
}
607604
value = StringType(bytes, (size_t) PYBIND11_BYTES_SIZE(src.ptr()));
608-
if (IsView) {
609-
loader_life_support::add_patient(src);
610-
}
611605
return true;
612606
}
613607
if (PyByteArray_Check(src.ptr())) {
@@ -618,9 +612,6 @@ struct string_caster {
618612
pybind11_fail("Unexpected PyByteArray_AsString() failure.");
619613
}
620614
value = StringType(bytearray, (size_t) PyByteArray_Size(src.ptr()));
621-
if (IsView) {
622-
loader_life_support::add_patient(src);
623-
}
624615
return true;
625616
}
626617

tests/test_stl.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,16 +582,6 @@ TEST_SUBMODULE(stl, m) {
582582
[](const std::list<std::string> &) { return 2; });
583583
m.def("func_with_string_or_vector_string_arg_overload", [](const std::string &) { return 3; });
584584

585-
#ifdef PYBIND11_HAS_STRING_VIEW
586-
m.def("func_with_string_views", [](const std::vector<std::string_view> &svs) {
587-
py::list l;
588-
for (std::string_view sv : svs) {
589-
l.append(sv);
590-
}
591-
return l;
592-
});
593-
#endif
594-
595585
class Placeholder {
596586
public:
597587
Placeholder() { print_created(this); }

tests/test_stl.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ def test_vector(doc):
2828
# Test regression caused by 936: pointers to stl containers weren't castable
2929
assert m.cast_ptr_vector() == ["lvalue", "lvalue"]
3030

31-
if hasattr(m, "func_with_string_views"):
32-
33-
def gen():
34-
return ("a" + str(x) for x in range(10000, 10010))
35-
36-
expected = list(gen())
37-
assert m.func_with_string_views(gen()) == expected
38-
assert m.func_with_string_views(x.encode() for x in gen()) == expected
39-
assert (
40-
m.func_with_string_views(bytearray(x.encode()) for x in gen()) == expected
41-
)
42-
4331

4432
def test_deque():
4533
"""std::deque <-> list"""

0 commit comments

Comments
 (0)