Skip to content

bpo-9566: Fix some Windows x64 compiler warnings #2492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/binascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick)
if (backtick && !bin_len)
*ascii_data++ = '`';
else
*ascii_data++ = ' ' + bin_len;
*ascii_data++ = ' ' + (unsigned char)bin_len;

for( ; bin_len > 0 || leftbits != 0 ; bin_len--, bin_data++ ) {
/* Shift the data (or padding) into our buffer */
Expand Down
4 changes: 2 additions & 2 deletions Modules/zlibmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ PyZlib_Free(voidpf ctx, void *ptr)
static void
arrange_input_buffer(z_stream *zst, Py_ssize_t *remains)
{
zst->avail_in = Py_MIN((size_t)*remains, UINT_MAX);
zst->avail_in = (uInt)Py_MIN((size_t)*remains, UINT_MAX);
*remains -= zst->avail_in;
}

Expand Down Expand Up @@ -177,7 +177,7 @@ arrange_output_buffer_with_maximum(z_stream *zst, PyObject **buffer,
}
}

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

return length;
Expand Down
18 changes: 9 additions & 9 deletions PC/_msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,8 @@ static PyTypeObject msidb_Type = {
};

#define Py_NOT_PERSIST(x, flag) \
(x != (int)(flag) && \
x != ((int)(flag) | MSIDBOPEN_PATCHFILE))
(x != (SIZE_T)(flag) && \
x != ((SIZE_T)(flag) | MSIDBOPEN_PATCHFILE))

#define Py_INVALID_PERSIST(x) \
(Py_NOT_PERSIST(x, MSIDBOPEN_READONLY) && \
Expand All @@ -972,7 +972,7 @@ static PyObject* msiopendb(PyObject *obj, PyObject *args)
behavior. */
if (Py_INVALID_PERSIST(persist))
return msierror(ERROR_INVALID_PARAMETER);
status = MsiOpenDatabase(path, (LPCSTR)persist, &h);
status = MsiOpenDatabase(path, (LPCSTR)(SIZE_T)persist, &h);
if (status != ERROR_SUCCESS)
return msierror(status);

Expand Down Expand Up @@ -1038,12 +1038,12 @@ PyInit__msi(void)
if (m == NULL)
return NULL;

PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (long)MSIDBOPEN_CREATEDIRECT);
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (long)MSIDBOPEN_CREATE);
PyModule_AddIntConstant(m, "MSIDBOPEN_DIRECT", (long)MSIDBOPEN_DIRECT);
PyModule_AddIntConstant(m, "MSIDBOPEN_READONLY", (long)MSIDBOPEN_READONLY);
PyModule_AddIntConstant(m, "MSIDBOPEN_TRANSACT", (long)MSIDBOPEN_TRANSACT);
PyModule_AddIntConstant(m, "MSIDBOPEN_PATCHFILE", (long)MSIDBOPEN_PATCHFILE);
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (long)(SIZE_T)MSIDBOPEN_CREATEDIRECT);
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (long)(SIZE_T)MSIDBOPEN_CREATE);
PyModule_AddIntConstant(m, "MSIDBOPEN_DIRECT", (long)(SIZE_T)MSIDBOPEN_DIRECT);
PyModule_AddIntConstant(m, "MSIDBOPEN_READONLY", (long)(SIZE_T)MSIDBOPEN_READONLY);
PyModule_AddIntConstant(m, "MSIDBOPEN_TRANSACT", (long)(SIZE_T)MSIDBOPEN_TRANSACT);
PyModule_AddIntConstant(m, "MSIDBOPEN_PATCHFILE", (long)(SIZE_T)MSIDBOPEN_PATCHFILE);

PyModule_AddIntMacro(m, MSICOLINFO_NAMES);
PyModule_AddIntMacro(m, MSICOLINFO_TYPES);
Expand Down
28 changes: 14 additions & 14 deletions PC/clinic/msvcrtmodule.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,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 *return_value = NULL;
intptr_t handle;
void *handle;
int flags;
long _return_value;

