Skip to content

Commit

Permalink
First batch of win32 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cruppstahl committed Oct 17, 2013
1 parent 7ffaad0 commit 26f94fe
Show file tree
Hide file tree
Showing 37 changed files with 320 additions and 106 deletions.
1 change: 1 addition & 0 deletions include/ham/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extern "C" {
*/
#if defined(HAM_OS_WIN32)
# define WIN32_MEAN_AND_LEAN
# include <winsock2.h>
# include <windows.h>
#endif

Expand Down
3 changes: 1 addition & 2 deletions samples/db1.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h> /* for exit() */
#include <stdint.h> /* for uint32_t */
#include <ham/hamsterdb.h>

#define LOOP 10
Expand All @@ -29,7 +28,7 @@ error(const char *foo, ham_status_t st) {

int
main(int argc, char **argv) {
uint32_t i;
ham_u32_t i;
ham_status_t st; /* status variable */
ham_env_t *env; /* hamsterdb environment object */
ham_db_t *db; /* hamsterdb database object */
Expand Down
7 changes: 3 additions & 4 deletions samples/env1.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h> /* for exit() */
#include <stdint.h> /* for uint32_t */
#include <ham/hamsterdb.h>

void
Expand All @@ -35,15 +34,15 @@ error(const char *foo, ham_status_t st) {

/* A structure for the "customer" database */
typedef struct {
uint32_t id; /* customer id */
ham_u32_t id; /* customer id */
char name[32]; /* customer name */
/* ... additional information could follow here */
} customer_t;

/* A structure for the "orders" database */
typedef struct {
uint32_t id; /* order id */
uint32_t customer_id; /* customer id */
ham_u32_t id; /* order id */
ham_u32_t customer_id; /* customer id */
char assignee[32]; /* assigned to whom? */
/* ... additional information could follow here */
} order_t;
Expand Down
7 changes: 3 additions & 4 deletions samples/env2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h> /* for exit() */
#include <stdint.h> /* for uint32_t */
#include <ham/hamsterdb.h>

void
Expand All @@ -41,15 +40,15 @@ error(const char *foo, ham_status_t st) {

/* A structure for the "customer" database */
typedef struct {
uint32_t id; /* customer id; will be the key of the customer table */
ham_u32_t id; /* customer id; will be the key of the customer table */
char name[32]; /* customer name */
/* ... additional information could follow here */
} customer_t;

/* A structure for the "orders" database */
typedef struct {
uint32_t id; /* order id; will be the key of the order table */
uint32_t customer_id; /* customer id */
ham_u32_t id; /* order id; will be the key of the order table */
ham_u32_t customer_id;/* customer id */
char assignee[32]; /* assigned to whom? */
/* ... additional information could follow here */
} order_t;
Expand Down
7 changes: 3 additions & 4 deletions samples/env3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <iostream>
#include <stdlib.h> /* for exit() */
#include <stdint.h> /* for uint32_t */
#include <ham/hamsterdb.hpp>

#define MAX_DBS 3
Expand All @@ -32,15 +31,15 @@

/* A structure for the "customer" database */
typedef struct {
uint32_t id; /* customer id; will be the key of the customer table */
ham_u32_t id; /* customer id; will be the key of the customer table */
char name[32]; /* customer name */
/* ... additional information could follow here */
} customer_t;

/* A structure for the "orders" database */
typedef struct {
uint32_t id; /* order id; will be the key of the order table */
uint32_t customer_id; /* customer id */
ham_u32_t id; /* order id; will be the key of the order table */
ham_u32_t customer_id;/* customer id */
char assignee[32]; /* assigned to whom? */
/* ... additional information could follow here */
} order_t;
Expand Down
3 changes: 2 additions & 1 deletion samples/server1.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ main()
ham_srv_config_t cfg;
ham_status_t st;
char input[1024];
int s;

/* create a new Environment; this Environment will be attached to the
* server */
Expand Down Expand Up @@ -85,7 +86,7 @@ main()
/* See client1.c for the corresponding client */
while (1) {
printf("> ");
int s = scanf("%s", &input[0]);
s = scanf("%s", &input[0]);
if (s == EOF || !strcmp(input, "exit")) {
printf("exiting...\n");
break;
Expand Down
4 changes: 4 additions & 0 deletions src/btree_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef HAM_BTREE_INDEX_H__
#define HAM_BTREE_INDEX_H__

#include <algorithm>

#include "endianswap.h"

#include "db.h"
Expand All @@ -25,6 +27,8 @@ namespace hamsterdb {

#include "packstart.h"

#undef max // avoid MSVC conflicts with std::max

//
// The persistent btree index descriptor. This structure manages the
// persistent btree metadata.
Expand Down
6 changes: 5 additions & 1 deletion src/btree_node_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef HAM_BTREE_NODE_LEGACY_H__
#define HAM_BTREE_NODE_LEGACY_H__

#include <algorithm>

#include "util.h"
#include "page.h"
#include "extkeys.h"
Expand All @@ -24,6 +26,8 @@ namespace hamsterdb {

#include "packstart.h"

#undef min // avoid MSVC conflicts with std::min

/*
* the internal representation of a serialized key
*/
Expand Down Expand Up @@ -208,7 +212,7 @@ class LegacyNodeLayout
dest->size = it->get_size();
}

size_t size = std::min(it->get_size(), db->get_keysize());
size_t size = std::min((ham_u16_t)it->get_size(), (ham_u16_t)db->get_keysize());
memcpy(dest->data, it->get_key(), size);

// TODO not really efficient; get rid of Db::get_extended_key
Expand Down
2 changes: 2 additions & 0 deletions src/btree_node_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "duplicates.h"
#include "env_local.h"

#undef min // avoid MSVC conflicts with std::min

namespace hamsterdb {

//
Expand Down
5 changes: 3 additions & 2 deletions src/os_win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include "config.h"

#include <winsock2.h>
#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -520,9 +520,10 @@ os_socket_connect(const char *hostname, ham_u16_t port, ham_u32_t timeout_sec,
tv.tv_sec = timeout_sec;
tv.tv_usec = 0;
if (::setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0) {
char buf[256];
ham_log(("unable to set socket timeout to %u sec: %u/%s", timeout_sec,
WSAGetLastError(), DisplayError(buf, sizeof(buf),
WSAGetLastError())));
WSAGetLastError())));
// fall through, this is not critical
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/server/hamserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#ifndef HAM_HAMSERVER_H__
#define HAM_HAMSERVER_H__

// otherwise uv.h includes <windows.h>, which includes
// <winsock.h>, which conflicts with <winsock2.h>
#define WIN32_LEAN_AND_MEAN

#include <vector>
#include <uv.h>

Expand Down
32 changes: 16 additions & 16 deletions tools/ham_bench/berkeleydb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ BerkeleyDatabase::do_open_env()
{
int ret = db_create(&m_db, 0, 0);
if (ret) {
ERROR(("db_create failed w/ status %d\n", ret));
LOG_ERROR(("db_create failed w/ status %d\n", ret));
return (db2ham(ret));
}

Expand All @@ -103,7 +103,7 @@ BerkeleyDatabase::do_open_env()

ret = m_db->set_cachesize(m_db, 0, m_config->cachesize, 1);
if (ret) {
ERROR(("db->set_cachesize failed w/ status %d\n", ret));
LOG_ERROR(("db->set_cachesize failed w/ status %d\n", ret));
return (db2ham(ret));
}

Expand All @@ -122,7 +122,7 @@ BerkeleyDatabase::do_open_env()
if (pagesize) {
ret = m_db->set_pagesize(m_db, pagesize);
if (ret) {
ERROR(("db->set_pagesize failed w/ status %d\n", ret));
LOG_ERROR(("db->set_pagesize failed w/ status %d\n", ret));
return (db2ham(ret));
}
}
Expand All @@ -139,7 +139,7 @@ BerkeleyDatabase::do_close_env()
if (m_db) {
ret = m_db->close(m_db, 0);
if (ret) {
ERROR(("db->close() failed w/ status %d\n", ret));
LOG_ERROR(("db->close() failed w/ status %d\n", ret));
return (db2ham(ret));
}
m_db = 0;
Expand Down Expand Up @@ -174,14 +174,14 @@ BerkeleyDatabase::do_create_db(int id)
break;
}
if (ret) {
ERROR(("set_bt_compare failed w/ status %d\n", ret));
LOG_ERROR(("set_bt_compare failed w/ status %d\n", ret));
return (db2ham(ret));
}

if (m_config->duplicate) {
ret = m_db->set_flags(m_db, DB_DUP);
if (ret) {
ERROR(("db->set_flags(DB_DUP) failed w/ status %d\n", ret));
LOG_ERROR(("db->set_flags(DB_DUP) failed w/ status %d\n", ret));
return (db2ham(ret));
}
}
Expand All @@ -197,13 +197,13 @@ BerkeleyDatabase::do_create_db(int id)
ret = m_db->open(m_db, 0, m_config->inmemory ? 0 : "test-berk.db",
0, DB_BTREE, DB_CREATE, 0644);
if (ret) {
ERROR(("db->open() failed w/ status %d\n", ret));
LOG_ERROR(("db->open() failed w/ status %d\n", ret));
return (db2ham(ret));
}

ret = m_db->cursor(m_db, 0, &m_cursor, 0);
if (ret) {
ERROR(("db->cursor() failed w/ status %d\n", ret));
LOG_ERROR(("db->cursor() failed w/ status %d\n", ret));
return (db2ham(ret));
}

Expand Down Expand Up @@ -237,19 +237,19 @@ BerkeleyDatabase::do_open_db(int id)
}

if (ret) {
ERROR(("set_bt_compare failed w/ status %d\n", ret));
LOG_ERROR(("set_bt_compare failed w/ status %d\n", ret));
return (db2ham(ret));
}

ret = m_db->open(m_db, 0, "test-berk.db", 0, DB_BTREE, 0, 0);
if (ret) {
ERROR(("db->open() failed w/ status %d\n", ret));
LOG_ERROR(("db->open() failed w/ status %d\n", ret));
return (db2ham(ret));
}

ret = m_db->cursor(m_db, 0, &m_cursor, 0);
if (ret) {
ERROR(("db->cursor() failed w/ status %d\n", ret));
LOG_ERROR(("db->cursor() failed w/ status %d\n", ret));
return (db2ham(ret));
}

Expand All @@ -264,7 +264,7 @@ BerkeleyDatabase::do_close_db()
if (m_cursor) {
ret = m_cursor->c_close(m_cursor);
if (ret) {
ERROR(("cursor->c_close() failed w/ status %d\n", ret));
LOG_ERROR(("cursor->c_close() failed w/ status %d\n", ret));
return (db2ham(ret));
}
m_cursor = 0;
Expand All @@ -278,7 +278,7 @@ BerkeleyDatabase::do_flush()
{
int ret = m_db->sync(m_db, 0);
if (ret) {
ERROR(("db->sync() failed w/ status %d\n", ret));
LOG_ERROR(("db->sync() failed w/ status %d\n", ret));
return (db2ham(ret));
}
return (0);
Expand Down Expand Up @@ -373,7 +373,7 @@ BerkeleyDatabase::do_cursor_create(Transaction *txn)

int ret = m_db->cursor(m_db, 0, &cursor, 0);
if (ret) {
ERROR(("db->cursor() failed w/ status %d\n", ret));
LOG_ERROR(("db->cursor() failed w/ status %d\n", ret));
exit(-1);
}

Expand Down Expand Up @@ -505,7 +505,7 @@ BerkeleyDatabase::do_cursor_close(Cursor *cursor)

int ret = c->c_close(c);
if (ret) {
ERROR(("cursor->close() failed w/ status %d\n", ret));
LOG_ERROR(("cursor->close() failed w/ status %d\n", ret));
exit(-1);
}

Expand All @@ -521,7 +521,7 @@ BerkeleyDatabase::db2ham(int ret)
case DB_NOTFOUND: return (HAM_KEY_NOT_FOUND);
}

TRACE(("unknown berkeley return code %d\n", ret));
LOG_TRACE(("unknown berkeley return code %d\n", ret));
return ((ham_status_t)ret);
}

Expand Down
2 changes: 2 additions & 0 deletions tools/ham_bench/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <cstdio>
#include <ham/hamsterdb.h>
#include <boost/thread.hpp>
#include <boost/cstdint.hpp> // MSVC 2008 does not have stdint
using namespace boost;

struct Configuration
{
Expand Down
3 changes: 2 additions & 1 deletion tools/ham_bench/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#ifndef DATABASE_H__
#define DATABASE_H__

#include <stdint.h>
#include <boost/cstdint.hpp>
using namespace boost;

#include <ham/hamsterdb.h>

Expand Down
4 changes: 2 additions & 2 deletions tools/ham_bench/datasource_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#ifndef DATASOURCE_BINARY_H__
#define DATASOURCE_BINARY_H__

#include <limits>
#include <string>
#include <boost/limits.hpp>
#include <boost/random.hpp>
#include <boost/random/uniform_01.hpp>

Expand Down Expand Up @@ -196,7 +196,7 @@ class BinaryZipfianDatasource : public Datasource
for (unsigned i = 0; i < (n * size); i++) {
do {
m_data[i] = m_rng() % 0xff;
} while (!std::isalnum(m_data[i]));
} while (!isalnum(m_data[i]));
}
}

Expand Down
Loading

0 comments on commit 26f94fe

Please sign in to comment.