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:
other tests don't fail (i.e. round-trip to/from c_double_complex)
@efimov-mikhail, you are on Debian 10 (buster), that has libffi v3.2.1; are you using this version?
if so, can you try to link CPython with never libffi (which, probably is available in backports)? Any v3.3+ should be fine.
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.
What do you think about adding some workaround to configure.ac?
It can be in form of something like this:
Write little code snippet which uses ffi_type_complex_double, calculate clog(1000.0) and exit with error code if creal(clog(1000.0)) less than 5.0.
Build this snippet with linking to libffi, test the result of binary execution.
And properly define FFI_ACTUALLY_HAS_COMPLEX_TYPE value.
v3.3 was released in Nov 2019. Not sure if this is acceptable, however. @Eclips4 ?
Write little code snippet which uses ffi_type_complex_double, calculate clog(1000.0) and exit with error code if creal(clog(1000.0)) less than 5.0.
Or some variant along this road.
I would rather create a test function, that get expected complex input (say 1.25+0.5j) and compares that with local values and then reports result. We should call this with ffi_call() and report result to the configure script.
It's a bug. There should be a proper fix to exclude bad library versions. I'm thinking on just <ignore libffi with versions less than 3.3>
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.
Moreover, supporting of complex numbers without C11 complex types is okay, and making harder assumptions on system libraries just for those types seems to be redundant.
Activity
Eclips4 commented on Oct 9, 2024
cc @skirpichev
skirpichev commented on Oct 10, 2024
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.
efimov-mikhail commented on Oct 10, 2024
The answer is "yes" on both questions.
All work fine with libffi-3.3-rc1.
What do you think about adding some workaround to configure.ac?
It can be in form of something like this:
Write little code snippet which uses ffi_type_complex_double, calculate clog(1000.0) and exit with error code if creal(clog(1000.0)) less than 5.0.
Build this snippet with linking to libffi, test the result of binary execution.
And properly define FFI_ACTUALLY_HAS_COMPLEX_TYPE value.
skirpichev commented on Oct 10, 2024
It's a bug. There should be a proper fix to exclude bad library versions. I'm thinking on just
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 1.25+0.5j) and compares that with local values and then reports result. We should call this with ffi_call() and report result to the configure script.
Let me know if you would like to work on this.
efimov-mikhail commented on Oct 10, 2024
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.
Moreover, supporting of complex numbers without C11 complex types is okay, and making harder assumptions on system libraries just for those types seems to be redundant.
Agree, checking
seems to be optimal.
Yes, I would like to create a PR.
skirpichev commented on Oct 10, 2024
Not at all. What I would suggest instead is something like
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.
pythongh-125206: Bug in ctypes with old libffi is fixed
pythongh-125206: Py_FFI_TARGET_HAS_COMPLEX_TYPE -> Py_FFI_SUPPORT_C_C…
gh-125206: Bug in ctypes with old libffi is fixed (#125322)
efimov-mikhail commented on Oct 15, 2024
Fixed
7 remaining items
gh-125206: Correct detection of complex numbers support in libffi (#1…
vstinner commented on Oct 30, 2024
Fixed again by change dcad8fe.
pythongh-125206: Correct detection of complex numbers support in libf…
pythongh-125206: Correct detection of complex numbers support in libf…
pythongh-125206: don't use CMPLX in configure test
gh-125206: don't use CMPLX in libffi complex configure test (#132865)
pythongh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private
gh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private (GH-135932)
pythongh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private (pythonGH-135932
[3.14] gh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private (GH-135932) (G…
pythongh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private (pythonGH-135932
pythongh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private (pythonGH-135932
pythongh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private (pythonGH-135932
pythongh-125206: Make _Py_FFI_SUPPORT_C_COMPLEX private (pythonGH-135932