From a7492b8cde7ee71da312de1cabc9439de6ac3980 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 6 Aug 2026 21:28:16 -0400 Subject: [PATCH] feat: add PYBIND11_NOINLINE_ATTR and PYBIND11_INLINE macros Decompose PYBIND11_NOINLINE into the attribute part plus inline, and add PYBIND11_INLINE, which becomes empty under PYBIND11_PRECOMPILED. Groundwork for optional pre-compilation; all current expansions are unchanged and PYBIND11_INLINE is not used yet. Assisted-by: ClaudeCode:claude-fable-5 --- include/pybind11/detail/common.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 740001db78..506a451a0e 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -160,11 +160,22 @@ // In contrast, FORWARD DECLARATIONS should never use this macro: // https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions #if defined(PYBIND11_NOINLINE_DISABLED) // Option for maximum portability and experimentation. -# define PYBIND11_NOINLINE inline +# define PYBIND11_NOINLINE_ATTR #elif defined(_MSC_VER) -# define PYBIND11_NOINLINE __declspec(noinline) inline +# define PYBIND11_NOINLINE_ATTR __declspec(noinline) #else -# define PYBIND11_NOINLINE __attribute__((noinline)) inline +# define PYBIND11_NOINLINE_ATTR __attribute__((noinline)) +#endif +#define PYBIND11_NOINLINE PYBIND11_NOINLINE_ATTR inline + +// PYBIND11_INLINE marks function definitions that live in a `-inl.h` file. It is `inline` in +// the default header-only mode. Defining PYBIND11_PRECOMPILED makes it empty: the definitions +// are then compiled once (into a static library linked into each extension module) and the +// headers only provide declarations. +#if defined(PYBIND11_PRECOMPILED) +# define PYBIND11_INLINE +#else +# define PYBIND11_INLINE inline #endif #if defined(_MSC_VER)