gh-121647: Define _Py_TYPEOF macro on more compilers - #121648
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Hello! Sorry for the delay in reviewing. Ideally, find a way to use Also, I'd prefer not adding the configure check. I don't see much benefit over |
|
Thanks for reviewing, I did the PR to see if it gets a better chance than #121643, however cpython has grown to requiring more patches ( On C23 |
|
Thanks. |
|
Just tested 3.15 master (default and --disable-gil), in addition to #134070 these are enough for slimcc to pass all tests (sans test_gdb, probably caused by lacking DWARF info). diff --git a/Include/internal/pycore_debug_offsets.h b/Include/internal/pycore_debug_offsets.h
index 66f14e6..fbdc40a 100644
--- a/Include/internal/pycore_debug_offsets.h
+++ b/Include/internal/pycore_debug_offsets.h
@@ -41,7 +41,7 @@ extern "C" {
#define _GENERATE_DEBUG_SECTION_APPLE(name)
#endif
-#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
+#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__) || (_Py__has_attribute(section) && _Py__has_attribute(used)))
#define _GENERATE_DEBUG_SECTION_LINUX(name) \
__attribute__((section("." Py_STRINGIFY(name)))) \
__attribute__((used))
diff --git a/Objects/mimalloc/init.c b/Objects/mimalloc/init.c
index 81b2410..3856a10 100644
--- a/Objects/mimalloc/init.c
+++ b/Objects/mimalloc/init.c
@@ -676,7 +676,7 @@ static void mi_cdecl mi_process_done(void) {
}
static bool mi_initialized = _mi_process_init();
-#elif defined(__GNUC__) || defined(__clang__)
+#elif defined(__GNUC__) || defined(__clang__) || _Py__has_attribute(constructor)
// GCC,Clang: use the constructor attribute |
|
Do you want to work on this PR, or may I take over? Does slimcc recognize
I don't think this bug is likely to hit CPython, so I'd prefer not working around it. |
Yes, it does! But the corresponding check of C23 style attributes should be
IMO
Please do! Thank you for taking care in this. |
|
This PR is stale because it has been open for 30 days with no activity. |
@vstinner already did this in 9e5e1f9
I agree we should not add another IMHO this now just boils down to change Line 545 in d125f00 to #elif defined(__GNUC__) || defined(__clang__) || (defined(_MSC_VER) && _MSC_VER >= 1939)to gain back safety warnings on Windows in case of mismatching pointers: cpython/Include/cpython/object.h Lines 349 to 351 in d125f00 which is very wortwhile IMHO. |
If Python is built with compiler A which supports @fuhsnn: Can you update your PR on the main branch and remove |
Extend the _Py_TYPEOF macro to use __typeof__() with MSVC 17.9 and newer, or decltype() under C++11 and newer.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
I added Py_CLEAR() and Py_SETREF() tests in test_cppext with commit 36c7440. So this change should now be tested with C++. |
|
I merged your updated (simpler) change, thanks! Sorry, it took a while to merge it. But better late than never ;-) IMO it's too late to backport this change to the 3.15 branch. I prefer to only change the main branch (Python 3.16) change to have enough time to test the change properly (starting with Python 3.16 alpha1 release, scheduled for 2026-10-13). |
|
|
|
|
Oh, test_cppext fails on Windows:
Toolkit version: I suppose that |
|
Extend the _Py_TYPEOF macro to more implementations of typeof and standardized equivalents on C23 and C++11. On MSVC, typeof is enabled through _MSC_VER check; for others, an autoconf probe is implemented.
_Py_TYPEOFon MSVC and other compilers supporting__typeof__#121647