]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-9566: Fix msvcrtmodule.c warnings
authorSegev Finer <segev208@gmail.com>
Thu, 29 Jun 2017 19:00:37 +0000 (22:00 +0300)
committerSegev Finer <segev208@gmail.com>
Thu, 29 Jun 2017 19:00:37 +0000 (22:00 +0300)
PC/clinic/msvcrtmodule.c.h
PC/msvcrtmodule.c

index 046b0583b0ca4edd765d32122ebbc2b68b87ef3e..3102f4f1fece4d8c9c27d70be0cc5d78e001da03 100644 (file)
@@ -121,13 +121,13 @@ PyDoc_STRVAR(msvcrt_open_osfhandle__doc__,
     {"open_osfhandle", (PyCFunction)msvcrt_open_osfhandle, METH_FASTCALL, msvcrt_open_osfhandle__doc__},
 
 static long
-msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags);
+msvcrt_open_osfhandle_impl(PyObject *module, void *handle, int flags);
 
 static PyObject *
 msvcrt_open_osfhandle(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
 {
     PyObject *return_value = NULL;
-    intptr_t handle;
+    void *handle;
     int flags;
     long _return_value;
 
@@ -160,7 +160,7 @@ PyDoc_STRVAR(msvcrt_get_osfhandle__doc__,
 #define MSVCRT_GET_OSFHANDLE_METHODDEF    \
     {"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_O, msvcrt_get_osfhandle__doc__},
 
-static intptr_t
+static void *
 msvcrt_get_osfhandle_impl(PyObject *module, int fd);
 
 static PyObject *
@@ -168,16 +168,16 @@ msvcrt_get_osfhandle(PyObject *module, PyObject *arg)
 {
     PyObject *return_value = NULL;
     int fd;
-    intptr_t _return_value;
+    void *_return_value;
 
     if (!PyArg_Parse(arg, "i:get_osfhandle", &fd)) {
         goto exit;
     }
     _return_value = msvcrt_get_osfhandle_impl(module, fd);
-    if ((_return_value == -1) && PyErr_Occurred()) {
+    if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
         goto exit;
     }
-    return_value = PyLong_FromVoidPtr((void *)_return_value);
+    return_value = PyLong_FromVoidPtr(_return_value);
 
 exit:
     return return_value;
@@ -438,30 +438,30 @@ PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__,
 #define MSVCRT_CRTSETREPORTFILE_METHODDEF    \
     {"CrtSetReportFile", (PyCFunction)msvcrt_CrtSetReportFile, METH_FASTCALL, msvcrt_CrtSetReportFile__doc__},
 
-static long
-msvcrt_CrtSetReportFile_impl(PyObject *module, int type, int file);
+static void *
+msvcrt_CrtSetReportFile_impl(PyObject *module, int type, void *file);
 
 static PyObject *
 msvcrt_CrtSetReportFile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
 {
     PyObject *return_value = NULL;
     int type;
-    int file;
-    long _return_value;
+    void *file;
+    void *_return_value;
 
     if (!_PyArg_NoStackKeywords("CrtSetReportFile", kwnames)) {
         goto exit;
     }
 
-    if (!_PyArg_ParseStack(args, nargs, "ii:CrtSetReportFile",
+    if (!_PyArg_ParseStack(args, nargs, "i"_Py_PARSE_INTPTR":CrtSetReportFile",
         &type, &file)) {
         goto exit;
     }
     _return_value = msvcrt_CrtSetReportFile_impl(module, type, file);
-    if ((_return_value == -1) && PyErr_Occurred()) {
+    if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
         goto exit;
     }
-    return_value = PyLong_FromLong(_return_value);
+    return_value = PyLong_FromVoidPtr(_return_value);
 
 exit:
     return return_value;
@@ -589,4 +589,4 @@ exit:
 #ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
     #define MSVCRT_SET_ERROR_MODE_METHODDEF
 #endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
-/*[clinic end generated code: output=9e82abfdd357b0da input=a9049054013a1b77]*/
+/*[clinic end generated code: output=bf069e62089190cd input=a9049054013a1b77]*/
index 59bf54fa0b7743625aaf1d9b37883fcf5f7863a2..4a696fe9eb20e6cb071513638818c1440deee3e8 100644 (file)
 #endif
 
 /*[python input]
-class intptr_t_converter(CConverter):
-    type = 'intptr_t'
+class HANDLE_converter(CConverter):
+    type = 'void *'
     format_unit = '"_Py_PARSE_INTPTR"'
 
-class handle_return_converter(long_return_converter):
-    type = 'intptr_t'
-    cast = '(void *)'
-    conversion_fn = 'PyLong_FromVoidPtr'
+class HANDLE_return_converter(CReturnConverter):
+    type = 'void *'
+
+    def render(self, function, data):
+        self.declare(data)
+        self.err_occurred_if("_return_value == INVALID_HANDLE_VALUE", data)
+        data.return_conversion.append(
+            'return_value = PyLong_FromVoidPtr(_return_value);\n')
 
 class byte_char_return_converter(CReturnConverter):
     type = 'int'
@@ -59,7 +63,7 @@ class wchar_t_return_converter(CReturnConverter):
         data.return_conversion.append(
             'return_value = PyUnicode_FromOrdinal(_return_value);\n')
 [python start generated code]*/
-/*[python end generated code: output=da39a3ee5e6b4b0d input=b59f1663dba11997]*/
+/*[python end generated code: output=da39a3ee5e6b4b0d input=dab543102cf6345d]*/
 
 /*[clinic input]
 module msvcrt
@@ -152,7 +156,7 @@ msvcrt_setmode_impl(PyObject *module, int fd, int flags)
 /*[clinic input]
 msvcrt.open_osfhandle -> long
 
-    handle: intptr_t
+    handle: HANDLE
     flags: int
     /
 
@@ -164,13 +168,13 @@ to os.fdopen() to create a file object.
 [clinic start generated code]*/
 
 static long
-msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags)
-/*[clinic end generated code: output=cede871bf939d6e3 input=cb2108bbea84514e]*/
+msvcrt_open_osfhandle_impl(PyObject *module, void *handle, int flags)
+/*[clinic end generated code: output=b2fb97c4b515e4e6 input=d5db190a307cf4bb]*/
 {
     int fd;
 
     _Py_BEGIN_SUPPRESS_IPH
-    fd = _open_osfhandle(handle, flags);
+    fd = _open_osfhandle((intptr_t)handle, flags);
     _Py_END_SUPPRESS_IPH
     if (fd == -1)
         PyErr_SetFromErrno(PyExc_OSError);
@@ -179,7 +183,7 @@ msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags)
 }
 
 /*[clinic input]
-msvcrt.get_osfhandle -> handle
+msvcrt.get_osfhandle -> HANDLE
 
     fd: int
     /
@@ -189,9 +193,9 @@ Return the file handle for the file descriptor fd.
 Raises OSError if fd is not recognized.
 [clinic start generated code]*/
 
-static intptr_t
+static void *
 msvcrt_get_osfhandle_impl(PyObject *module, int fd)
-/*[clinic end generated code: output=7ce761dd0de2b503 input=305900f4bfab76c7]*/
+/*[clinic end generated code: output=aca01dfe24637374 input=5fcfde9b17136aa2]*/
 {
     intptr_t handle = -1;
 
@@ -201,7 +205,7 @@ msvcrt_get_osfhandle_impl(PyObject *module, int fd)
     if (handle == -1)
         PyErr_SetFromErrno(PyExc_OSError);
 
-    return handle;
+    return (HANDLE)handle;
 }
 
 /* Console I/O */
@@ -389,10 +393,10 @@ msvcrt_ungetwch_impl(PyObject *module, int unicode_char)
 
 #ifdef _DEBUG
 /*[clinic input]
-msvcrt.CrtSetReportFile -> long
+msvcrt.CrtSetReportFile -> HANDLE
 
     type: int
-    file: int
+    file: HANDLE
     /
 
 Wrapper around _CrtSetReportFile.
@@ -400,14 +404,14 @@ Wrapper around _CrtSetReportFile.
 Only available on Debug builds.
 [clinic start generated code]*/
 
-static long
-msvcrt_CrtSetReportFile_impl(PyObject *module, int type, int file)
-/*[clinic end generated code: output=df291c7fe032eb68 input=bb8f721a604fcc45]*/
+static void *
+msvcrt_CrtSetReportFile_impl(PyObject *module, int type, void *file)
+/*[clinic end generated code: output=9393e8c77088bbe9 input=290809b5f19e65b9]*/
 {
-    long res;
+    HANDLE res;
 
     _Py_BEGIN_SUPPRESS_IPH
-    res = (long)_CrtSetReportFile(type, (_HFILE)file);
+    res = _CrtSetReportFile(type, file);
     _Py_END_SUPPRESS_IPH
 
     return res;
@@ -540,6 +544,20 @@ insertint(PyObject *d, char *name, int value)
     }
 }
 
+static void
+insertptr(PyObject *d, char *name, void *value)
+{
+    PyObject *v = PyLong_FromVoidPtr(value);
+    if (v == NULL) {
+        /* Don't bother reporting this error */
+        PyErr_Clear();
+    }
+    else {
+        PyDict_SetItemString(d, name, v);
+        Py_DECREF(v);
+    }
+}
+
 PyMODINIT_FUNC
 PyInit_msvcrt(void)
 {
@@ -568,9 +586,9 @@ PyInit_msvcrt(void)
     insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE);
     insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW);
     insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE);
-    insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR);
-    insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT);
-    insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE);
+    insertptr(d, "CRTDBG_FILE_STDERR", _CRTDBG_FILE_STDERR);
+    insertptr(d, "CRTDBG_FILE_STDOUT", _CRTDBG_FILE_STDOUT);
+    insertptr(d, "CRTDBG_REPORT_FILE", _CRTDBG_REPORT_FILE);
 #endif
 
     /* constants for the crt versions */