From 19ddfb317fc57239cc4f7144683c060bdb8317e7 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sun, 24 May 2020 15:13:05 +0200 Subject: [PATCH] [Ada] Fix warnings in C runtime files on Windows gcc/ada/ * adaint.h (__gnat_expect_portable_execvp): Fix prototype. (__gnat_expect_poll): Likewise. * expect.c [_WIN32]: Include adaint.h file. (__gnat_waitpid): Remove useless variable. (__gnat_expect_portable_execvp): Add ATTRIBUTE_UNUSED on parameter. * raise-gcc.c [SEH] (__gnat_personality_v0): Add ATTRIBUTE_UNUSED. * socket.c [_WIN32] (__gnat_getservbyport): Add ATTRIBUTE_UNUSED on a couple of parameters. (__gnat_gethostbyname): Likewise. (__gnat_gethostbyaddr): Likewise. (__gnat_getservbyname): Likewise. (__gnat_last_socket_in_set): Use variables local to loops. (__gnat_socket_ioctl): Cast 3rd parameter to proper type if _WIN32. (__gnat_inet_pton): Cast 2nd parameter to proper type if _WIN32. * sysdep.c (__gnat_localtime_tzoff): Remove superfluous test. * terminals.c [_WIN32]: Include io.h file. (is_gui_app): Remove useless variables and fix unsigned comparison. (nt_spawnve): Add ATTRIBUTE_UNUSED on first parameter. Initialize a local variable and remove others that are useless. Add missing cast (__gnat_setup_child_communication): Remove useless variable and call Use proper formatting string in call to sprintf. (__gnat_setup_parent_communication): Cast to proper type. (find_child_console): Fix prototype and remove useless variable. (find_process_handle): Likewise. (_gnat_interrupt_process): Move to after __gnat_interrupt_pid. (__gnat_reset_tty): Add ATTRIBUTE_UNUSED on parameter, remove return (__gnat_setup_winsize): Add ATTRIBUTE_UNUSED on all parameters. --- gcc/ada/adaint.h | 5 ++- gcc/ada/expect.c | 7 ++-- gcc/ada/raise-gcc.c | 2 +- gcc/ada/socket.c | 26 ++++++------ gcc/ada/sysdep.c | 2 +- gcc/ada/terminals.c | 97 ++++++++++++++++++++------------------------- 6 files changed, 64 insertions(+), 75 deletions(-) diff --git a/gcc/ada/adaint.h b/gcc/ada/adaint.h index e20e8d4d580..4f42f6c658d 100644 --- a/gcc/ada/adaint.h +++ b/gcc/ada/adaint.h @@ -282,9 +282,10 @@ extern char *mktemp (char *); extern void __gnat_set_exit_status (int); extern int __gnat_expect_fork (void); -extern void __gnat_expect_portable_execvp (char *, char *[]); +extern void __gnat_expect_portable_execvp (int *, char *, char *[]); extern int __gnat_pipe (int *); -extern int __gnat_expect_poll (int *, int, int, int *); +extern int __gnat_expect_poll (int *, int, int, int *, + int *); extern void __gnat_set_binary_mode (int); extern void __gnat_set_text_mode (int); extern void __gnat_set_mode (int,int); diff --git a/gcc/ada/expect.c b/gcc/ada/expect.c index add455c86a6..718886d96bd 100644 --- a/gcc/ada/expect.c +++ b/gcc/ada/expect.c @@ -78,6 +78,7 @@ #include #include #include +#include "adaint.h" #include "mingw32.h" int @@ -85,11 +86,10 @@ __gnat_waitpid (int pid) { HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid); DWORD exitcode = 1; - DWORD res; if (h != NULL) { - res = WaitForSingleObject (h, INFINITE); + (void) WaitForSingleObject (h, INFINITE); GetExitCodeProcess (h, &exitcode); CloseHandle (h); } @@ -105,7 +105,8 @@ __gnat_expect_fork (void) } void -__gnat_expect_portable_execvp (int *pid, char *cmd, char *argv[]) +__gnat_expect_portable_execvp (int *pid, char *cmd ATTRIBUTE_UNUSED, + char *argv[]) { *pid = __gnat_portable_no_block_spawn (argv); } diff --git a/gcc/ada/raise-gcc.c b/gcc/ada/raise-gcc.c index 559a42f15d2..1446bfaaeb7 100644 --- a/gcc/ada/raise-gcc.c +++ b/gcc/ada/raise-gcc.c @@ -1611,7 +1611,7 @@ __gnat_personality_seh0 (PEXCEPTION_RECORD ms_exc, void *this_frame, /* Define __gnat_personality_v0 for convenience */ -PERSONALITY_STORAGE _Unwind_Reason_Code +PERSONALITY_STORAGE ATTRIBUTE_UNUSED _Unwind_Reason_Code __gnat_personality_v0 (version_arg_t version_arg, phases_arg_t phases_arg, _Unwind_Exception_Class uw_exception_class, diff --git a/gcc/ada/socket.c b/gcc/ada/socket.c index dd73c6ab613..96baebfc25a 100644 --- a/gcc/ada/socket.c +++ b/gcc/ada/socket.c @@ -333,8 +333,8 @@ __gnat_getservbyport (int port, const char *proto, } #else int -__gnat_gethostbyname (const char *name, - struct hostent *ret, char *buf, size_t buflen, +__gnat_gethostbyname (const char *name, struct hostent *ret, + char *buf ATTRIBUTE_UNUSED, size_t buflen ATTRIBUTE_UNUSED, int *h_errnop) { struct hostent *rh; @@ -349,8 +349,8 @@ __gnat_gethostbyname (const char *name, } int -__gnat_gethostbyaddr (const char *addr, int len, int type, - struct hostent *ret, char *buf, size_t buflen, +__gnat_gethostbyaddr (const char *addr, int len, int type, struct hostent *ret, + char *buf ATTRIBUTE_UNUSED, size_t buflen ATTRIBUTE_UNUSED, int *h_errnop) { struct hostent *rh; @@ -365,8 +365,8 @@ __gnat_gethostbyaddr (const char *addr, int len, int type, } int -__gnat_getservbyname (const char *name, const char *proto, - struct servent *ret, char *buf, size_t buflen) +__gnat_getservbyname (const char *name, const char *proto, struct servent *ret, + char *buf ATTRIBUTE_UNUSED, size_t buflen ATTRIBUTE_UNUSED) { struct servent *rh; rh = getservbyname (name, proto); @@ -377,8 +377,8 @@ __gnat_getservbyname (const char *name, const char *proto, } int -__gnat_getservbyport (int port, const char *proto, - struct servent *ret, char *buf, size_t buflen) +__gnat_getservbyport (int port, const char *proto, struct servent *ret, + char *buf ATTRIBUTE_UNUSED, size_t buflen ATTRIBUTE_UNUSED) { struct servent *rh; rh = getservbyport (port, proto); @@ -397,19 +397,18 @@ __gnat_getservbyport (int port, const char *proto, void __gnat_last_socket_in_set (fd_set *set, int *last) { - int s; int l; l = -1; #ifdef _WIN32 /* More efficient method for NT. */ - for (s = 0; s < set->fd_count; s++) + for (unsigned int s = 0; s < set->fd_count; s++) if ((int) set->fd_array[s] > l) l = set->fd_array[s]; #else - for (s = *last; s != -1; s--) + for (int s = *last; s != -1; s--) if (FD_ISSET (s, set)) { l = s; @@ -517,7 +516,7 @@ __gnat_get_h_errno (void) { int __gnat_socket_ioctl (int fd, IOCTL_Req_T req, int *arg) { #if defined (_WIN32) - return ioctlsocket (fd, req, arg); + return ioctlsocket (fd, req, (unsigned long *)arg); #elif defined (__APPLE__) /* * On Darwin, req is an unsigned long, and we want to convert without sign @@ -553,7 +552,8 @@ __gnat_inet_pton (int af, const char *src, void *dst) { int rc; ss.ss_family = af; - rc = WSAStringToAddressA (src, af, NULL, (struct sockaddr *)&ss, &sslen); + rc = WSAStringToAddressA ((char *)src, af, NULL, (struct sockaddr *)&ss, + &sslen); if (rc == 0) { switch (af) { case AF_INET: diff --git a/gcc/ada/sysdep.c b/gcc/ada/sysdep.c index 3f96c5fa633..51ffbd5545e 100644 --- a/gcc/ada/sysdep.c +++ b/gcc/ada/sysdep.c @@ -703,7 +703,7 @@ __gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off) to get timezone settings that depend on the year. We cannot use them as we still support Windows XP and Windows 2003. */ - status = (tzi_status >= 0 && tzi_status <= 2) + status = tzi_status <= 2 && FileTimeToSystemTime (&utc_time.ft_time, &utc_sys_time) && SystemTimeToTzSpecificLocalTime (&tzi, &utc_sys_time, &local_sys_time) && SystemTimeToFileTime (&local_sys_time, &local_time.ft_time); diff --git a/gcc/ada/terminals.c b/gcc/ada/terminals.c index a46923e963c..81388a7771b 100644 --- a/gcc/ada/terminals.c +++ b/gcc/ada/terminals.c @@ -153,6 +153,7 @@ __gnat_setup_winsize (void *desc ATTRIBUTE_UNUSED, #include #include +#include #define MAXPATHLEN 1024 @@ -194,9 +195,6 @@ is_gui_app (char *exe) { HANDLE hImage; - DWORD bytes; - DWORD iSection; - DWORD SectionOffset; DWORD CoffHeaderOffset; DWORD MoreDosHeader[16]; CHAR *file; @@ -207,7 +205,6 @@ is_gui_app (char *exe) IMAGE_DOS_HEADER image_dos_header; IMAGE_FILE_HEADER image_file_header; IMAGE_OPTIONAL_HEADER image_optional_header; - IMAGE_SECTION_HEADER image_section_header; /* * Open the reference file. @@ -264,7 +261,7 @@ is_gui_app (char *exe) */ CoffHeaderOffset = AbsoluteSeek(hImage, image_dos_header.e_lfanew) + sizeof(ULONG); - if (CoffHeaderOffset < 0) { + if (CoffHeaderOffset == (DWORD) -1) { CloseHandle (hImage); return -1; } @@ -278,9 +275,6 @@ is_gui_app (char *exe) return -1; } - SectionOffset = CoffHeaderOffset + IMAGE_SIZEOF_FILE_HEADER + - IMAGE_SIZEOF_NT_OPTIONAL_HEADER; - ReadBytes(hImage, &image_file_header, IMAGE_SIZEOF_FILE_HEADER); /* @@ -351,18 +345,18 @@ ReadBytes (HANDLE hFile, LPVOID buffer, DWORD size) } static int -nt_spawnve (char *exe, char **argv, char *env, struct TTY_Process *process) +nt_spawnve (char *exe ATTRIBUTE_UNUSED, char **argv, char *env, + struct TTY_Process *process) { STARTUPINFO start; SECURITY_ATTRIBUTES sec_attrs; SECURITY_DESCRIPTOR sec_desc; DWORD flags; - char dir[ MAXPATHLEN ]; int pid; int is_gui, use_cmd; char *cmdline, *parg, **targ; int do_quoting = 0; - char escape_char; + char escape_char = 0; int arglen; /* we have to do some conjuring here to put argv and envp into the @@ -483,12 +477,8 @@ nt_spawnve (char *exe, char **argv, char *env, struct TTY_Process *process) if (need_quotes) { int escape_char_run = 0; - char * first; - char * last; p = *targ; - first = p; - last = p + strlen (p) - 1; *parg++ = '"'; for ( ; *p; p++) { @@ -572,8 +562,8 @@ nt_spawnve (char *exe, char **argv, char *env, struct TTY_Process *process) flags, env, NULL, &start, &process->procinfo)) goto EH_Fail; - pid = (int) process->procinfo.hProcess; - process->pid=pid; + pid = (int) (intptr_t) process->procinfo.hProcess; + process->pid = pid; return pid; @@ -635,7 +625,6 @@ __gnat_setup_child_communication int Use_Pipes) { int cpid; - HANDLE parent; SECURITY_ATTRIBUTES sec_attrs; char slavePath [MAX_PATH]; char **nargv; @@ -644,8 +633,6 @@ __gnat_setup_child_communication char pipeNameIn[100]; HANDLE hSlaveInDrv = NULL; /* Handle to communicate with slave driver */ - parent = GetCurrentProcess (); - /* Set inheritance for the pipe handles */ sec_attrs.nLength = sizeof (SECURITY_ATTRIBUTES); sec_attrs.bInheritHandle = TRUE; @@ -674,7 +661,7 @@ __gnat_setup_child_communication /* We create a named pipe for Input, as we handle input by sending special commands to the explaunch process, that uses it to feed the actual input of the process */ - sprintf(pipeNameIn, "%sIn%08x_%08x", EXP_PIPE_BASENAME, + sprintf(pipeNameIn, "%sIn%08lx_%08x", EXP_PIPE_BASENAME, GetCurrentProcessId(), pipeNameId); pipeNameId++; @@ -765,8 +752,8 @@ __gnat_setup_parent_communication int* err, int* pid) { - *in = _open_osfhandle ((long) process->w_infd, 0); - *out = _open_osfhandle ((long) process->w_outfd, 0); + *in = _open_osfhandle ((intptr_t) process->w_infd, 0); + *out = _open_osfhandle ((intptr_t) process->w_outfd, 0); /* child's stderr is always redirected to outfd */ *err = *out; *pid = process->pid; @@ -811,13 +798,13 @@ cache_system_info (void) os_subtype = OS_NT; } -static BOOL CALLBACK -find_child_console (HWND hwnd, child_process * cp) +static WINBOOL CALLBACK +find_child_console (HWND hwnd, LPARAM param) { - DWORD thread_id; + child_process *cp = (child_process *) param; DWORD process_id; - thread_id = GetWindowThreadProcessId (hwnd, &process_id); + (void) GetWindowThreadProcessId (hwnd, &process_id); if (process_id == cp->procinfo->dwProcessId) { char window_class[32]; @@ -836,27 +823,6 @@ find_child_console (HWND hwnd, child_process * cp) return TRUE; } -int -__gnat_interrupt_process (struct TTY_Process* p) -{ - char buf[2]; - DWORD written; - BOOL bret; - - if (p->usePipe == TRUE) { - bret = FALSE; - } else { - buf[0] = EXP_SLAVE_KILL; - buf[1] = EXP_KILL_CTRL_C; - bret = WriteFile (p->w_infd, buf, 2, &written, NULL); - } - - if (bret == FALSE) { - return __gnat_interrupt_pid (p->procinfo.dwProcessId); - } - return 0; -} - int __gnat_interrupt_pid (int pid) { @@ -943,6 +909,27 @@ __gnat_interrupt_pid (int pid) return rc; } +int +__gnat_interrupt_process (struct TTY_Process* p) +{ + char buf[2]; + DWORD written; + BOOL bret; + + if (p->usePipe == TRUE) { + bret = FALSE; + } else { + buf[0] = EXP_SLAVE_KILL; + buf[1] = EXP_KILL_CTRL_C; + bret = WriteFile (p->w_infd, buf, 2, &written, NULL); + } + + if (bret == FALSE) { + return __gnat_interrupt_pid (p->procinfo.dwProcessId); + } + return 0; +} + /* kill a process, as this implementation use CreateProcess on Win32 we need to use Win32 TerminateProcess API */ int @@ -974,13 +961,13 @@ typedef struct { HANDLE hwnd; } pid_struct; -static BOOL CALLBACK -find_process_handle (HWND hwnd, pid_struct * ps) +static WINBOOL CALLBACK +find_process_handle (HWND hwnd, LPARAM param) { - DWORD thread_id; + pid_struct *ps = (pid_struct *) param; DWORD process_id; - thread_id = GetWindowThreadProcessId (hwnd, &process_id); + (void) GetWindowThreadProcessId (hwnd, &process_id); if (process_id == ps->dwProcessId) { ps->hwnd = hwnd; @@ -1085,9 +1072,8 @@ __gnat_new_tty (void) } void -__gnat_reset_tty (TTY_Handle* t) +__gnat_reset_tty (TTY_Handle* t ATTRIBUTE_UNUSED) { - return; } void @@ -1097,7 +1083,8 @@ __gnat_close_tty (TTY_Handle* t) } void -__gnat_setup_winsize (void *desc, int rows, int columns) +__gnat_setup_winsize (void *desc ATTRIBUTE_UNUSED, + int rows ATTRIBUTE_UNUSED, int columns ATTRIBUTE_UNUSED) { } -- 2.30.2