Add an --enable-gcc-warnings option (lifted from Tor) to the configure script. When provided, and when we are using GCC, we enable a bunch of extra GCC warnings in the compiler. Also, make the code all build happily with these warnings.
svn:r553
o The kqueue implementation now restores original signal handlers correctly when its signal events are removed.
o Check return value of event_add in signal.c
o Add a more powerful evbuffer_readln as a replacement for evbuffer_readline. The new function handles more newline styles, and is more useful with buffers that may contain a nul characters.
- o Do not mangle socket handles on 64-bit windows.
-
+ o Do not mangle socket handles on 64-bit windows.
+ o The configure script now takes an --enable-gcc-warnigns option that turns on many optional gcc warnings. (Nick has been building with these for a while, but they might be useful to other developers.)
Changes in 1.4.0:
CFLAGS="$CFLAGS -Wall"
fi
+AC_ARG_ENABLE(gcc-warnings,
+ AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings with GCC))
+
AC_PROG_LIBTOOL
dnl Uncomment "AC_DISABLE_SHARED" to make shared librraries not get
[Define to appropriate substitue if compiler doesnt have __func__])))
+# Add some more warnings which we use in development but not in the
+# released versions. (Some relevant gcc versions can't handle these.)
+if test x$enable_gcc_warnings = xyes; then
+
+ AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
+#if !defined(__GNUC__) || (__GNUC__ < 4)
+#error
+#endif]), have_gcc4=yes, have_gcc4=no)
+
+ AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
+#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+#error
+#endif]), have_gcc42=yes, have_gcc42=no)
+
+ CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast -Wswitch-enum -Werror"
+ CFLAGS="$CFLAGS -Wno-unused-parameter -Wno-sign-compare"
+
+ if test x$have_gcc4 = xyes ; then
+ # These warnings break gcc 3.3.5 and work on gcc 4.0.2
+ CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement"
+ #CFLAGS="$CFLAGS -Wold-style-definition"
+ fi
+
+ if test x$have_gcc42 = xyes ; then
+ # These warnings break gcc 4.0.2 and work on gcc 4.2
+ CFLAGS="$CFLAGS -Waddress -Wnormalized=id -Woverride-init"
+ fi
+
+##This will break the world on some 64-bit architectures
+# CFLAGS="$CFLAGS -Winline"
+
+fi
+
AC_OUTPUT(Makefile test/Makefile sample/Makefile)
/* XXX EVBUFFER_LENGTH returns an unsigned value, so this test
* is always true. What is the intent of this test? -NM */
- if (EVBUFFER_LENGTH(req->output_buffer) >= 0) {
+ if (1) { // || EVBUFFER_LENGTH(req->output_buffer) >= 0) {
/*
* For a request, we add the POST data, for a reply, this
* is the regular data.
poll_del,
poll_recalc,
poll_dispatch,
- poll_dealloc
+ poll_dealloc,
+ 0
};
void *
#include <event.h>
-void
+static void
fifo_read(int fd, short event, void *arg)
{
char buf[255];
#else
struct stat st;
- char *fifo = "event.fifo";
+ const char *fifo = "event.fifo";
int socket;
if (lstat (fifo, &st) == 0) {
int called = 0;
-void
+static void
signal_cb(int fd, short event, void *arg)
{
struct event *signal = arg;
int lasttime;
-void
+static void
timeout_cb(int fd, short event, void *arg)
{
struct timeval tv;
select_del,
select_recalc,
select_dispatch,
- select_dealloc
+ select_dealloc,
+ 0
};
static int select_resize(struct selectop *sop, int fdsz);
-void
+static void
read_cb(int fd, short which, void *arg)
{
int idx = (int) arg, widx = idx + 1;
}
}
-struct timeval *
+static struct timeval *
run_once(void)
{
int *cp, i, space;
int i, c;
struct timeval *tv;
int *cp;
- extern char *optarg;
num_pipes = 100;
num_active = 1;
#define read(fd,buf,len) recv((fd),(buf),(len),0)
#endif
-void
+static void
simple_read_cb(int fd, short event, void *arg)
{
char buf[256];
called++;
}
-void
+static void
simple_write_cb(int fd, short event, void *arg)
{
int len;
test_ok = 1;
}
-void
+static void
multiple_write_cb(int fd, short event, void *arg)
{
struct event *ev = arg;
}
}
-void
+static void
multiple_read_cb(int fd, short event, void *arg)
{
struct event *ev = arg;
}
}
-void
+static void
timeout_cb(int fd, short event, void *arg)
{
struct timeval tv;
test_ok = 1;
}
-void signal_cb_sa(int sig)
+static void
+signal_cb_sa(int sig)
{
test_ok = 2;
}
-void
+static void
signal_cb(int fd, short event, void *arg)
{
struct event *ev = arg;
int nread;
};
-void
+static void
combined_read_cb(int fd, short event, void *arg)
{
struct both *both = arg;
exit(1);
}
-void
+static void
combined_write_cb(int fd, short event, void *arg)
{
struct both *both = arg;
/* Test infrastructure */
-int
-setup_test(char *name)
+static int
+setup_test(const char *name)
{
fprintf(stdout, "%s", name);
return (0);
}
-int
+static int
cleanup_test(void)
{
#ifndef WIN32
return (0);
}
-void
+static void
test_simpleread(void)
{
struct event ev;
cleanup_test();
}
-void
+static void
test_simplewrite(void)
{
struct event ev;
cleanup_test();
}
-void
+static void
test_multiple(void)
{
struct event ev, ev2;
cleanup_test();
}
-void
+static void
test_persistent(void)
{
struct event ev, ev2;
cleanup_test();
}
-void
+static void
test_combined(void)
{
struct both r1, r2, w1, w2;
cleanup_test();
}
-void
+static void
test_simpletimeout(void)
{
struct timeval tv;
}
#ifndef WIN32
-void
+extern struct event_base *current_base;
+static void
test_fork(void)
{
int status;
if ((pid = fork()) == 0) {
/* in the child */
- extern struct event_base *current_base;
if (event_reinit(current_base) == -1) {
fprintf(stderr, "FAILED (reinit)\n");
exit(1);
cleanup_test();
}
-void
+static void
test_simplesignal(void)
{
struct event ev;
cleanup_test();
}
-void
+static void
test_immediatesignal(void)
{
struct event ev;
cleanup_test();
}
-void
+static void
test_signal_dealloc(void)
{
/* make sure that signal_event is event_del'ed and pipe closed */
cleanup_test();
}
-void
+static void
test_signal_pipeloss(void)
{
/* make sure that the base1 pipe is closed correctly. */
* for event mechanisms that use our signal pipe trick. kqueue handles
* signals internally, and all interested kqueues get all the signals.
*/
-void
+static void
test_signal_switchbase(void)
{
struct event ev1, ev2;
* assert that a signal event removed from the event queue really is
* removed - with no possibility of it's parent handler being fired.
*/
-void
-test_signal_assert()
+static void
+test_signal_assert(void)
{
struct event ev;
struct event_base *base = event_init();
/*
* assert that we restore our previous signal handler properly.
*/
-void
-test_signal_restore()
+static void
+test_signal_restore(void)
{
struct event ev;
struct event_base *base = event_init();
}
#endif
-void
+static void
test_free_active_base(void)
{
struct event_base *base1;
cleanup_test();
}
-void
+static void
test_event_base_new(void)
{
struct event_base *base;
cleanup_test();
}
-void
+static void
test_loopexit(void)
{
struct timeval tv, tv_start, tv_end;
test_ok = 0;
}
-void
+static void
test_loopbreak(void)
{
struct event ev1, ev2;
cleanup_test();
}
-void
+static void
test_evbuffer(void) {
struct evbuffer *evb = evbuffer_new();
cleanup_test();
}
-void
+static void
test_evbuffer_readln(void)
{
struct evbuffer *evb = evbuffer_new();
cleanup_test();
}
-void
+static void
test_evbuffer_find(void)
{
u_char* p;
- char* test1 = "1234567890\r\n";
- char* test2 = "1234567890\r";
+ const char* test1 = "1234567890\r\n";
+ const char* test2 = "1234567890\r";
#define EVBUFFER_INITIAL_LENGTH 256
char test3[EVBUFFER_INITIAL_LENGTH];
unsigned int i;
evbuffer_free(buf);
}
-void
+static void
readcb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(bev->input) == 8333) {
}
}
-void
+static void
writecb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(bev->output) == 0)
test_ok++;
}
-void
+static void
errorcb(struct bufferevent *bev, short what, void *arg)
{
test_ok = -2;
}
-void
+static void
test_bufferevent(void)
{
struct bufferevent *bev1, *bev2;
int count;
};
-void
+static void
test_priorities_cb(int fd, short what, void *arg)
{
struct test_pri_event *pri = arg;
event_add(&pri->ev, &tv);
}
-void
+static void
test_priorities(int npriorities)
{
char buf[32];
test_ok |= 2;
}
-void
+static void
test_multiple_events_for_same_fd(void)
{
struct event e1, e2;
int decode_int(uint32_t *pnumber, struct evbuffer *evbuf);
-void
+static void
read_once_cb(int fd, short event, void *arg)
{
char buf[256];
called++;
}
-void
+static void
test_want_only_once(void)
{
struct event ev;
#define TEST_MAX_INT 6
-void
+static void
evtag_int_test(void)
{
struct evbuffer *tmp = evbuffer_new();
fprintf(stdout, "\t%s: OK\n", __func__);
}
-void
+static void
evtag_fuzz(void)
{
u_char buffer[4096];
fprintf(stdout, "OK\n");
}
-void
+static void
rpc_test(void)
{
struct msg *msg, *msg2;
static int dns_ok = 0;
static int dns_err = 0;
-void
+void dns_suite(void);
+
+static void
dns_gethostbyname_cb(int result, char type, int count, int ttl,
void *addresses, void *arg)
{
event_loopexit(NULL);
}
-void
+static void
dns_gethostbyname(void)
{
fprintf(stdout, "Simple DNS resolve: ");
}
}
-void
+static void
dns_gethostbyname6(void)
{
fprintf(stdout, "IPv6 DNS resolve: ");
}
}
-void
+static void
dns_gethostbyaddr(void)
{
struct in_addr in;
}
}
-void
+static void
dns_server_gethostbyname_cb(int result, char type, int count, int ttl,
void *addresses, void *arg)
{
}
}
-void
+static void
dns_server(void)
{
int sock;
/* set if a test needs to call loopexit on a base */
static struct event_base *base;
+void http_suite(void);
+
void http_basic_cb(struct evhttp_request *req, void *arg);
void http_post_cb(struct evhttp_request *req, void *arg);
void http_dispatcher_cb(struct evhttp_request *req, void *arg);
#define NI_MAXSERV 1024
#endif
-int
+static int
http_connect(const char *address, u_short port)
{
/* Stupid code for connecting */
return (fd);
}
-void
+static void
http_readcb(struct bufferevent *bev, void *arg)
{
const char *what = "This is funny";
}
}
-void
+static void
http_writecb(struct bufferevent *bev, void *arg)
{
if (EVBUFFER_LENGTH(bev->output) == 0) {
}
}
-void
+static void
http_errorcb(struct bufferevent *bev, short what, void *arg)
{
test_ok = -2;
evbuffer_free(evb);
}
-void
+static void
http_basic_test(void)
{
struct bufferevent *bev;
int fd;
- char *http_request;
+ const char *http_request;
short port = -1;
test_ok = 0;
void http_request_done(struct evhttp_request *, void *);
-void
+static void
http_connection_test(int persistent)
{
short port = -1;
evbuffer_free(evb);
}
-void
+static void
http_dispatcher_test_done(struct evhttp_request *req, void *arg)
{
const char *what = "DISPATCHER_TEST";
event_loopexit(NULL);
}
-void
+static void
http_dispatcher_test(void)
{
short port = -1;
#define POST_DATA "Okay. Not really printf"
-void
+static void
http_post_test(void)
{
short port = -1;
event_loopexit(NULL);
}
-void
+static void
http_failure_readcb(struct bufferevent *bev, void *arg)
{
const char *what = "400 Bad Request";
/*
* Testing that the HTTP server can deal with a malformed request.
*/
-void
+static void
http_failure_test(void)
{
struct bufferevent *bev;
int fd;
- char *http_request;
+ const char *http_request;
short port = -1;
test_ok = 0;
}
-void
+static void
http_close_detection(void)
{
short port = -1;
fprintf(stdout, "OK\n");
}
-void
+static void
http_highport_test(void)
{
int i = -1;
exit(1);
}
-void
+static void
http_bad_header_test(void)
{
struct evkeyvalq headers;
exit(1);
}
-void
+static void
http_base_test(void)
{
struct bufferevent *bev;
int fd;
- char *http_request;
+ const char *http_request;
short port = -1;
test_ok = 0;
#include "regress.gen.h"
+void rpc_suite(void);
+
extern int test_ok;
static struct evhttp *
static int need_input_hook = 0;
static int need_output_hook = 0;
-void
+static void
MessageCb(EVRPC_STRUCT(Message)* rpc, void *arg)
{
struct kill* kill_reply = rpc->reply;
static EVRPC_STRUCT(NeverReply) *saved_rpc;
-void
+static void
NeverReplyCb(EVRPC_STRUCT(NeverReply)* rpc, void *arg)
{
test_ok += 1;
need_input_hook = 1;
need_output_hook = 1;
- assert(evrpc_add_hook(base, INPUT, rpc_hook_add_header, "input")
+ assert(evrpc_add_hook(base, INPUT, rpc_hook_add_header, (void*)"input")
!= NULL);
- assert(evrpc_add_hook(base, OUTPUT, rpc_hook_add_header, "output")
+ assert(evrpc_add_hook(base, OUTPUT, rpc_hook_add_header, (void*)"output")
!= NULL);
pool = rpc_pool_with_connection(port);
- assert(evrpc_add_hook(pool, INPUT, rpc_hook_remove_header, "output"));
+ assert(evrpc_add_hook(pool, INPUT, rpc_hook_remove_header, (void*)"output"));
/* set up the basic message */
msg = msg_new();
int test_okay = 1;
int called = 0;
-void
+static void
read_cb(int fd, short event, void *arg)
{
char buf[256];
main (int argc, char **argv)
{
struct event ev;
- char *test = "test string";
+ const char *test = "test string";
int pair[2];
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
struct event *ev[NEVENT];
-int
+static int
rand_int(int n)
{
#ifdef WIN32
#endif
}
-void
+static void
time_cb(int fd, short event, void *arg)
{
struct timeval tv;
int test_okay = 1;
int called = 0;
-void
+static void
write_cb(int fd, short event, void *arg)
{
- char *test = "test string";
+ const char *test = "test string";
int len;
len = write(fd, test, strlen(test) + 1);