Skip to content

Commit

Permalink
Compile without warnings on mingw64
Browse files Browse the repository at this point in the history
This is mostly a matter of catching cases where we were still
assuming that evutil_socket_t could be used as an int.
  • Loading branch information
nmathewson committed Nov 1, 2012
1 parent 2479d96 commit 94866c2
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 67 deletions.
48 changes: 26 additions & 22 deletions event.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ HT_GENERATE(event_debug_map, event_debug_entry, node, hash_debug_entry,
} else { \
event_errx(_EVENT_ERR_ABORT, \
"%s: noting an add on a non-setup event %p" \
" (events: 0x%x, fd: %d, flags: 0x%x)", \
" (events: 0x%x, fd: "EV_SOCK_FMT \
", flags: 0x%x)", \
__func__, (ev), (ev)->ev_events, \
(ev)->ev_fd, (ev)->ev_flags); \
EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \
} \
EVLOCK_UNLOCK(_event_debug_map_lock, 0); \
} \
Expand All @@ -260,9 +261,10 @@ HT_GENERATE(event_debug_map, event_debug_entry, node, hash_debug_entry,
} else { \
event_errx(_EVENT_ERR_ABORT, \
"%s: noting a del on a non-setup event %p" \
" (events: 0x%x, fd: %d, flags: 0x%x)", \
" (events: 0x%x, fd: "EV_SOCK_FMT \
", flags: 0x%x)", \
__func__, (ev), (ev)->ev_events, \
(ev)->ev_fd, (ev)->ev_flags); \
EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \
} \
EVLOCK_UNLOCK(_event_debug_map_lock, 0); \
} \
Expand All @@ -278,9 +280,10 @@ HT_GENERATE(event_debug_map, event_debug_entry, node, hash_debug_entry,
if (!dent) { \
event_errx(_EVENT_ERR_ABORT, \
"%s called on a non-initialized event %p" \
" (events: 0x%x, fd: %d, flags: 0x%x)", \
" (events: 0x%x, fd: "EV_SOCK_FMT\
", flags: 0x%x)", \
__func__, (ev), (ev)->ev_events, \
(ev)->ev_fd, (ev)->ev_flags); \
EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \
} \
EVLOCK_UNLOCK(_event_debug_map_lock, 0); \
} \
Expand All @@ -296,9 +299,10 @@ HT_GENERATE(event_debug_map, event_debug_entry, node, hash_debug_entry,
if (dent && dent->added) { \
event_errx(_EVENT_ERR_ABORT, \
"%s called on an already added event %p" \
" (events: 0x%x, fd: %d, flags: 0x%x)", \
" (events: 0x%x, fd: "EV_SOCK_FMT", " \
"flags: 0x%x)", \
__func__, (ev), (ev)->ev_events, \
(ev)->ev_fd, (ev)->ev_flags); \
EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \
} \
EVLOCK_UNLOCK(_event_debug_map_lock, 0); \
} \
Expand Down Expand Up @@ -2026,9 +2030,9 @@ event_add_internal(struct event *ev, const struct timeval *tv,
_event_debug_assert_is_setup(ev);

event_debug((
"event_add: event: %p (fd %d), %s%s%scall %p",
"event_add: event: %p (fd "EV_SOCK_FMT"), %s%s%scall %p",
ev,
(int)ev->ev_fd,
EV_SOCK_ARG(ev->ev_fd),
ev->ev_events & EV_READ ? "EV_READ " : " ",
ev->ev_events & EV_WRITE ? "EV_WRITE " : " ",
tv ? "EV_TIMEOUT " : " ",
Expand Down Expand Up @@ -2190,8 +2194,8 @@ event_del_internal(struct event *ev)
struct event_base *base;
int res = 0, notify = 0;

event_debug(("event_del: %p (fd %d), callback %p",
ev, (int)ev->ev_fd, ev->ev_callback));
event_debug(("event_del: %p (fd "EV_SOCK_FMT"), callback %p",
ev, EV_SOCK_ARG(ev->ev_fd), ev->ev_callback));

/* An event without a base has not been added */
if (ev->ev_base == NULL)
Expand Down Expand Up @@ -2281,8 +2285,8 @@ event_active_nolock(struct event *ev, int res, short ncalls)
{
struct event_base *base;

event_debug(("event_active: %p (fd %d), res %d, callback %p",
ev, (int)ev->ev_fd, (int)res, ev->ev_callback));
event_debug(("event_active: %p (fd "EV_SOCK_FMT"), res %d, callback %p",
ev, EV_SOCK_ARG(ev->ev_fd), (int)res, ev->ev_callback));


/* We get different kinds of events, add them together */
Expand Down Expand Up @@ -2496,8 +2500,8 @@ event_queue_remove(struct event_base *base, struct event *ev, int queue)
EVENT_BASE_ASSERT_LOCKED(base);

if (!(ev->ev_flags & queue)) {
event_errx(1, "%s: %p(fd %d) not on queue %x", __func__,
ev, ev->ev_fd, queue);
event_errx(1, "%s: %p(fd "EV_SOCK_FMT") not on queue %x", __func__,
ev, EV_SOCK_ARG(ev->ev_fd), queue);
return;
}

Expand Down Expand Up @@ -2570,8 +2574,8 @@ event_queue_insert(struct event_base *base, struct event *ev, int queue)
if (queue & EVLIST_ACTIVE)
return;

event_errx(1, "%s: %p(fd %d) already on queue %x", __func__,
ev, ev->ev_fd, queue);
event_errx(1, "%s: %p(fd "EV_SOCK_FMT") already on queue %x", __func__,
ev, EV_SOCK_ARG(ev->ev_fd), queue);
return;
}

Expand Down Expand Up @@ -2822,8 +2826,8 @@ event_base_dump_events(struct event_base *base, FILE *output)
int i;
fprintf(output, "Inserted events:\n");
TAILQ_FOREACH(e, &base->eventqueue, ev_next) {
fprintf(output, " %p [fd %ld]%s%s%s%s%s\n",
(void*)e, (long)e->ev_fd,
fprintf(output, " %p [fd "EV_SOCK_FMT"]%s%s%s%s%s\n",
(void*)e, EV_SOCK_ARG(e->ev_fd),
(e->ev_events&EV_READ)?" Read":"",
(e->ev_events&EV_WRITE)?" Write":"",
(e->ev_events&EV_SIGNAL)?" Signal":"",
Expand All @@ -2836,8 +2840,8 @@ event_base_dump_events(struct event_base *base, FILE *output)
continue;
fprintf(output, "Active events [priority %d]:\n", i);
TAILQ_FOREACH(e, &base->eventqueue, ev_next) {
fprintf(output, " %p [fd %ld]%s%s%s%s\n",
(void*)e, (long)e->ev_fd,
fprintf(output, " %p [fd "EV_SOCK_FMT"]%s%s%s%s\n",
(void*)e, EV_SOCK_ARG(e->ev_fd),
(e->ev_res&EV_READ)?" Read active":"",
(e->ev_res&EV_WRITE)?" Write active":"",
(e->ev_res&EV_SIGNAL)?" Signal active":"",
Expand Down
6 changes: 4 additions & 2 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,8 @@ evhttp_read_header(struct evhttp_connection *evcon,
break;

default:
event_warnx("%s: bad header on %d", __func__, fd);
event_warnx("%s: bad header on "EV_SOCK_FMT, __func__,
EV_SOCK_ARG(fd));
evhttp_connection_fail(evcon, EVCON_HTTP_INVALID_HEADER);
break;
}
Expand Down Expand Up @@ -3742,7 +3743,8 @@ evhttp_get_request(struct evhttp *http, evutil_socket_t fd,

evcon = evhttp_get_request_connection(http, fd, sa, salen);
if (evcon == NULL) {
event_sock_warn(fd, "%s: cannot get connection on %d", __func__, fd);
event_sock_warn(fd, "%s: cannot get connection on "EV_SOCK_FMT,
__func__, EV_SOCK_ARG(fd));
evutil_closesocket(fd);
return;
}
Expand Down
6 changes: 3 additions & 3 deletions sample/event-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <event.h>

static void
fifo_read(int fd, short event, void *arg)
fifo_read(evutil_socket_t fd, short event, void *arg)
{
char buf[255];
int len;
Expand All @@ -42,7 +42,7 @@ fifo_read(int fd, short event, void *arg)
event_add(ev, NULL);

fprintf(stderr, "fifo_read called with fd: %d, event: %d, arg: %p\n",
fd, event, arg);
(int)fd, event, arg);
#ifdef WIN32
len = ReadFile((HANDLE)fd, buf, sizeof(buf) - 1, &dwBytesRead, NULL);

Expand Down Expand Up @@ -126,7 +126,7 @@ main(int argc, char **argv)

/* Initalize one event */
#ifdef WIN32
event_set(&evfifo, (int)socket, EV_READ, fifo_read, &evfifo);
event_set(&evfifo, (evutil_socket_t)socket, EV_READ, fifo_read, &evfifo);
#else
event_set(&evfifo, socket, EV_READ, fifo_read, &evfifo);
#endif
Expand Down
3 changes: 1 addition & 2 deletions sample/signal-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ main(int argc, char **argv)
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD(2, 2);

err = WSAStartup(wVersionRequested, &wsaData);
(void) WSAStartup(wVersionRequested, &wsaData);
#endif

/* Initalize the event library */
Expand Down
3 changes: 1 addition & 2 deletions sample/time-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ main(int argc, char **argv)
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD(2, 2);

err = WSAStartup(wVersionRequested, &wsaData);
(void)WSAStartup(wVersionRequested, &wsaData);
#endif

if (argc == 2 && !strcmp(argv[1], "-p")) {
Expand Down
12 changes: 6 additions & 6 deletions test/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@
#include <evutil.h>

static int count, writes, fired;
static int *pipes;
static evutil_socket_t *pipes;
static int num_pipes, num_active, num_writes;
static struct event *events;


static void
read_cb(evutil_socket_t fd, short which, void *arg)
{
long idx = (long) arg, widx = idx + 1;
ev_intptr_t idx = (ev_intptr_t) arg, widx = idx + 1;
u_char ch;

count += recv(fd, (char*)&ch, sizeof(ch), 0);
Expand All @@ -85,14 +85,14 @@ read_cb(evutil_socket_t fd, short which, void *arg)
static struct timeval *
run_once(void)
{
int *cp, space;
evutil_socket_t *cp, space;
long i;
static struct timeval ts, te;

for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
if (event_initialized(&events[i]))
event_del(&events[i]);
event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (void *) i);
event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (void *)(ev_intptr_t) i);
event_add(&events[i], NULL);
}

Expand Down Expand Up @@ -130,7 +130,7 @@ main(int argc, char **argv)
#endif
int i, c;
struct timeval *tv;
int *cp;
evutil_socket_t *cp;

#ifdef WIN32
WSADATA WSAData;
Expand Down Expand Up @@ -165,7 +165,7 @@ main(int argc, char **argv)
#endif

events = calloc(num_pipes, sizeof(struct event));
pipes = calloc(num_pipes * 2, sizeof(int));
pipes = calloc(num_pipes * 2, sizeof(evutil_socket_t));
if (events == NULL || pipes == NULL) {
perror("malloc");
exit(1);
Expand Down
18 changes: 10 additions & 8 deletions test/bench_cascade.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@
*/

static int fired;
static int *pipes;
static evutil_socket_t *pipes;
static struct event *events;

static void
read_cb(evutil_socket_t fd, short which, void *arg)
{
char ch;
long idx = (long) arg;
evutil_socket_t sock = (evutil_socket_t)(ev_intptr_t)arg;

recv(fd, &ch, sizeof(ch), 0);
if (idx >= 0) {
if (send(idx, "e", 1, 0) < 0)
if (sock >= 0) {
if (send(sock, "e", 1, 0) < 0)
perror("send");
}
fired++;
Expand All @@ -80,11 +80,12 @@ read_cb(evutil_socket_t fd, short which, void *arg)
static struct timeval *
run_once(int num_pipes)
{
int *cp, i;
int i;
evutil_socket_t *cp;
static struct timeval ts, te, tv_timeout;

events = calloc(num_pipes, sizeof(struct event));
pipes = calloc(num_pipes * 2, sizeof(int));
pipes = calloc(num_pipes * 2, sizeof(evutil_socket_t));

if (events == NULL || pipes == NULL) {
perror("malloc");
Expand All @@ -106,8 +107,9 @@ run_once(int num_pipes)
tv_timeout.tv_sec = 60;

for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
long fd = i < num_pipes - 1 ? cp[3] : -1;
event_set(&events[i], cp[0], EV_READ, read_cb, (void *) fd);
evutil_socket_t fd = i < num_pipes - 1 ? cp[3] : -1;
event_set(&events[i], cp[0], EV_READ, read_cb,
(void *)(ev_intptr_t)fd);
event_add(&events[i], &tv_timeout);
}

Expand Down
4 changes: 3 additions & 1 deletion test/regress_bufferevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include "event2/util.h"

#include "bufferevent-internal.h"
#include "util-internal.h"
#ifdef WIN32
#include "iocp-internal.h"
#endif
Expand Down Expand Up @@ -557,7 +558,8 @@ want_fail_eventcb(struct bufferevent *bev, short what, void *ctx)
if (what & BEV_EVENT_ERROR) {
s = bufferevent_getfd(bev);
err = evutil_socket_error_to_string(evutil_socket_geterror(s));
TT_BLATHER(("connection failure on %d: %s", s, err));
TT_BLATHER(("connection failure on "EV_SOCK_FMT": %s",
EV_SOCK_ARG(s), err));
test_ok = 1;
} else {
TT_FAIL(("didn't fail? what %hd", what));
Expand Down
6 changes: 3 additions & 3 deletions test/regress_dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ dns_gethostbyname_cb(int result, char type, int count, int ttl,
if (ttl < 0)
goto out;
for (i = 0; i < count; ++i) {
const char *b = inet_ntop(AF_INET6, &in6_addrs[i], buf,sizeof(buf));
const char *b = evutil_inet_ntop(AF_INET6, &in6_addrs[i], buf,sizeof(buf));
if (b)
TT_BLATHER(("%s ", b));
else
Expand Down Expand Up @@ -325,7 +325,7 @@ dns_server_gethostbyname_cb(int result, char type, int count, int ttl,
char buf[INET6_ADDRSTRLEN+1];
if (memcmp(&in6_addrs[0].s6_addr, "abcdefghijklmnop", 16)
|| ttl != 123) {
const char *b = inet_ntop(AF_INET6, &in6_addrs[0],buf,sizeof(buf));
const char *b = evutil_inet_ntop(AF_INET6, &in6_addrs[0],buf,sizeof(buf));
printf("Bad IPv6 response \"%s\" %d. ", b, ttl);
dns_ok = 0;
goto out;
Expand Down Expand Up @@ -1244,7 +1244,7 @@ test_getaddrinfo_async(void *arg)
memset(&local_outcome, 0, sizeof(local_outcome));
r = evdns_getaddrinfo(dns_base, "www.google.com", "80",
&hints, gai_cb, &local_outcome);
tt_int_op(r,==,0);
tt_ptr_op(r,==,NULL);
tt_int_op(local_outcome.err,==,EVUTIL_EAI_NONAME);
tt_ptr_op(local_outcome.ai,==,NULL);

Expand Down
3 changes: 1 addition & 2 deletions test/regress_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,10 @@ main(int argc, const char **argv)
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD(2, 2);

err = WSAStartup(wVersionRequested, &wsaData);
(void) WSAStartup(wVersionRequested, &wsaData);
#endif

#ifndef WIN32
Expand Down
4 changes: 2 additions & 2 deletions test/regress_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ eventcb(struct bufferevent *bev, short what, void *ctx)
static void
open_ssl_bufevs(struct bufferevent **bev1_out, struct bufferevent **bev2_out,
struct event_base *base, int is_open, int flags, SSL *ssl1, SSL *ssl2,
int *fd_pair, struct bufferevent **underlying_pair)
evutil_socket_t *fd_pair, struct bufferevent **underlying_pair)
{
int state1 = is_open ? BUFFEREVENT_SSL_OPEN :BUFFEREVENT_SSL_CONNECTING;
int state2 = is_open ? BUFFEREVENT_SSL_OPEN :BUFFEREVENT_SSL_ACCEPTING;
Expand Down Expand Up @@ -273,7 +273,7 @@ regress_bufferevent_openssl(void *arg)
const int filter = strstr((char*)data->setup_data, "filter")!=NULL;
int flags = BEV_OPT_DEFER_CALLBACKS;
struct bufferevent *bev_ll[2] = { NULL, NULL };
int *fd_pair = NULL;
evutil_socket_t *fd_pair = NULL;

tt_assert(cert);
tt_assert(key);
Expand Down
2 changes: 1 addition & 1 deletion test/regress_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ test_evutil_getaddrinfo(void *arg)
hints.ai_flags = EVUTIL_AI_NUMERICHOST;
r = evutil_getaddrinfo("www.google.com", "80", &hints, &ai);
tt_int_op(r, ==, EVUTIL_EAI_NONAME);
tt_int_op(ai, ==, NULL);
tt_ptr_op(ai, ==, NULL);

/* Try symbolic service names wit AI_NUMERICSERV */
memset(&hints, 0, sizeof(hints));
Expand Down
Loading

0 comments on commit 94866c2

Please sign in to comment.