-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
CTypes test failed, complex double problem #125206
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
Comments
cc @skirpichev |
Looks to be libffi issue. Here is what I see.
It seems, that real support for complex types was added on x86_65 in v3.3-rc0. Similar failure was on Sparc during testing my pr, see this. I hoped, it was workarounded. Edit: yes, they just did it - https://github.com/libffi/libffi/blob/v3.2.1/src/x86/ffitarget.h. Unfortunately, there is no way to detect libffi support for complex types at compilation time. There is even no version define. |
The answer is "yes" on both questions.
What do you think about adding some workaround to configure.ac? |
It's a bug. There should be a proper fix to exclude bad library versions. I'm thinking on just diff --git a/configure.ac b/configure.ac
index 1864e94ace..559b513062 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4043,7 +4043,7 @@ AS_VAR_IF([ac_sys_system], [Darwin], [
])
])
AS_VAR_IF([have_libffi], [missing], [
- PKG_CHECK_MODULES([LIBFFI], [libffi], [have_libffi=yes], [
+ PKG_CHECK_MODULES([LIBFFI], [libffi >= 3.3], [have_libffi=yes], [
WITH_SAVE_ENV([
CPPFLAGS="$CPPFLAGS $LIBFFI_CFLAGS"
LDFLAGS="$LDFLAGS $LIBFFI_LIBS" v3.3 was released in Nov 2019. Not sure if this is acceptable, however. @Eclips4 ?
Or some variant along this road. I would rather create a test function, that get expected complex input (say Let me know if you would like to work on this. |
IMO, there is no need to fully ignore libffi linking with old versions since workaround is simple and issue only relates to complex double/float/long double types.
Agree, checking
seems to be optimal.
Yes, I would like to create a PR. |
Not at all. What I would suggest instead is something like int
foo (double complex z)
{
const double complex expected = CMPLX(1.25, -0.5);
return z == expected;
} Then ffi_call this with expected argument. All this is actually about passing arguments correctly. You can try to use instead libm complex functions, but you shouldn't compare computed values exactly.
Ok. Feel free to ping me for review. |
Workaround for old libffi versions is added. Module ctypes now supports C11 double complex only with libffi >= 3.3.0.
Workaround for old libffi versions is added. Module ctypes now supports C11 double complex only with libffi >= 3.3.0. Co-authored-by: Sergey B Kirpichev <[email protected]>
Fixed |
Oops, no. Apparently, it's not a right fix. E.g. in current main on Ubuntu: https://github.com/python/cpython/actions/runs/11563256070/job/32186185385 it prints "checking libffi has complex type support... no". |
Ah, I see:
|
Fixed again by change dcad8fe. |
Bug report
Bug description:
Python binary has been built in the standard way:
But test_ctypes fails:
System:
GCC:
I've tried to fix it by myself but the result has not been achieved in a reasonable amount of time.
There is a simple test I've provided:
So, it's not a problem in my libc version.
Moreover, this problem can be reproduced with standard libm.so (/lib/x86_64-linux-gnu/libm-2.28.so):
IMHO, some problem lies in using ctypes.c_double_complex as an argument and return value types.
FYI, with double argtype and restype clog works like classical double log:
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: