From: Daniele Varrazzo Date: Wed, 24 Jul 2024 08:37:30 +0000 (+0200) Subject: refactor(c): more idiomatic type-punned pointer warning workaround X-Git-Tag: 3.2.2~9^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F877%2Fhead;p=thirdparty%2Fpsycopg.git refactor(c): more idiomatic type-punned pointer warning workaround We are using memcpy in all the other cases. --- diff --git a/psycopg_c/psycopg_c/types/numeric.pyx b/psycopg_c/psycopg_c/types/numeric.pyx index ff4dacec2..31dc75b3e 100644 --- a/psycopg_c/psycopg_c/types/numeric.pyx +++ b/psycopg_c/psycopg_c/types/numeric.pyx @@ -393,10 +393,9 @@ cdef class Float4BinaryLoader(CLoader): cdef uint32_t bedata memcpy(&bedata, data, sizeof(bedata)) cdef uint32_t asint = endian.be32toh(bedata) - # avoid warning: - # dereferencing type-punned pointer will break strict-aliasing rules - cdef char *swp = &asint - return PyFloat_FromDouble((swp)[0]) + cdef float f + memcpy(&f, &asint, sizeof(asint)) + return PyFloat_FromDouble(f) @cython.final @@ -408,8 +407,9 @@ cdef class Float8BinaryLoader(CLoader): cdef uint64_t bedata memcpy(&bedata, data, sizeof(bedata)) cdef uint64_t asint = endian.be64toh(bedata) - cdef char *swp = &asint - return PyFloat_FromDouble((swp)[0]) + cdef double d + memcpy(&d, &asint, sizeof(asint)) + return PyFloat_FromDouble(d) @cython.final