More msvc build tweaks.

svn:r1262
This commit is contained in:
Nick Mathewson 2009-05-01 00:54:14 +00:00
parent b2e8fd0e41
commit e865eb938c
8 changed files with 67 additions and 35 deletions

View File

@ -202,7 +202,7 @@
/* #undef _EVENT_HAVE_SYS_MMAN_H */ /* #undef _EVENT_HAVE_SYS_MMAN_H */
/* Define to 1 if you have the <sys/param.h> header file. */ /* Define to 1 if you have the <sys/param.h> header file. */
#define _EVENT_HAVE_SYS_PARAM_H 1 /* #define _EVENT_HAVE_SYS_PARAM_H 1 */
/* Define to 1 if you have the <sys/queue.h> header file. */ /* Define to 1 if you have the <sys/queue.h> header file. */
/* #undef _EVENT_HAVE_SYS_QUEUE_H */ /* #undef _EVENT_HAVE_SYS_QUEUE_H */
@ -332,6 +332,6 @@
#define _EVENT_socklen_t unsigned int #define _EVENT_socklen_t unsigned int
/* Define to `int' if <sys/types.h> does not define. */ /* Define to `int' if <sys/types.h> does not define. */
#define _EVENT_ssize_t SSIZE_T #define _EVENT_ssize_t intptr_t
#endif #endif

View File

