Skip to content

Commit 09de72c

Browse files
committed
Fix crash when calling pybind11::print in a subsystem:windows build
in line: file = module_::import("sys").attr("stdout"); the file will be none in a windows application build. won't be catched since there's no exception, and crashed in later access
1 parent ce9f83c commit 09de72c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

include/pybind11/pybind11.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,6 +3548,9 @@ PYBIND11_NOINLINE void print(const tuple &args, const dict &kwargs) {
35483548
}
35493549
}
35503550

3551+
if (file.is_none())
3552+
return;
3553+
35513554
auto write = file.attr("write");
35523555
write(std::move(line));
35533556
write(kwargs.contains("end") ? kwargs["end"] : str("\n"));

0 commit comments

Comments
 (0)