@@ -1092,10 +1092,32 @@ d_get(void *ptr, Py_ssize_t size)
1092
1092
}
1093
1093
1094
1094
#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
1099
1121
static PyObject *
1100
1122
C_set (void * ptr , PyObject * value , Py_ssize_t size )
1101
1123
{
0 commit comments