]> granicus.if.org Git - libevent/commitdiff
More msvc build tweaks.
authorNick Mathewson <nickm@torproject.org>
Fri, 1 May 2009 00:54:14 +0000 (00:54 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 1 May 2009 00:54:14 +0000 (00:54 +0000)
svn:r1262

WIN32-Code/event-config.h
buffer.c
buffer_iocp.c
bufferevent_pair.c
evbuffer-internal.h
evdns.c
event_tagging.c
http.c

index 0cc35f3d4b86bed2edff933921731f785b86f337..be1e4c564deeb852b94248797fb995568a59d14f 100644 (file)
 /* #undef _EVENT_HAVE_SYS_MMAN_H */
 
 /* 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. */
 /* #undef _EVENT_HAVE_SYS_QUEUE_H */
 #define _EVENT_socklen_t unsigned int
 
 /* Define to `int' if <sys/types.h> does not define. */
-#define _EVENT_ssize_t SSIZE_T
+#define _EVENT_ssize_t intptr_t
 
 #endif
index b48d5d4d8bfcdcc4ac5e4a98d8569e4bb2b22755..18ee114947cd5c6894b76f46db42bbe36549adcd 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -32,6 +32,7 @@
 #ifdef WIN32
 #include <winsock2.h>
 #include <windows.h>
+#include <io.h>
 #endif
 
 #ifdef _EVENT_HAVE_VASPRINTF
@@ -839,27 +840,28 @@ evbuffer_pullup(struct evbuffer *buf, ssize_t size)
 
         chain = buf->first;
 
-       if (size == -1)
+       if (size < 0)
                size = buf->total_len;
        /* 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
         * NULL */
-       if (size == 0 || size > buf->total_len)
+       if (size == 0 || (size_t)size > buf->total_len)
                 goto done;
 
        /* No need to pull up anything; the first size bytes are
         * already here. */
-        if (chain->off >= size) {
+        if (chain->off >= (size_t)size) {
                 result = chain->buffer + chain->misalign;
                 goto done;
         }
 
        /* Make sure that none of the chains we need to copy from is pinned. */
        remaining = size - chain->off;
+       assert(remaining >= 0);
        for (tmp=chain->next; tmp; tmp=tmp->next) {
                if (CHAIN_PINNED(tmp))
                        goto done;
-               if (tmp->off >= remaining)
+               if (tmp->off >= (size_t)remaining)
                        break;
                remaining -= tmp->off;
        }
@@ -875,7 +877,7 @@ evbuffer_pullup(struct evbuffer *buf, ssize_t size)
                tmp->off = size;
                size -= old_off;
                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 */
                size_t old_off = 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 */
 
        /* 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;
 
                memcpy(buffer, chain->buffer + chain->misalign, chain->off);
@@ -946,7 +948,8 @@ static inline int
 evbuffer_strchr(struct evbuffer_iterator *it, const char chr)
 {
        struct evbuffer_chain *chain = it->chain;
-       int i = it->off, count = 0;
+       unsigned i = it->off;
+       int count = 0;
        while (chain != NULL) {
                char *buffer = (char *)chain->buffer + chain->misalign;
                for (; i < chain->off; ++i, ++count) {
@@ -967,7 +970,8 @@ static inline int
 evbuffer_strpbrk(struct evbuffer_iterator *it, const char *chrset)
 {
        struct evbuffer_chain *chain = it->chain;
-       int i = it->off, count = 0;
+       unsigned i = it->off;
+       int count = 0;
        while (chain != NULL) {
                char *buffer = (char *)chain->buffer + chain->misalign;
                for (; i < chain->off; ++i, ++count) {
@@ -989,7 +993,7 @@ evbuffer_strpbrk(struct evbuffer_iterator *it, const char *chrset)
 
 static inline int
 evbuffer_strspn(
-       struct evbuffer_chain *chain, int i, const char *chrset)
+       struct evbuffer_chain *chain, unsigned i, const char *chrset)
 {
        int count = 0;
        while (chain != NULL) {
@@ -1017,7 +1021,7 @@ evbuffer_getchr(struct evbuffer_iterator *it, char *pchr)
        struct evbuffer_chain *chain = it->chain;
        int off = it->off;
 
-       while (off >= chain->off) {
+       while ((size_t)off >= chain->off) {
                off -= chain->off;
                chain = chain->next;
                if (chain == NULL)
@@ -1153,7 +1157,7 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
                        buf->total_len += datlen;
                         buf->n_add_for_cb += datlen;
                        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 */
                        evbuffer_chain_align(chain);
 
@@ -1224,7 +1228,7 @@ evbuffer_prepend(struct evbuffer *buf, const void *data, size_t datlen)
 
        /* we cannot touch immutable buffers */
        if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) {
-               if (chain->misalign >= datlen) {
+               if ((size_t)chain->misalign >= datlen) {
                        /* we have enough space */
                        memcpy(chain->buffer + chain->misalign - datlen,
                            data, datlen);
@@ -1460,6 +1464,9 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
        struct evbuffer_chain *chain;
        int nvecs;
 
+       if (howmuch < 0)
+               return -1;
+
        chain = buf->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[1].IOV_PTR_FIELD = CHAIN_SPACE_PTR(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
                         * space on its own. */
                        chain = prev;
@@ -1481,7 +1488,7 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
                        /* We'll need both chains. */
                        chain = prev;
                        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;
                        }
                }
@@ -1491,7 +1498,7 @@ _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,
                nvecs = 1;
                vecs[0].IOV_PTR_FIELD = CHAIN_SPACE_PTR(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;
        }
 
@@ -1542,7 +1549,7 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
                 */
                if (chain == NULL || 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;
        }
 #endif
@@ -1611,7 +1618,7 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
 
 #ifdef USE_IOVEC_IMPL
        if (nvecs == 2) {
-               size_t space = CHAIN_SPACE_LEN(chain);
+               ssize_t space = CHAIN_SPACE_LEN(chain);
                if (space < n) {
                        chain->off += space;
                        chain->next->off += n-space;
@@ -1644,6 +1651,9 @@ ssize_t howmuch)
        struct evbuffer_chain *chain = buffer->first;
        int n, i = 0;
 
+       if (howmuch < 0)
+               return -1;
+
         ASSERT_EVBUFFER_LOCKED(buffer);
        /* XXX make this top out at some maximal data length?  if the
         * buffer has (say) 1MB in it, split over 128 chains, there's
@@ -1655,7 +1665,7 @@ ssize_t howmuch)
                        break;
 #endif
                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;
                        howmuch -= chain->off;
                } else {
@@ -1962,7 +1972,7 @@ evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap)
 
                if (sz < 0)
                        goto done;
-               if (sz < space) {
+               if ((size_t)sz < space) {
                        chain->off += sz;
                        buf->total_len += sz;
                         buf->n_add_for_cb += sz;
@@ -2135,6 +2145,9 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
                if (tmp == NULL)
                        return (-1);
 
+#ifdef WIN32
+#define lseek _lseek
+#endif
                if (lseek(fd, offset, SEEK_SET) == -1) {
                        evbuffer_free(tmp);
                        return (-1);
@@ -2161,6 +2174,9 @@ evbuffer_add_file(struct evbuffer *outbuf, int fd,
                        evbuffer_add_buffer(outbuf, tmp);
                        evbuffer_free(tmp);
 
+#ifdef WIN32
+#define close _close
+#endif
                        close(fd);
                }
        }
index 8430f8d72f3fcbd574f8d1ad008a90d47630d1f3..bae08434e0a8cf17b0b938f1654ff562b76b1e9e 100644 (file)
    objects on Windows.
 */
 
-#include <windows.h>
-#include <assert.h>
-#include <stdio.h>
-
 #include "event2/buffer.h"
 #include "event2/buffer_compat.h"
 #include "event2/util.h"
 #include "iocp-internal.h"
 #include "mm-internal.h"
 
+#include <windows.h>
+#include <assert.h>
+#include <stdio.h>
+
 #define MAX_WSABUFS 16
 
 /** 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);
 
        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)
                        n=nBytes;
                chain->off += n;
@@ -197,7 +197,7 @@ evbuffer_launch_write(struct evbuffer *buf, ssize_t at_most)
                /* Nothing to write */
                r = 0;
                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;
        }
        evbuffer_freeze(buf, 1);
@@ -213,7 +213,7 @@ evbuffer_launch_write(struct evbuffer *buf, ssize_t at_most)
                b->buf = chain->buffer + chain->misalign;
                _evbuffer_chain_pin(chain, EVBUFFER_MEM_PINNED_W);
 
-               if (at_most > chain->off) {
+               if ((size_t)at_most > chain->off) {
                        b->len = chain->off;
                        at_most -= chain->off;
                } else {
index 068a80a84d1da39ec328a4244ab2cd99b6dc9d32..476ed96a6941df8ea87e01c3e3218d9bad2b6e16 100644 (file)
 #include <sys/types.h>
 #include <assert.h>
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
 #ifdef HAVE_CONFIG_H
 #include "event-config.h"
 #endif
index f33bae788daaa2714cdb1bcab228b5105c8ce6bc..b70e430516fc157d153a93419dec33723f35a46d 100644 (file)
@@ -32,9 +32,13 @@ extern "C" {
 #endif
 
 #include "event-config.h"
-#include "evutil.h"
+#include "event2/util.h"
+#include "util-internal.h"
 #include "defer-internal.h"
 
+#ifdef WIN32
+#include <winsock2.h>
+#endif
 #include <sys/queue.h>
 /* minimum allocation for a chain. */
 #define MIN_BUFFER_SIZE        256
diff --git a/evdns.c b/evdns.c
index a1d9431dd5410d47bf2c03d1d203db99fd794aec..8f2eb1453a8efa1d6e235c68c3e280019b5984a9 100644 (file)
--- a/evdns.c
+++ b/evdns.c
 #include <sys/stat.h>
 #include <stdio.h>
 #include <stdarg.h>
+#ifdef WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif
 
 #include <event2/dns.h>
 #include <event2/dns_struct.h>
 #include "evthread-internal.h"
 #ifdef WIN32
 #include <ctype.h>
-#include <winsock2.h>
 #include <windows.h>
-#include <ws2tcpip.h>
 #include <iphlpapi.h>
 #include <io.h>
 #else
@@ -989,6 +991,9 @@ reply_parse(struct evdns_base *base, u8 *packet, int length) {
                        sizeof(tmp_name))<0)                    \
                        goto err;                               \
        } while(0)
+#ifdef _MSC_VER
+#define strcasecmp _strcmpi
+#endif
 #define TEST_NAME                                                      \
        do { tmp_name[0] = '\0';                                        \
                cmp_name[0] = '\0';                                     \
index 4af91c23b4104fee37ba72ce50f3cc8db4b4e5f6..c18b93f252ae3720d43df0627320ed415a366d68 100644 (file)
@@ -65,6 +65,7 @@
 #include "event2/buffer.h"
 #include "log-internal.h"
 #include "mm-internal.h"
+#include "util-internal.h"
 
 int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf);
 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);
        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);
        else
                return result;
@@ -473,7 +474,7 @@ evtag_unmarshal_int64(struct evbuffer *evbuf, ev_uint32_t need_tag,
 
        result = decode_int64_internal(pinteger, evbuf, 0);
        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);
        else
                return result;
diff --git a/http.c b/http.c
index d5a0b8ee7500d72ee86573bd13078de4e6fc8e9d..1e2c57875df0de8bdc759deb746f7d12cd404885 100644 (file)
--- a/http.c
+++ b/http.c
@@ -777,7 +777,8 @@ evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf)
                        return (MORE_DATA_EXPECTED);
 
                /* 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;
                if (req->chunk_cb != NULL) {
                        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)
 {
        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++) {
                c = uri[i];