Skip to content

Commit f9c709c

Browse files
committed
+ comment on clang workaround
1 parent 6d9d5ab commit f9c709c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Modules/_ctypes/cfield.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,10 +1092,32 @@ d_get(void *ptr, Py_ssize_t size)
10921092
}
10931093

10941094
#ifdef __STDC_IEC_559_COMPLEX__
1095-
#if defined(__clang__) && __has_builtin(__builtin_complex) && \
1096-
!defined(CMPLX)
1097-
# define CMPLX(x, y) __builtin_complex ((double) (x), (double) (y))
1098-
#endif
1095+
/* Other compilers (than clang), that claims to
1096+
implement C11 *and* define __STDC_IEC_559_COMPLEX__ don't have
1097+
issue with CMPLX(). This is specific to glibc & clang combination:
1098+
https://sourceware.org/bugzilla/show_bug.cgi?id=26287
1099+
1100+
Here we fallback to using __builtin_complex(), available in clang
1101+
v12+. Else CMPLX implemented following C11 6.2.5p13: "Each complex type
1102+
has the same representation and alignment requirements as an array
1103+
type containing exactly two elements of the corresponding real type;
1104+
the first element is equal to the real part, and the second element
1105+
to the imaginary part, of the complex number.
1106+
*/
1107+
# if !defined(CMPLX)
1108+
# if defined(__clang__) && __has_builtin(__builtin_complex)
1109+
# define CMPLX(x, y) __builtin_complex ((double) (x), (double) (y))
1110+
# else
1111+
inline double complex
1112+
CMPLX(double real, imag)
1113+
{
1114+
double complex z;
1115+
((double *)(&z))[0] = real;
1116+
((double *)(&z))[1] = imag;
1117+
return z;
1118+
}
1119+
# endif
1120+
# endif
10991121
static PyObject *
11001122
C_set(void *ptr, PyObject *value, Py_ssize_t size)
11011123
{

0 commit comments

Comments
 (0)