rktio: use -Wall and fix warnings

This commit is contained in:
Matthew Flatt 2017-06-13 07:17:46 -06:00
parent a929c58712
commit 2f5797f1d5
13 changed files with 81 additions and 68 deletions

View File

@ -3036,6 +3036,11 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu
# If using gcc, we want all warnings:
if test "$CC" = "gcc" ; then
CFLAGS="$CFLAGS -Wall"
fi
if test -n "$ac_tool_prefix"; then
# Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
@ -4188,11 +4193,11 @@ if test "${enable_shared}" = "yes" ; then
fi
fi
AR="${LIBTOOLPROG} --mode=link --tag=CC $CC${need_gcc_static_libgcc}${ar_libtool_no_undefined} -release ${plt_lib_version} -rpath ${abslibdir} \$(ARLIBFLAGS) -o"
AR="${LIBTOOLPROG} --mode=link --tag=CC $CC${need_gcc_static_libgcc}${ar_libtool_no_undefined} -release ${plt_lib_version} \$(ARLIBFLAGS) -o"
STATIC_AR="${LIBTOOLPROG} --mode=link --tag=CC $CC -o"
ARFLAGS=""
RANLIB=":"
RKTLINKER="${LIBTOOLPROG} --mode=link --tag=CC $CC${need_gcc_static_libgcc} -rpath ${abslibdir}"
RKTLINKER="${LIBTOOLPROG} --mode=link --tag=CC $CC${need_gcc_static_libgcc}"
CC="${LIBTOOLPROG} --mode=compile --tag=CC $CC"
LIBSFX=la
LTO="lo"

View File

