Skip to content

Commit 679b566

Browse files
segevfinerzooba
authored andcommitted
bpo-9566: Fix some Windows x64 compiler warnings (#2492)
* bpo-9566: Silence liblzma warnings * bpo-9566: Silence tcl warnings * bpo-9566: Silence tk warnings * bpo-9566: Silence tix warnings * bpo-9566: Fix some library warnings * bpo-9566: Fix msvcrtmodule.c warnings * bpo-9566: Silence _bz2 warnings * bpo-9566: Fixed some _ssl warnings * bpo-9566: Fix _msi warnings * bpo-9566: Silence _ctypes warnings * Revert "bpo-9566: Fixed some _ssl warnings" This reverts commit a639001. * bpo-9566: Also consider NULL as a possible error in HANDLE_return_converter * bpo-9566: whitespace fixes
1 parent f085191 commit 679b566

File tree

12 files changed

+84
-59
lines changed

12 files changed

+84
-59
lines changed

Modules/binascii.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick)
372372
if (backtick && !bin_len)
373373
*ascii_data++ = '`';
374374
else
375-
*ascii_data++ = ' ' + bin_len;
375+
*ascii_data++ = ' ' + (unsigned char)bin_len;
376376

377377
for( ; bin_len > 0 || leftbits != 0 ; bin_len--, bin_data++ ) {
378378
/* Shift the data (or padding) into our buffer */

Modules/zlibmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ PyZlib_Free(voidpf ctx, void *ptr)
142142
static void
143143
arrange_input_buffer(z_stream *zst, Py_ssize_t *remains)
144144
{
145-
zst->avail_in = Py_MIN((size_t)*remains, UINT_MAX);
145+
zst->avail_in = (uInt)Py_MIN((size_t)*remains, UINT_MAX);
146146
*remains -= zst->avail_in;
147147
}
148148

@@ -177,7 +177,7 @@ arrange_output_buffer_with_maximum(z_stream *zst, PyObject **buffer,
177177
}
178178
}
179179

180-
zst->avail_out = Py_MIN((size_t)(length - occupied), UINT_MAX);
180+
zst->avail_out = (uInt)Py_MIN((size_t)(length - occupied), UINT_MAX);
181181
zst->next_out = (Byte *)PyBytes_AS_STRING(*buffer) + occupied;
182182

183183
return length;

PC/_msi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,8 @@ static PyTypeObject msidb_Type = {
948948
};
949949

950950
#define Py_NOT_PERSIST(x, flag) \
951-
(x != (int)(flag) && \
952-
x != ((int)(flag) | MSIDBOPEN_PATCHFILE))
951+
(x != (SIZE_T)(flag) && \
952+
x != ((SIZE_T)(flag) | MSIDBOPEN_PATCHFILE))
953953

954954
#define Py_INVALID_PERSIST(x) \
955955
(Py_NOT_PERSIST(x, MSIDBOPEN_READONLY) && \
@@ -972,7 +972,7 @@ static PyObject* msiopendb(PyObject *obj, PyObject *args)
972972
behavior. */
973973
if (Py_INVALID_PERSIST(persist))
974974
return msierror(ERROR_INVALID_PARAMETER);
975-
status = MsiOpenDatabase(path, (LPCSTR)persist, &h);
975+
status = MsiOpenDatabase(path, (LPCSTR)(SIZE_T)persist, &h);
976976
if (status != ERROR_SUCCESS)
977977
return msierror(status);
978978

@@ -1038,12 +1038,12 @@ PyInit__msi(void)
10381038
if (m == NULL)
10391039
return NULL;
10401040

1041-
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (long)MSIDBOPEN_CREATEDIRECT);
1042-
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (long)MSIDBOPEN_CREATE);
1043-
PyModule_AddIntConstant(m, "MSIDBOPEN_DIRECT", (long)MSIDBOPEN_DIRECT);
1044-
PyModule_AddIntConstant(m, "MSIDBOPEN_READONLY", (long)MSIDBOPEN_READONLY);
1045-
PyModule_AddIntConstant(m, "MSIDBOPEN_TRANSACT", (long)MSIDBOPEN_TRANSACT);
1046-
PyModule_AddIntConstant(m, "MSIDBOPEN_PATCHFILE", (long)MSIDBOPEN_PATCHFILE);
1041+
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (long)(SIZE_T)MSIDBOPEN_CREATEDIRECT);
1042+
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (long)(SIZE_T)MSIDBOPEN_CREATE);
1043+
PyModule_AddIntConstant(m, "MSIDBOPEN_DIRECT", (long)(SIZE_T)MSIDBOPEN_DIRECT);
1044+
PyModule_AddIntConstant(m, "MSIDBOPEN_READONLY", (long)(SIZE_T)MSIDBOPEN_READONLY);
1045+
PyModule_AddIntConstant(m, "MSIDBOPEN_TRANSACT", (long)(SIZE_T)MSIDBOPEN_TRANSACT);
1046+
PyModule_AddIntConstant(m, "MSIDBOPEN_PATCHFILE", (long)(SIZE_T)MSIDBOPEN_PATCHFILE);
10471047

