File tree 1 file changed +9
-6
lines changed
1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ from libc.stdint cimport (
10
10
uint32_t,
11
11
uint64_t,
12
12
)
13
+ from libc.string cimport memcpy
13
14
14
15
15
16
def read_float_with_byteswap (bytes data , Py_ssize_t offset , bint byteswap ):
@@ -82,12 +83,14 @@ cdef extern from *:
82
83
83
84
84
85
cdef float _byteswap_float(float num):
85
- cdef uint32_t * intptr = < uint32_t * > & num
86
- intptr[0 ] = _byteswap4(intptr[0 ])
87
- return num
86
+ cdef uint32_t num_uint
87
+ memcpy(& num_uint, & num, sizeof(float ))
88
+ num_uint = _byteswap4(num_uint)
89
+ return (< float * > & num_uint)[0 ]
88
90
89
91
90
92
cdef double _byteswap_double(double num):
91
- cdef uint64_t * intptr = < uint64_t * > & num
92
- intptr[0 ] = _byteswap8(intptr[0 ])
93
- return num
93
+ cdef uint64_t num_uint
94
+ memcpy(& num_uint, & num, sizeof(double ))
95
+ num_uint = _byteswap8(num_uint)
96
+ return (< double * > & num_uint)[0 ]
You can’t perform that action at this time.
0 commit comments