summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-09-17 20:46:38 (GMT)
committerGitHub <noreply@github.com>2021-09-17 20:46:38 (GMT)
commite4044e9f893350b4623677c048d33414a77edf55 (patch)
tree7a0aec99a457847f8912bc3c675a709eacf7bd10 /Include
parent51ebb7f4f5e9bdcf8279a1d91be9569706f6bead (diff)
downloadcpython-e4044e9f893350b4623677c048d33414a77edf55.zip
cpython-e4044e9f893350b4623677c048d33414a77edf55.tar.gz
cpython-e4044e9f893350b4623677c048d33414a77edf55.tar.bz2
bpo-45116: Py_DEBUG ignores Py_ALWAYS_INLINE (GH-28419)
If the Py_DEBUG macro is defined, the Py_ALWAYS_INLINE macro does nothing.
Diffstat (limited to 'Include')
-rw-r--r--Include/pyport.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/Include/pyport.h b/Include/pyport.h
index af7fbe7..d27d083 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -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