[Python-checkins] Fix compilation warnings on Windows (GH-8627)

Victor Stinner webhook-mailer at python.org
Thu Aug 2 12:03:03 EDT 2018


https://github.com/python/cpython/commit/dd4d8b4d80065409dae69f966fd7617e5b3d97f1
commit: dd4d8b4d80065409dae69f966fd7617e5b3d97f1
branch: 2.7
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-08-02T18:02:59+02:00
summary:

Fix compilation warnings on Windows (GH-8627)

* Fix compilation warning in _ctypes module on Window

(cherry picked from commit 20f11fe43c47b68c8b9dd6539d2d40b66c9957f9)

* Fix compilation warnings on Windows 64-bit

(cherry picked from commit 725e4212229bf68f87d4f66c1815d444ddfc7aa5)

* Fix compiler warning in unicodeobject.c

Explicitly case to Py_UNICODE to fix the warning:

Objects\unicodeobject.c(4225): warning C4244: '=' :
conversion from 'long' to 'Py_UNICODE', possible loss of data

The downcast cannot overflow since we check that value <= 0x10ffff.

files:
M Modules/_ctypes/libffi_msvc/ffi.c
M Modules/_sqlite/util.c
M Objects/unicodeobject.c

diff --git a/Modules/_ctypes/libffi_msvc/ffi.c b/Modules/_ctypes/libffi_msvc/ffi.c
index f28c3e0a3859..587c94b7e61f 100644
--- a/Modules/_ctypes/libffi_msvc/ffi.c
+++ b/Modules/_ctypes/libffi_msvc/ffi.c
@@ -119,7 +119,7 @@ void ffi_prep_args(char *stack, extended_cif *ecif)
       argp += z;
     }
 
-  if (argp - stack > ecif->cif->bytes) 
+  if (argp >= stack && (unsigned)(argp - stack) > ecif->cif->bytes)
     {
       Py_FatalError("FFI BUG: not enough stack space for arguments");
     }
diff --git a/Modules/_sqlite/util.c b/Modules/_sqlite/util.c
index a24dd8c63473..73772250f914 100644
--- a/Modules/_sqlite/util.c
+++ b/Modules/_sqlite/util.c
@@ -132,7 +132,7 @@ _pysqlite_long_from_int64(sqlite_int64 value)
     }
 # endif
 #endif
-    return PyInt_FromLong(value);
+    return PyInt_FromLong(Py_SAFE_DOWNCAST(value, sqlite_int64, long));
 }
 
 sqlite_int64
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 8bf04df2c86c..b76db619ad76 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4222,7 +4222,7 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
                         p = PyUnicode_AS_UNICODE(v) + oldpos;
                     }
                     value -= 0x10000;
-                    *p++ = 0xD800 | (value >> 10);
+                    *p++ = 0xD800 | (Py_UNICODE)(value >> 10);
                     *p++ = 0xDC00 | (value & 0x3FF);
                     extrachars -= 2;
                 }



More information about the Python-checkins mailing list