@@ -792,6 +792,44 @@ D_get(void *ptr, Py_ssize_t size)
792792 return PyComplex_FromDoubles (x [0 ], x [1 ]);
793793}
794794
795+ static PyObject *
796+ D_set_sw (void * ptr , PyObject * value , Py_ssize_t size )
797+ {
798+ assert (NUM_BITS (size ) || (size == 2 * sizeof (double )));
799+ Py_complex c = PyComplex_AsCComplex (value );
800+
801+ if (c .real == -1 && PyErr_Occurred ()) {
802+ return NULL ;
803+ }
804+ #ifdef WORDS_BIGENDIAN
805+ if (PyFloat_Pack8 (c .real , ptr , 1 )
806+ || PyFloat_Pack8 (c .imag , ptr + sizeof (double ), 1 ))
807+ {
808+ return NULL ;
809+ }
810+ #else
811+ if (PyFloat_Pack8 (c .real , ptr , 0 )
812+ || PyFloat_Pack8 (c .imag , ptr + sizeof (double ), 0 ))
813+ {
814+ return NULL ;
815+ }
816+ #endif
817+ _RET (value );
818+ }
819+
820+ static PyObject *
821+ D_get_sw (void * ptr , Py_ssize_t size )
822+ {
823+ assert (NUM_BITS (size ) || (size == 2 * sizeof (double )));
824+ #ifdef WORDS_BIGENDIAN
825+ return PyComplex_FromDoubles (PyFloat_Unpack8 (ptr , 1 ),
826+ PyFloat_Unpack8 (ptr + sizeof (double ), 1 ));
827+ #else
828+ return PyComplex_FromDoubles (PyFloat_Unpack8 (ptr , 0 ),
829+ PyFloat_Unpack8 (ptr + sizeof (double ), 0 ));
830+ #endif
831+ }
832+
795833/* F: float complex */
796834static PyObject *
797835F_set (void * ptr , PyObject * value , Py_ssize_t size )
@@ -817,6 +855,44 @@ F_get(void *ptr, Py_ssize_t size)
817855 return PyComplex_FromDoubles (x [0 ], x [1 ]);
818856}
819857
858+ static PyObject *
859+ F_set_sw (void * ptr , PyObject * value , Py_ssize_t size )
860+ {
861+ assert (NUM_BITS (size ) || (size == 2 * sizeof (float )));
862+ Py_complex c = PyComplex_AsCComplex (value );
863+
864+ if (c .real == -1 && PyErr_Occurred ()) {
865+ return NULL ;
866+ }
867+ #ifdef WORDS_BIGENDIAN
868+ if (PyFloat_Pack4 (c .real , ptr , 1 )
869+ || PyFloat_Pack4 (c .imag , ptr + sizeof (float ), 1 ))
870+ {
871+ return NULL ;
872+ }
873+ #else
874+ if (PyFloat_Pack4 (c .real , ptr , 0 )
875+ || PyFloat_Pack4 (c .imag , ptr + sizeof (float ), 0 ))
876+ {
877+ return NULL ;
878+ }
879+ #endif
880+ _RET (value );
881+ }
882+
883+ static PyObject *
884+ F_get_sw (void * ptr , Py_ssize_t size )
885+ {
886+ assert (NUM_BITS (size ) || (size == 2 * sizeof (float )));
887+ #ifdef WORDS_BIGENDIAN
888+ return PyComplex_FromDoubles (PyFloat_Unpack4 (ptr , 1 ),
889+ PyFloat_Unpack4 (ptr + sizeof (float ), 1 ));
890+ #else
891+ return PyComplex_FromDoubles (PyFloat_Unpack4 (ptr , 0 ),
892+ PyFloat_Unpack4 (ptr + sizeof (float ), 0 ));
893+ #endif
894+ }
895+
820896/* G: long double complex */
821897static PyObject *
822898G_set (void * ptr , PyObject * value , Py_ssize_t size )
@@ -1602,7 +1678,9 @@ for base_code, base_c_type in [
16021678#if defined(_Py_FFI_SUPPORT_C_COMPLEX )
16031679 if (Py_FFI_COMPLEX_AVAILABLE ) {
16041680 TABLE_ENTRY (D , & ffi_type_complex_double );
1681+ TABLE_ENTRY_SW (D , & ffi_type_complex_double );
16051682 TABLE_ENTRY (F , & ffi_type_complex_float );
1683+ TABLE_ENTRY_SW (F , & ffi_type_complex_float );
16061684 TABLE_ENTRY (G , & ffi_type_complex_longdouble );
16071685 }
16081686#endif
0 commit comments