Commit 4d28b39f authored by Matti Picus's avatar Matti Picus
Browse files

use /W3 /WX to turn warnings into errors and fix a batch of them

The rpython changes will need backporting

--HG--
branch : compilation_warnings
parent a8cf9fb1fc4b
Pipeline #21793 failed with stage
in 1 minute and 1 second
......@@ -306,13 +306,15 @@ class W_WinConsoleIO(W_RawIOBase):
name = rffi.utf82wcharp(space.utf8_w(w_path), pathlen)
self.handle = win32traits.CreateFile(name,
rwin32.ALL_READ_WRITE, rwin32.SHARE_READ_WRITE,
rffi.NULL, win32traits.OPEN_EXISTING,
lltype.nullptr(rwin32.LPSECURITY_ATTRIBUTES.TO),
win32traits.OPEN_EXISTING,
0, rffi.cast(rwin32.HANDLE, 0))
if self.handle == rwin32.INVALID_HANDLE_VALUE:
self.handle = win32traits.CreateFile(name,
access,
rwin32.SHARE_READ_WRITE,
rffi.NULL, win32traits.OPEN_EXISTING,
lltype.nullptr(rwin32.LPSECURITY_ATTRIBUTES.TO),
win32traits.OPEN_EXISTING,
0, rffi.cast(rwin32.HANDLE, 0))
lltype.free(name, flavor='raw')
......
......@@ -125,7 +125,7 @@ but the handle is not closed. You would call this function when you
need the underlying win32 handle to exist beyond the lifetime of the
handle object."""
key = self.as_int()
self.hkey = rwin32.NULL_HANDLE
self.hkey = lltype.nullptr(rwin32.HKEY.TO)
return space.newint(key)
......@@ -200,7 +200,7 @@ closed when the hkey object is destroyed by Python."""
if ret != 0:
raiseWindowsError(space, ret, 'RegCloseKey')
if isinstance(w_hkey, W_HKEY):
space.interp_w(W_HKEY, w_hkey).hkey = rwin32.NULL_HANDLE
space.interp_w(W_HKEY, w_hkey).hkey = lltype.nullptr(rwin32.HKEY.TO)
def FlushKey(space, w_hkey):
......
......@@ -1236,7 +1236,7 @@ def attach_c_functions(space, eci, prefix):
)
state.C.flag_setters = {}
for c_name, attr in _flags:
_, setter = rffi.CExternVariable(rffi.SIGNED, c_name, eci_flags,
_, setter = rffi.CExternVariable(rffi.INT, c_name, eci_flags,
_nowrapper=True, c_type='int')
state.C.flag_setters[attr] = setter
......
......@@ -30,7 +30,7 @@ eci = ExternalCompilationInfo(
separate_module_sources=[separate_module_source])
pypy_GetFinalPathNameByHandle = rffi.llexternal(
'pypy_GetFinalPathNameByHandle',
[rffi.VOIDP, rwin32.HANDLE, rffi.CWCHARP, rwin32.DWORD, rwin32.DWORD],
[rffi.VOIDP, rwin32.HANDLE, rwin32.LPSTR, rwin32.DWORD, rwin32.DWORD],
rwin32.DWORD, compilation_info=eci)
......@@ -98,7 +98,8 @@ def make__getfinalpathname_impl(traits):
raise LLNotImplemented("GetFinalPathNameByHandle not available on "
"this platform")
hFile = win32traits.CreateFile(traits.as_str0(path), 0, 0, None,
hFile = win32traits.CreateFile(traits.as_str0(path), 0, 0,
lltype.nullptr(rwin32.LPSECURITY_ATTRIBUTES.TO),
win32traits.OPEN_EXISTING,
win32traits.FILE_FLAG_BACKUP_SEMANTICS,
rwin32.NULL_HANDLE)
......@@ -109,7 +110,7 @@ def make__getfinalpathname_impl(traits):
try:
usize = win32traits.GetFinalPathNameByHandle(
hFile,
lltype.nullptr(traits.CCHARP.TO),
rffi.cast(rwin32.LPSTR, 0),
rffi.cast(rwin32.DWORD, 0),
VOLUME_NAME_DOS)
if usize == 0:
......@@ -119,7 +120,7 @@ def make__getfinalpathname_impl(traits):
with rffi.scoped_alloc_unicodebuffer(size + 1) as buf:
result = win32traits.GetFinalPathNameByHandle(
hFile,
buf.raw,
rffi.cast(rwin32.LPSTR, buf.raw),
usize,
VOLUME_NAME_DOS)
if result == 0:
......
......@@ -211,6 +211,7 @@ class CallbackData(W_Root):
SETTERS = {}
for index, (name, params) in enumerate(HANDLERS.items()):
print 'parsing HANDLER', name, params
arg_names = ['arg%d' % (i,) for i in range(len(params))]
warg_names = ['w_arg%d' % (i,) for i in range(len(params))]
......@@ -235,10 +236,13 @@ for index, (name, params) in enumerate(HANDLERS.items()):
elif ARG == rffi.CCHARP:
converters.append(
'w_arg%d = parser.w_convert_charp(space, arg%d)' % (i, i))
elif ARG == rffi.CONST_CCHARP:
converters.append(
'w_arg%d = parser.w_convert_ccharp(space, arg%d)' % (i, i))
elif ARG == INTERNED_CCHARP:
converters.append(
'w_arg%d = parser.w_convert_interned(space, arg%d)' % (i, i))
ARG = rffi.CCHARP
ARG = rffi.CONST_CCHARP
elif ARG == lltype.Ptr(XML_Content):
converters.append(
'w_arg%d = parser.w_convert_model(space, arg%d)' % (i, i))
......@@ -324,7 +328,7 @@ def UnknownEncodingHandlerData_callback(ll_userdata, name, info):
space = userdata.space
parser = userdata.parser()
name = rffi.charp2str(name)
name = rffi.constcharp2str(name)
try:
parser.UnknownEncodingHandler(space, name, info)
......@@ -337,7 +341,7 @@ def UnknownEncodingHandlerData_callback(ll_userdata, name, info):
result = 1
return rffi.cast(rffi.INT, result)
callback_type = lltype.Ptr(lltype.FuncType(
[rffi.VOIDP, rffi.CCHARP, XML_Encoding_Ptr], rffi.INT))
[rffi.VOIDP, rffi.CONST_CCHARP, XML_Encoding_Ptr], rffi.INT))
XML_SetUnknownEncodingHandler = expat_external(
'XML_SetUnknownEncodingHandler',
[XML_Parser, callback_type, rffi.VOIDP], lltype.Void)
......@@ -378,7 +382,7 @@ XML_GetErrorCode = expat_external(
'XML_GetErrorCode', [XML_Parser], rffi.INT)
XML_ErrorString = expat_external(
'XML_ErrorString', [rffi.INT],
rffi.CCHARP)
rffi.CONST_CCHARP)
XML_GetCurrentLineNumber = expat_external(
'XML_GetCurrentLineNumber', [XML_Parser], rffi.INT)
XML_GetErrorLineNumber = XML_GetCurrentLineNumber
......@@ -494,10 +498,16 @@ getting the advantage of providing document type information to the parser.
else:
return space.w_None
def w_convert_ccharp(self, space, data):
if data:
return self.w_convert(space, rffi.constcharp2str(data))
else:
return space.w_None
def w_convert_interned(self, space, data):
if not data:
return space.w_None
w_data = self.w_convert_charp(space, data)
w_data = self.w_convert_ccharp(space, rffi.cast(rffi.CONST_CCHARP, data))
if not self.w_intern:
return w_data
......@@ -711,7 +721,7 @@ information passed to the ExternalEntityRefHandler."""
# Error management
def set_error(self, space, code):
err = rffi.charp2strn(XML_ErrorString(code), 200)
err = rffi.constcharp2str(XML_ErrorString(code))[:200]
lineno = XML_GetCurrentLineNumber(self.itself)
colno = XML_GetCurrentColumnNumber(self.itself)
msg = "%s: line %d, column %d" % (err, lineno, colno)
......@@ -867,5 +877,5 @@ Return a new XML parser object."""
def ErrorString(space, code):
"""ErrorString(errno) -> string
Returns string error for given number."""
return space.newtext(rffi.charp2str(XML_ErrorString(code)))
return space.newtext(rffi.constcharp2str(XML_ErrorString(code)))
......@@ -21,7 +21,7 @@ def test_build():
parser = interp_pyexpat.XML_ParserCreate("test")
interp_pyexpat.XML_ParserFree(parser)
res = interp_pyexpat.XML_ErrorString(3)
os.write(1, rffi.charp2str(res))
os.write(1, rffi.constcharp2str(res))
return 0
t = TranslationContext()
......
......@@ -56,8 +56,9 @@ if _WIN32:
libraries = ('ws2_32',)
calling_conv = 'win'
header_lines = [
'#include <WinSock2.h>',
'#include <WS2tcpip.h>',
'#define WIN32_LEAN_AND_MEAN',
'#include <winsock2.h>',
'#include <Ws2tcpip.h>',
# winsock2 defines AF_UNIX, but not sockaddr_un
'#undef AF_UNIX',
]
......@@ -135,6 +136,11 @@ class CConfig:
WSAEAFNOSUPPORT = platform.DefinedConstantInteger('WSAEAFNOSUPPORT')
EISCONN = platform.DefinedConstantInteger('EISCONN')
WSAEISCONN = platform.DefinedConstantInteger('WSAEISCONN')
LPWSAOVERLAPPED = platform.SimpleType(
"LPWSAOVERLAPPED", rffi.CCHARP)
LPWSAOVERLAPPED_COMPLETION_ROUTINE = platform.SimpleType(
"LPWSAOVERLAPPED_COMPLETION_ROUTINE", rffi.CCHARP)
constant_names = '''
AF_AAL5 AF_APPLETALK AF_ASH AF_ATMPVC AF_ATMSVC AF_AX25 AF_BLUETOOTH AF_BRIDGE
AD_DECnet AF_ECONET AF_INET AF_INET6 AF_IPX AF_IRDA AF_KEY AF_LLC AF_NETBEUI
......@@ -1192,8 +1198,13 @@ getaddrinfo = external('getaddrinfo', [CCHARP, CCHARP,
addrinfo_ptr,
lltype.Ptr(rffi.CArray(addrinfo_ptr))], rffi.INT)
freeaddrinfo = external('freeaddrinfo', [addrinfo_ptr], lltype.Void)
getnameinfo = external('getnameinfo', [sockaddr_ptr, socklen_t, CCHARP,
size_t, CCHARP, size_t, rffi.INT], rffi.INT)
if _WIN32:
from rpython.rlib import rwin32
getnameinfo = external('getnameinfo', [sockaddr_ptr, socklen_t, CCHARP,
rwin32.DWORD, CCHARP, rwin32.DWORD, rffi.INT], rffi.INT)
else:
getnameinfo = external('getnameinfo', [sockaddr_ptr, socklen_t, CCHARP,
size_t, CCHARP, size_t, rffi.INT], rffi.INT)
if sys.platform.startswith("openbsd") or sys.platform.startswith("darwin"):
htonl = external('htonl', [rffi.UINT], rffi.UINT, releasegil=False, macro=True)
......@@ -1270,8 +1281,11 @@ freeccharp = jit.dont_look_inside(rffi.llexternal("free_ptr_to_charp",
[rffi.CCHARPP],rffi.INT,save_err=SAVE_ERR,compilation_info=compilation_info))
freesignedp = jit.dont_look_inside(rffi.llexternal("free_pointer_to_signedp",
[rffi.SIGNEDPP],rffi.INT,save_err=SAVE_ERR,compilation_info=compilation_info))
send = external('send', [socketfd_type, rffi.CCHARP, size_t, rffi.INT],
if WIN32:
send = external('send', [socketfd_type, rffi.CCHARP, rffi.INT, rffi.INT],
rffi.INT, save_err=SAVE_ERR)
else:
send = external('send', [socketfd_type, rffi.CCHARP, size_t, rffi.INT],
ssize_t, save_err=SAVE_ERR)
sendto = external('sendto', [socketfd_type, rffi.VOIDP, size_t, rffi.INT,
sockaddr_ptr, socklen_t], ssize_t,
......@@ -1362,7 +1376,8 @@ elif WIN32:
[socketfd_type, rwin32.DWORD,
rffi.VOIDP, rwin32.DWORD,
rffi.VOIDP, rwin32.DWORD,
rwin32.LPDWORD, rffi.VOIDP, rffi.VOIDP],
rwin32.LPDWORD, cConfig.LPWSAOVERLAPPED,
cConfig.LPWSAOVERLAPPED_COMPLETION_ROUTINE],
rffi.INT, save_err=SAVE_ERR)
WSAPROTOCOL_INFOW = cConfig.WSAPROTOCOL_INFOW
......
......@@ -45,14 +45,14 @@ if _WIN32:
#include <stdio.h>
#include <windows.h>
/* Get the module where the "fopen" function resides in */
/* Get the module where the "fopen_s" function resides in */
RPY_EXTERN
HMODULE pypy_get_libc_handle(void) {
MEMORY_BASIC_INFORMATION mi;
char buf[1000];
memset(&mi, 0, sizeof(mi));
if( !VirtualQueryEx(GetCurrentProcess(), &fopen, &mi, sizeof(mi)) )
if( !VirtualQueryEx(GetCurrentProcess(), &fopen_s, &mi, sizeof(mi)) )
return (HMODULE)0;
GetModuleFileName((HMODULE)mi.AllocationBase, buf, 500);
......
......@@ -11,6 +11,7 @@ from rpython.rlib.rstring import StringBuilder
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rtyper.tool import rffi_platform as platform
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rlib._os_support import UNDERSCORE_ON_WIN32
includes = ['stdio.h', 'sys/types.h']
if os.name == "posix":
......@@ -57,11 +58,11 @@ NEWLINE_CRLF = 4
def llexternal(*args, **kwargs):
return rffi.llexternal(*args, compilation_info=eci, **kwargs)
c_fopen = llexternal('fopen', [rffi.CCHARP, rffi.CCHARP], FILEP,
c_fopen = llexternal(UNDERSCORE_ON_WIN32 + 'fopen', [rffi.CCHARP, rffi.CCHARP], FILEP,
save_err=rffi.RFFI_SAVE_ERRNO)
c_popen = llexternal('popen', [rffi.CCHARP, rffi.CCHARP], FILEP,
save_err=rffi.RFFI_SAVE_ERRNO)
c_fdopen = llexternal(('_' if os.name == 'nt' else '') + 'fdopen',
c_fdopen = llexternal(UNDERSCORE_ON_WIN32 + 'fdopen',
[rffi.INT, rffi.CCHARP], FILEP,
save_err=rffi.RFFI_SAVE_ERRNO)
c_tmpfile = llexternal('tmpfile', [], FILEP,
......
......@@ -796,9 +796,14 @@ def getfullpathname(path):
result = rstring.assert_str0(result)
return result
c_getcwd = external(UNDERSCORE_ON_WIN32 + 'getcwd',
[rffi.CCHARP, rffi.SIZE_T], rffi.CCHARP,
save_err=rffi.RFFI_SAVE_ERRNO)
if _WIN32:
c_getcwd = external(UNDERSCORE_ON_WIN32 + 'getcwd',
[rffi.CCHARP, rffi.INT], rffi.CCHARP,
save_err=rffi.RFFI_SAVE_ERRNO)
else:
c_getcwd = external(UNDERSCORE_ON_WIN32 + 'getcwd',
[rffi.CCHARP, rffi.SIZE_T], rffi.CCHARP,
save_err=rffi.RFFI_SAVE_ERRNO)
c_wgetcwd = external(UNDERSCORE_ON_WIN32 + 'wgetcwd',
[rffi.CWCHARP, rffi.SIZE_T], rffi.CWCHARP,
save_err=rffi.RFFI_SAVE_ERRNO)
......@@ -808,6 +813,7 @@ def getcwd():
bufsize = 256
while True:
buf = lltype.malloc(rffi.CCHARP.TO, bufsize, flavor='raw')
# bufsize is annotated as Unsigned
res = c_getcwd(buf, bufsize)
if res:
break # ok
......@@ -1565,7 +1571,8 @@ def utime(path, times):
path = traits.as_str0(path)
hFile = win32traits.CreateFile(path,
win32traits.FILE_WRITE_ATTRIBUTES, 0,
None, win32traits.OPEN_EXISTING,
lltype.nullptr(rwin32.LPSECURITY_ATTRIBUTES.TO),
win32traits.OPEN_EXISTING,
win32traits.FILE_FLAG_BACKUP_SEMANTICS,
rwin32.NULL_HANDLE)
if hFile == rwin32.INVALID_HANDLE_VALUE:
......@@ -1743,7 +1750,7 @@ def tmpnam():
#___________________________________________________________________
c_getpid = external('getpid', [], rffi.PID_T,
c_getpid = external(UNDERSCORE_ON_WIN32 + 'getpid', [], rffi.PID_T,
releasegil=False, save_err=rffi.RFFI_SAVE_ERRNO)
c_getppid = external('getppid', [], rffi.PID_T,
releasegil=False, save_err=rffi.RFFI_SAVE_ERRNO)
......
......@@ -134,6 +134,7 @@ def winexternal(name, args, result, **kwds):
if WIN32:
HANDLE = rffi.COpaquePtr(typedef='HANDLE')
HKEY = rffi.COpaquePtr(typedef='HKEY')
assert rffi.cast(HANDLE, -1) == rffi.cast(HANDLE, -1)
LPHANDLE = rffi.CArrayPtr(HANDLE)
......@@ -258,11 +259,11 @@ if WIN32:
raise WindowsError(ERROR_INVALID_HANDLE, "Invalid file handle")
return handle
_open_osfhandle = rffi.llexternal('_open_osfhandle', [rffi.INTP, rffi.INT], rffi.INT)
_open_osfhandle = rffi.llexternal('_open_osfhandle', [rffi.INTPTR_T, rffi.INT], rffi.INT)
def open_osfhandle(handle, flags):
from rpython.rlib.rposix import FdValidator
fd = _open_osfhandle(handle, flags)
fd = _open_osfhandle(rffi.cast(rffi.INTPTR_T, handle), flags)
with FdValidator(fd):
return fd
......
......@@ -45,7 +45,7 @@ def external(name, args, result, **kwds):
return rffi.llexternal(name, args, result, compilation_info=eci,
calling_conv='win', **kwds)
HKEY = rwin32.HANDLE
HKEY = rwin32.HKEY
PHKEY = rffi.CArrayPtr(HKEY)
REGSAM = rwin32.DWORD
......@@ -84,7 +84,7 @@ def get_traits(suffix):
RegCreateKeyEx = external(
'RegCreateKeyEx' + suffix,
[HKEY, strp, rwin32.DWORD, strp, rwin32.DWORD,
REGSAM, rffi.VOIDP, PHKEY, rwin32.LPDWORD],
REGSAM, rwin32.LPSECURITY_ATTRIBUTES, PHKEY, rwin32.LPDWORD],
rffi.LONG)
RegDeleteValue = external(
......
......@@ -1371,6 +1371,9 @@ class _abstract_ptr(object):
# None is acceptable for any pointer
elif isinstance(ARG, Ptr) and a is None:
pass
elif isinstance(a, int) and typeOf(a) is Signed:
# 64-bit windows: allow silent casting bare int to signed
pass
# Any pointer is convertible to void*
elif ARG is rffi.VOIDP and isinstance(typeOf(a), Ptr):
pass
......
......@@ -174,7 +174,7 @@
to an unsigned integer, which is also what CPython's ord()
does. */
#define OP_CAST_UNICHAR_TO_INT(x,r) r = ((unsigned int)(x))
#define OP_CAST_INT_TO_UNICHAR(x,r) r = (x)
#define OP_CAST_INT_TO_UNICHAR(x,r) r = ((wchar_t)(x))
/* bool operations */
......
......@@ -174,7 +174,7 @@ class MsvcPlatform(Platform):
if _find_executable('jom.exe'):
make = 'jom.exe'
cflags = ('/MD', '/O2', '/FS', '/Zi')
cflags = ('/MD', '/O2', '/FS', '/Zi', '-D_CRT_SECURE_NO_WARNINGS')
# allow >2GB address space, set stack to 3MB (1MB is too small)
link_flags = ('/nologo', '/debug','/LARGEADDRESSAWARE',
'/STACK:3145728', '/MANIFEST:EMBED')
......@@ -375,7 +375,6 @@ class MsvcPlatform(Platform):
('LINKFILES', eci.link_files),
('MASM', self.masm),
('MAKE', 'nmake.exe'),
('_WIN32', '1'),
]
if shared:
definitions.insert(0, ('WTARGET', wtarget_name.basename))
......@@ -503,6 +502,7 @@ class MsvcPlatform(Platform):
'echo #include "stdlib.h" >> $@.tmp',
'echo #include "windows.h" >> $@.tmp',
'echo int $(PYPY_MAIN_FUNCTION)(int, char*[]); >> $@.tmp',
'echo #pragma warning(disable : 4100) >> $@.tmp',
'echo int WINAPI WinMain( >> $@.tmp',
'echo HINSTANCE hInstance, /* handle to current instance */ >> $@.tmp',
'echo HINSTANCE hPrevInstance, /* handle to previous instance */ >> $@.tmp',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment