From: Daniele Varrazzo Date: Thu, 20 Oct 2022 21:58:08 +0000 (+0200) Subject: refactor(c/array): types hygiene around endianness conversions X-Git-Tag: 3.1.5~12^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61aeefc0388e6e31071fe8095b0484ca100d8060;p=thirdparty%2Fpsycopg.git refactor(c/array): types hygiene around endianness conversions --- diff --git a/psycopg_c/psycopg_c/types/array.pyx b/psycopg_c/psycopg_c/types/array.pyx index 3b8d828a9..c157d7205 100644 --- a/psycopg_c/psycopg_c/types/array.pyx +++ b/psycopg_c/psycopg_c/types/array.pyx @@ -4,13 +4,14 @@ C optimized functions to manipulate arrays # Copyright (C) 2022 The Psycopg Team -from libc.stdint cimport int32_t +from libc.stdint cimport int32_t, uint32_t from libc.string cimport strchr from cpython.mem cimport PyMem_Malloc, PyMem_Free from cpython.ref cimport Py_INCREF from cpython.list cimport PyList_New, PyList_SET_ITEM from psycopg_c.pq cimport _buffer_as_string_and_size +from psycopg_c.pq.libpq cimport Oid from psycopg_c._psycopg cimport endian from psycopg import errors as e @@ -140,9 +141,9 @@ def array_load_binary(data: Buffer, tx: Transformer) -> List[Any]: _buffer_as_string_and_size(data, &buf, &length) # head is ndims, hasnull, elem oid - cdef int32_t *buf32 = buf + cdef uint32_t *buf32 = buf cdef int ndims = endian.be32toh(buf32[0]) - cdef int oid = endian.be32toh(buf32[2]) + cdef Oid oid = endian.be32toh(buf32[2]) load = tx.get_loader(oid, PQ_BINARY).load @@ -159,13 +160,13 @@ def array_load_binary(data: Buffer, tx: Transformer) -> List[Any]: nelems *= dim dims.append(dim) - buf += (3 + 2 * ndims) * sizeof(int32_t) + buf += (3 + 2 * ndims) * sizeof(uint32_t) cdef list out = PyList_New(nelems) cdef Py_ssize_t size for i in range(nelems): - size = endian.be32toh((buf)[0]) - buf += sizeof(int32_t) + size = endian.be32toh((buf)[0]) + buf += sizeof(uint32_t) if size == -1: Py_INCREF(None) PyList_SET_ITEM(out, i, None)