Expand Down Expand Up @@ -148,24 +148,24 @@ 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 *
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 == NULL || _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;
Expand Down Expand Up @@ -426,26 +426,26 @@ 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 *return_value = NULL;
int type;
int file;
long _return_value;
void *file;
void *_return_value;

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 == NULL || _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;
Expand Down Expand Up @@ -569,4 +569,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg)
#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
#define MSVCRT_SET_ERROR_MODE_METHODDEF
#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
/*[clinic end generated code: output=8e9e57c48c4defcc input=a9049054013a1b77]*/
/*[clinic end generated code: output=e86cf578e7f1ffd2 input=a9049054013a1b77]*/
70 changes: 45 additions & 25 deletions PC/msvcrtmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@
#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 == NULL || _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'
Expand All @@ -59,7 +65,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=2b25dc89e9e59534]*/

/*[clinic input]
module msvcrt
Expand Down Expand Up @@ -152,7 +158,7 @@ msvcrt_setmode_impl(PyObject *module, int fd, int flags)
/*[clinic input]
msvcrt.open_osfhandle -> long

handle: intptr_t
handle: HANDLE
flags: int
/

Expand All @@ -164,13 +170,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);
Expand All @@ -179,7 +185,7 @@ msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags)
}

/*[clinic input]
msvcrt.get_osfhandle -> handle
msvcrt.get_osfhandle -> HANDLE

fd: int
/
Expand All @@ -189,9 +195,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;

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

return handle;
return (HANDLE)handle;
}

/* Console I/O */
Expand Down Expand Up @@ -389,25 +395,25 @@ 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.

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;
Expand Down Expand Up @@ -540,6 +546,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)
{
Expand Down Expand Up @@ -568,9 +588,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 */
Expand Down
2 changes: 1 addition & 1 deletion PC/winreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
HKEY retKey;
long rc;

rc = RegCreateKeyExW(key, sub_key, reserved, NULL, (DWORD)NULL,
rc = RegCreateKeyExW(key, sub_key, reserved, NULL, 0,
access, NULL, &retKey, NULL);
if (rc != ERROR_SUCCESS) {
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
Expand Down
1 change: 1 addition & 0 deletions PCbuild/_bz2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<ClCompile>
<AdditionalIncludeDirectories>$(bz2Dir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_FILE_OFFSET_BITS=64;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<BaseAddress>0x1D170000</BaseAddress>
Expand Down
4 changes: 3 additions & 1 deletion PCbuild/_ctypes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
<ClCompile Include="..\Modules\_ctypes\cfield.c" />
<ClCompile Include="..\Modules\_ctypes\libffi_msvc\ffi.c" />
<ClCompile Include="..\Modules\_ctypes\malloc_closure.c" />
<ClCompile Include="..\Modules\_ctypes\libffi_msvc\prep_cif.c" />
<ClCompile Include="..\Modules\_ctypes\libffi_msvc\prep_cif.c">
<DisableSpecificWarnings Condition="'$(Platform)'=='x64'">4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<ClCompile Include="..\Modules\_ctypes\stgdict.c" />
<ClCompile Include="..\Modules\_ctypes\libffi_msvc\win32.c">
<ExcludedFromBuild Condition="'$(Platform)'=='x64'">true</ExcludedFromBuild>
Expand Down
2 changes: 1 addition & 1 deletion PCbuild/liblzma.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<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>
<DisableSpecificWarnings>4028;4113;4244;4267;4996</DisableSpecificWarnings>
<DisableSpecificWarnings>4028;4113;4133;4244;4267;4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions PCbuild/tcl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@
<TclOpts Condition="$(Configuration) == 'Debug'">symbols,msvcrt</TclOpts>
<TclDirs>INSTALLDIR="$(OutDir.TrimEnd(`\`))" INSTALL_DIR="$(OutDir.TrimEnd(`\`))"</TclDirs>
<DebugFlags Condition="'$(Configuration)' == 'Debug'">DEBUGFLAGS="-wd4456 -wd4457 -wd4458 -wd4459 -wd4996"</DebugFlags>
<WarningsFlags>WARNINGS="-W3 -wd4311 -wd4312"</WarningsFlags>
<NMakeBuildCommandLine>setlocal
set VCINSTALLDIR=$(VCInstallDir)
cd /D "$(tclDir)win"
nmake -f makefile.vc MACHINE=$(TclMachine) OPTS=$(TclOpts) $(TclDirs) $(DebugFlags) core shell dlls
nmake -f makefile.vc MACHINE=$(TclMachine) OPTS=$(TclOpts) $(TclDirs) $(DebugFlags) install-binaries install-libraries
nmake -f makefile.vc MACHINE=$(TclMachine) OPTS=$(TclOpts) $(TclDirs) $(DebugFlags) $(WarningsFlags) core shell dlls
nmake -f makefile.vc MACHINE=$(TclMachine) OPTS=$(TclOpts) $(TclDirs) $(DebugFlags) $(WarningsFlags) install-binaries install-libraries
copy /Y ..\license.terms "$(OutDir)\tcllicense.terms"
</NMakeBuildCommandLine>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion PCbuild/tix.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<TixDirs>BUILDDIRTOP="$(BuildDirTop)" TCL_DIR="$(tclDir.TrimEnd(`\`))" TK_DIR="$(tkDir.TrimEnd(`\`))" INSTALL_DIR="$(OutDir.TrimEnd(`\`))"</TixDirs>
<DebugFlags Condition="'$(Configuration)' == 'Debug'">DEBUG=1 NODEBUG=0 TCL_DBGX=g TK_DBGX=g</DebugFlags>
<DebugFlags Condition="'$(Configuration)' != 'Debug'">DEBUG=0 NODEBUG=1</DebugFlags>
<CFlags>-c -W3 -nologo -MD -wd4028 -wd4090</CFlags>
<CFlags>-c -W3 -nologo -MD -wd4028 -wd4090 -wd4244 -wd4267 -wd4312</CFlags>
<NMakeBuildCommandLine>setlocal
set VCINSTALLDIR=$(VCInstallDir)
cd /D "$(tixDir)win"
Expand Down
5 changes: 3 additions & 2 deletions PCbuild/tk.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@
<TkOpts Condition="$(Configuration) == 'Debug'">symbols,msvcrt</TkOpts>
<TkDirs>TCLDIR="$(tclDir.TrimEnd(`\`))" INSTALLDIR="$(OutDir.TrimEnd(`\`))"</TkDirs>
<DebugFlags Condition="'$(Configuration)' == 'Debug'">DEBUGFLAGS="-wd4456 -wd4457 -wd4458 -wd4459 -wd4996"</DebugFlags>
<WarningsFlags>WARNINGS="-W3 -wd4244 -wd4267 -wd4311 -wd4312 -wd4334"</WarningsFlags>
<NMakeBuildCommandLine>setlocal
set VCINSTALLDIR=$(VCInstallDir)
cd /D "$(tkDir)win"
nmake /nologo -f makefile.vc RC=rc MACHINE=$(TclMachine) OPTS=$(TkOpts) $(TkDirs) $(DebugFlags) all
nmake /nologo -f makefile.vc RC=rc MACHINE=$(TclMachine) OPTS=$(TkOpts) $(TkDirs) $(DebugFlags) install-binaries install-libraries
nmake /nologo -f makefile.vc RC=rc MACHINE=$(TclMachine) OPTS=$(TkOpts) $(TkDirs) $(DebugFlags) $(WarningsFlags) all
nmake /nologo -f makefile.vc RC=rc MACHINE=$(TclMachine) OPTS=$(TkOpts) $(TkDirs) $(DebugFlags) $(WarningsFlags) install-binaries install-libraries
copy /Y ..\license.terms "$(OutDir)\tklicense.terms"
</NMakeBuildCommandLine>
</PropertyGroup>
Expand Down