From d495d3e047126ba2d5df7ced028cd5a444e8cb2d Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 7 Aug 2026 08:36:59 -0400 Subject: [PATCH] fix: make gil.h self-contained for PyPy/GraalPy and silence -Wredundant-decls gil.h evaluated PYBIND11_SIMPLE_GIL_MANAGEMENT before including common.h, which defines it on PyPy/GraalPy. Every existing TU included common.h first through pybind11.h, so this only surfaced when src/type_caster_base.cpp reached gil.h directly. Also suppress GCC -Wredundant-decls for the isinstance_generic declaration duplicated in pytypes.h. Assisted-by: ClaudeCode:claude-fable-5 --- include/pybind11/detail/type_caster_base.h | 4 ++++ include/pybind11/gil.h | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 4163673df..095475974 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -219,7 +219,11 @@ public: // (get_value_and_holder, allocate_layout, and deallocate_layout are declared inside // struct instance in detail/common.h; definitions are in type_caster_base-inl.h.) +PYBIND11_WARNING_PUSH +PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls") +// also forward-declared in pytypes.h bool isinstance_generic(handle obj, const std::type_info &tp); +PYBIND11_WARNING_POP handle get_object_handle(const void *ptr, const detail::type_info *type); diff --git a/include/pybind11/gil.h b/include/pybind11/gil.h index 9e799b3cf..e43d4cb2e 100644 --- a/include/pybind11/gil.h +++ b/include/pybind11/gil.h @@ -9,9 +9,12 @@ #pragma once +// common.h must come first: on PyPy/GraalPy it defines PYBIND11_SIMPLE_GIL_MANAGEMENT, +// which selects the branch below. +#include "detail/common.h" + #if defined(PYBIND11_SIMPLE_GIL_MANAGEMENT) -# include "detail/common.h" # include "gil_simple.h" PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) @@ -23,7 +26,6 @@ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) #else -# include "detail/common.h" # include "detail/internals.h" # include