@ -16,6 +16,11 @@ AC_ARG_ENABLE(shared, [ --enable-shared create shared libraries (ok, b
AC_PROG_CC
# If using gcc, we want all warnings:
if test "$CC" = "gcc" ; then
CFLAGS="$CFLAGS -Wall"
fi
AC_PROG_RANLIB
if test "$AR" = '' ; then
AR="${ac_tool_prefix}ar"

View File

@ -242,7 +242,7 @@ void rktio_poll_add_fs_change(rktio_t *rktio, rktio_fs_change_t *fc, rktio_poll_
void rktio_poll_set_add_nosleep(rktio_t *rktio, rktio_poll_set_t *fds);
#ifdef RKTIO_SYSTEM_WINDOWS
void rktio_poll_set_add_handle(rktio_t *rktio, HANDLE h, rktio_poll_set_t *fds, int repost);
void rktio_poll_set_add_handle(rktio_t *rktio, intptr_t h, rktio_poll_set_t *fds, int repost);
void rktio_poll_set_add_eventmask(rktio_t *rktio, rktio_poll_set_t *fds, int mask);
#endif

View File

@ -1,3 +1,10 @@
#if ((defined(_MSC_VER) || defined(__MINGW32__)) \
&& (defined(__WIN32__) || defined(WIN32) || defined(_WIN32)))
# define RKTIO_SYSTEM_WINDOWS
#else
# define RKTIO_SYSTEM_UNIX
#endif
/* Whether `intptr_t' is available. */
#undef HAVE_INTPTR_T

View File

@ -66,13 +66,13 @@ typedef struct Win_FD_Output_Thread {
works. We still use a thread to detect when the
write has ben flushed, which in turn is needed to
know whether future writes will immediately succeed. */
volatile flushed, needflush; /* Used for non-blocking, only. The flushed
flag communicates from the flush-testing thread
to the main thread. For efficiency, we request
flush checking only when needed (instead of
after every write); needflush indicates that
a flush check is currently needed, but hasn't
been started. */
volatile int flushed, needflush; /* Used for non-blocking, only. The flushed
flag communicates from the flush-testing thread
to the main thread. For efficiency, we request
flush checking only when needed (instead of
after every write); needflush indicates that
a flush check is currently needed, but hasn't
been started. */
volatile int done, err_no;
volatile unsigned int buflen, bufstart, bufend; /* used for blocking, only */
unsigned char *buffer; /* used for blocking, only */
@ -147,7 +147,7 @@ static void init_read_fd(rktio_t *rktio, rktio_fd_t *rfd)
/* Replace buffer with a malloced one: */
bfr = malloc(RKTIO_FD_BUFFSIZE);
rfd->buffer = bfr;
th->buffer = bfr;
th->buffer = (unsigned char *)bfr;
th->fd = rfd->fd;
th->avail = 0;
@ -286,8 +286,6 @@ void rktio_reliably_close(intptr_t s) {
int rktio_close(rktio_t *rktio, rktio_fd_t *rfd)
{
#ifdef RKTIO_SYSTEM_UNIX
int cr;
# ifdef USE_FCNTL_AND_FORK_FOR_FILE_LOCKS
if (!(rfd->modes & RKTIO_OPEN_SOCKET))
release_lockf(rfd->fd);
@ -613,28 +611,28 @@ void rktio_poll_add(rktio_t *rktio, rktio_fd_t *rfd, rktio_poll_set_t *fds, int
if (rfd->th->avail || rfd->th->err || rfd->th->eof) {
/* Data is ready. We shouldn't be trying to sleep, so force an
immediate wake-up: */
rktio_fdset_add_nosleep(fds);
rktio_poll_set_add_nosleep(rktio, fds);
} else {
rfd->th->checking = 1;
ReleaseSemaphore(rfd->th->checking_sema, 1, NULL);
rktio_fdset_add_handle(rfd->th->ready_sema, fds, 1);
rktio_poll_set_add_handle(rktio, (intptr_t)rfd->th->ready_sema, fds, 1);
}
} else
rktio_fdset_add_handle(rfd->th->ready_sema, fds, 1);
rktio_poll_set_add_handle(rktio, (intptr_t)rfd->th->ready_sema, fds, 1);
} else if (rktio_fd_is_regular_file(rktio, rfd)) {
/* regular files never block */
rktio_fdset_add_nosleep(fds);
rktio_poll_set_add_nosleep(rktio, fds);
} else {
/* This case is not currently used. See fd_byte_ready. */
rktio_fdset_add_handle(rfd->fd, fds, 0);
rktio_poll_set_add_handle(rktio, (intptr_t)rfd->fd, fds, 0);
}
}
if (modes & RKTIO_POLL_WRITE) {
if (rfd->oth && !rktio_poll_write_ready(rktio, rfd))
rktio_poll_set_add_handle(rfd->oth->ready_sema, fds, 1);
rktio_poll_set_add_handle(rktio, (intptr_t)rfd->oth->ready_sema, fds, 1);
else
rktio_poll_set_nosleep(fds);
rktio_poll_set_nosleep(rktio, fds);
}
}
#endif

View File

@ -9,12 +9,13 @@
#include <stdlib.h>
#ifdef RKTIO_SYSTEM_UNIX
# include <fcntl.h>
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
# include <pwd.h>
# include <grp.h>
# include <dirent.h>
#endif
#ifdef RKTIO_SYSTEM_WINDOWS
# include <shlobj.h>
# include <direct.h>
#endif
#ifdef RKTIO_SYSTEM_UNIX
@ -108,6 +109,10 @@ static void init_procs()
# define GET_FF_MODDATE(fd) convert_date(&fd.ftLastWriteTime)
# define GET_FF_NAME(fd) fd.cFileName
# define MKDIR_NO_MODE_FLAG
#define is_drive_letter(c) (((unsigned char)c < 128) && isalpha((unsigned char)c))
static time_t convert_date(const FILETIME *ft)
{
LONGLONG l, delta;
@ -418,7 +423,7 @@ static int UNC_stat(rktio_t *rktio, const char *dirname, int *flags, int *isdir,
if (dest) free(dest);
dest_len = len + 1;
dest = malloc(dest_len);
len = GetFinalPathNameByHandleProcW(h, dest, dest_len, rktioFILE_NAME_NORMALIZED);
len = GetFinalPathNameByHandleProc(h, dest, dest_len, rktioFILE_NAME_NORMALIZED);
} while (len > dest_len);
if (!len) {
@ -756,9 +761,8 @@ static int enable_write_permission(rktio_t *rktio, const char *fn)
int rktio_delete_file(rktio_t *rktio, char *fn, int enable_write_on_fail)
{
int errid;
#ifdef RKTIO_SYSTEM_WINDOWS
int errid;
if (DeleteFileW(WIDE_PATH_temp(fn)))
return 1;
errid = GetLastError();
@ -803,7 +807,6 @@ int rktio_rename_file(rktio_t *rktio, char *dest, char *src, int exists_ok)
/* Then we have the great misfortune of running in Windows 9x. If
exists_ok, then do something no less stupid than the OS
itself: */
int errid;
if (exists_ok)
MSC_W_IZE(unlink)(MSC_WIDE_PATH_temp(dest));
if (MoveFileW(src_w, WIDE_PATH_temp(dest))) {
@ -878,7 +881,6 @@ int rktio_make_directory(rktio_t *rktio, char *filename)
set_racket_error(RKTIO_ERROR_UNSUPPORTED);
return 0;
#else
int exists_already = 0;
int len, copied = 0;
/* Make sure path doesn't have trailing separator: */
@ -1226,7 +1228,6 @@ int rktio_set_file_or_directory_permissions(rktio_t *rktio, char *filename, int
# endif
# ifdef RKTIO_SYSTEM_WINDOWS
{
int len = strlen(filename);
int ALWAYS_SET_BITS = ((RKTIO_UNC_READ | RKTIO_UNC_EXEC)
| ((RKTIO_UNC_READ | RKTIO_UNC_EXEC) << 3)
| ((RKTIO_UNC_READ | RKTIO_UNC_EXEC) << 6));
@ -1314,7 +1315,6 @@ rktio_directory_list_t *rktio_directory_list_start(rktio_t *rktio, char *filenam
retry:
{
char *nf;
int is_ssq = 0, is_unc = 0, d, nd;
len = strlen(filename);
pattern = malloc(len + 14);
@ -1347,7 +1347,7 @@ rktio_directory_list_t *rktio_directory_list_start(rktio_t *rktio, char *filenam
nd = 0;
}
}
memcpy(pattern + d, nf + nd, len - nd);
memcpy(pattern + d, filename + nd, len - nd);
len += (d - nd);
if (len && !IS_A_DOS_SEP(pattern[len - 1]))
pattern[len++] = '\\';
@ -1410,7 +1410,6 @@ rktio_directory_list_t *rktio_directory_list_start(rktio_t *rktio, char *filenam
{
rktio_directory_list_t *dl;
DIR *dir;
int nlen;
dir = opendir(filename ? filename : ".");
if (!dir) {
@ -1633,7 +1632,7 @@ char **rktio_filesystem_root_list(rktio_t *rktio)
if (GetDiskFreeSpace(s + ds, &a, &b, &c, &d)) {
if ((ss_count + 1) == ss_len) {
new_ss = malloc(sizeof(char*) * ss_len * 2);
mempcy(ss, new_ss, ss_count * sizeof(char*));
memcpy(ss, new_ss, ss_count * sizeof(char*));
ss = new_ss;
ss_len *= 2;
}
@ -1793,7 +1792,7 @@ char *rktio_system_path(rktio_t *rktio, int which)
{
/* Everything else is in ~: */
char *home_str, *ex_home, *alt_home, *home;
char *home_str, *alt_home, *home;
if ((which == RKTIO_PATH_PREF_DIR)
|| (which == RKTIO_PATH_PREF_FILE)
@ -1905,7 +1904,7 @@ char *rktio_system_path(rktio_t *rktio, int which)
}
if (SHGetSpecialFolderLocation(NULL, which_folder, &items) == S_OK) {
int ok;
int ok;
IMalloc *mi;
wchar_t *buf;
@ -1916,7 +1915,8 @@ char *rktio_system_path(rktio_t *rktio, int which)
mi->lpVtbl->Free(mi, items);
mi->lpVtbl->Release(mi);
home = NARROW_PATH_copy_then_free(buf);
if (ok)
home = NARROW_PATH_copy_then_free(buf);
}
}
@ -1961,7 +1961,7 @@ char *rktio_system_path(rktio_t *rktio, int which)
s = name;
i = wc_strlen(s) - 1;
i = wcslen(s) - 1;
while (i && (s[i] != '\\')) {
--i;

View File

@ -69,7 +69,6 @@ rktio_fs_change_t *rktio_fs_change(rktio_t *rktio, char *path)
{
int ok = 0;
#ifndef NO_FILESYSTEM_CHANGE_EVTS
int errid = 0;
# if defined(HAVE_KQUEUE_SYSCALL)
rktio_ltps_t *lt;
rktio_ltps_handle_t *lth;
@ -219,7 +218,7 @@ void rktio_poll_add_fs_change(rktio_t *rktio, rktio_fs_change_t *fc, rktio_poll_
#if defined(NO_FILESYSTEM_CHANGE_EVTS)
#elif defined(RKTIO_SYSTEM_WINDOWS)
rktio_poll_set_add_handle(rktio, (HANDLE)fc->fd, fds, 0);
rktio_poll_set_add_handle(rktio, fc->fd, fds, 0);
#elif defined(HAVE_INOTIFY_SYSCALL)
int fd;
fd = do_inotify_fd(rktio);

View File

@ -47,10 +47,13 @@ typedef struct rktio_ltps_handle_pair_t {
static rktio_ltps_handle_pair_t *ltps_hash_get(rktio_ltps_t *lt, intptr_t fd);
static void ltps_hash_set(rktio_ltps_t *lt, intptr_t fd, rktio_ltps_handle_pair_t *v);
static void ltps_hash_remove(rktio_ltps_t *lt, intptr_t fd);
static int ltps_is_hash_empty(rktio_ltps_t *lt);
static void ltps_hash_init(rktio_ltps_t *lt);
static void ltps_hash_free(rktio_ltps_t *lt);
#if !defined(HAVE_KQUEUE_SYSCALL) && !defined(HAVE_EPOLL_SYSCALL)
static int ltps_is_hash_empty(rktio_ltps_t *lt);
#endif
/*========================================================================*/
rktio_ltps_handle_pair_t *make_ltps_handle_pair()
@ -363,7 +366,8 @@ rktio_ltps_handle_t *rktio_ltps_add(rktio_t *rktio, rktio_ltps_t *lt, rktio_fd_t
} else
s = NULL;
}
}
} else
s = NULL;
return s;
#endif
@ -710,11 +714,6 @@ static void ltps_hash_set(rktio_ltps_t *lt, intptr_t fd, rktio_ltps_handle_pair_
}
}
static int ltps_is_hash_empty(rktio_ltps_t *lt)
{
return (lt->count == 0);
}
static void ltps_hash_init(rktio_ltps_t *lt)
{
lt->buckets = NULL;
@ -735,3 +734,10 @@ static void ltps_hash_free(rktio_ltps_t *lt)
free(lt->buckets);
}
}
#if !defined(HAVE_KQUEUE_SYSCALL) && !defined(HAVE_EPOLL_SYSCALL)
static int ltps_is_hash_empty(rktio_ltps_t *lt)
{
return (lt->count == 0);
}
#endif

View File

@ -602,7 +602,7 @@ void rktio_poll_add_addrinfo_lookup(rktio_t *rktio, rktio_addrinfo_lookup_t *loo
ghbn_unlock(rktio);
# ifdef RKTIO_SYSTEM_WINDOWS
rktio_poll_set_add_handle(lookup->done_sema, fds, 1);
rktio_poll_set_add_handle(rktio, (intptr_t)lookup->done_sema, fds, 1);
# else
{
rktio_poll_set_t *fds2;
@ -704,7 +704,6 @@ rktio_addrinfo_lookup_t *rktio_start_addrinfo_lookup(rktio_t *rktio,
{
rktio_addrinfo_lookup_t *lookup;
char buf[32], *service;
int err;
struct rktio_addrinfo_t *hints;
if (portno >= 0) {
@ -1109,7 +1108,6 @@ static rktio_connect_t *try_connect(rktio_t *rktio, rktio_connect_t *conn);
rktio_connect_t *rktio_start_connect(rktio_t *rktio, rktio_addrinfo_t *dest, rktio_addrinfo_t *src)
{
rktio_connect_t *conn;
int errid;
#ifdef USE_TCP
TCP_INIT("tcp-connect");
@ -1266,13 +1264,9 @@ static int get_no_portno(rktio_t *rktio, rktio_socket_t socket);
rktio_listener_t *rktio_listen(rktio_t *rktio, rktio_addrinfo_t *src, int backlog, int reuse)
{
#ifdef RKTIO_TCP_LISTEN_IPV6_ONLY_SOCKOPT
int no_ipv6 = 0;
#endif
{
rktio_addrinfo_t *addr;
int err, count = 0, pos = 0, i;
int count = 0, pos = 0;
rktio_listener_t *l = NULL;
#ifdef RKTIO_TCP_LISTEN_IPV6_ONLY_SOCKOPT
int any_v4 = 0, any_v6 = 0;
@ -1564,7 +1558,8 @@ void rktio_poll_add_receive(rktio_t *rktio, rktio_listener_t *listener, rktio_po
rktio_fd_t *rktio_accept(rktio_t *rktio, rktio_listener_t *listener)
{
int was_closed = 0, errid, ready_pos;
int
ready_pos;
rktio_socket_t s, ls;
unsigned int l;
char tcp_accept_addr[RKTIO_SOCK_NAME_MAX_LEN];
@ -1958,6 +1953,8 @@ int rktio_udp_change_multicast_group(rktio_t *rktio, rktio_fd_t *rfd,
optname = IP_ADD_MEMBERSHIP;
else if (action == RKTIO_DROP_MEMBERSHIP)
optname = IP_DROP_MEMBERSHIP;
else
optname = 0;
status = setsockopt(s, IPPROTO_IP, optname, (void *) &mreq, mreq_len);

View File

@ -525,8 +525,9 @@ int rktio_get_fd_limit(rktio_poll_set_t *fds)
return 0;
}
void rktio_poll_set_add_handle(HANDLE h, rktio_poll_set_t *fds, int repost)
void rktio_poll_set_add_handle(rktio_t *rktio, intptr_t _h, rktio_poll_set_t *fds, int repost)
{
HANDLE h = (HANDLE)_h;
rktio_poll_set_t *efd = fds;
HANDLE *hs;
int i, new_i, *rps;

View File

@ -1,10 +1,3 @@
#if ((defined(_MSC_VER) || defined(__MINGW32__)) \
&& (defined(__WIN32__) || defined(WIN32) || defined(_WIN32)))
# define RKTIO_SYSTEM_WINDOWS
#else
# define RKTIO_SYSTEM_UNIX
#endif
#if defined(__APPLE__) && defined(__MACH__) && !defined(OS_X)
# define OS_X
#endif

View File

@ -830,7 +830,7 @@ void rktio_poll_add_process(rktio_t *rktio, rktio_process_t *sp, rktio_poll_set_
}
#ifdef RKTIO_SYSTEM_WINDOWS
rktio_poll_set_add_handle(rktio, sp->handle, fds, 0);
rktio_poll_set_add_handle(rktio, (intptr_t)sp->handle, fds, 0);
#endif
}
@ -1239,12 +1239,11 @@ rktio_process_result_t *rktio_process(rktio_t *rktio,
{
rktio_process_result_t *result;
intptr_t to_subprocess[2], from_subprocess[2], err_subprocess[2];
int i, pid, errid;
int pid, errid;
#if defined(RKTIO_SYSTEM_UNIX)
# if !defined(CENTRALIZED_SIGCHILD)
System_Child *sc;
# endif
int fork_errno = 0;
#else
void *sc = 0;
#endif
@ -1255,9 +1254,12 @@ rktio_process_result_t *rktio_process(rktio_t *rktio,
#endif
int new_process_group = (flags & RKTIO_PROCESS_NEW_GROUP);
int stderr_is_stdout = (flags & RKTIO_PROCESS_STDOUT_AS_STDERR);
#if defined(RKTIO_SYSTEM_WINDOWS)
int windows_exact_cmdline = (flags & RKTIO_PROCESS_WINDOWS_EXACT_CMDLINE);
int windows_chain_termination_to_child = (flags & RKTIO_PROCESS_WINDOWS_CHAIN_TERMINATION);
int i;
#endif
/* avoid compiler warnings: */
to_subprocess[0] = -1;
to_subprocess[1] = -1;

View File

@ -312,7 +312,7 @@ char *rktio_convert_from_wchar(const wchar_t *ws, int free_given)
intptr_t len, l;
char *s;
l = wc_slen(ws) + 1; /* add nul terminator */
l = wcslen(ws) + 1; /* add nul terminator */
len = utf16ish_to_utf8ish((unsigned short *)ws, l, NULL);