Skip to content

Commit

Permalink
Support build cython codes with -Werror=strict-aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk committed Mar 4, 2024
1 parent d81f47c commit c3b3f5d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions thriftpy2/protocol/cybin/cybin.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sys

from libc.stdlib cimport free, malloc
from libc.stdint cimport int16_t, int32_t, int64_t
from libc.string cimport memcpy
from cpython cimport bool

import six
Expand Down Expand Up @@ -99,7 +100,9 @@ cdef inline int write_i64(CyTransportBase buf, int64_t val) except -1:


cdef inline int write_double(CyTransportBase buf, double val) except -1:
cdef int64_t v = htobe64((<int64_t*>(&val))[0])
cdef int64_t v
memcpy(&v, &val, 8)
v = htobe64(v)
buf.c_write(<char*>(&v), 8)
return 0

Expand Down Expand Up @@ -269,6 +272,7 @@ cdef c_read_val(CyTransportBase buf, TType ttype, spec=None,
cdef int size
cdef int64_t n
cdef TType v_type, k_type, orig_type, orig_key_type
cdef double double_value

if ttype == T_BOOL:
return <bint>read_i08(buf)
Expand All @@ -287,7 +291,8 @@ cdef c_read_val(CyTransportBase buf, TType ttype, spec=None,

elif ttype == T_DOUBLE:
n = read_i64(buf)
return (<double*>(&n))[0]
memcpy(&double_value, &n, 8)
return double_value

elif ttype == T_BINARY:
size = read_i32(buf)
Expand Down

0 comments on commit c3b3f5d

Please sign in to comment.