@ -32,6 +32,7 @@
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h> #include <winsock2.h>
#include <windows.h> #include <windows.h>
#include <io.h>
#endif #endif
#ifdef _EVENT_HAVE_VASPRINTF #ifdef _EVENT_HAVE_VASPRINTF
@ -839,27 +840,28 @@ evbuffer_pullup(struct evbuffer *buf, ssize_t size)
chain = buf->first; chain = buf->first;
if (size == -1) if (size < 0)
size = buf->total_len; size = buf->total_len;
/* if size > buf->total_len, we cannot guarantee to the user that she /* if size > buf->total_len, we cannot guarantee to the user that she
* is going to have a long enough buffer afterwards; so we return * is going to have a long enough buffer afterwards; so we return
* NULL */ * NULL */
if (size == 0 || size > buf->total_len) if (size == 0 || (size_t)size > buf->total_len)
goto done; goto done;
/* No need to pull up anything; the first size bytes are /* No need to pull up anything; the first size bytes are
* already here. */ * already here. */
if (chain->off >= size) { if (chain->off >= (size_t)size) {
result = chain->buffer + chain->misalign; result = chain->buffer + chain->misalign;
goto done; goto done;
} }
/* Make sure that none of the chains we need to copy from is pinned. */ /* Make sure that none of the chains we need to copy from is pinned. */
remaining = size - chain->off; remaining = size - chain->off;
assert(remaining >= 0);
for (tmp=chain->next; tmp; tmp=tmp->next) { for (tmp=chain->next; tmp; tmp=tmp->next) {
if (CHAIN_PINNED(tmp)) if (CHAIN_PINNED(tmp))
goto done; goto done;
if (tmp->off >= remaining) if (tmp->off >= (size_t)remaining)
break; break;
remaining -= tmp->off; remaining -= tmp->off;
} }
@ -875,7 +877,7 @@ evbuffer_pullup(struct evbuffer *buf, ssize_t size)
tmp->off = size; tmp->off = size;
size -= old_off; size -= old_off;
chain = chain->next; chain = chain->next;
} else if (chain->buffer_len - chain->misalign >= size) { } else if (chain->buffer_len - chain->misalign >= (size_t)size) {
/* already have enough space in the first chain */ /* already have enough space in the first chain */
size_t old_off = chain->off; size_t old_off = chain->off;
buffer = chain->buffer + chain->misalign + chain->off; buffer = chain->buffer + chain->misalign + chain->off;
@ -896,7 +898,7 @@ evbuffer_pullup(struct evbuffer *buf, ssize_t size)
/* TODO(niels): deal with buffers that point to NULL like sendfile */ /* TODO(niels): deal with buffers that point to NULL like sendfile */
/* Copy and free every chunk that will be entirely pulled into tmp */ /* Copy and free every chunk that will be entirely pulled into tmp */
for (; chain != NULL && size >= chain->off; chain = next) { for (; chain != NULL && (size_t)size >= chain->off; chain = next) {
next = chain->next; next = chain->next;
memcpy(buffer, chain->buffer + chain->misalign, chain->off); memcpy(buffer, chain->buffer + chain->misalign, chain->off);
@ -946,7 +948,8 @@ static inline int
evbuffer_strchr(struct evbuffer_iterator *it, const char chr) evbuffer_strchr(struct evbuffer_iterator *it, const char chr)
{ {
struct evbuffer_chain *chain = it->chain; struct evbuffer_chain *chain = it->chain;
int i = it->off, count = 0; unsigned i = it->off;
int count = 0;
while (chain != NULL) { while (chain != NULL) {
char *buffer = (char *)chain->buffer + chain->misalign; char *buffer = (char *)chain->buffer + chain->misalign;
for (; i < chain->off; ++i, ++count) { for (; i < chain->off; ++i, ++count) {
@ -967,7 +970,8 @@ static inline int
evbuffer_strpbrk(struct evbuffer_iterator *it, const char *chrset) evbuffer_strpbrk(struct evbuffer_iterator *it, const char *chrset)
{ {
struct evbuffer_chain *chain = it->chain; struct evbuffer_chain *chain = it->chain;
int i = it->off, count = 0; unsigned i = it->off;
int count = 0;
while (chain != NULL) { while (chain != NULL) {
char *buffer = (char *)chain->buffer + chain->misalign; char *buffer = (char *)chain->buffer + chain->misalign;
for (; i < chain->off; ++i, ++count) { for (; i < chain->off; ++i, ++count) {
@ -989,7 +993,7 @@ evbuffer_strpbrk(struct evbuffer_iterator *it, const char *chrset)
static inline int static inline int
evbuffer_strspn( evbuffer_strspn(
struct evbuffer_chain *chain, int i, const char *chrset) struct evbuffer_chain *chain, unsigned i, const char *chrset)
{ {
int count = 0; int count = 0;
while (chain != NULL) { while (chain != NULL) {
@ -1017,7 +1021,7 @@ evbuffer_getchr(struct evbuffer_iterator *it, char *pchr)
struct evbuffer_chain *chain = it->chain; struct evbuffer_chain *chain = it->chain;
int off = it->off; int off = it->off;
while (off >= chain->off) { while ((size_t)off >= chain->off) {
off -= chain->off; off -= chain->off;
chain = chain->next; chain = chain->next;
if (chain == NULL) if (chain == NULL)
@ -1153,7 +1157,7 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
buf->total_len += datlen; buf->total_len += datlen;
buf->n_add_for_cb += datlen; buf->n_add_for_cb += datlen;
goto out; goto out;
} else if (chain->misalign >= datlen && !CHAIN_PINNED(chain)) { } else if ((size_t)chain->misalign >= datlen && !CHAIN_PINNED(chain)) {
/* we can fit the data into the misalignment */ /* we can fit the data into the misalignment */
evbuffer_chain_align(chain); evbuffer_chain_align(chain);
@ -1224,7 +1228,7 @@ evbuffer_prepend(struct evbuffer *buf, const void *data, size_t datlen)
/* we cannot touch immutable buffers */ /* we cannot touch immutable buffers */
if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) { if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) {
if (chain->misalign >= datlen) { if ((size_t)chain->misalign >= datlen) {
/* we have enough space */ /* we have enough space */
memcpy(chain->buffer + chain->misalign - datlen, memcpy(chain->buffer + chain->misalign - datlen,
data, datlen); data, datlen);
@ -1460,6 +1464,9 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
struct evbuffer_chain *chain; struct evbuffer_chain *chain;
int nvecs; int nvecs;
if (howmuch < 0)
return -1;
chain = buf->last; chain = buf->last;
if (chain->off == 0 && buf->previous_to_last && if (chain->off == 0 && buf->previous_to_last &&
@ -1472,7 +1479,7 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
vecs[0].IOV_LEN_FIELD = CHAIN_SPACE_LEN(prev); vecs[0].IOV_LEN_FIELD = CHAIN_SPACE_LEN(prev);
vecs[1].IOV_PTR_FIELD = CHAIN_SPACE_PTR(chain); vecs[1].IOV_PTR_FIELD = CHAIN_SPACE_PTR(chain);
vecs[1].IOV_LEN_FIELD = CHAIN_SPACE_LEN(chain); vecs[1].IOV_LEN_FIELD = CHAIN_SPACE_LEN(chain);
if (vecs[0].IOV_LEN_FIELD >= howmuch) { if (vecs[0].IOV_LEN_FIELD >= (size_t)howmuch) {
/* The next-to-last chain has enough /* The next-to-last chain has enough
* space on its own. */ * space on its own. */
chain = prev; chain = prev;
@ -1481,7 +1488,7 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
/* We'll need both chains. */ /* We'll need both chains. */
chain = prev; chain = prev;
nvecs = 2; nvecs = 2;
if (vecs[0].IOV_LEN_FIELD + vecs[1].IOV_LEN_FIELD > howmuch) { if (vecs[0].IOV_LEN_FIELD + vecs[1].IOV_LEN_FIELD > (size_t)howmuch) {
vecs[1].IOV_LEN_FIELD = howmuch - vecs[0].IOV_LEN_FIELD; vecs[1].IOV_LEN_FIELD = howmuch - vecs[0].IOV_LEN_FIELD;
} }
} }
@ -1491,7 +1498,7 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
nvecs = 1; nvecs = 1;
vecs[0].IOV_PTR_FIELD = CHAIN_SPACE_PTR(chain); vecs[0].IOV_PTR_FIELD = CHAIN_SPACE_PTR(chain);
vecs[0].IOV_LEN_FIELD = CHAIN_SPACE_LEN(chain); vecs[0].IOV_LEN_FIELD = CHAIN_SPACE_LEN(chain);
if (vecs[0].IOV_LEN_FIELD > howmuch) if (vecs[0].IOV_LEN_FIELD > (size_t)howmuch)
vecs[0].IOV_LEN_FIELD = howmuch; vecs[0].IOV_LEN_FIELD = howmuch;
} }
@ -1542,7 +1549,7 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
*/ */
if (chain == NULL || n < EVBUFFER_MAX_READ) if (chain == NULL || n < EVBUFFER_MAX_READ)
n = EVBUFFER_MAX_READ; n = EVBUFFER_MAX_READ;
else if (n > chain->buffer_len << 2) else if ((size_t)n > chain->buffer_len << 2)
n = chain->buffer_len << 2; n = chain->buffer_len << 2;
} }
#endif #endif
@ -1611,7 +1618,7 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
#ifdef USE_IOVEC_IMPL #ifdef USE_IOVEC_IMPL
if (nvecs == 2) { if (nvecs == 2) {
size_t space = CHAIN_SPACE_LEN(chain); ssize_t space = CHAIN_SPACE_LEN(chain);
if (space < n) { if (space < n) {
chain->off += space; chain->off += space;
chain->next->off += n-space; chain->next->off += n-space;
@ -1644,6 +1651,9 @@ ssize_t howmuch)
struct evbuffer_chain *chain = buffer->first; struct evbuffer_chain *chain = buffer->first;
int n, i = 0; int n, i = 0;
if (howmuch < 0)
return -1;
ASSERT_EVBUFFER_LOCKED(buffer); ASSERT_EVBUFFER_LOCKED(buffer);
/* XXX make this top out at some maximal data length? if the /* XXX make this top out at some maximal data length? if the
* buffer has (say) 1MB in it, split over 128 chains, there's * buffer has (say) 1MB in it, split over 128 chains, there's
@ -1655,7 +1665,7 @@ ssize_t howmuch)
break; break;
#endif #endif
iov[i].IOV_PTR_FIELD = chain->buffer + chain->misalign; iov[i].IOV_PTR_FIELD = chain->buffer + chain->misalign;
if (howmuch >= chain->off) { if ((size_t)howmuch >= chain->off) {
iov[i++].IOV_LEN_FIELD = chain->off; iov[i++].IOV_LEN_FIELD = chain->off;
howmuch -= chain->off; howmuch -= chain->off;
} else { } else {
@ -1962,7 +1972,7 @@ evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap)
if (sz < 0) if (sz < 0)
goto done; goto done;
if (sz < space) { if ((size_t)sz < space) {
chain->off += sz; chain->off += sz;
buf->total_len += sz; buf->total_len += sz;
buf->n_add_for_cb += sz; buf->n_add_for_cb += sz;
@ -2135,6 +2145,9 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
if (tmp == NULL) if (tmp == NULL)
return (-1); return (-1);
#ifdef WIN32
#define lseek _lseek
#endif
if (lseek(fd, offset, SEEK_SET) == -1) { if (lseek(fd, offset, SEEK_SET) == -1) {
evbuffer_free(tmp); evbuffer_free(tmp);
return (-1); return (-1);
@ -2161,6 +2174,9 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
evbuffer_add_buffer(outbuf, tmp); evbuffer_add_buffer(outbuf, tmp);
evbuffer_free(tmp); evbuffer_free(tmp);
#ifdef WIN32
#define close _close
#endif
close(fd); close(fd);
} }
} }

View File

@ -31,10 +31,6 @@
objects on Windows. objects on Windows.
*/ */
#include <windows.h>
#include <assert.h>
#include <stdio.h>
#include "event2/buffer.h" #include "event2/buffer.h"
#include "event2/buffer_compat.h" #include "event2/buffer_compat.h"
#include "event2/util.h" #include "event2/util.h"
@ -46,6 +42,10 @@
#include "iocp-internal.h" #include "iocp-internal.h"
#include "mm-internal.h" #include "mm-internal.h"
#include <windows.h>
#include <assert.h>
#include <stdio.h>
#define MAX_WSABUFS 16 #define MAX_WSABUFS 16
/** Wrapper for an OVERLAPPED that holds the necessary info to notice /** Wrapper for an OVERLAPPED that holds the necessary info to notice
@ -123,7 +123,7 @@ read_completed(struct event_overlapped *eo, uintptr_t _, ssize_t nBytes)
evbuffer_unfreeze(evbuf, 0); evbuffer_unfreeze(evbuf, 0);
if (chain == evbuf->previous_to_last) { if (chain == evbuf->previous_to_last) {
size_t n = chain->buffer_len - (chain->misalign + chain->off); ssize_t n = chain->buffer_len - (chain->misalign + chain->off);
if (n>nBytes) if (n>nBytes)
n=nBytes; n=nBytes;
chain->off += n; chain->off += n;
@ -197,7 +197,7 @@ evbuffer_launch_write(struct evbuffer *buf, ssize_t at_most)
/* Nothing to write */ /* Nothing to write */
r = 0; r = 0;
goto done; goto done;
} else if (at_most > buf->total_len || at_most < 0) { } else if (at_most < 0 || (size_t)at_most > buf->total_len) {
at_most = buf->total_len; at_most = buf->total_len;
} }
evbuffer_freeze(buf, 1); evbuffer_freeze(buf, 1);
@ -213,7 +213,7 @@ evbuffer_launch_write(struct evbuffer *buf, ssize_t at_most)
b->buf = chain->buffer + chain->misalign; b->buf = chain->buffer + chain->misalign;
_evbuffer_chain_pin(chain, EVBUFFER_MEM_PINNED_W); _evbuffer_chain_pin(chain, EVBUFFER_MEM_PINNED_W);
if (at_most > chain->off) { if ((size_t)at_most > chain->off) {
b->len = chain->off; b->len = chain->off;
at_most -= chain->off; at_most -= chain->off;
} else { } else {

View File

@ -27,6 +27,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <assert.h> #include <assert.h>
#ifdef WIN32
#include <winsock2.h>
#endif
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "event-config.h" #include "event-config.h"
#endif #endif

View File

@ -32,9 +32,13 @@ extern "C" {
#endif #endif
#include "event-config.h" #include "event-config.h"
#include "evutil.h" #include "event2/util.h"
#include "util-internal.h"
#include "defer-internal.h" #include "defer-internal.h"
#ifdef WIN32
#include <winsock2.h>
#endif
#include <sys/queue.h> #include <sys/queue.h>
/* minimum allocation for a chain. */ /* minimum allocation for a chain. */
#define MIN_BUFFER_SIZE 256 #define MIN_BUFFER_SIZE 256

View File

@ -97,6 +97,10 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#include <event2/dns.h> #include <event2/dns.h>
#include <event2/dns_struct.h> #include <event2/dns_struct.h>
@ -118,9 +122,7 @@
#include "evthread-internal.h" #include "evthread-internal.h"
#ifdef WIN32 #ifdef WIN32
#include <ctype.h> #include <ctype.h>
#include <winsock2.h>
#include <windows.h> #include <windows.h>
#include <ws2tcpip.h>
#include <iphlpapi.h> #include <iphlpapi.h>
#include <io.h> #include <io.h>
#else #else
@ -989,6 +991,9 @@ reply_parse(struct evdns_base *base, u8 *packet, int length) {
sizeof(tmp_name))<0) \ sizeof(tmp_name))<0) \
goto err; \ goto err; \
} while(0) } while(0)
#ifdef _MSC_VER
#define strcasecmp _strcmpi
#endif
#define TEST_NAME \ #define TEST_NAME \
do { tmp_name[0] = '\0'; \ do { tmp_name[0] = '\0'; \
cmp_name[0] = '\0'; \ cmp_name[0] = '\0'; \

View File

@ -65,6 +65,7 @@
#include "event2/buffer.h" #include "event2/buffer.h"
#include "log-internal.h" #include "log-internal.h"
#include "mm-internal.h" #include "mm-internal.h"
#include "util-internal.h"
int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf); int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf);
int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t tag); int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t tag);
@ -447,7 +448,7 @@ evtag_unmarshal_int(struct evbuffer *evbuf, ev_uint32_t need_tag,
result = decode_int_internal(pinteger, evbuf, 0); result = decode_int_internal(pinteger, evbuf, 0);
evbuffer_drain(evbuf, len); evbuffer_drain(evbuf, len);
if (result < 0 || result > len) /* XXX Should this be != rather than > ?*/ if (result < 0 || (size_t)result > len) /* XXX Should this be != rather than > ?*/
return (-1); return (-1);
else else
return result; return result;
@ -473,7 +474,7 @@ evtag_unmarshal_int64(struct evbuffer *evbuf, ev_uint32_t need_tag,
result = decode_int64_internal(pinteger, evbuf, 0); result = decode_int64_internal(pinteger, evbuf, 0);
evbuffer_drain(evbuf, len); evbuffer_drain(evbuf, len);
if (result < 0 || result > len) /* XXX Should this be != rather than > ?*/ if (result < 0 || (size_t)result > len) /* XXX Should this be != rather than > ?*/
return (-1); return (-1);
else else
return result; return result;

6
http.c
View File

@ -777,7 +777,8 @@ evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf)
return (MORE_DATA_EXPECTED); return (MORE_DATA_EXPECTED);
/* Completed chunk */ /* Completed chunk */
evbuffer_remove_buffer(buf, req->input_buffer, req->ntoread); /* XXXX fixme: what if req->ntoread is > SIZE_T_MAX? */
evbuffer_remove_buffer(buf, req->input_buffer, (size_t)req->ntoread);
req->ntoread = -1; req->ntoread = -1;
if (req->chunk_cb != NULL) { if (req->chunk_cb != NULL) {
req->flags |= EVHTTP_REQ_DEFER_FREE; req->flags |= EVHTTP_REQ_DEFER_FREE;
@ -2148,7 +2149,8 @@ evhttp_decode_uri_internal(
const char *uri, size_t length, char *ret, int always_decode_plus) const char *uri, size_t length, char *ret, int always_decode_plus)
{ {
char c; char c;
int i, j, in_query = always_decode_plus; int j, in_query = always_decode_plus;
unsigned i;
for (i = j = 0; i < length; i++) { for (i = j = 0; i < length; i++) {
c = uri[i]; c = uri[i];