Skip to content

Commit f626d7d

Browse files
committed
Add test for the fix.
1 parent 1da4759 commit f626d7d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

tests/test_pytypes.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ TEST_SUBMODULE(pytypes, m) {
289289
return capsule;
290290
});
291291

292+
m.def("return_capsule_with_explicit_nullptr_dtor", []() {
293+
py::print("creating capsule with explicit nullptr dtor");
294+
return py::capsule((void *) 1234, (void (*)(void *)) nullptr); // PR #4221
295+
});
296+
292297
// test_accessors
293298
m.def("accessor_api", [](const py::object &o) {
294299
auto d = py::dict();

tests/test_pytypes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@ def test_capsule(capture):
299299
"""
300300
)
301301

302+
with capture:
303+
a = m.return_capsule_with_explicit_nullptr_dtor()
304+
del a
305+
pytest.gc_collect()
306+
assert (
307+
capture.unordered
308+
== """
309+
creating capsule with explicit nullptr dtor
310+
"""
311+
)
312+
302313

303314
def test_accessors():
304315
class SubTestObject:

0 commit comments

Comments
 (0)