]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
chore(c): drop warnings related to breaking strict-aliasing rules
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 24 Jul 2024 08:32:32 +0000 (10:32 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 24 Jul 2024 09:54:04 +0000 (11:54 +0200)
psycopg_c/psycopg_c/types/datetime.pyx
psycopg_c/psycopg_c/types/numeric.pyx

index 2e1f1eee315391815537bb04a0779abfcb006e51..44b227eda3b5f816e47e5e02d6c985f55a79ad16 100644 (file)
@@ -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((<uint64_t *>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((<uint32_t *>bedata)[2])
+        cdef int32_t months = endian.be32toh((<uint32_t *>bedata)[3])
 
         cdef int years
         with cython.cdivision(True):
index 5f93a108c79f9d159a7552ba6cbf69d5e12f659e..ff4dacec2aa5a55dea91d0194f87eba4b4b4b0b5 100644 (file)
@@ -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((<uint64_t *>&d)[0])
+        cdef uint64_t ival
+        memcpy(&ival, &d, sizeof(ival))
+        cdef uint64_t beval = endian.htobe64(ival)
         cdef uint64_t *buf = <uint64_t *>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 = <float>PyFloat_AsDouble(obj)
-        cdef uint32_t beval = endian.htobe32((<uint32_t *>&f)[0])
+        cdef uint32_t ival
+        memcpy(&ival, &f, sizeof(ival))
+        cdef uint32_t beval = endian.htobe32(ival)
         cdef uint32_t *buf = <uint32_t *>CDumper.ensure_size(
             rv, offset, sizeof(beval))
         memcpy(buf, &beval, sizeof(beval))