10481048
PyModule_AddIntMacro(m, MSICOLINFO_NAMES);
10491049
PyModule_AddIntMacro(m, MSICOLINFO_TYPES);

PC/clinic/msvcrtmodule.c.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ PyDoc_STRVAR(msvcrt_open_osfhandle__doc__,
113113
{"open_osfhandle", (PyCFunction)msvcrt_open_osfhandle, METH_FASTCALL, msvcrt_open_osfhandle__doc__},
114114

115115
static long
116-
msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags);
116+
msvcrt_open_osfhandle_impl(PyObject *module, void *handle, int flags);
117117

118118
static PyObject *
119119
msvcrt_open_osfhandle(PyObject *module, PyObject **args, Py_ssize_t nargs)
120120
{
121121
PyObject *return_value = NULL;
122-
intptr_t handle;
122+
void *handle;
123123
int flags;
124124
long _return_value;
125125

@@ -148,24 +148,24 @@ PyDoc_STRVAR(msvcrt_get_osfhandle__doc__,
148148
#define MSVCRT_GET_OSFHANDLE_METHODDEF \
149149
{"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_O, msvcrt_get_osfhandle__doc__},
150150

151-
static intptr_t
151+
static void *
152152
msvcrt_get_osfhandle_impl(PyObject *module, int fd);
153153

154154
static PyObject *
155155
msvcrt_get_osfhandle(PyObject *module, PyObject *arg)
156156
{
157157
PyObject *return_value = NULL;
158158
int fd;
159-
intptr_t _return_value;
159+
void *_return_value;
160160

161161
if (!PyArg_Parse(arg, "i:get_osfhandle", &fd)) {
162162
goto exit;
163163
}
164164
_return_value = msvcrt_get_osfhandle_impl(module, fd);
165-
if ((_return_value == -1) && PyErr_Occurred()) {
165+
if ((_return_value == NULL || _return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
166166
goto exit;
167167
}
168-
return_value = PyLong_FromVoidPtr((void *)_return_value);
168+
return_value = PyLong_FromVoidPtr(_return_value);
169169

170170
exit:
171171
return return_value;
@@ -426,26 +426,26 @@ PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__,
426426
#define MSVCRT_CRTSETREPORTFILE_METHODDEF \
427427
{"CrtSetReportFile", (PyCFunction)msvcrt_CrtSetReportFile, METH_FASTCALL, msvcrt_CrtSetReportFile__doc__},
428428

429-
static long
430-
msvcrt_CrtSetReportFile_impl(PyObject *module, int type, int file);
429+
static void *
430+
msvcrt_CrtSetReportFile_impl(PyObject *module, int type, void *file);
431431

432432
static PyObject *
433433
msvcrt_CrtSetReportFile(PyObject *module, PyObject **args, Py_ssize_t nargs)
434434
{
435435
PyObject *return_value = NULL;
436436
int type;
437-
int file;
438-
long _return_value;
437+
void *file;
438+
void *_return_value;
439439

440-
if (!_PyArg_ParseStack(args, nargs, "ii:CrtSetReportFile",
440+
if (!_PyArg_ParseStack(args, nargs, "i"_Py_PARSE_INTPTR":CrtSetReportFile",
441441
&type, &file)) {
442442
goto exit;
443443
}
444444
_return_value = msvcrt_CrtSetReportFile_impl(module, type, file);
445-
if ((_return_value == -1) && PyErr_Occurred()) {
445+
if ((_return_value == NULL || _return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
446446
goto exit;
447447
}
448-
return_value = PyLong_FromLong(_return_value);
448+
return_value = PyLong_FromVoidPtr(_return_value);
449449

450450
exit:
451451
return return_value;
@@ -569,4 +569,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg)
569569
#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
570570
#define MSVCRT_SET_ERROR_MODE_METHODDEF
571571
#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
572-
/*[clinic end generated code: output=8e9e57c48c4defcc input=a9049054013a1b77]*/
572+
/*[clinic end generated code: output=e86cf578e7f1ffd2 input=a9049054013a1b77]*/

PC/msvcrtmodule.c

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@
3333
#endif
3434

3535
/*[python input]
36-
class intptr_t_converter(CConverter):
37-
type = 'intptr_t'
36+
class HANDLE_converter(CConverter):
37+
type = 'void *'
3838
format_unit = '"_Py_PARSE_INTPTR"'
3939
40-
class handle_return_converter(long_return_converter):
41-
type = 'intptr_t'
42-
cast = '(void *)'
43-
conversion_fn = 'PyLong_FromVoidPtr'
40+
class HANDLE_return_converter(CReturnConverter):
41+
type = 'void *'
42+
43+
def render(self, function, data):
44+
self.declare(data)
45+
self.err_occurred_if(
46+
"_return_value == NULL || _return_value == INVALID_HANDLE_VALUE",
47+
data)
48+
data.return_conversion.append(
49+
'return_value = PyLong_FromVoidPtr(_return_value);\n')
4450
4551
class byte_char_return_converter(CReturnConverter):
4652
type = 'int'
@@ -59,7 +65,7 @@ class wchar_t_return_converter(CReturnConverter):
5965
data.return_conversion.append(
6066
'return_value = PyUnicode_FromOrdinal(_return_value);\n')
6167
[python start generated code]*/
62-
/*[python end generated code: output=da39a3ee5e6b4b0d input=b59f1663dba11997]*/
68+
/*[python end generated code: output=da39a3ee5e6b4b0d input=2b25dc89e9e59534]*/
6369

6470
/*[clinic input]
6571
module msvcrt
@@ -152,7 +158,7 @@ msvcrt_setmode_impl(PyObject *module, int fd, int flags)
152158
/*[clinic input]
153159
msvcrt.open_osfhandle -> long
154160
155-
handle: intptr_t
161+
handle: HANDLE
156162
flags: int
157163
/
158164
@@ -164,13 +170,13 @@ to os.fdopen() to create a file object.
164170
[clinic start generated code]*/
165171

166172
static long
167-
msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags)
168-
/*[clinic end generated code: output=cede871bf939d6e3 input=cb2108bbea84514e]*/
173+
msvcrt_open_osfhandle_impl(PyObject *module, void *handle, int flags)
174+
/*[clinic end generated code: output=b2fb97c4b515e4e6 input=d5db190a307cf4bb]*/
169175
{
170176
int fd;
171177

172178
_Py_BEGIN_SUPPRESS_IPH
173-
fd = _open_osfhandle(handle, flags);
179+
fd = _open_osfhandle((intptr_t)handle, flags);
174180
_Py_END_SUPPRESS_IPH
175181
if (fd == -1)
176182
PyErr_SetFromErrno(PyExc_OSError);
@@ -179,7 +185,7 @@ msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags)
179185
}
180186

181187
/*[clinic input]
182-
msvcrt.get_osfhandle -> handle
188+
msvcrt.get_osfhandle -> HANDLE
183189
184190
fd: int
185191
/
@@ -189,9 +195,9 @@ Return the file handle for the file descriptor fd.
189195
Raises OSError if fd is not recognized.
190196
[clinic start generated code]*/
191197

192-
static intptr_t
198+
static void *
193199
msvcrt_get_osfhandle_impl(PyObject *module, int fd)
194-
/*[clinic end generated code: output=7ce761dd0de2b503 input=305900f4bfab76c7]*/
200+
/*[clinic end generated code: output=aca01dfe24637374 input=5fcfde9b17136aa2]*/
195201
{
196202
intptr_t handle = -1;
197203

@@ -201,7 +207,7 @@ msvcrt_get_osfhandle_impl(PyObject *module, int fd)
201207
if (handle == -1)
202208
PyErr_SetFromErrno(PyExc_OSError);
203209

204-
return handle;
210+
return (HANDLE)handle;
205211
}
206212

207213
/* Console I/O */
@@ -389,25 +395,25 @@ msvcrt_ungetwch_impl(PyObject *module, int unicode_char)
389395

390396
#ifdef _DEBUG
391397
/*[clinic input]
392-
msvcrt.CrtSetReportFile -> long
398+
msvcrt.CrtSetReportFile -> HANDLE
393399
394400
type: int
395-
file: int
401+
file: HANDLE
396402
/
397403
398404
Wrapper around _CrtSetReportFile.
399405
400406
Only available on Debug builds.
401407
[clinic start generated code]*/
402408

403-
static long
404-
msvcrt_CrtSetReportFile_impl(PyObject *module, int type, int file)
405-
/*[clinic end generated code: output=df291c7fe032eb68 input=bb8f721a604fcc45]*/
409+
static void *
410+
msvcrt_CrtSetReportFile_impl(PyObject *module, int type, void *file)
411+
/*[clinic end generated code: output=9393e8c77088bbe9 input=290809b5f19e65b9]*/
406412
{
407-
long res;
413+
HANDLE res;
408414

409415
_Py_BEGIN_SUPPRESS_IPH
410-
res = (long)_CrtSetReportFile(type, (_HFILE)file);
416+
res = _CrtSetReportFile(type, file);
411417
_Py_END_SUPPRESS_IPH
412418

413419
return res;
@@ -540,6 +546,20 @@ insertint(PyObject *d, char *name, int value)
540546
}
541547
}
542548

549+
static void
550+
insertptr(PyObject *d, char *name, void *value)
551+
{
552+
PyObject *v = PyLong_FromVoidPtr(value);
553+
if (v == NULL) {
554+
/* Don't bother reporting this error */
555+
PyErr_Clear();
556+
}
557+
else {
558+
PyDict_SetItemString(d, name, v);
559+
Py_DECREF(v);
560+
}
561+
}
562+
543563
PyMODINIT_FUNC
544564
PyInit_msvcrt(void)
545565
{
@@ -568,9 +588,9 @@ PyInit_msvcrt(void)
568588
insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE);
569589
insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW);
570590
insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE);
571-
insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR);
572-
insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT);
573-
insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE);
591+
insertptr(d, "CRTDBG_FILE_STDERR", _CRTDBG_FILE_STDERR);
592+
insertptr(d, "CRTDBG_FILE_STDOUT", _CRTDBG_FILE_STDOUT);
593+
insertptr(d, "CRTDBG_REPORT_FILE", _CRTDBG_REPORT_FILE);
574594
#endif
575595

576596
/* constants for the crt versions */

PC/winreg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
905905
HKEY retKey;
906906
long rc;
907907

908-
rc = RegCreateKeyExW(key, sub_key, reserved, NULL, (DWORD)NULL,
908+
rc = RegCreateKeyExW(key, sub_key, reserved, NULL, 0,
909909
access, NULL, &retKey, NULL);
910910
if (rc != ERROR_SUCCESS) {
911911
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");

PCbuild/_bz2.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<ClCompile>
6565
<AdditionalIncludeDirectories>$(bz2Dir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
6666
<PreprocessorDefinitions>WIN32;_FILE_OFFSET_BITS=64;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
67+
<DisableSpecificWarnings>4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
6768
</ClCompile>
6869
<Link>
6970
<BaseAddress>0x1D170000</BaseAddress>

PCbuild/_ctypes.vcxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
<ClCompile Include="..\Modules\_ctypes\cfield.c" />
8484
<ClCompile Include="..\Modules\_ctypes\libffi_msvc\ffi.c" />
8585
<ClCompile Include="..\Modules\_ctypes\malloc_closure.c" />
86-
<ClCompile Include="..\Modules\_ctypes\libffi_msvc\prep_cif.c" />
86+
<ClCompile Include="..\Modules\_ctypes\libffi_msvc\prep_cif.c">
87+
<DisableSpecificWarnings Condition="'$(Platform)'=='x64'">4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
88+
</ClCompile>
8789
<ClCompile Include="..\Modules\_ctypes\stgdict.c" />
8890
<ClCompile Include="..\Modules\_ctypes\libffi_msvc\win32.c">
8991
<ExcludedFromBuild Condition="'$(Platform)'=='x64'">true</ExcludedFromBuild>

PCbuild/liblzma.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
6565
<Optimization>Disabled</Optimization>
6666
<AdditionalIncludeDirectories>$(lzmaDir)windows;$(lzmaDir)src/liblzma/common;$(lzmaDir)src/common;$(lzmaDir)src/liblzma/api;$(lzmaDir)src/liblzma/check;$(lzmaDir)src/liblzma/delta;$(lzmaDir)src/liblzma/lz;$(lzmaDir)src/liblzma/lzma;$(lzmaDir)src/liblzma/rangecoder;$(lzmaDir)src/liblzma/simple</AdditionalIncludeDirectories>
67-
<DisableSpecificWarnings>4028;4113;4244;4267;4996</DisableSpecificWarnings>
67+
<DisableSpecificWarnings>4028;4113;4133;4244;4267;4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
6868
</ClCompile>
6969
</ItemDefinitionGroup>
7070
<ItemGroup>

PCbuild/tcl.vcxproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@
5555
<TclOpts Condition="$(Configuration) == 'Debug'">symbols,msvcrt</TclOpts>
5656
<TclDirs>INSTALLDIR="$(OutDir.TrimEnd(`\`))" INSTALL_DIR="$(OutDir.TrimEnd(`\`))"</TclDirs>
5757
<DebugFlags Condition="'$(Configuration)' == 'Debug'">DEBUGFLAGS="-wd4456 -wd4457 -wd4458 -wd4459 -wd4996"</DebugFlags>
58+
<WarningsFlags>WARNINGS="-W3 -wd4311 -wd4312"</WarningsFlags>
5859
<NMakeBuildCommandLine>setlocal
5960
set VCINSTALLDIR=$(VCInstallDir)
6061
cd /D "$(tclDir)win"
61-
nmake -f makefile.vc MACHINE=$(TclMachine) OPTS=$(TclOpts) $(TclDirs) $(DebugFlags) core shell dlls
62-
nmake -f makefile.vc MACHINE=$(TclMachine) OPTS=$(TclOpts) $(TclDirs) $(DebugFlags) install-binaries install-libraries
62+
nmake -f makefile.vc MACHINE=$(TclMachine) OPTS=$(TclOpts) $(TclDirs) $(DebugFlags) $(WarningsFlags) core shell dlls
63+
nmake -f makefile.vc MACHINE=$(TclMachine) OPTS=$(TclOpts) $(TclDirs) $(DebugFlags) $(WarningsFlags) install-binaries install-libraries
6364
copy /Y ..\license.terms "$(OutDir)\tcllicense.terms"
6465
</NMakeBuildCommandLine>
6566
</PropertyGroup>

0 commit comments

Comments
 (0)