From: Daniele Varrazzo Date: Wed, 24 Jul 2024 08:32:32 +0000 (+0200) Subject: chore(c): drop warnings related to breaking strict-aliasing rules X-Git-Tag: 3.2.2~9^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57f4d2cf897887eecd3860a9bd36fe45498bc6c5;p=thirdparty%2Fpsycopg.git chore(c): drop warnings related to breaking strict-aliasing rules --- diff --git a/psycopg_c/psycopg_c/types/datetime.pyx b/psycopg_c/psycopg_c/types/datetime.pyx index 2e1f1eee3..44b227eda 100644 --- a/psycopg_c/psycopg_c/types/datetime.pyx +++ b/psycopg_c/psycopg_c/types/datetime.pyx @@ -971,11 +971,11 @@ cdef class IntervalBinaryLoader(CLoader): format = PQ_BINARY cdef object cload(self, const char *data, size_t length): - cdef int32_t bedata[4] + cdef int64_t bedata[2] memcpy(&bedata, data, sizeof(bedata)) - cdef int64_t val = endian.be64toh((bedata)[0]) - cdef int32_t days = endian.be32toh(bedata[2]) - cdef int32_t months = endian.be32toh(bedata[3]) + cdef int64_t val = endian.be64toh(bedata[0]) + cdef int32_t days = endian.be32toh((bedata)[2]) + cdef int32_t months = endian.be32toh((bedata)[3]) cdef int years with cython.cdivision(True): diff --git a/psycopg_c/psycopg_c/types/numeric.pyx b/psycopg_c/psycopg_c/types/numeric.pyx index 5f93a108c..ff4dacec2 100644 --- a/psycopg_c/psycopg_c/types/numeric.pyx +++ b/psycopg_c/psycopg_c/types/numeric.pyx @@ -346,7 +346,9 @@ cdef class FloatBinaryDumper(CDumper): cdef Py_ssize_t cdump(self, obj, bytearray rv, Py_ssize_t offset) except -1: cdef double d = PyFloat_AsDouble(obj) - cdef uint64_t beval = endian.htobe64((&d)[0]) + cdef uint64_t ival + memcpy(&ival, &d, sizeof(ival)) + cdef uint64_t beval = endian.htobe64(ival) cdef uint64_t *buf = CDumper.ensure_size( rv, offset, sizeof(beval)) memcpy(buf, &beval, sizeof(beval)) @@ -361,7 +363,9 @@ cdef class Float4BinaryDumper(CDumper): cdef Py_ssize_t cdump(self, obj, bytearray rv, Py_ssize_t offset) except -1: cdef float f = PyFloat_AsDouble(obj) - cdef uint32_t beval = endian.htobe32((&f)[0]) + cdef uint32_t ival + memcpy(&ival, &f, sizeof(ival)) + cdef uint32_t beval = endian.htobe32(ival) cdef uint32_t *buf = CDumper.ensure_size( rv, offset, sizeof(beval)) memcpy(buf, &beval, sizeof(beval))