Skip to content
Browse files

Fix windows build

Change-Id: I60b512cb5b85ec38d0b87d7b3754de40c7f8a42d
Reviewed-on: http://review.couchbase.org/20340
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent f6c8959 commit 74c75aafb86472630d97baa44086b996af879772 @avsej avsej committed with trondn Aug 30, 2012
View
4 Makefile.am
@@ -47,6 +47,8 @@ pkginclude_HEADERS = \
libhttpparser_la_SOURCES = \
contrib/http_parser/http_parser.c \
contrib/http_parser/http_parser.h
+libhttpparser_la_CFLAGS = $(AM_NOWARN_CFLAGS)
+libhttpparser_la_CPPFLAGS = $(AM_NOWARN_CPPFLAGS)
libvbucket_la_SOURCES = \
include/libvbucket/vbucket.h \
@@ -57,6 +59,8 @@ libvbucket_la_SOURCES = \
contrib/libvbucket/vbucket.c
libvbucket_la_LIBADD = libketama.la libcrc32.la
libvbucket_la_DEPENDENCIES = libketama.la libcrc32.la
+libvbucket_la_CFLAGS = $(AM_NOWARN_CFLAGS)
+libvbucket_la_CPPFLAGS = $(AM_NOWARN_CPPFLAGS)
libketama_la_SOURCES = contrib/libvbucket/ketama.c
libketama_la_CFLAGS = $(AM_NOWARN_CFLAGS)
View
13 NMakefile
@@ -17,7 +17,7 @@
INSTALL=..\deps
CC_NODEBUG = cl.exe /O2 /DNDEBUG /MD /LD
CC_DEBUG = cl.exe /Od /D_DEBUG /RTC1 /Z7 /LDd /W3 /MDd
-CFLAGS = /Iinclude /Iwin32 /Icontrib /I$(INSTALL)\include /Isrc /I. /nologo /W3 /EHsc /DWIN32 /FD /c -D_CRT_SECURE_NO_WARNINGS -DLIBCOUCHBASE_INTERNAL=1
+CFLAGS = /Iinclude /Iwin32 /Icontrib /Iplugins\io\win32 /I$(INSTALL)\include /Isrc /I. /nologo /W3 /EHsc /DWIN32 /FD /c -D_CRT_SECURE_NO_WARNINGS -DLIBCOUCHBASE_INTERNAL=1
DLLLDFLAGS = /dll /incremental:no /opt:ref,icf /version:1.1
LDFLAGS = /nologo /LIBPATH:$(INSTALL)\lib
LD = link.exe
@@ -51,7 +51,7 @@ tests_getopt_test_C_SOURCES = win32\getopt.c
tests_getopt_test_OBJECTS = $(tests_getopt_test_C_SOURCES:.c=.dobj) \
$(tests_getopt_test_CXX_SOURCES:.cc=.dobj)
-tools_cbc_CXX_SOURCES = tools\cbc.cc tools\cbc-receive.cc tools\cbc-send.cc \
+tools_cbc_CXX_SOURCES = tools\cbc.cc \
tools\cbc-util.cc tools\commandlineparser.cc tools\configuration.cc
tools_cbc_C_SOURCES = win32\getopt.c
tools_cbc_OBJECTS = $(tools_cbc_CXX_SOURCES:.cc=.obj) \
@@ -79,21 +79,18 @@ check: $(check_PROGRAMS)
libcouchbase.dll: $(libcouchbase_la_OBJECTS)
$(LD) $(LDFLAGS) $(DLLLDFLAGS) /out:libcouchbase.dll \
$(libcouchbase_la_OBJECTS) \
- libvbucket.lib \
ws2_32.lib
libcouchbase_debug.dll: $(libcouchbase_la_debug_OBJECTS)
$(LD) $(LDFLAGS) $(DLLLDFLAGS) /out:libcouchbase_debug.dll \
$(libcouchbase_la_debug_OBJECTS) \
- libvbucket_debug.lib \
ws2_32.lib
tests\getopt-test.exe: $(tests_getopt_test_OBJECTS)
$(LD) $(LDFLAGS) -out:tests\getopt-test.exe $(tests_getopt_test_OBJECTS)
tools\cbc.exe: $(tools_cbc_OBJECTS) libcouchbase.dll
$(LD) $(LDFLAGS) -out:tools\cbc.exe $(tools_cbc_OBJECTS) \
- libvbucket.lib \
libcouchbase.lib ws2_32.lib
example\pillowfight.exe: $(example_pillowfight_OBJECTS) libcouchbase_debug.dll
@@ -126,8 +123,8 @@ INSTALLDIRS=$(INSTALL) $(INSTALL)\include $(INSTALL)\include\libcouchbase $(INST
install: $(INSTALLDIRS) libcouchbase.dll libcouchbase_debug.dll $(bin_PROGRAMS)
copy include\libcouchbase\** $(INSTALL)\include\libcouchbase
- -del $(INSTALL)\include\libcouchbase\configuration.h.in
- copy win32\libcouchbase\configuration.h $(INSTALL)\include\libcouchbase
+ -del $(INSTALL)\include\libcouchbase\configuration.h.in
+ copy win32\libcouchbase\configuration.h $(INSTALL)\include\libcouchbase
copy libcouchbase.dll $(INSTALL)\lib
copy libcouchbase.dll $(INSTALL)\bin
copy libcouchbase.exp $(INSTALL)\lib
@@ -136,7 +133,7 @@ install: $(INSTALLDIRS) libcouchbase.dll libcouchbase_debug.dll $(bin_PROGRAMS)
copy libcouchbase_debug.dll $(INSTALL)\bin
copy libcouchbase_debug.exp $(INSTALL)\lib
copy libcouchbase_debug.lib $(INSTALL)\lib
- copy tools\cbc.exe $(INSTALL)\bin
+ copy tools\cbc.exe $(INSTALL)\bin
uninstall:
-del $(INSTALL)\lib\libcouchbase_debug.dll \
View
1 contrib/libvbucket/vbucket.c
@@ -23,7 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <strings.h>
#include <errno.h>
#include "cJSON.h"
View
4 example/couchview_yajl.c
@@ -303,7 +303,7 @@ static void data_callback(lcb_http_request_t request,
struct cookie_st *c = (struct cookie_st *)cookie;
yajl_status st;
const unsigned char *bytes = resp->v.v0.bytes;
- unsigned int nbytes = resp->v.v0.nbytes;
+ lcb_size_t nbytes = resp->v.v0.nbytes;
if (error != LCB_SUCCESS) {
return;
@@ -344,7 +344,7 @@ static void complete_callback(lcb_http_request_t request,
struct cookie_st *c = (struct cookie_st *)cookie;
yajl_status st;
const unsigned char *bytes = resp->v.v0.bytes;
- unsigned int nbytes = resp->v.v0.nbytes;
+ lcb_size_t nbytes = resp->v.v0.nbytes;
const char * const *headers = resp->v.v0.headers;
if (headers) {
View
6 include/memcached/protocol_binary.h
@@ -36,7 +36,11 @@
#ifndef PROTOCOL_BINARY_H
#define PROTOCOL_BINARY_H
-#include <stdint.h>
+#if !defined HAVE_STDINT_H && defined WIN32
+# include "win_stdint.h"
+#else
+# include <stdint.h>
+#endif
#include <memcached/vbucket.h>
/**
View
2 m4/couchbase.m4
@@ -63,7 +63,7 @@ AC_DEFUN([COUCHBASE_GENERIC_COMPILER], [
GCC_C89=-std=c89
GCC_C99=-std=gnu99
GCC_LDFLAGS=""
- GCC_CPP_WARNINGS="-Wall -pedantic -Wshadow -fdiagnostics-show-option -Wformat -fno-strict-aliasing -Wno-strict-aliasing -Wextra"
+ GCC_CPP_WARNINGS="-Wall -pedantic -Wshadow -Wconversion -fdiagnostics-show-option -Wformat -fno-strict-aliasing -Wno-strict-aliasing -Wextra"
GCC_C_COMPILER_WARNINGS="-Wundef -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wmissing-declarations -Wcast-align"
GCC_CXX_COMPILER_WARNINGS="-std=gnu++98 -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wno-long-long -Wno-redundant-decls"
View
14 plugins/io/win32/plugin-win32.c
@@ -152,7 +152,7 @@ static lcb_ssize_t lcb_io_recv(struct lcb_io_opt_st *iops,
{
DWORD fl = 0;
DWORD nr;
- WSABUF wsabuf = { len, buffer };
+ WSABUF wsabuf = { (ULONG)len, buffer };
(void)flags;
if (WSARecv(sock, &wsabuf, 1, &nr, &fl, NULL, NULL) == SOCKET_ERROR) {
@@ -179,9 +179,9 @@ static lcb_ssize_t lcb_io_recvv(struct lcb_io_opt_st *iops,
assert(niov == 2);
wsabuf[0].buf = iov[0].iov_base;
- wsabuf[0].len = iov[0].iov_len;
+ wsabuf[0].len = (ULONG)iov[0].iov_len;
wsabuf[1].buf = iov[1].iov_base;
- wsabuf[1].len = iov[1].iov_len;
+ wsabuf[1].len = (ULONG)iov[1].iov_len;
if (WSARecv(sock, wsabuf, iov[1].iov_len ? 2 : 1,
&nr, &fl, NULL, NULL) == SOCKET_ERROR) {
@@ -206,7 +206,7 @@ static lcb_ssize_t lcb_io_send(struct lcb_io_opt_st *iops,
{
DWORD fl = 0;
DWORD nw;
- WSABUF wsabuf = { len, (char *)msg };
+ WSABUF wsabuf = { (ULONG)len, (char *)msg };
(void)flags;
if (WSASend(sock, &wsabuf, 1, &nw, fl, NULL, NULL) == SOCKET_ERROR) {
@@ -228,9 +228,9 @@ static lcb_ssize_t lcb_io_sendv(struct lcb_io_opt_st *iops,
assert(niov == 2);
wsabuf[0].buf = iov[0].iov_base;
- wsabuf[0].len = iov[0].iov_len;
+ wsabuf[0].len = (ULONG)iov[0].iov_len;
wsabuf[1].buf = iov[1].iov_base;
- wsabuf[1].len = iov[1].iov_len;
+ wsabuf[1].len = (ULONG)iov[1].iov_len;
if (WSASend(sock, wsabuf, iov[1].iov_len ? 2 : 1,
&nw, fl, NULL, NULL) == SOCKET_ERROR) {
@@ -273,7 +273,7 @@ static int lcb_io_connect(struct lcb_io_opt_st *iops,
const struct sockaddr *name,
unsigned int namelen)
{
- int ret = WSAConnect(sock, name, namelen, NULL, NULL, NULL, NULL);
+ int ret = WSAConnect(sock, name, (int)namelen, NULL, NULL, NULL, NULL);
if (ret == SOCKET_ERROR) {
iops->error = getError();
}
View
2 src/arithmetic.c
@@ -40,7 +40,7 @@ lcb_error_t lcb_arithmetic(lcb_t instance,
protocol_binary_request_incr req;
int vb, idx;
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
lcb_time_t exp = items[ii]->v.v0.exptime;
int create = items[ii]->v.v0.create;
lcb_int64_t delta = items[ii]->v.v0.delta;
View
10 src/base64.c
@@ -25,7 +25,7 @@
/**
* An array of the legal charracters used for direct lookup
*/
-static const uint8_t code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const lcb_uint8_t code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* Encode up to 3 characters to 4 output character.
@@ -35,7 +35,7 @@ static const uint8_t code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw
* @param num the number of characters from s to encode
* @return 0 upon success, -1 otherwise.
*/
-static int encode_rest(const uint8_t *s, uint8_t *d, lcb_size_t num)
+static int encode_rest(const lcb_uint8_t *s, lcb_uint8_t *d, lcb_size_t num)
{
lcb_uint32_t val = 0;
@@ -70,7 +70,7 @@ static int encode_rest(const uint8_t *s, uint8_t *d, lcb_size_t num)
* @param s pointer to the input stream
* @param d pointer to the output stream
*/
-static int encode_triplet(const uint8_t *s, uint8_t *d)
+static int encode_triplet(const lcb_uint8_t *s, lcb_uint8_t *d)
{
lcb_uint32_t val = (lcb_uint32_t)((*s << 16) | (*(s + 1) << 8) | (*(s + 2)));
d[3] = code[val & 63] ;
@@ -94,8 +94,8 @@ int lcb_base64_encode(const char *src, char *dst, lcb_size_t sz)
lcb_size_t triplets = len / 3;
lcb_size_t rest = len % 3;
lcb_size_t ii;
- const uint8_t *in = (const uint8_t *)src;
- uint8_t *out = (uint8_t *)dst;
+ const lcb_uint8_t *in = (const lcb_uint8_t *)src;
+ lcb_uint8_t *out = (lcb_uint8_t *)dst;
if (sz < (lcb_size_t)((triplets + 1) * 4)) {
return -1;
View
47 src/compat.c
@@ -69,11 +69,9 @@ static lcb_error_t create_memcached(const struct lcb_memcached_st *user,
{
ringbuffer_t buffer;
char *copy = strdup(user->serverlist);
- char head[1024];
int first;
char *ptr = copy;
int fail;
- lcb_ssize_t offset = 0;
if (copy == NULL) {
return LCB_CLIENT_ENOMEM;
@@ -84,41 +82,28 @@ static lcb_error_t create_memcached(const struct lcb_memcached_st *user,
return LCB_CLIENT_ENOMEM;
}
- head[0] = '\0';
- offset += snprintf(head + offset, sizeof(head) - offset, "%s", "{");
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- "\"bucketType\":\"memcached\",");
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- "\"nodeLocator\":\"ketama\",");
+ ringbuffer_strcat(&buffer, "{\"bucketType\":\"memcached\",\"nodeLocator\":\"ketama\",");
if (user->username != NULL) {
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- "\"authType\":\"sasl\",");
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- "\"name\":\"");
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- user->username);
- offset += snprintf(head + offset, sizeof(head) - offset, "%s", "\",");
+ ringbuffer_strcat(&buffer, "\"authType\":\"sasl\",\"name\":\"");
+ ringbuffer_write(&buffer, user->username, strlen(user->username));
+ ringbuffer_strcat(&buffer, "\",");
if (user->password != NULL) {
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- "\"saslPassword\":\"");
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- user->password);
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- "\",");
+ ringbuffer_strcat(&buffer, "\"saslPassword\":\"");
+ ringbuffer_write(&buffer, user->password, strlen(user->password));
+ ringbuffer_strcat(&buffer, "\",");
}
}
- offset += snprintf(head + offset, sizeof(head) - offset, "%s",
- "\"nodes\": [");
- ringbuffer_write(&buffer, head, strlen(head));
+ ringbuffer_strcat(&buffer, "\"nodes\": [");
/* Let's add the hosts... */
first = 1;
do {
char *tok;
char *next = strchr(ptr, ';');
const char *port = "11211";
- lcb_ssize_t length;
+ int length;
+ char buf[256];
if (next != NULL) {
*next = '\0';
@@ -133,17 +118,19 @@ static lcb_error_t create_memcached(const struct lcb_memcached_st *user,
}
}
- length = snprintf(head, sizeof(head),
+ length = snprintf(buf, sizeof(buf),
"%c{\"hostname\":\"%s\",\"ports\":{\"direct\":%s}}",
first ? ' ' : ',', ptr, port);
+ if (length < 0) {
+ free(copy);
+ return LCB_CLIENT_ENOMEM;
+ }
first = 0;
-
- if (ringbuffer_ensure_capacity(&buffer, length) == -1) {
+ if (ringbuffer_ensure_capacity(&buffer, (lcb_size_t)length) == -1) {
free(copy);
return LCB_CLIENT_ENOMEM;
}
-
- ringbuffer_write(&buffer, head, length);
+ ringbuffer_write(&buffer, buf, (lcb_size_t)length);
if (next != NULL) {
ptr = next + 1;
View
13 src/config_static.h
@@ -54,6 +54,10 @@
#include <unistd.h>
#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
@@ -70,10 +74,19 @@
#include <sys/uio.h>
#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
#ifdef _WIN32
#include "win32/win_errno_sock.h"
typedef int ssize_t;
#define snprintf _snprintf
+#define strcasecmp(a,b) _stricmp(a,b)
#undef strdup
#define strdup _strdup
#else
View
10 src/get.c
@@ -76,7 +76,7 @@ lcb_error_t lcb_unlock(lcb_t instance,
protocol_binary_request_no_extras req;
int vb, idx;
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
lcb_cas_t cas = items[ii]->v.v0.cas;
(void)vbucket_map(instance->vbucket_config, key, nkey, &vb, &idx);
@@ -135,7 +135,7 @@ lcb_error_t lcb_get_replica(lcb_t instance,
req.message.header.request.opcode = CMD_GET_REPLICA;
for (ii = 0; ii < num; ++ii) {
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
vb = vbucket_get_vbucket_by_key(instance->vbucket_config,
key, nkey);
idx = vbucket_get_replica(instance->vbucket_config, vb, 0);
@@ -180,7 +180,7 @@ static lcb_error_t lcb_single_get(lcb_t instance,
int vb, idx;
lcb_size_t nbytes;
const void *key = item->v.v0.key;
- uint16_t nkey = item->v.v0.nkey;
+ lcb_size_t nkey = item->v.v0.nkey;
lcb_time_t exp = item->v.v0.exptime;
(void)vbucket_map(instance->vbucket_config, key, nkey, &vb, &idx);
@@ -254,7 +254,7 @@ static lcb_error_t lcb_multi_get(lcb_t instance,
for (ii = 0; ii < num; ++ii) {
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
(void)vbucket_map(instance->vbucket_config, key, nkey,
&servers[ii].vb, &servers[ii].idx);
if (servers[ii].idx < 0 || servers[ii].idx > (int)instance->nservers) {
@@ -272,7 +272,7 @@ static lcb_error_t lcb_multi_get(lcb_t instance,
for (ii = 0; ii < num; ++ii) {
protocol_binary_request_gat req;
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
lcb_time_t exp = items[ii]->v.v0.exptime;
int vb;
View
2 src/gethrtime.c
@@ -89,7 +89,7 @@ hrtime_t gethrtime(void)
}
ret = (hrtime_t)tv.tv_sec * 1000000000;
- ret += tv.tv_usec * 1000;
+ ret += (hrtime_t)tv.tv_usec * 1000;
return ret;
#elif defined(HAVE_QUERYPERFORMANCECOUNTER)
double ret;
View
32 src/hashset.c
@@ -17,8 +17,8 @@
#include "internal.h"
-static const int prime_1 = 73;
-static const int prime_2 = 5009;
+static const unsigned int prime_1 = 73;
+static const unsigned int prime_2 = 5009;
hashset_t hashset_create()
{
@@ -28,9 +28,9 @@ hashset_t hashset_create()
return NULL;
}
set->nbits = 3;
- set->capacity = 1 << set->nbits;
+ set->capacity = (lcb_size_t)(1 << set->nbits);
set->mask = set->capacity - 1;
- set->items = calloc(set->capacity, sizeof(size_t));
+ set->items = calloc(set->capacity, sizeof(lcb_size_t));
if (set->items == NULL) {
hashset_destroy(set);
return NULL;
@@ -39,7 +39,7 @@ hashset_t hashset_create()
return set;
}
-size_t hashset_num_items(hashset_t set)
+lcb_size_t hashset_num_items(hashset_t set)
{
return set->nitems;
}
@@ -54,8 +54,8 @@ void hashset_destroy(hashset_t set)
static int hashset_add_member(hashset_t set, void *item)
{
- size_t value = (size_t)item;
- size_t ii;
+ lcb_size_t value = (lcb_size_t)item;
+ lcb_size_t ii;
if (value == 0 || value == 1) {
return -1;
@@ -78,17 +78,17 @@ static int hashset_add_member(hashset_t set, void *item)
static void maybe_rehash(hashset_t set)
{
- size_t *old_items;
- size_t old_capacity, ii;
+ lcb_size_t *old_items;
+ lcb_size_t old_capacity, ii;
- if ((float)set->nitems >= set->capacity * 0.85) {
+ if ((float)set->nitems >= (lcb_size_t)((double)set->capacity * 0.85)) {
old_items = set->items;
old_capacity = set->capacity;
set->nbits++;
- set->capacity = 1 << set->nbits;
+ set->capacity = (lcb_size_t)(1 << set->nbits);
set->mask = set->capacity - 1;
- set->items = calloc(set->capacity, sizeof(size_t));
+ set->items = calloc(set->capacity, sizeof(lcb_size_t));
set->nitems = 0;
assert(set->items);
for (ii = 0; ii < old_capacity; ii++) {
@@ -107,8 +107,8 @@ int hashset_add(hashset_t set, void *item)
int hashset_remove(hashset_t set, void *item)
{
- size_t value = (size_t)item;
- size_t ii = set->mask & (prime_1 * value);
+ lcb_size_t value = (lcb_size_t)item;
+ lcb_size_t ii = set->mask & (prime_1 * value);
while (set->items[ii] != 0) {
if (set->items[ii] == value) {
@@ -124,8 +124,8 @@ int hashset_remove(hashset_t set, void *item)
int hashset_is_member(hashset_t set, void *item)
{
- size_t value = (size_t)item;
- size_t ii = set->mask & (prime_1 * value);
+ lcb_size_t value = (lcb_size_t)item;
+ lcb_size_t ii = set->mask & (prime_1 * value);
while (set->items[ii] != 0) {
if (set->items[ii] == value) {
View
14 src/hashset.h
@@ -15,8 +15,6 @@
* limitations under the License.
*/
-#include <stdlib.h>
-
#ifndef LIBCOUCHBASE_HASHSET_H
#define LIBCOUCHBASE_HASHSET_H 1
@@ -25,12 +23,12 @@ extern "C" {
#endif
struct hashset_st {
- size_t nbits;
- size_t mask;
+ lcb_size_t nbits;
+ lcb_size_t mask;
- size_t capacity;
- size_t *items;
- size_t nitems;
+ lcb_size_t capacity;
+ lcb_size_t *items;
+ lcb_size_t nitems;
};
typedef struct hashset_st *hashset_t;
@@ -41,7 +39,7 @@ extern "C" {
/* destroy hashset instance */
void hashset_destroy(hashset_t set);
- size_t hashset_num_items(hashset_t set);
+ lcb_size_t hashset_num_items(hashset_t set);
/* add item into the hashset.
*
View
56 src/http.c
@@ -65,7 +65,7 @@ void lcb_http_request_destroy(lcb_http_request_t req)
}
static int http_parser_header_cb(http_parser *p, const char *bytes,
- size_t nbytes)
+ lcb_size_t nbytes)
{
lcb_http_request_t req = p->data;
struct lcb_http_header_st *item;
@@ -104,13 +104,13 @@ static int http_parser_headers_complete_cb(http_parser *p)
return 0;
}
-static inline void setup_lcb_http_resp_t(lcb_http_resp_t *resp,
- lcb_http_status_t status,
- const char *path,
- lcb_size_t npath,
- const char *const *headers,
- const void *bytes,
- lcb_size_t nbytes)
+static void setup_lcb_http_resp_t(lcb_http_resp_t *resp,
+ lcb_http_status_t status,
+ const char *path,
+ lcb_size_t npath,
+ const char *const *headers,
+ const void *bytes,
+ lcb_size_t nbytes)
{
memset(resp, 0, sizeof(*resp));
resp->version = 0;
@@ -122,7 +122,7 @@ static inline void setup_lcb_http_resp_t(lcb_http_resp_t *resp,
resp->v.v0.nbytes = nbytes;
}
-static int http_parser_body_cb(http_parser *p, const char *bytes, size_t nbytes)
+static int http_parser_body_cb(http_parser *p, const char *bytes, lcb_size_t nbytes)
{
lcb_error_t rc;
lcb_http_request_t req = p->data;
@@ -224,7 +224,7 @@ static int request_do_fill_input_buffer(lcb_http_request_t req)
return 0;
}
-static int request_do_read(lcb_http_request_t req)
+static lcb_ssize_t request_do_read(lcb_http_request_t req)
{
lcb_size_t nb = 0, np = 0;
char *bytes;
@@ -250,7 +250,7 @@ static int request_do_read(lcb_http_request_t req)
}
if (nbytes > 0) {
- nb = http_parser_execute(req->parser, &req->parser_settings, bytes, nbytes);
+ nb = (lcb_size_t)http_parser_execute(req->parser, &req->parser_settings, bytes, nbytes);
ringbuffer_consumed(&req->input, nbytes);
if (np) { /* release peek storage */
free(bytes);
@@ -261,7 +261,7 @@ static int request_do_read(lcb_http_request_t req)
if (req->cancelled || req->completed) {
return 0;
} else {
- return nb;
+ return (lcb_ssize_t)nb;
}
}
return 0;
@@ -303,8 +303,7 @@ static void request_event_handler(lcb_socket_t sock, short which, void *arg)
lcb_http_request_t req = arg;
lcb_t instance = req->instance;
lcb_server_t *server = req->server;
- int rv;
- (void)sock;
+ lcb_ssize_t rv;
lcb_http_resp_t resp;
if (which & LCB_READ_EVENT) {
@@ -349,6 +348,7 @@ static void request_event_handler(lcb_socket_t sock, short which, void *arg)
}
/* Make it known that this was a success. */
lcb_error_handler(instance, LCB_SUCCESS, NULL);
+ (void)sock;
}
static lcb_error_t request_connect(lcb_http_request_t req);
@@ -394,7 +394,7 @@ static lcb_error_t request_connect(lcb_http_request_t req)
if (req->io->connect(req->io,
req->sock,
req->curr_ai->ai_addr,
- (int)req->curr_ai->ai_addrlen) == 0) {
+ (unsigned int)req->curr_ai->ai_addrlen) == 0) {
/* connected */
request_connected(req);
return LCB_SUCCESS;
@@ -613,13 +613,13 @@ lcb_http_request_t lcb_make_http_request(lcb_t instance,
}
nn = strlen(method_strings[req->method]) + req->url_info.field_data[UF_PATH].len + sizeof(http_version);
if (req->url_info.field_set & UF_QUERY) {
- nn += req->url_info.field_data[UF_QUERY].len + 1;
+ nn += (lcb_size_t)req->url_info.field_data[UF_QUERY].len + 1;
}
nn += sizeof(req_headers);
if (nauth) {
nn += 23 + nauth; /* Authorization: Basic ... */
}
- nn += 10 + req->url_info.field_data[UF_HOST].len +
+ nn += 10 + (lcb_size_t)req->url_info.field_data[UF_HOST].len +
req->url_info.field_data[UF_PORT].len; /* Host: example.com:666\r\n\r\n */
if (nbody) {
if (content_type == NULL) {
@@ -671,14 +671,20 @@ lcb_http_request_t lcb_make_http_request(lcb_t instance,
BUFF_APPEND(&req->output, req->url + req->url_info.field_data[UF_PORT].off - 1, nn + 1);
if (req->method != LCB_HTTP_METHOD_GET && nbody) {
char *post_headers = calloc(512, sizeof(char));
+ int ret;
if (post_headers == NULL) {
lcb_http_request_destroy(req);
*error = lcb_synchandler_return(instance, LCB_CLIENT_ENOMEM);
return NULL;
}
- nn = snprintf(post_headers, 512, "\r\nContent-Type: %s\r\n"
- "Content-Length: %ld\r\n\r\n", content_type, (long)nbody);
- if (!ringbuffer_ensure_capacity(&req->output, nbody + nn)) {
+ ret = snprintf(post_headers, 512, "\r\nContent-Type: %s\r\n"
+ "Content-Length: %ld\r\n\r\n", content_type, (long)nbody);
+ if (ret < 0) {
+ lcb_http_request_destroy(req);
+ *error = lcb_synchandler_return(instance, LCB_CLIENT_ENOMEM);
+ return NULL;
+ }
+ if (!ringbuffer_ensure_capacity(&req->output, nbody + (lcb_size_t)ret)) {
lcb_http_request_destroy(req);
*error = lcb_synchandler_return(instance, LCB_CLIENT_ENOMEM);
return NULL;
@@ -704,11 +710,11 @@ lcb_http_request_t lcb_make_http_request(lcb_t instance,
http_parser_init(req->parser, HTTP_RESPONSE);
/* Set back reference to the request */
req->parser->data = req;
- req->parser_settings.on_body = http_parser_body_cb;
- req->parser_settings.on_message_complete = http_parser_complete_cb;
- req->parser_settings.on_header_field = http_parser_header_cb;
- req->parser_settings.on_header_value = http_parser_header_cb;
- req->parser_settings.on_headers_complete = http_parser_headers_complete_cb;
+ req->parser_settings.on_body = (http_data_cb)http_parser_body_cb;
+ req->parser_settings.on_message_complete = (http_cb)http_parser_complete_cb;
+ req->parser_settings.on_header_field = (http_data_cb)http_parser_header_cb;
+ req->parser_settings.on_header_value = (http_data_cb)http_parser_header_cb;
+ req->parser_settings.on_headers_complete = (http_cb)http_parser_headers_complete_cb;
/* Store request reference in the server struct */
hashset_add(server->http_requests, req);
View
8 src/instance.c
@@ -119,7 +119,7 @@ static int setup_boostrap_hosts(lcb_t ret, const char *host)
unsigned long size = (unsigned long)ptr - (unsigned long)start;
/* skip the entry if it's too long */
if (size < sizeof(nm)) {
- memcpy(nm, start, ptr - start);
+ memcpy(nm, start, (lcb_size_t)(ptr - start));
*(nm + size) = '\0';
}
++ptr;
@@ -390,7 +390,7 @@ lcb_error_t lcb_apply_vbucket_config(lcb_t instance, VBUCKET_CONFIG_HANDLE confi
sizeof(instance->sasl.password.buffer));
passwd = vbucket_config_get_password(instance->vbucket_config);
if (passwd) {
- instance->sasl.password.secret.len = strlen(passwd);
+ instance->sasl.password.secret.len = (unsigned long)strlen(passwd);
if (instance->sasl.password.secret.len < sizeof(instance->sasl.password.buffer) - offsetof(sasl_secret_t, data)) {
memcpy(instance->sasl.password.secret.data, passwd, instance->sasl.password.secret.len);
} else {
@@ -399,7 +399,7 @@ lcb_error_t lcb_apply_vbucket_config(lcb_t instance, VBUCKET_CONFIG_HANDLE confi
}
memcpy(instance->sasl.callbacks, sasl_callbacks, sizeof(sasl_callbacks));
- instance->nreplicas = vbucket_config_get_num_replicas(instance->vbucket_config);
+ instance->nreplicas = (lcb_uint16_t)vbucket_config_get_num_replicas(instance->vbucket_config);
instance->dist_type = vbucket_config_get_distribution_type(instance->vbucket_config);
/*
* Run through all of the vbuckets and build a map of what they need.
@@ -812,7 +812,7 @@ static void vbucket_stream_handler(lcb_socket_t sock, short which, void *arg)
}
- instance->n_http_uri_sent += nw;
+ instance->n_http_uri_sent += (lcb_size_t)nw;
if (instance->n_http_uri_sent == strlen(instance->http_uri)) {
instance->io->update_event(instance->io, instance->sock,
instance->event, LCB_READ_EVENT,
View
18 src/internal.h
@@ -134,7 +134,7 @@ extern "C" {
/** The URL request to send to the server */
char *http_uri;
- size_t n_http_uri_sent;
+ lcb_size_t n_http_uri_sent;
/** The event item representing _this_ object */
@@ -146,7 +146,7 @@ extern "C" {
struct {
char *header;
buffer_t input;
- size_t chunk_size;
+ lcb_size_t chunk_size;
buffer_t chunk;
} vbucket_stream;
@@ -155,12 +155,12 @@ extern "C" {
/* The current synchronous mode */
lcb_syncmode_t syncmode;
- evutil_socket_t sock;
+ lcb_socket_t sock;
struct addrinfo *ai;
struct addrinfo *curr_ai;
/** The number of couchbase server in the configuration */
- size_t nservers;
+ lcb_size_t nservers;
/** The array of the couchbase servers */
lcb_server_t *servers;
@@ -247,7 +247,7 @@ extern "C" {
/** The REST API server as hostname:port */
char *rest_api_server;
/** The socket to the server */
- evutil_socket_t sock;
+ lcb_socket_t sock;
/** The address information for this server (the one to release) */
struct addrinfo *root_ai;
/** The address information for this server (the one we're trying) */
@@ -303,7 +303,7 @@ extern "C" {
struct lcb_http_request_st {
/** The socket to the server */
- evutil_socket_t sock;
+ lcb_socket_t sock;
struct lcb_io_opt_st *io;
/** The origin node */
lcb_server_t *server;
@@ -495,9 +495,9 @@ extern "C" {
lcb_size_t nbuf,
lcb_error_t *uerr);
- evutil_socket_t lcb_gai2sock(lcb_t instance,
- struct addrinfo **curr_ai,
- int *connerr);
+ lcb_socket_t lcb_gai2sock(lcb_t instance,
+ struct addrinfo **curr_ai,
+ int *connerr);
lcb_error_t lcb_apply_vbucket_config(lcb_t instance,
VBUCKET_CONFIG_HANDLE config);
View
4 src/observe.c
@@ -77,7 +77,7 @@ lcb_error_t lcb_observe(lcb_t instance,
opaque = ++instance->seqno;
for (ii = 0; ii < num; ++ii) {
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
vbid = vbucket_get_vbucket_by_key(instance->vbucket_config, key, nkey);
for (jj = -1; jj < instance->nreplicas; ++jj) {
@@ -107,7 +107,7 @@ lcb_error_t lcb_observe(lcb_t instance,
}
{
- lcb_uint16_t vb = htons(vbid);
+ lcb_uint16_t vb = htons((lcb_uint16_t)vbid);
lcb_uint16_t len = htons((lcb_uint16_t)nkey);
ringbuffer_ensure_capacity(&rr->body, sizeof(vb) + sizeof(len) + nkey);
rr->nbody += ringbuffer_write(&rr->body, &vb, sizeof(vb));
View
2 src/remove.c
@@ -40,7 +40,7 @@ lcb_error_t lcb_remove(lcb_t instance,
protocol_binary_request_delete req;
int vb, idx;
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
lcb_cas_t cas = items[ii]->v.v0.cas;
(void)vbucket_map(instance->vbucket_config, key, nkey, &vb, &idx);
View
13 src/ringbuffer.c
@@ -160,6 +160,15 @@ lcb_size_t ringbuffer_write(ringbuffer_t *buffer,
return nw;
}
+lcb_size_t ringbuffer_strcat(ringbuffer_t *buffer, const char *str)
+{
+ lcb_size_t len = strlen(str);
+ if (!ringbuffer_ensure_capacity(buffer, len)) {
+ return 0;
+ }
+ return ringbuffer_write(buffer, str, len);
+}
+
static void maybe_reset(ringbuffer_t *buffer)
{
if (buffer->nbytes == 0) {
@@ -318,9 +327,9 @@ void ringbuffer_get_iov(ringbuffer_t *buffer,
iov[0].iov_len = buffer->size - buffer->nbytes;
if (buffer->write_head >= buffer->read_head) {
/* I may write all the way to the end! */
- iov[0].iov_len = (buffer->root + buffer->size) - buffer->write_head;
+ iov[0].iov_len = (lcb_size_t)((buffer->root + buffer->size) - buffer->write_head);
/* And all the way up to the read head */
- iov[1].iov_len = buffer->read_head - buffer->root;
+ iov[1].iov_len = (lcb_size_t)(buffer->read_head - buffer->root);
}
}
}
View
2 src/store.c
@@ -47,7 +47,7 @@ lcb_error_t lcb_store(lcb_t instance,
lcb_storage_t operation = items[ii]->v.v0.operation;
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
lcb_cas_t cas = items[ii]->v.v0.cas;
lcb_uint32_t flags = items[ii]->v.v0.flags;
lcb_time_t exp = items[ii]->v.v0.exptime;
View
4 src/touch.c
@@ -53,7 +53,7 @@ lcb_error_t lcb_touch(lcb_t instance,
}
for (ii = 0; ii < num; ++ii) {
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
(void)vbucket_map(instance->vbucket_config, key, nkey,
&servers[ii].vb, &servers[ii].idx);
if (servers[ii].idx < 0 || servers[ii].idx > (int)instance->nservers) {
@@ -69,7 +69,7 @@ lcb_error_t lcb_touch(lcb_t instance,
for (ii = 0; ii < num; ++ii) {
protocol_binary_request_touch req;
const void *key = items[ii]->v.v0.key;
- uint16_t nkey = items[ii]->v.v0.nkey;
+ lcb_size_t nkey = items[ii]->v.v0.nkey;
lcb_time_t exp = items[ii]->v.v0.exptime;
server = instance->servers + servers[ii].idx;
vb = servers[ii].vb;
View
6 src/utilities.c
@@ -147,10 +147,10 @@ void lcb_sockconn_errinfo(int connerr,
*
* This function will 'advance' the current addrinfo structure, as well.
*/
-evutil_socket_t lcb_gai2sock(lcb_t instance, struct addrinfo **ai,
- int *connerr)
+lcb_socket_t lcb_gai2sock(lcb_t instance, struct addrinfo **ai,
+ int *connerr)
{
- evutil_socket_t ret = INVALID_SOCKET;
+ lcb_socket_t ret = INVALID_SOCKET;
*connerr = 0;
for (; *ai; *ai = (*ai)->ai_next) {
View
4 tests/getopt-test.cc
@@ -23,9 +23,7 @@
*
* @author Trond Norbye
*/
-#include <string.h>
-#include <sys/types.h>
-#include <stdlib.h>
+#include "config.h"
#include <iostream>
#include <getopt.h>
#include <vector>
View
1 tests/hashset-unit-test.cc
@@ -16,6 +16,7 @@
*/
#include "config.h"
+#include <libcouchbase/couchbase.h>
#include "hashset.h"
#include <gtest/gtest.h>
View
4 tests/smoke-test.c
@@ -320,7 +320,7 @@ static void test_get2(void)
if (keys[ii] == NULL) {
err_exit("Failed to allocate memory for key");
}
- keys[ii][3] = (char)ii + 'a';
+ keys[ii][3] = (char)(ii + 'a');
memset(&storecmd, 0, sizeof(storecmd));
storecmd.v.v0.key = key;
storecmd.v.v0.nkey = nkey;
@@ -385,7 +385,7 @@ static void test_touch1(void)
if (keys[ii] == NULL) {
err_exit("Failed to allocate memory for key");
}
- keys[ii][3] = (char)ii + 'a';
+ keys[ii][3] = (char)(ii + 'a');
memset(&storecmd, 0, sizeof(storecmd));
storecmd.v.v0.key = key;
storecmd.v.v0.nkey = nkey;
View
6 tools/cbc.cc
@@ -502,7 +502,7 @@ extern "C" {
status == LCB_OBSERVE_PERSISTED) {
cerr << "\" CAS:" << hex << cas;
}
- cerr << " IsMaster:" << boolalpha << (bool)is_master
+ cerr << " IsMaster:" << boolalpha << (is_master != 0)
<< dec << " TimeToPersist:" << ttp
<< " TimeToReplicate:" << ttr << endl;
} else {
@@ -1520,9 +1520,9 @@ static void handleCommandLineOptions(enum cbc_command_t cmd, int argc, char **ar
static void lowercase(string &str)
{
- lcb_ssize_t len = str.length();
+ lcb_size_t len = str.length();
stringstream ss;
- for (lcb_ssize_t ii = 0; ii < len; ++ii) {
+ for (lcb_size_t ii = 0; ii < len; ++ii) {
ss << static_cast<char>(tolower(str[ii]));
}
str.assign(ss.str());
View
4 tools/commandlineparser.cc
@@ -15,13 +15,11 @@
* limitations under the License.
*/
+#include "config.h"
#include <getopt.h>
#include <vector>
#include <sstream>
-#include <string.h>
-#include <stdlib.h>
#include <iostream>
-
#include "commandlineparser.h"
using namespace std;
View
6 win32/libcouchbase/configuration.h
@@ -40,11 +40,11 @@ extern "C" {
#endif
#ifdef _WIN32
-#define PACKAGE_STRING "lcb 1.1.0dp9"
+#define PACKAGE_STRING "libcouchbase 1.1.0dp9"
typedef __int64 lcb_int64_t;
typedef __int32 lcb_int32_t;
- typedef unsigned long lcb_size_t;
- typedef long lcb_ssize_t;
+ typedef size_t lcb_size_t;
+ typedef ssize_t lcb_ssize_t;
typedef unsigned __int8 lcb_uint8_t;
typedef unsigned __int16 lcb_vbucket_t;
typedef unsigned __int16 lcb_uint16_t;
View
8 win32/strings.h
@@ -1,8 +0,0 @@
-#ifndef STRINGS_H
-#define STRINGS_H
-
-#define strcasecmp(a,b) _stricmp(a,b)
-#define strdup(a) _strdup(a)
-#define snprintf _snprintf
-
-#endif

0 comments on commit 74c75aa

Please sign in to comment.
Something went wrong with that request. Please try again.