From 3d093c0f7afdd9475a4ca3a6683cc00b9e2c48cc Mon Sep 17 00:00:00 2001 From: inventshah <39803835+inventshah@users.noreply.github.com> Date: Wed, 13 Aug 2025 13:48:48 -0500 Subject: [PATCH 1/3] mark _PyOptimizer_Optimize as no inline --- .../next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst | 2 ++ Python/optimizer.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst diff --git a/Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst b/Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst new file mode 100644 index 00000000000000..d019522d46a680 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst @@ -0,0 +1,2 @@ +Mark :c:func:`_PyOptimizer_Optimize` as :c:macro:`Py_NO_INLINE` to +prevent stack overflow crashes on MacOS. diff --git a/Python/optimizer.c b/Python/optimizer.c index f06df9644a1614..a3aa99285bb71c 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -109,7 +109,7 @@ uop_optimize(_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, /* Returns 1 if optimized, 0 if not optimized, and -1 for an error. * If optimized, *executor_ptr contains a new reference to the executor */ -int +Py_NO_INLINE int _PyOptimizer_Optimize( _PyInterpreterFrame *frame, _Py_CODEUNIT *start, _PyExecutorObject **executor_ptr, int chain_depth) From 318c4fd6381483f6ba20793c1039384b4d4998c1 Mon Sep 17 00:00:00 2001 From: Sachin Shah <39803835+inventshah@users.noreply.github.com> Date: Wed, 13 Aug 2025 14:04:30 -0500 Subject: [PATCH 2/3] Update Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- .../next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst b/Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst index d019522d46a680..dcf0e643dc1ed3 100644 --- a/Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst +++ b/Misc/NEWS.d/next/C_API/2025-08-13-13-41-04.gh-issue-137573.r6uwRf.rst @@ -1,2 +1,2 @@ -Mark :c:func:`_PyOptimizer_Optimize` as :c:macro:`Py_NO_INLINE` to -prevent stack overflow crashes on MacOS. +Mark ``_PyOptimizer_Optimize`` as :c:macro:`Py_NO_INLINE` to +prevent stack overflow crashes on macOS. From 6831ee72a3edc3b7d273173ee1026a5e1d94e634 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 14 Aug 2025 09:32:25 +0200 Subject: [PATCH 3/3] Add a comment for the future --- Python/optimizer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/optimizer.c b/Python/optimizer.c index a3aa99285bb71c..1d899ee8971368 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -109,6 +109,7 @@ uop_optimize(_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, /* Returns 1 if optimized, 0 if not optimized, and -1 for an error. * If optimized, *executor_ptr contains a new reference to the executor */ +// gh-137573: inlining this function causes stack overflows Py_NO_INLINE int _PyOptimizer_Optimize( _PyInterpreterFrame *frame, _Py_CODEUNIT *start,