forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-61103: Support double complex (_Complex) type in ctypes (pyt…
…hon#120894) Example: ```pycon >>> import ctypes >>> ctypes.__STDC_IEC_559_COMPLEX__ 1 >>> libm = ctypes.CDLL('libm.so.6') >>> libm.clog.argtypes = [ctypes.c_double_complex] >>> libm.clog.restype = ctypes.c_double_complex >>> libm.clog(1+1j) (0.34657359027997264+0.7853981633974483j) ``` Co-authored-by: Nice Zombies <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
- Loading branch information
Showing
17 changed files
with
316 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2024-06-23-07-23-08.gh-issue-61103.ca_U_l.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Support :c:expr:`double complex` C type in :mod:`ctypes` via | ||
:class:`~ctypes.c_double_complex` if compiler has C11 complex | ||
arithmetic. Patch by Sergey B Kirpichev. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Workarounds for buggy complex number arithmetic implementations. */ | ||
|
||
#ifndef Py_HAVE_C_COMPLEX | ||
# error "this header file should only be included if Py_HAVE_C_COMPLEX is defined" | ||
#endif | ||
|
||
#include <complex.h> | ||
|
||
/* Other compilers (than clang), that claims to | ||
implement C11 *and* define __STDC_IEC_559_COMPLEX__ - don't have | ||
issue with CMPLX(). This is specific to glibc & clang combination: | ||
https://sourceware.org/bugzilla/show_bug.cgi?id=26287 | ||
Here we fallback to using __builtin_complex(), available in clang | ||
v12+. Else CMPLX implemented following C11 6.2.5p13: "Each complex type | ||
has the same representation and alignment requirements as an array | ||
type containing exactly two elements of the corresponding real type; | ||
the first element is equal to the real part, and the second element | ||
to the imaginary part, of the complex number. | ||
*/ | ||
#if !defined(CMPLX) | ||
# if defined(__clang__) && __has_builtin(__builtin_complex) | ||
# define CMPLX(x, y) __builtin_complex ((double) (x), (double) (y)) | ||
# else | ||
static inline double complex | ||
CMPLX(double real, double imag) | ||
{ | ||
double complex z; | ||
((double *)(&z))[0] = real; | ||
((double *)(&z))[1] = imag; | ||
return z; | ||
} | ||
# endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.