Commit a19234e8 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

merge intel c++ changes from changeset 6813. addresses #1185

git-svn-id: file:///svn/toku/tokudb.1195@7730 c7de825b-a66e-492c-adef-691d508d4ae1
parent ab0ac5ad
......@@ -106,7 +106,7 @@ void toku_ydb_error_all_cases(const DB_ENV * env,
BOOL include_stderrstring,
BOOL use_stderr_if_nothing_else,
const char *fmt, va_list ap);
};
}
void DbEnv::err(int error, const char *fmt, ...) {
va_list ap;
......
......@@ -7,7 +7,7 @@
char *data_dir;
int dbcreate(char *dbfile, char *dbname, int dbflags, int argc, char *argv[]) {
static int dbcreate(char *dbfile, char *dbname, int dbflags, int argc, char *argv[]) {
int r;
DbEnv *env = new DbEnv(DB_CXX_NO_EXCEPTIONS);
if (data_dir) {
......@@ -43,7 +43,7 @@ int dbcreate(char *dbfile, char *dbname, int dbflags, int argc, char *argv[]) {
return 0;
}
int usage() {
static int usage() {
printf("db_create [-s DBNAME] [-D] [-S] DBFILE [KEY VAL]*\n");
printf("[--set_data_dir DIRNAME]\n");
return 1;
......
......@@ -2,7 +2,7 @@
#include <assert.h>
#include <db_cxx.h>
void hexdump(Dbt *d) {
static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
printf(" ");
......@@ -11,10 +11,10 @@ void hexdump(Dbt *d) {
printf("\n");
}
int dbdump(char *dbfile, char *dbname) {
static int dbdump(char *dbfile, char *dbname) {
int r;
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS);
......@@ -24,7 +24,7 @@ int dbdump(char *dbfile, char *dbname) {
r = db.open(0, dbfile, dbname, DB_UNKNOWN, 0, 0777);
if (r != 0) {
printf("cant open %s:%s %d:%s\n", dbfile, dbname, r, db_strerror(r));
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 1;
......@@ -60,13 +60,13 @@ int dbdump(char *dbfile, char *dbname) {
r = cursor->close(); assert(r == 0);
r = db.close(0); assert(r == 0);
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 0;
}
int usage() {
static int usage() {
printf("db_dump [-s DBNAME] DBFILE\n");
return 1;
}
......
......@@ -3,7 +3,7 @@
#include <assert.h>
#include <db_cxx.h>
void hexdump(Dbt *d) {
static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
printf(" ");
......@@ -12,10 +12,10 @@ void hexdump(Dbt *d) {
printf("\n");
}
int dbdump(char *dbfile, char *dbname) {
static int dbdump(char *dbfile, char *dbname) {
int r;
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
DbEnv env(0);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, 0);
......@@ -27,7 +27,7 @@ int dbdump(char *dbfile, char *dbname) {
assert(r==0);
} catch (DbException e) {
printf("Cannot open %s:%s due to error %d\n", dbfile, dbname, e.get_errno());
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 1;
......@@ -56,13 +56,13 @@ int dbdump(char *dbfile, char *dbname) {
r = cursor->close(); assert(r == 0);
r = db.close(0); assert(r == 0);
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 0;
}
int usage() {
static int usage() {
printf("db_dump [-s DBNAME] DBFILE\n");
return 1;
}
......
......@@ -2,7 +2,7 @@
#include <assert.h>
#include <db_cxx.h>
void hexdump(Dbt *d) {
static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
printf(" ");
......@@ -11,7 +11,7 @@ void hexdump(Dbt *d) {
printf("\n");
}
void hexput(Dbt *d, unsigned char c) {
static void hexput(Dbt *d, int c) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
int ulen = d->get_ulen();
......@@ -21,18 +21,18 @@ void hexput(Dbt *d, unsigned char c) {
d->set_data(cp);
d->set_ulen(newulen);
}
cp[n++] = c;
cp[n++] = (unsigned char)c;
d->set_size(n);
}
int hextrans(int c) {
static int hextrans(int c) {
if ('0' <= c && c <= '9') return c - '0';
if ('a' <= c && c <= 'f') return c - 'a' + 10;
if ('A' <= c && c <= 'F') return c - 'A' + 10;
return 0;
}
int hexload(Dbt *d) {
static int hexload(Dbt *d) {
d->set_size(0);
int c = getchar();
if (c == EOF || c != ' ') return 0;
......@@ -49,10 +49,10 @@ int hexload(Dbt *d) {
return 1;
}
int dbload(char *dbfile, char *dbname) {
static int dbload(char *dbfile, char *dbname) {
int r;
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS);
......@@ -62,7 +62,7 @@ int dbload(char *dbfile, char *dbname) {
r = db.open(0, dbfile, dbname, DB_BTREE, DB_CREATE, 0777);
if (r != 0) {
printf("cant open %s:%s\n", dbfile, dbname);
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 1;
......@@ -81,13 +81,13 @@ int dbload(char *dbfile, char *dbname) {
if (val.get_data()) free(val.get_data());
r = db.close(0); assert(r == 0);
#if USE_ENV
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 0;
}
int usage() {
static int usage() {
printf("db_load [-s DBNAME] DBFILE\n");
return 1;
}
......
......@@ -13,7 +13,7 @@
int verbose = 0;
#define TC(expr, expect) ({ \
#define TC(expr, expect) \
if (verbose) printf("%s expect %d\n", #expr, expect); \
try { \
expr; \
......@@ -21,10 +21,9 @@ int verbose = 0;
} catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \
} \
})
}
#define TCRET(expr, expect) ({ \
#define TCRET(expr, expect) \
if (verbose) printf("%s expect %d\n", #expr, expect); \
try { \
int r = expr; \
......@@ -32,10 +31,9 @@ int verbose = 0;
} catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \
} \
})
}
void test_env_exceptions (void) {
static void test_env_exceptions (void) {
{
DbEnv env(0);
TC(env.open("no.such.dir", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0777), ENOENT);
......@@ -83,7 +81,7 @@ void test_env_exceptions (void) {
}
void test_db_exceptions (void) {
static void test_db_exceptions (void) {
DbEnv env(0);
TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
TC( ({ Db db(&env, -1); assert(0); }), EINVAL); // Create with flags=-1 should do an EINVAL
......@@ -148,7 +146,7 @@ void test_db_exceptions (void) {
}
void test_dbc_exceptions () {
static void test_dbc_exceptions () {
DbEnv env(0);
TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
Db db(&env, 0);
......
......@@ -6,15 +6,14 @@
#define FNAME __FILE__ ".tdb"
#define TC(expr, expect) ({ \
#define TC(expr, expect) \
try { \
expr; \
assert(expect==0); \
} catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \
} \
})
}
void test_no_env () {
#if 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment