Skip to content

bpo-45116: Py_DEBUG ignores Py_ALWAYS_INLINE #28419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ complete listing.
worse performances (due to increased code size for example). The compiler is
usually smarter than the developer for the cost/benefit analysis.

If Python is :ref:`built in debug mode <debug-build>` (if the ``Py_DEBUG``
macro is defined), the :c:macro:`Py_ALWAYS_INLINE` macro does nothing.

It must be specified before the function return type. Usage::

static inline Py_ALWAYS_INLINE int random(void) { return 4; }
Expand Down
11 changes: 10 additions & 1 deletion Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,19 @@ extern "C" {
// worse performances (due to increased code size for example). The compiler is
// usually smarter than the developer for the cost/benefit analysis.
//
// If Python is built in debug mode (if the Py_DEBUG macro is defined), the
// Py_ALWAYS_INLINE macro does nothing.
//
// It must be specified before the function return type. Usage:
//
// static inline Py_ALWAYS_INLINE int random(void) { return 4; }
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
#if defined(Py_DEBUG)
// If Python is built in debug mode, usually compiler optimizations are
// disabled. In this case, Py_ALWAYS_INLINE can increase a lot the stack
// memory usage. For example, forcing inlining using gcc -O0 increases the
// stack usage from 6 KB to 15 KB per Python function call.
# define Py_ALWAYS_INLINE
#elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
# define Py_ALWAYS_INLINE __attribute__((always_inline))
#elif defined(_MSC_VER)
# define Py_ALWAYS_INLINE __forceinline
Expand Down