From 09de72c9c39216b733248a287ea9cb00f7507c45 Mon Sep 17 00:00:00 2001 From: oxine Date: Wed, 25 Mar 2026 20:56:59 +0800 Subject: [PATCH 1/2] 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 --- include/pybind11/pybind11.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 454638e299..65f3eaa32c 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -3548,6 +3548,9 @@ PYBIND11_NOINLINE void print(const tuple &args, const dict &kwargs) { } } + if (file.is_none()) + return; + auto write = file.attr("write"); write(std::move(line)); write(kwargs.contains("end") ? kwargs["end"] : str("\n")); From ffc1810cba2e9d8103da352ca7be84e7093f5011 Mon Sep 17 00:00:00 2001 From: oxine Date: Wed, 25 Mar 2026 21:59:18 +0800 Subject: [PATCH 2/2] clang tidy --- include/pybind11/pybind11.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 65f3eaa32c..f5af543254 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -3548,8 +3548,9 @@ PYBIND11_NOINLINE void print(const tuple &args, const dict &kwargs) { } } - if (file.is_none()) + if (file.is_none()) { return; + } auto write = file.attr("write"); write(std::move(line));