Commit 5f772b51 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 71871aa0
...@@ -106,7 +106,7 @@ void toku_ydb_error_all_cases(const DB_ENV * env, ...@@ -106,7 +106,7 @@ void toku_ydb_error_all_cases(const DB_ENV * env,
BOOL include_stderrstring, BOOL include_stderrstring,
BOOL use_stderr_if_nothing_else, BOOL use_stderr_if_nothing_else,
const char *fmt, va_list ap); const char *fmt, va_list ap);
}; }
void DbEnv::err(int error, const char *fmt, ...) { void DbEnv::err(int error, const char *fmt, ...) {
va_list ap; va_list ap;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
char *data_dir; 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; int r;
DbEnv *env = new DbEnv(DB_CXX_NO_EXCEPTIONS); DbEnv *env = new DbEnv(DB_CXX_NO_EXCEPTIONS);
if (data_dir) { if (data_dir) {
...@@ -43,7 +43,7 @@ int dbcreate(char *dbfile, char *dbname, int dbflags, int argc, char *argv[]) { ...@@ -43,7 +43,7 @@ int dbcreate(char *dbfile, char *dbname, int dbflags, int argc, char *argv[]) {
return 0; return 0;
} }
int usage() { static int usage() {
printf("db_create [-s DBNAME] [-D] [-S] DBFILE [KEY VAL]*\n"); printf("db_create [-s DBNAME] [-D] [-S] DBFILE [KEY VAL]*\n");
printf("[--set_data_dir DIRNAME]\n"); printf("[--set_data_dir DIRNAME]\n");
return 1; return 1;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <assert.h> #include <assert.h>
#include <db_cxx.h> #include <db_cxx.h>
void hexdump(Dbt *d) { static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data(); unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size(); int n = d->get_size();
printf(" "); printf(" ");
...@@ -11,10 +11,10 @@ void hexdump(Dbt *d) { ...@@ -11,10 +11,10 @@ void hexdump(Dbt *d) {
printf("\n"); printf("\n");
} }
int dbdump(char *dbfile, char *dbname) { static int dbdump(char *dbfile, char *dbname) {
int r; int r;
#if USE_ENV #if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS); DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS); Db db(&env, DB_CXX_NO_EXCEPTIONS);
...@@ -24,7 +24,7 @@ int dbdump(char *dbfile, char *dbname) { ...@@ -24,7 +24,7 @@ int dbdump(char *dbfile, char *dbname) {
r = db.open(0, dbfile, dbname, DB_UNKNOWN, 0, 0777); r = db.open(0, dbfile, dbname, DB_UNKNOWN, 0, 0777);
if (r != 0) { if (r != 0) {
printf("cant open %s:%s %d:%s\n", dbfile, dbname, r, db_strerror(r)); 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); r = env.close(0); assert(r == 0);
#endif #endif
return 1; return 1;
...@@ -60,13 +60,13 @@ int dbdump(char *dbfile, char *dbname) { ...@@ -60,13 +60,13 @@ int dbdump(char *dbfile, char *dbname) {
r = cursor->close(); assert(r == 0); r = cursor->close(); assert(r == 0);
r = db.close(0); 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); r = env.close(0); assert(r == 0);
#endif #endif
return 0; return 0;
} }
int usage() { static int usage() {
printf("db_dump [-s DBNAME] DBFILE\n"); printf("db_dump [-s DBNAME] DBFILE\n");
return 1; return 1;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <assert.h> #include <assert.h>
#include <db_cxx.h> #include <db_cxx.h>
void hexdump(Dbt *d) { static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data(); unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size(); int n = d->get_size();
printf(" "); printf(" ");
...@@ -12,10 +12,10 @@ void hexdump(Dbt *d) { ...@@ -12,10 +12,10 @@ void hexdump(Dbt *d) {
printf("\n"); printf("\n");
} }
int dbdump(char *dbfile, char *dbname) { static int dbdump(char *dbfile, char *dbname) {
int r; int r;
#if USE_ENV #if defined(USE_ENV) && USE_ENV
DbEnv env(0); DbEnv env(0);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, 0); Db db(&env, 0);
...@@ -27,7 +27,7 @@ int dbdump(char *dbfile, char *dbname) { ...@@ -27,7 +27,7 @@ int dbdump(char *dbfile, char *dbname) {
assert(r==0); assert(r==0);
} catch (DbException e) { } catch (DbException e) {
printf("Cannot open %s:%s due to error %d\n", dbfile, dbname, e.get_errno()); 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); r = env.close(0); assert(r == 0);
#endif #endif
return 1; return 1;
...@@ -56,13 +56,13 @@ int dbdump(char *dbfile, char *dbname) { ...@@ -56,13 +56,13 @@ int dbdump(char *dbfile, char *dbname) {
r = cursor->close(); assert(r == 0); r = cursor->close(); assert(r == 0);
r = db.close(0); 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); r = env.close(0); assert(r == 0);
#endif #endif
return 0; return 0;
} }
int usage() { static int usage() {
printf("db_dump [-s DBNAME] DBFILE\n"); printf("db_dump [-s DBNAME] DBFILE\n");
return 1; return 1;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <assert.h> #include <assert.h>
#include <db_cxx.h> #include <db_cxx.h>
void hexdump(Dbt *d) { static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data(); unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size(); int n = d->get_size();
printf(" "); printf(" ");
...@@ -11,7 +11,7 @@ void hexdump(Dbt *d) { ...@@ -11,7 +11,7 @@ void hexdump(Dbt *d) {
printf("\n"); printf("\n");
} }
void hexput(Dbt *d, unsigned char c) { static void hexput(Dbt *d, int c) {
unsigned char *cp = (unsigned char *) d->get_data(); unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size(); int n = d->get_size();
int ulen = d->get_ulen(); int ulen = d->get_ulen();
...@@ -21,18 +21,18 @@ void hexput(Dbt *d, unsigned char c) { ...@@ -21,18 +21,18 @@ void hexput(Dbt *d, unsigned char c) {
d->set_data(cp); d->set_data(cp);
d->set_ulen(newulen); d->set_ulen(newulen);
} }
cp[n++] = c; cp[n++] = (unsigned char)c;
d->set_size(n); d->set_size(n);
} }
int hextrans(int c) { static int hextrans(int c) {
if ('0' <= c && c <= '9') return c - '0'; 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;
if ('A' <= c && c <= 'F') return c - 'A' + 10; if ('A' <= c && c <= 'F') return c - 'A' + 10;
return 0; return 0;
} }
int hexload(Dbt *d) { static int hexload(Dbt *d) {
d->set_size(0); d->set_size(0);
int c = getchar(); int c = getchar();
if (c == EOF || c != ' ') return 0; if (c == EOF || c != ' ') return 0;
...@@ -49,10 +49,10 @@ int hexload(Dbt *d) { ...@@ -49,10 +49,10 @@ int hexload(Dbt *d) {
return 1; return 1;
} }
int dbload(char *dbfile, char *dbname) { static int dbload(char *dbfile, char *dbname) {
int r; int r;
#if USE_ENV #if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS); DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS); Db db(&env, DB_CXX_NO_EXCEPTIONS);
...@@ -62,7 +62,7 @@ int dbload(char *dbfile, char *dbname) { ...@@ -62,7 +62,7 @@ int dbload(char *dbfile, char *dbname) {
r = db.open(0, dbfile, dbname, DB_BTREE, DB_CREATE, 0777); r = db.open(0, dbfile, dbname, DB_BTREE, DB_CREATE, 0777);
if (r != 0) { if (r != 0) {
printf("cant open %s:%s\n", dbfile, dbname); printf("cant open %s:%s\n", dbfile, dbname);
#if USE_ENV #if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0); r = env.close(0); assert(r == 0);
#endif #endif
return 1; return 1;
...@@ -81,13 +81,13 @@ int dbload(char *dbfile, char *dbname) { ...@@ -81,13 +81,13 @@ int dbload(char *dbfile, char *dbname) {
if (val.get_data()) free(val.get_data()); if (val.get_data()) free(val.get_data());
r = db.close(0); 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); r = env.close(0); assert(r == 0);
#endif #endif
return 0; return 0;
} }
int usage() { static int usage() {
printf("db_load [-s DBNAME] DBFILE\n"); printf("db_load [-s DBNAME] DBFILE\n");
return 1; return 1;
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
int verbose = 0; int verbose = 0;
#define TC(expr, expect) ({ \ #define TC(expr, expect) \
if (verbose) printf("%s expect %d\n", #expr, expect); \ if (verbose) printf("%s expect %d\n", #expr, expect); \
try { \ try { \
expr; \ expr; \
...@@ -21,10 +21,9 @@ int verbose = 0; ...@@ -21,10 +21,9 @@ int verbose = 0;
} catch (DbException e) { \ } catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \ if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \ assert(e.get_errno()==expect); \
} \ }
})
#define TCRET(expr, expect) ({ \ #define TCRET(expr, expect) \
if (verbose) printf("%s expect %d\n", #expr, expect); \ if (verbose) printf("%s expect %d\n", #expr, expect); \
try { \ try { \
int r = expr; \ int r = expr; \
...@@ -32,10 +31,9 @@ int verbose = 0; ...@@ -32,10 +31,9 @@ int verbose = 0;
} catch (DbException e) { \ } catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \ if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \ assert(e.get_errno()==expect); \
} \ }
})
void test_env_exceptions (void) { static void test_env_exceptions (void) {
{ {
DbEnv env(0); DbEnv env(0);
TC(env.open("no.such.dir", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0777), ENOENT); TC(env.open("no.such.dir", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0777), ENOENT);
...@@ -83,7 +81,7 @@ void test_env_exceptions (void) { ...@@ -83,7 +81,7 @@ void test_env_exceptions (void) {
} }
void test_db_exceptions (void) { static void test_db_exceptions (void) {
DbEnv env(0); DbEnv env(0);
TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 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 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) { ...@@ -148,7 +146,7 @@ void test_db_exceptions (void) {
} }
void test_dbc_exceptions () { static void test_dbc_exceptions () {
DbEnv env(0); DbEnv env(0);
TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0); TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
Db db(&env, 0); Db db(&env, 0);
......
...@@ -6,15 +6,14 @@ ...@@ -6,15 +6,14 @@
#define FNAME __FILE__ ".tdb" #define FNAME __FILE__ ".tdb"
#define TC(expr, expect) ({ \ #define TC(expr, expect) \
try { \ try { \
expr; \ expr; \
assert(expect==0); \ assert(expect==0); \
} catch (DbException e) { \ } catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \ if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \ assert(e.get_errno()==expect); \
} \ }
})
void test_no_env () { void test_no_env () {
#if 0 #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