]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Drop compile warinings on MSVC
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Jun 2021 14:14:12 +0000 (15:14 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Jun 2021 15:37:11 +0000 (16:37 +0100)
psycopg_c/psycopg_c/_psycopg/copy.pyx
psycopg_c/psycopg_c/_psycopg/transform.pyx
psycopg_c/psycopg_c/pq/pgconn.pyx
psycopg_c/psycopg_c/pq/pgresult.pyx
psycopg_c/psycopg_c/types/datetime.pyx
psycopg_c/psycopg_c/types/numeric.pyx

index dc02beb53fd7795c6d45d1955aa947e2f3e57d14..a52afc4cb3cab16fdb8439235a0dec7cf180586a 100644 (file)
@@ -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(<int16_t>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 = (<RowDumper>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(<int32_t>size)
                 target = PyByteArray_AS_STRING(out)  # might have been moved by cdump
                 memcpy(target + pos, <void *>&besize, sizeof(besize))
             else:
@@ -67,7 +67,7 @@ def format_row_binary(
                     (<RowDumper>row_dumper).dumpfunc, <PyObject *>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(<int32_t>size)
                 memcpy(target, <void *>&besize, sizeof(besize))
                 memcpy(target + sizeof(besize), buf, size)
 
@@ -155,7 +155,7 @@ def format_row_text(
         if nesc > 0:
             tmpsize = size + nesc
             target = <unsigned char *>CDumper.ensure_size(out, pos, tmpsize)
-            for j in range(size - 1, -1, -1):
+            for j in range(<int>size - 1, -1, -1):
                 target[j + nesc] = target[j]
                 if copy_escape_lut[target[j]] != 0:
                     nesc -= 1
index 7502f44b729564629704b040e052c1a65a2b423e..4fdc48022a343ddb1a330836b058c7c692e2b638 100644 (file)
@@ -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
index 72f239c34d302480b7acaac27815874e32408ade..7e99112aeaaa3c3785f3db5f6891cf4707ecb6dc 100644 (file)
@@ -77,7 +77,7 @@ cdef class PGconn:
     @property
     def pgconn_ptr(self) -> Optional[int]:
         if self._pgconn_ptr:
-            return <long><void *>self._pgconn_ptr
+            return <long long><void *>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, <int>cnparams, ctypes,
                 <const char *const *>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, <int>cnparams, ctypes,
                 <const char *const *>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 = <libpq.Oid *>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, <int>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, <const char *const *>cvalues,
+                self._pgconn_ptr, name, <int>cnparams, <const char *const *>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 = <libpq.Oid *>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, <int>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, <int>cnparams,
                 <const char *const *>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, <int>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] = <int>length
 
     cdef libpq.Oid *atypes = NULL
     if tparam_types:
index cab97b210b5464f7eb70e7bcad66a1c4bbcec13b..a99de26570f7d091d27a4b3ff05a25a388f33327 100644 (file)
@@ -38,7 +38,7 @@ cdef class PGresult:
     @property
     def pgresult_ptr(self) -> Optional[int]:
         if self._pgresult_ptr:
-            return <long><void *>self._pgresult_ptr
+            return <long long><void *>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 = <libpq.PGresAttDesc *>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, <int>num, attrs)
         PyMem_Free(attrs)
         if (res == 0):
             raise e.OperationalError("PQsetResultAttrs failed")
index 80368db5bb018090bcae134a7123077c0a11bce3..a917e29ac84a77c6109a182a94ed146d4a26d2e7 100644 (file)
@@ -483,7 +483,7 @@ cdef class TimeBinaryLoader(CLoader):
             val //= 60
 
             m = val % 60
-            h = val // 60
+            h = <int>(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 = <int>(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(<int>days, <int>secs, <int>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(<int>days, <int>secs, <int>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 = <int>(aval // 1_000_000)
             us = aval % 1_000_000
 
             usdays = ussecs // 86_400
index 75af361b1e61ebf7ccd7455e60c6434e874bd6ad..37084c379faf1952be69a098aa686fb8a0bb1369 100644 (file)
@@ -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 = <int16_t *>CDumper.ensure_size(
             rv, offset, sizeof(int16_t))
-        cdef int16_t val = PyLong_AsLongLong(obj)
+        cdef int16_t val = <int16_t>PyLong_AsLongLong(obj)
         # swap bytes if needed
         cdef uint16_t *ptvar = <uint16_t *>(&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 = <int32_t *>CDumper.ensure_size(
             rv, offset, sizeof(int32_t))
-        cdef int32_t val = PyLong_AsLongLong(obj)
+        cdef int32_t val = <int32_t>PyLong_AsLongLong(obj)
         # swap bytes if needed
         cdef uint32_t *ptvar = <uint32_t *>(&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 = <uint16_t>len(digits)
 
         # Find the last nonzero digit
         cdef int nzdigits = ndigits