This should hopefully work around issue #304, at least when C is used.
When Python is used we raise an error instead.
Close #304
- Raise `DataError` dumping arrays of mixed types (:ticket:`#301`).
- Fix handling of incorrect server results, with blank sqlstate (:ticket:`#303`).
+- Fix bad Float4 conversion on ppc64le/musllinux (:ticket:`#304`).
Psycopg 3.0.13
def pack_float4_bug_304(x: float) -> bytes:
raise e.InterfaceError(
- "cannot dump Float4: Python affected by bug #304,"
- " see https://github.com/psycopg/psycopg/issues/304"
+ "cannot dump Float4: Python affected by bug #304. Note that the psycopg-c"
+ " and psycopg-binary packages are not affected by this issue."
+ " See https://github.com/psycopg/psycopg/issues/304"
)
return sizeof(uint64_t)
+@cython.final
+cdef class Float4BinaryDumper(CDumper):
+
+ format = PQ_BINARY
+ oid = oids.FLOAT4_OID
+
+ 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 *intptr = <uint32_t *>&f
+ cdef uint32_t *buf = <uint32_t *>CDumper.ensure_size(
+ rv, offset, sizeof(uint32_t))
+ buf[0] = endian.htobe32(intptr[0])
+ return sizeof(uint32_t)
+
+
@cython.final
cdef class FloatLoader(CLoader):