From 36c7440c480da622735788af656c728af28cd9eb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 8 Sep 2026 10:11:32 -0400 Subject: [PATCH 1/4] gh-121617: Fix Py_CLEAR() in C++: replace NULL with _Py_NULL (#157067) * Enhance Py_CLEAR() test in test_cext and test_cppext. Check that Py_CLEAR(obj) sets obj to NULL. * Add also tests on Py_SETREF() and Py_BEGIN_CRITICAL_SECTION(). --- Include/refcount.h | 2 +- Lib/test/test_cext/extension.c | 12 ++++++++++-- Lib/test/test_cppext/extension.cpp | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Include/refcount.h b/Include/refcount.h index 80fe7ff70a11e8..8a3d440fd14b1e 100644 --- a/Include/refcount.h +++ b/Include/refcount.h @@ -484,7 +484,7 @@ static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op) do { \ _Py_TYPEOF(op)* _tmp_op_ptr = &(op); \ _Py_TYPEOF(op) _tmp_old_op = (*_tmp_op_ptr); \ - if (_tmp_old_op != NULL) { \ + if (_tmp_old_op != _Py_NULL) { \ *_tmp_op_ptr = _Py_NULL; \ Py_DECREF(_tmp_old_op); \ } \ diff --git a/Lib/test/test_cext/extension.c b/Lib/test/test_cext/extension.c index 895eca50f03b98..543a8096f16f8a 100644 --- a/Lib/test/test_cext/extension.c +++ b/Lib/test/test_cext/extension.c @@ -95,9 +95,17 @@ _testcext_exec(PyObject *module) Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int)); assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0); - // Test Py_CLEAR() - obj = NULL; + // Test Py_CLEAR(): use typeof()/__typeof__() if available, or memcpy() + obj = Py_None; Py_CLEAR(obj); + assert(obj == NULL); + +#ifndef Py_LIMITED_API + // Test Py_SETREF(): use typeof()/__typeof__() if available, or memcpy() + obj = Py_None; + Py_SETREF(obj, NULL); + assert(obj == NULL); +#endif // Test that Py_BEGIN_CRITICAL_SECTION is available Py_BEGIN_CRITICAL_SECTION(module); diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp index 4db63df94f5233..62ce81e2b510c7 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -294,6 +294,22 @@ _testcppext_exec(PyObject *module) Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int)); assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0); + // Test Py_CLEAR(): use typeof()/__typeof__() if available, or memcpy() + PyObject *obj = Py_None; + Py_CLEAR(obj); + assert(obj == _Py_NULL); + +#ifndef Py_LIMITED_API + // Test Py_SETREF(): use typeof()/__typeof__() if available, or memcpy() + obj = Py_None; + Py_SETREF(obj, _Py_NULL); + assert(obj == _Py_NULL); +#endif + + // Test that Py_BEGIN_CRITICAL_SECTION is available + Py_BEGIN_CRITICAL_SECTION(module); + Py_END_CRITICAL_SECTION(); + return 0; } From 7f3d7d06efd0e7ffa1ac1d07a15a3ae8121a020c Mon Sep 17 00:00:00 2001 From: Vyron Vasileiadis Date: Tue, 8 Sep 2026 18:01:58 +0300 Subject: [PATCH 2/4] gh-157135: Fix documentation errors in the `math.atan{2}pi` functions (#157136) --- Doc/library/math.rst | 2 +- Modules/mathmodule.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/math.rst b/Doc/library/math.rst index efe411e5a43f27..70e61bb92fa728 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -90,7 +90,7 @@ noted otherwise, all return values are floats. :func:`atan(x) ` Arc tangent of *x*, in radians :func:`atanpi(x) ` Arc tangent of *x*, in half-turns :func:`atan2(y, x) ` ``atan(y / x)``, in radians -:func:`atan2pi(y, x) ` ``atan(y / x)``, in half-turns +:func:`atan2pi(y, x) ` ``atanpi(y / x)``, in half-turns :func:`cos(x) ` Cosine of *x* radians :func:`cospi(x) ` Cosine of *x⋅π* radians :func:`sin(x) ` Sine of *x* radians diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index eaa1850b8aee1a..7988a77ab0abcc 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -256,7 +256,7 @@ m_asinpi(double x) #ifndef HAVE_ATANPI /* - asin(x)/pi. It conforms to C23 Annex 'F'. + atan(x)/pi. It conforms to C23 Annex 'F'. */ static double @@ -274,7 +274,7 @@ m_atanpi(double x) #ifndef HAVE_ATAN2PI /* - asin(x)/pi. It conforms to C23 Annex 'F'. + atan2(y, x)/pi. It conforms to C23 Annex 'F'. */ static double @@ -1136,7 +1136,7 @@ FUNC1D(atanh, atanh, 0, FUNC1D(atanpi, m_atanpi, 0, "atanpi($module, x, /)\n--\n\n" "Return the arc tangent (measured in half-turns) of x.\n\n" - "The result is between 0 and 1.", + "The result is between -1/2 and 1/2.", "expected a number in range from -1 up to 1, got %s") FUNC1(cbrt, cbrt, 0, "cbrt($module, x, /)\n--\n\n" From da461eacea5f30da8c3977679b8ca4cced005958 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 8 Sep 2026 11:51:00 -0400 Subject: [PATCH 3/4] gh-121617: Fix Py_CLEAR() memcpy in C++: replace NULL with _Py_NULL (#157188) --- Include/refcount.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/refcount.h b/Include/refcount.h index 8a3d440fd14b1e..b21697ae1780fa 100644 --- a/Include/refcount.h +++ b/Include/refcount.h @@ -494,7 +494,7 @@ static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op) do { \ PyObject **_tmp_op_ptr = _Py_CAST(PyObject**, &(op)); \ PyObject *_tmp_old_op = (*_tmp_op_ptr); \ - if (_tmp_old_op != NULL) { \ + if (_tmp_old_op != _Py_NULL) { \ PyObject *_null_ptr = _Py_NULL; \ memcpy(_tmp_op_ptr, &_null_ptr, sizeof(PyObject*)); \ Py_DECREF(_tmp_old_op); \ From f37e8ff839afc5838643c76b302c2ad382d62632 Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Tue, 8 Sep 2026 17:51:25 +0200 Subject: [PATCH 4/4] gh-152433: Use regular LoadLibrary in UWP for Windows system libs (GH-156972) --- Include/internal/pycore_fileutils_windows.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Include/internal/pycore_fileutils_windows.h b/Include/internal/pycore_fileutils_windows.h index 4c42f16beb12a4..b79aa9fb465376 100644 --- a/Include/internal/pycore_fileutils_windows.h +++ b/Include/internal/pycore_fileutils_windows.h @@ -55,11 +55,7 @@ static inline BOOL _Py_GetFileInformationByName( static int GetFileInformationByName_init = -1; if (GetFileInformationByName_init < 0) { -#ifdef MS_WINDOWS_DESKTOP HMODULE hMod = LoadLibraryW(L"api-ms-win-core-file-l2-1-4"); -#else - HMODULE hMod = LoadPackagedLibrary(L"api-ms-win-core-file-l2-1-4", 0); -#endif GetFileInformationByName_init = 0; if (hMod) { GetFileInformationByName = (PGetFileInformationByName)GetProcAddress(