Skip to content

Commit a7492b8

Browse files
committed
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
1 parent bdd7f79 commit a7492b8

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

include/pybind11/detail/common.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,22 @@
160160
// In contrast, FORWARD DECLARATIONS should never use this macro:
161161
// https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions
162162
#if defined(PYBIND11_NOINLINE_DISABLED) // Option for maximum portability and experimentation.
163-
# define PYBIND11_NOINLINE inline
163+
# define PYBIND11_NOINLINE_ATTR
164164
#elif defined(_MSC_VER)
165-
# define PYBIND11_NOINLINE __declspec(noinline) inline
165+
# define PYBIND11_NOINLINE_ATTR __declspec(noinline)
166166
#else
167-
# define PYBIND11_NOINLINE __attribute__((noinline)) inline
167+
# define PYBIND11_NOINLINE_ATTR __attribute__((noinline))
168+
#endif
169+
#define PYBIND11_NOINLINE PYBIND11_NOINLINE_ATTR inline
170+
171+
// PYBIND11_INLINE marks function definitions that live in a `-inl.h` file. It is `inline` in
172+
// the default header-only mode. Defining PYBIND11_PRECOMPILED makes it empty: the definitions
173+
// are then compiled once (into a static library linked into each extension module) and the
174+
// headers only provide declarations.
175+
#if defined(PYBIND11_PRECOMPILED)
176+
# define PYBIND11_INLINE
177+
#else
178+
# define PYBIND11_INLINE inline
168179
#endif
169180

170181
#if defined(_MSC_VER)

0 commit comments

Comments
 (0)