-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-128156: Guard use of ffi_type_complex_double
on macOS system libffi
#128680
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but we need some feedback from MacOS experts.
cc: @ronaldoussoren @python/macos-team |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I verified that with the PR we could now build and install cpython on the current macOS 15.2 using MACOSX_DEPLOYMENT_TARGET=10.14 and then also install and execute the same binaries on a macOS 10.14.x system. As expected, on 15.2 the three complex types were available and on 10.14, they were not. And test_ctypes ran without errors on both systems. Nice work, @encukou !
Thank you for the thorough review! |
Not sure if it's my system or not but I'm unable to compile :( In file included from ./Modules/_ctypes/callproc.c:87:0:
./Modules/_ctypes/ctypes.h:12:72: error: missing binary operator before token "("
# if USING_APPLE_OS_LIBFFI && defined(__has_builtin) && __has_builtin(__builtin_available)
Other uses of #if defined(__APPLE__) && defined(__has_builtin)
I'm using OpenSUSE and gcc 7.5 |
I think we should do the following: diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h
index 1330754a7e0..dc079f2441b 100644
--- a/Modules/_ctypes/ctypes.h
+++ b/Modules/_ctypes/ctypes.h
@@ -9,8 +9,12 @@
// For Apple's libffi, this must be determined at runtime (see gh-128156).
#if defined(Py_HAVE_C_COMPLEX) && defined(Py_FFI_SUPPORT_C_COMPLEX)
# include "../_complex.h" // complex
-# if USING_APPLE_OS_LIBFFI && defined(__has_builtin) && __has_builtin(__builtin_available)
-# define Py_FFI_COMPLEX_AVAILABLE __builtin_available(macOS 10.15, *)
+# ifdef __has_builtin
+# if USING_APPLE_OS_LIBFFI && __has_builtin(__builtin_available)
+# define Py_FFI_COMPLEX_AVAILABLE __builtin_available(macOS 10.15, *)
+# else
+# define Py_FFI_COMPLEX_AVAILABLE 1
+# endif
# else
# define Py_FFI_COMPLEX_AVAILABLE 1
# endif This is also what's recommended by https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fbuiltin.html. |
Isn't `#if defined(__has_builtin)` equivalent to `#ifdef __has_builtin`?
|
Yes, but somehow this doesn't work so I don't know :( (I'll check tomorrow again but the current code doesn't compile on my side) |
I'd be interested to know what compiler, OS and configure settings you're using. |
I'm using gcc 7.5.0, my OS is openSUSE 15.5 and I used |
See #129141 for the relevant issue. |
formattable.fmt{C,E,F}
now have a runtime guard (ifUSING_APPLE_OS_LIBFFI
).The list of type codes (previously
SIMPLE_TYPE_CHARS
) is now generated at runtime.ffi_type_complex_double
is unguarded #128156📚 Documentation preview 📚: https://cpython-previews--128680.org.readthedocs.build/