From 87600544b92f3362e21abb3b6629c778347f9dfa Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 29 Jun 2021 15:14:12 +0100 Subject: [PATCH] Drop compile warinings on MSVC --- psycopg_c/psycopg_c/_psycopg/copy.pyx | 8 ++--- psycopg_c/psycopg_c/_psycopg/transform.pyx | 6 ++-- psycopg_c/psycopg_c/pq/pgconn.pyx | 34 +++++++++++----------- psycopg_c/psycopg_c/pq/pgresult.pyx | 6 ++-- psycopg_c/psycopg_c/types/datetime.pyx | 10 +++---- psycopg_c/psycopg_c/types/numeric.pyx | 6 ++-- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/psycopg_c/psycopg_c/_psycopg/copy.pyx b/psycopg_c/psycopg_c/_psycopg/copy.pyx index dc02beb53..a52afc4cb 100644 --- a/psycopg_c/psycopg_c/_psycopg/copy.pyx +++ b/psycopg_c/psycopg_c/_psycopg/copy.pyx @@ -24,7 +24,7 @@ def format_row_binary( ) -> bytearray: """Convert a row of adapted data to the data to send for binary copy""" cdef Py_ssize_t rowlen = len(row) - cdef uint16_t berowlen = endian.htobe16(rowlen) + cdef uint16_t berowlen = endian.htobe16(rowlen) cdef Py_ssize_t pos # offset in 'out' where to write if out is None: @@ -58,7 +58,7 @@ def format_row_binary( size = (row_dumper).cdumper.cdump( item, out, pos + sizeof(besize)) # Also add the size of the item, before the item - besize = endian.htobe32(size) + besize = endian.htobe32(size) target = PyByteArray_AS_STRING(out) # might have been moved by cdump memcpy(target + pos, &besize, sizeof(besize)) else: @@ -67,7 +67,7 @@ def format_row_binary( (row_dumper).dumpfunc, item, NULL) _buffer_as_string_and_size(b, &buf, &size) target = CDumper.ensure_size(out, pos, size + sizeof(besize)) - besize = endian.htobe32(size) + besize = endian.htobe32(size) memcpy(target, &besize, sizeof(besize)) memcpy(target + sizeof(besize), buf, size) @@ -155,7 +155,7 @@ def format_row_text( if nesc > 0: tmpsize = size + nesc target = CDumper.ensure_size(out, pos, tmpsize) - for j in range(size - 1, -1, -1): + for j in range(size - 1, -1, -1): target[j + nesc] = target[j] if copy_escape_lut[target[j]] != 0: nesc -= 1 diff --git a/psycopg_c/psycopg_c/_psycopg/transform.pyx b/psycopg_c/psycopg_c/_psycopg/transform.pyx index 7502f44b7..4fdc48022 100644 --- a/psycopg_c/psycopg_c/_psycopg/transform.pyx +++ b/psycopg_c/psycopg_c/_psycopg/transform.pyx @@ -132,7 +132,7 @@ cdef class Transformer: types: Sequence[int], formats: Sequence[Format]) -> None: self._c_set_row_types(len(types), types, formats) - cdef void _c_set_row_types(self, int ntypes, list types, list formats): + cdef void _c_set_row_types(self, Py_ssize_t ntypes, list types, list formats): cdef list loaders = PyList_New(ntypes) # these are used more as Python object than C @@ -223,7 +223,7 @@ cdef class Transformer: cpdef dump_sequence(self, object params, object formats): # Verify that they are not none and that PyList_GET_ITEM won't blow up - cdef int nparams = len(params) + cdef Py_ssize_t nparams = len(params) cdef list ps = PyList_New(nparams) cdef tuple ts = PyTuple_New(nparams) cdef list fs = PyList_New(nparams) @@ -388,7 +388,7 @@ cdef class Transformer: return record cpdef object load_sequence(self, record: Sequence[Optional[bytes]]): - cdef int nfields = len(record) + cdef Py_ssize_t nfields = len(record) out = PyTuple_New(nfields) cdef PyObject *loader # borrowed RowLoader cdef int col diff --git a/psycopg_c/psycopg_c/pq/pgconn.pyx b/psycopg_c/psycopg_c/pq/pgconn.pyx index 72f239c34..7e99112ae 100644 --- a/psycopg_c/psycopg_c/pq/pgconn.pyx +++ b/psycopg_c/psycopg_c/pq/pgconn.pyx @@ -77,7 +77,7 @@ cdef class PGconn: @property def pgconn_ptr(self) -> Optional[int]: if self._pgconn_ptr: - return self._pgconn_ptr + return self._pgconn_ptr else: return None @@ -222,7 +222,7 @@ cdef class PGconn: ) -> PGresult: _ensure_pgconn(self) - cdef int cnparams + cdef Py_ssize_t cnparams cdef libpq.Oid *ctypes cdef char *const *cvalues cdef int *clengths @@ -233,7 +233,7 @@ cdef class PGconn: cdef libpq.PGresult *pgresult with nogil: pgresult = libpq.PQexecParams( - self._pgconn_ptr, command, cnparams, ctypes, + self._pgconn_ptr, command, cnparams, ctypes, cvalues, clengths, cformats, result_format) _clear_query_params(ctypes, cvalues, clengths, cformats) if pgresult is NULL: @@ -250,7 +250,7 @@ cdef class PGconn: ) -> None: _ensure_pgconn(self) - cdef int cnparams + cdef Py_ssize_t cnparams cdef libpq.Oid *ctypes cdef char *const *cvalues cdef int *clengths @@ -261,7 +261,7 @@ cdef class PGconn: cdef int rv with nogil: rv = libpq.PQsendQueryParams( - self._pgconn_ptr, command, cnparams, ctypes, + self._pgconn_ptr, command, cnparams, ctypes, cvalues, clengths, cformats, result_format) _clear_query_params(ctypes, cvalues, clengths, cformats) if not rv: @@ -278,7 +278,7 @@ cdef class PGconn: _ensure_pgconn(self) cdef int i - cdef int nparams = len(param_types) if param_types else 0 + cdef Py_ssize_t nparams = len(param_types) if param_types else 0 cdef libpq.Oid *atypes = NULL if nparams: atypes = PyMem_Malloc(nparams * sizeof(libpq.Oid)) @@ -288,7 +288,7 @@ cdef class PGconn: cdef int rv with nogil: rv = libpq.PQsendPrepare( - self._pgconn_ptr, name, command, nparams, atypes + self._pgconn_ptr, name, command, nparams, atypes ) PyMem_Free(atypes) if not rv: @@ -305,7 +305,7 @@ cdef class PGconn: ) -> None: _ensure_pgconn(self) - cdef int cnparams + cdef Py_ssize_t cnparams cdef libpq.Oid *ctypes cdef char *const *cvalues cdef int *clengths @@ -316,7 +316,7 @@ cdef class PGconn: cdef int rv with nogil: rv = libpq.PQsendQueryPrepared( - self._pgconn_ptr, name, cnparams, cvalues, + self._pgconn_ptr, name, cnparams, cvalues, clengths, cformats, result_format) _clear_query_params(ctypes, cvalues, clengths, cformats) if not rv: @@ -333,7 +333,7 @@ cdef class PGconn: _ensure_pgconn(self) cdef int i - cdef int nparams = len(param_types) if param_types else 0 + cdef Py_ssize_t nparams = len(param_types) if param_types else 0 cdef libpq.Oid *atypes = NULL if nparams: atypes = PyMem_Malloc(nparams * sizeof(libpq.Oid)) @@ -343,7 +343,7 @@ cdef class PGconn: cdef libpq.PGresult *rv with nogil: rv = libpq.PQprepare( - self._pgconn_ptr, name, command, nparams, atypes) + self._pgconn_ptr, name, command, nparams, atypes) PyMem_Free(atypes) if rv is NULL: raise MemoryError("couldn't allocate PGresult") @@ -358,7 +358,7 @@ cdef class PGconn: ) -> PGresult: _ensure_pgconn(self) - cdef int cnparams + cdef Py_ssize_t cnparams cdef libpq.Oid *ctypes cdef char *const *cvalues cdef int *clengths @@ -369,7 +369,7 @@ cdef class PGconn: cdef libpq.PGresult *rv with nogil: rv = libpq.PQexecPrepared( - self._pgconn_ptr, name, cnparams, + self._pgconn_ptr, name, cnparams, cvalues, clengths, cformats, result_format) @@ -468,7 +468,7 @@ cdef class PGconn: cdef Py_ssize_t length _buffer_as_string_and_size(buffer, &cbuffer, &length) - rv = libpq.PQputCopyData(self._pgconn_ptr, cbuffer, length) + rv = libpq.PQputCopyData(self._pgconn_ptr, cbuffer, length) if rv < 0: raise e.OperationalError(f"sending copy data failed: {error_message(self)}") return rv @@ -545,7 +545,7 @@ cdef void notice_receiver(void *arg, const libpq.PGresult *res_ptr) with gil: res._pgresult_ptr = NULL # avoid destroying the pgresult_ptr -cdef (int, libpq.Oid *, char * const*, int *, int *) _query_params_args( +cdef (Py_ssize_t, libpq.Oid *, char * const*, int *, int *) _query_params_args( list param_values: Optional[Sequence[Optional[bytes]]], param_types: Optional[Sequence[int]], list param_formats: Optional[Sequence[int]], @@ -560,7 +560,7 @@ cdef (int, libpq.Oid *, char * const*, int *, int *) _query_params_args( else: tparam_types = param_types - cdef int nparams = len(param_values) if param_values else 0 + cdef Py_ssize_t nparams = len(param_values) if param_values else 0 if tparam_types is not None and len(tparam_types) != nparams: raise ValueError( "got %d param_values but %d param_types" @@ -590,7 +590,7 @@ cdef (int, libpq.Oid *, char * const*, int *, int *) _query_params_args( # on internal error, e.g. if obj is not a buffer) _buffer_as_string_and_size(obj, &ptr, &length) aparams[i] = ptr - alenghts[i] = length + alenghts[i] = length cdef libpq.Oid *atypes = NULL if tparam_types: diff --git a/psycopg_c/psycopg_c/pq/pgresult.pyx b/psycopg_c/psycopg_c/pq/pgresult.pyx index cab97b210..a99de2657 100644 --- a/psycopg_c/psycopg_c/pq/pgresult.pyx +++ b/psycopg_c/psycopg_c/pq/pgresult.pyx @@ -38,7 +38,7 @@ cdef class PGresult: @property def pgresult_ptr(self) -> Optional[int]: if self._pgresult_ptr: - return self._pgresult_ptr + return self._pgresult_ptr else: return None @@ -137,7 +137,7 @@ cdef class PGresult: return libpq.PQoidValue(self._pgresult_ptr) def set_attributes(self, descriptions: List[PGresAttDesc]): - cdef int num = len(descriptions) + cdef Py_ssize_t num = len(descriptions) cdef libpq.PGresAttDesc *attrs = PyMem_Malloc( num * sizeof(libpq.PGresAttDesc)) @@ -151,7 +151,7 @@ cdef class PGresult: attrs[i].typlen = descr.typlen attrs[i].atttypmod = descr.atttypmod - cdef int res = libpq.PQsetResultAttrs(self._pgresult_ptr, num, attrs) + cdef int res = libpq.PQsetResultAttrs(self._pgresult_ptr, num, attrs) PyMem_Free(attrs) if (res == 0): raise e.OperationalError("PQsetResultAttrs failed") diff --git a/psycopg_c/psycopg_c/types/datetime.pyx b/psycopg_c/psycopg_c/types/datetime.pyx index 80368db5b..a917e29ac 100644 --- a/psycopg_c/psycopg_c/types/datetime.pyx +++ b/psycopg_c/psycopg_c/types/datetime.pyx @@ -483,7 +483,7 @@ cdef class TimeBinaryLoader(CLoader): val //= 60 m = val % 60 - h = val // 60 + h = (val // 60) try: return cdt.time_new(h, m, s, us, None) @@ -552,7 +552,7 @@ cdef class TimetzBinaryLoader(CLoader): val //= 60 m = val % 60 - h = val // 60 + h = (val // 60) # Python < 3.7 didn't support seconds in the timezones if PY_VERSION_HEX >= 0x03070000: @@ -713,7 +713,7 @@ cdef class TimestampBinaryLoader(CLoader): secs %= 86_400 try: - delta = cdt.timedelta_new(days, secs, micros) + delta = cdt.timedelta_new(days, secs, micros) if val > 0: return pg_datetime_epoch + delta else: @@ -845,7 +845,7 @@ cdef class TimestamptzBinaryLoader(_BaseTimestamptzLoader): secs %= 86_400 try: - delta = cdt.timedelta_new(days, secs, micros) + delta = cdt.timedelta_new(days, secs, micros) if val > 0: dt = pg_datetimetz_epoch + delta else: @@ -992,7 +992,7 @@ cdef class IntervalBinaryLoader(CLoader): # Group the micros in biggers stuff or timedelta_new might overflow with cython.cdivision(True): - ussecs = aval // 1_000_000 + ussecs = (aval // 1_000_000) us = aval % 1_000_000 usdays = ussecs // 86_400 diff --git a/psycopg_c/psycopg_c/types/numeric.pyx b/psycopg_c/psycopg_c/types/numeric.pyx index 75af361b1..37084c379 100644 --- a/psycopg_c/psycopg_c/types/numeric.pyx +++ b/psycopg_c/psycopg_c/types/numeric.pyx @@ -124,7 +124,7 @@ cdef class Int2BinaryDumper(CDumper): cdef Py_ssize_t cdump(self, obj, bytearray rv, Py_ssize_t offset) except -1: cdef int16_t *buf = CDumper.ensure_size( rv, offset, sizeof(int16_t)) - cdef int16_t val = PyLong_AsLongLong(obj) + cdef int16_t val = PyLong_AsLongLong(obj) # swap bytes if needed cdef uint16_t *ptvar = (&val) buf[0] = endian.htobe16(ptvar[0]) @@ -142,7 +142,7 @@ cdef class Int4BinaryDumper(CDumper): cdef Py_ssize_t cdump(self, obj, bytearray rv, Py_ssize_t offset) except -1: cdef int32_t *buf = CDumper.ensure_size( rv, offset, sizeof(int32_t)) - cdef int32_t val = PyLong_AsLongLong(obj) + cdef int32_t val = PyLong_AsLongLong(obj) # swap bytes if needed cdef uint32_t *ptvar = (&val) buf[0] = endian.htobe32(ptvar[0]) @@ -586,7 +586,7 @@ cdef class DecimalBinaryDumper(CDumper): return length cdef int exp = pyexp - cdef uint16_t ndigits = len(digits) + cdef uint16_t ndigits = len(digits) # Find the last nonzero digit cdef int nzdigits = ndigits -- 2.47.3