1212#include "pycore_long.h" // _PyLong_AsByteArray()
1313#include "pycore_moduleobject.h" // _PyModule_GetState()
1414
15- #ifdef Py_HAVE_C_COMPLEX
16- # include "_complex.h" // complex
17- #endif
1815#include <stddef.h> // offsetof()
1916
2017/*[clinic input]
@@ -495,25 +492,23 @@ nu_double(_structmodulestate *state, const char *p, const formatdef *f)
495492 return PyFloat_FromDouble (x );
496493}
497494
498- #ifdef Py_HAVE_C_COMPLEX
499495static PyObject *
500496nu_float_complex (_structmodulestate * state , const char * p , const formatdef * f )
501497{
502- float complex x ;
498+ float x [ 2 ] ;
503499
504500 memcpy (& x , p , sizeof (x ));
505- return PyComplex_FromDoubles (creal ( x ), cimag ( x ) );
501+ return PyComplex_FromDoubles (x [ 0 ], x [ 1 ] );
506502}
507503
508504static PyObject *
509505nu_double_complex (_structmodulestate * state , const char * p , const formatdef * f )
510506{
511- double complex x ;
507+ double x [ 2 ] ;
512508
513509 memcpy (& x , p , sizeof (x ));
514- return PyComplex_FromDoubles (creal ( x ), cimag ( x ) );
510+ return PyComplex_FromDoubles (x [ 0 ], x [ 1 ] );
515511}
516- #endif
517512
518513static PyObject *
519514nu_void_p (_structmodulestate * state , const char * p , const formatdef * f )
@@ -788,13 +783,12 @@ np_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
788783 return 0 ;
789784}
790785
791- #ifdef Py_HAVE_C_COMPLEX
792786static int
793787np_float_complex (_structmodulestate * state , char * p , PyObject * v ,
794788 const formatdef * f )
795789{
796790 Py_complex c = PyComplex_AsCComplex (v );
797- float complex x = CMPLXF (( float )c .real , (float )c .imag ) ;
791+ float x [ 2 ] = {( float )c .real , (float )c .imag } ;
798792
799793 if (c .real == -1 && PyErr_Occurred ()) {
800794 PyErr_SetString (state -> StructError ,
@@ -810,7 +804,7 @@ np_double_complex(_structmodulestate *state, char *p, PyObject *v,
810804 const formatdef * f )
811805{
812806 Py_complex c = PyComplex_AsCComplex (v );
813- double complex x = CMPLX ( c .real , c .imag ) ;
807+ double x [ 2 ] = { c .real , c .imag } ;
814808
815809 if (c .real == -1 && PyErr_Occurred ()) {
816810 PyErr_SetString (state -> StructError ,
@@ -820,25 +814,6 @@ np_double_complex(_structmodulestate *state, char *p, PyObject *v,
820814 memcpy (p , & x , sizeof (x ));
821815 return 0 ;
822816}
823- #else
824- static int
825- np_complex_stub (_structmodulestate * state , char * p , PyObject * v ,
826- const formatdef * f )
827- {
828- PyErr_Format (state -> StructError ,
829- "'%c' format not supported on this system" ,
830- f -> format );
831- return -1 ;
832- }
833- static PyObject *
834- nu_complex_stub (_structmodulestate * state , const char * p , const formatdef * f )
835- {
836- PyErr_Format (state -> StructError ,
837- "'%c' format not supported on this system" ,
838- f -> format );
839- return NULL ;
840- }
841- #endif
842817
843818static int
844819np_void_p (_structmodulestate * state , char * p , PyObject * v , const formatdef * f )
@@ -878,13 +853,8 @@ static const formatdef native_table[] = {
878853 {'e' , sizeof (short ), _Alignof(short ), nu_halffloat , np_halffloat },
879854 {'f' , sizeof (float ), _Alignof(float ), nu_float , np_float },
880855 {'d' , sizeof (double ), _Alignof(double ), nu_double , np_double },
881- #ifdef Py_HAVE_C_COMPLEX
882- {'F' , sizeof (float complex ), _Alignof(float complex ), nu_float_complex , np_float_complex },
883- {'D' , sizeof (double complex ), _Alignof(double complex ), nu_double_complex , np_double_complex },
884- #else
885- {'F' , 1 , 0 , nu_complex_stub , np_complex_stub },
886- {'D' , 1 , 0 , nu_complex_stub , np_complex_stub },
887- #endif
856+ {'F' , 2 * sizeof (float ), _Alignof(float [2 ]), nu_float_complex , np_float_complex },
857+ {'D' , 2 * sizeof (double ), _Alignof(double [2 ]), nu_double_complex , np_double_complex },
888858 {'P' , sizeof (void * ), _Alignof(void * ), nu_void_p , np_void_p },
889859 {0 }
890860};
@@ -985,7 +955,6 @@ bu_double(_structmodulestate *state, const char *p, const formatdef *f)
985955 return unpack_double (p , 0 );
986956}
987957
988- #ifdef Py_HAVE_C_COMPLEX
989958static PyObject *
990959bu_float_complex (_structmodulestate * state , const char * p , const formatdef * f )
991960{
@@ -1015,7 +984,6 @@ bu_double_complex(_structmodulestate *state, const char *p, const formatdef *f)
1015984 }
1016985 return PyComplex_FromDoubles (x , y );
1017986}
1018- #endif
1019987
1020988static PyObject *
1021989bu_bool (_structmodulestate * state , const char * p , const formatdef * f )
@@ -1156,7 +1124,6 @@ bp_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
11561124 return PyFloat_Pack8 (x , p , 0 );
11571125}
11581126
1159- #ifdef Py_HAVE_C_COMPLEX
11601127static int
11611128bp_float_complex (_structmodulestate * state , char * p , PyObject * v , const formatdef * f )
11621129{
@@ -1186,7 +1153,6 @@ bp_double_complex(_structmodulestate *state, char *p, PyObject *v, const formatd
11861153 }
11871154 return PyFloat_Pack8 (x .imag , p + 8 , 0 );
11881155}
1189- #endif
11901156
11911157static int
11921158bp_bool (_structmodulestate * state , char * p , PyObject * v , const formatdef * f )
@@ -1218,13 +1184,8 @@ static formatdef bigendian_table[] = {
12181184 {'e' , 2 , 0 , bu_halffloat , bp_halffloat },
12191185 {'f' , 4 , 0 , bu_float , bp_float },
12201186 {'d' , 8 , 0 , bu_double , bp_double },
1221- #ifdef Py_HAVE_C_COMPLEX
12221187 {'F' , 8 , 0 , bu_float_complex , bp_float_complex },
12231188 {'D' , 16 , 0 , bu_double_complex , bp_double_complex },
1224- #else
1225- {'F' , 1 , 0 , nu_complex_stub , np_complex_stub },
1226- {'D' , 1 , 0 , nu_complex_stub , np_complex_stub },
1227- #endif
12281189 {0 }
12291190};
12301191
@@ -1324,7 +1285,6 @@ lu_double(_structmodulestate *state, const char *p, const formatdef *f)
13241285 return unpack_double (p , 1 );
13251286}
13261287
1327- #ifdef Py_HAVE_C_COMPLEX
13281288static PyObject *
13291289lu_float_complex (_structmodulestate * state , const char * p , const formatdef * f )
13301290{
@@ -1354,7 +1314,6 @@ lu_double_complex(_structmodulestate *state, const char *p, const formatdef *f)
13541314 }
13551315 return PyComplex_FromDoubles (x , y );
13561316}
1357- #endif
13581317
13591318static int
13601319lp_int (_structmodulestate * state , char * p , PyObject * v , const formatdef * f )
@@ -1489,7 +1448,6 @@ lp_double(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
14891448 return PyFloat_Pack8 (x , p , 1 );
14901449}
14911450
1492- #ifdef Py_HAVE_C_COMPLEX
14931451static int
14941452lp_float_complex (_structmodulestate * state , char * p , PyObject * v , const formatdef * f )
14951453{
@@ -1520,7 +1478,6 @@ lp_double_complex(_structmodulestate *state, char *p, PyObject *v, const formatd
15201478 }
15211479 return PyFloat_Pack8 (x .imag , p + 8 , 1 );
15221480}
1523- #endif
15241481
15251482static formatdef lilendian_table [] = {
15261483 {'x' , 1 , 0 , NULL },
@@ -1542,13 +1499,8 @@ static formatdef lilendian_table[] = {
15421499 {'e' , 2 , 0 , lu_halffloat , lp_halffloat },
15431500 {'f' , 4 , 0 , lu_float , lp_float },
15441501 {'d' , 8 , 0 , lu_double , lp_double },
1545- #ifdef Py_HAVE_C_COMPLEX
15461502 {'F' , 8 , 0 , lu_float_complex , lp_float_complex },
15471503 {'D' , 16 , 0 , lu_double_complex , lp_double_complex },
1548- #else
1549- {'F' , 1 , 0 , nu_complex_stub , np_complex_stub },
1550- {'D' , 1 , 0 , nu_complex_stub , np_complex_stub },
1551- #endif
15521504 {0 }
15531505};
15541506
0 commit comments