Commit 3b9a6fab authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

Get rid of many icc warnings. Addresses #1185.

git-svn-id: file:///svn/tokudb.1131b+1080a+1185@6391 c7de825b-a66e-492c-adef-691d508d4ae1
parent c5af1cbb
...@@ -47,7 +47,7 @@ LIBNAME=libdb.$(LIBEXT) ...@@ -47,7 +47,7 @@ LIBNAME=libdb.$(LIBEXT)
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage # GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CFLAGS += -Wall $(OPTFLAGS) $(GCOV_FLAGS) CFLAGS += -Wall $(OPTFLAGS) $(GCOV_FLAGS)
ifneq ($(CC),icc) ifneq ($(CC),icc)
CFLAGS += -Werror -g3 -ggdb3 CFLAGS += -Werror -g3 -ggdb3
else else
CFLAGS += -g CFLAGS += -g
CFLAGS += -diag-disable 981 # Don't complain about "operands are evaluated in unspecified order". This seems to be generated whenever more than one argument to a function or operand is computed by function call. CFLAGS += -diag-disable 981 # Don't complain about "operands are evaluated in unspecified order". This seems to be generated whenever more than one argument to a function or operand is computed by function call.
......
...@@ -19,7 +19,8 @@ DBT value; ...@@ -19,7 +19,8 @@ DBT value;
DBC *dbc; DBC *dbc;
DB_TXN *const null_txn = 0; DB_TXN *const null_txn = 0;
void setup_db(char* name) { static void
setup_db (char* name) {
int r; int r;
system("rm -rf " ENVDIR); system("rm -rf " ENVDIR);
...@@ -33,14 +34,16 @@ void setup_db(char* name) { ...@@ -33,14 +34,16 @@ void setup_db(char* name) {
r = db->open(db, null_txn, name, "main", DB_BTREE, DB_CREATE, 0666); CKERR(r); r = db->open(db, null_txn, name, "main", DB_BTREE, DB_CREATE, 0666); CKERR(r);
} }
void close_db() { static void
close_db (void) {
int r; int r;
r = db->close(db, 0); CKERR(r); r = db->close(db, 0); CKERR(r);
r = env->close(env, 0); CKERR(r); r = env->close(env, 0); CKERR(r);
} }
void insert() { static void
insert (void) {
int r; int r;
dbt_init(&key, "key", sizeof("key")); dbt_init(&key, "key", sizeof("key"));
...@@ -52,7 +55,8 @@ void insert() { ...@@ -52,7 +55,8 @@ void insert() {
r = db->put(db, null_txn, &key, &value, DB_YESOVERWRITE); CKERR(r); r = db->put(db, null_txn, &key, &value, DB_YESOVERWRITE); CKERR(r);
} }
void cursor_range_with_delete(u_int32_t flag) { static void
cursor_range_with_delete (u_int32_t flag) {
int r; int r;
r = db->cursor(db, null_txn, &dbc, 0); CKERR(r); r = db->cursor(db, null_txn, &dbc, 0); CKERR(r);
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#include "test.h" #include "test.h"
void test_cursor_flags(int cursor_flags, int expectr) { static void
test_cursor_flags (int cursor_flags, int expectr) {
if (verbose) printf("test_cursor_flags:%d %d\n", cursor_flags, expectr); if (verbose) printf("test_cursor_flags:%d %d\n", cursor_flags, expectr);
DB_ENV * const null_env = 0; DB_ENV * const null_env = 0;
......
...@@ -12,9 +12,8 @@ ...@@ -12,9 +12,8 @@
#include "test.h" #include "test.h"
static void
expect_cursor_get (DBC *cursor, int k, int v, int op) {
void expect_cursor_get(DBC *cursor, int k, int v, int op) {
int kk, vv; int kk, vv;
DBT key, val; DBT key, val;
int r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), op); int r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), op);
...@@ -23,7 +22,8 @@ void expect_cursor_get(DBC *cursor, int k, int v, int op) { ...@@ -23,7 +22,8 @@ void expect_cursor_get(DBC *cursor, int k, int v, int op) {
assert(val.size == sizeof vv); memcpy(&vv, val.data, val.size); assert(vv == v); free(val.data); assert(val.size == sizeof vv); memcpy(&vv, val.data, val.size); assert(vv == v); free(val.data);
} }
DBC *new_cursor(DB *db, int k, int v, int op) { static DBC *
new_cursor (DB *db, int k, int v, int op) {
DBC *cursor; DBC *cursor;
int r; int r;
r = db->cursor(db, 0, &cursor, 0); assert(r == 0); r = db->cursor(db, 0, &cursor, 0); assert(r == 0);
...@@ -31,7 +31,8 @@ DBC *new_cursor(DB *db, int k, int v, int op) { ...@@ -31,7 +31,8 @@ DBC *new_cursor(DB *db, int k, int v, int op) {
return cursor; return cursor;
} }
int db_put(DB *db, int k, int v) { static int
db_put (DB *db, int k, int v) {
DBT key, val; DBT key, val;
int r = db->put(db, 0, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0); int r = db->put(db, 0, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
return r; return r;
...@@ -45,7 +46,8 @@ int db_put(DB *db, int k, int v) { ...@@ -45,7 +46,8 @@ int db_put(DB *db, int k, int v) {
the reverse parameter controls where in insertions are made to test the <, =, > the reverse parameter controls where in insertions are made to test the <, =, >
cases in the brt_nonleaf_expand function */ cases in the brt_nonleaf_expand function */
void test_cursor_nonleaf_expand(int n, int reverse) { static void
test_cursor_nonleaf_expand (int n, int reverse) {
if (verbose) printf("test_cursor_nonleaf_expand:%d %d\n", n, reverse); if (verbose) printf("test_cursor_nonleaf_expand:%d %d\n", n, reverse);
DB_ENV * const null_env = 0; DB_ENV * const null_env = 0;
......
...@@ -11,19 +11,13 @@ ...@@ -11,19 +11,13 @@
// ENVDIR is defined in the Makefile // ENVDIR is defined in the Makefile
int dbtcmp(DBT *dbt1, DBT *dbt2) {
int r;
r = dbt1->size - dbt2->size; if (r) return r;
return memcmp(dbt1->data, dbt2->data, dbt1->size);
}
DB *db; DB *db;
DB_ENV* dbenv; DB_ENV* dbenv;
DBC* cursors[(int)256]; DBC* cursors[(int)256];
DB_TXN* null_txn = NULL; DB_TXN* null_txn = NULL;
void put(int _key, int _data) { static void
put (int _key, int _data) {
int r; int r;
DBT key; DBT key;
DBT data; DBT data;
...@@ -42,7 +36,8 @@ void put(int _key, int _data) { ...@@ -42,7 +36,8 @@ void put(int _key, int _data) {
CKERR(r); CKERR(r);
} }
void cget(u_int32_t flag, BOOL find, char txn, int _key, int _data) { static void
cget (u_int32_t flag, BOOL find, char txn, int _key, int _data) {
assert(cursors[(int)txn]); assert(cursors[(int)txn]);
int r; int r;
...@@ -90,7 +85,8 @@ void cget(u_int32_t flag, BOOL find, char txn, int _key, int _data) { ...@@ -90,7 +85,8 @@ void cget(u_int32_t flag, BOOL find, char txn, int _key, int _data) {
else CKERR2(r, DB_NOTFOUND); else CKERR2(r, DB_NOTFOUND);
} }
void init_dbc(char name) { static void
init_dbc (char name) {
int r; int r;
assert(!cursors[(int)name]); assert(!cursors[(int)name]);
...@@ -99,7 +95,8 @@ void init_dbc(char name) { ...@@ -99,7 +95,8 @@ void init_dbc(char name) {
assert(cursors[(int)name]); assert(cursors[(int)name]);
} }
void close_dbc(char name) { static void
close_dbc (char name) {
int r; int r;
assert(cursors[(int)name]); assert(cursors[(int)name]);
...@@ -108,7 +105,8 @@ void close_dbc(char name) { ...@@ -108,7 +105,8 @@ void close_dbc(char name) {
cursors[(int)name] = NULL; cursors[(int)name] = NULL;
} }
void setup_dbs(u_int32_t dup_flags) { static void
setup_dbs (u_int32_t dup_flags) {
int r; int r;
system("rm -rf " ENVDIR); system("rm -rf " ENVDIR);
...@@ -136,7 +134,8 @@ void setup_dbs(u_int32_t dup_flags) { ...@@ -136,7 +134,8 @@ void setup_dbs(u_int32_t dup_flags) {
for (a = 'a'; a <= 'z'; a++) init_dbc(a); for (a = 'a'; a <= 'z'; a++) init_dbc(a);
} }
void close_dbs(void) { static void
close_dbs (void) {
char a; char a;
for (a = 'a'; a <= 'z'; a++) { for (a = 'a'; a <= 'z'; a++) {
if (cursors[(int)a]) close_dbc(a); if (cursors[(int)a]) close_dbc(a);
...@@ -151,7 +150,8 @@ void close_dbs(void) { ...@@ -151,7 +150,8 @@ void close_dbs(void) {
dbenv = NULL; dbenv = NULL;
} }
void test(u_int32_t dup_flags) { static void
test (u_int32_t dup_flags) {
/* ********************************************************************** */ /* ********************************************************************** */
int key; int key;
int data; int data;
......
...@@ -13,46 +13,16 @@ ...@@ -13,46 +13,16 @@
#include "test.h" #include "test.h"
static void
void db_put(DB *db, int k, int v) { db_put (DB *db, int k, int v) {
DB_TXN * const null_txn = 0; DB_TXN * const null_txn = 0;
DBT key, val; DBT key, val;
int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0); int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0); assert(r == 0);
} }
void db_get(DB *db, int k) { static int
DB_TXN * const null_txn = 0; cursor_get (DBC *cursor, unsigned int *k, unsigned int *v, int op) {
DBT key, val;
int r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
assert(val.size == sizeof vv);
memcpy(&vv, val.data, val.size);
printf("do_search %d\n", htonl(vv));
free(val.data);
}
void db_del(DB *db, int k) {
DB_TXN * const null_txn = 0;
DBT key;
int r = db->del(db, null_txn, dbt_init(&key, &k, sizeof k), 0);
assert(r == 0);
}
void expect_db_get(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
int r = db->get(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), 0);
assert(r == 0);
int vv;
assert(val.size == sizeof vv);
memcpy(&vv, val.data, val.size);
assert(vv == v);
free(val.data);
}
int cursor_get(DBC *cursor, unsigned int *k, unsigned int *v, int op) {
DBT key, val; DBT key, val;
int r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), op); int r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), op);
if (r == 0) { if (r == 0) {
...@@ -64,49 +34,8 @@ int cursor_get(DBC *cursor, unsigned int *k, unsigned int *v, int op) { ...@@ -64,49 +34,8 @@ int cursor_get(DBC *cursor, unsigned int *k, unsigned int *v, int op) {
return r; return r;
} }
void expect_cursor_get(DBC *cursor, unsigned int k, unsigned int v) { static void
DBT key, val; test_cursor_sticky (int n, int dup_mode) {
int r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), DB_NEXT);
assert(r == 0);
assert(key.size == sizeof k);
unsigned int kk;
memcpy(&kk, key.data, key.size);
assert(val.size == sizeof v);
unsigned int vv;
memcpy(&vv, val.data, val.size);
if (kk != k || vv != v) printf("expect key %d got %d - %d %d\n", htonl(k), htonl(kk), htonl(v), htonl(vv));
assert(kk == k);
assert(vv == v);
free(key.data);
free(val.data);
}
void expect_cursor_set(DBC *cursor, int k, int expectr) {
DBT key, val;
int r = cursor->c_get(cursor, dbt_init(&key, &k, sizeof k), dbt_init_malloc(&val), DB_SET);
assert(r == expectr);
if (val.data) free(val.data);
}
void expect_cursor_get_both(DBC *cursor, int k, int v) {
DBT key, val;
int r = cursor->c_get(cursor, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_GET_BOTH);
assert(r == 0);
}
void expect_cursor_get_current(DBC *cursor, unsigned int k, unsigned int v) {
DBT key, val;
int r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), DB_CURRENT);
assert(r == 0);
unsigned int kk, vv;
assert(key.size == sizeof kk); memcpy(&kk, key.data, key.size); assert(kk == k);
assert(val.size == sizeof vv); memcpy(&vv, val.data, val.size); assert(vv == v);
free(key.data); free(val.data);
}
void test_cursor_sticky(int n, int dup_mode) {
if (verbose) printf("test_cursor_sticky:%d %d\n", n, dup_mode); if (verbose) printf("test_cursor_sticky:%d %d\n", n, dup_mode);
DB_ENV * const null_env = 0; DB_ENV * const null_env = 0;
......
...@@ -40,34 +40,40 @@ struct primary_data { ...@@ -40,34 +40,40 @@ struct primary_data {
struct name_key name; struct name_key name;
}; };
void free_pd (struct primary_data *pd) { static void
free_pd (struct primary_data *pd) {
free(pd->name.name); free(pd->name.name);
free(pd); free(pd);
} }
void write_uchar_to_dbt (DBT *dbt, const unsigned char c) { static void
write_uchar_to_dbt (DBT *dbt, const unsigned char c) {
assert(dbt->size+1 <= dbt->ulen); assert(dbt->size+1 <= dbt->ulen);
((char*)dbt->data)[dbt->size++]=c; ((char*)dbt->data)[dbt->size++]=c;
} }
void write_uint_to_dbt (DBT *dbt, const unsigned int v) { static void
write_uchar_to_dbt(dbt, (v>>24)&0xff); write_uint_to_dbt (DBT *dbt, const unsigned int v) {
write_uchar_to_dbt(dbt, (v>>16)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>>24)&0xff));
write_uchar_to_dbt(dbt, (v>> 8)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>>16)&0xff));
write_uchar_to_dbt(dbt, (v>> 0)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>> 8)&0xff));
write_uchar_to_dbt(dbt, (unsigned char)((v>> 0)&0xff));
} }
void write_timestamp_to_dbt (DBT *dbt, const struct timestamp *ts) { static void
write_timestamp_to_dbt (DBT *dbt, const struct timestamp *ts) {
write_uint_to_dbt(dbt, ts->tv_sec); write_uint_to_dbt(dbt, ts->tv_sec);
write_uint_to_dbt(dbt, ts->tv_usec); write_uint_to_dbt(dbt, ts->tv_usec);
} }
void write_pk_to_dbt (DBT *dbt, const struct primary_key *pk) { static void
write_pk_to_dbt (DBT *dbt, const struct primary_key *pk) {
write_uint_to_dbt(dbt, pk->rand); write_uint_to_dbt(dbt, pk->rand);
write_timestamp_to_dbt(dbt, &pk->ts); write_timestamp_to_dbt(dbt, &pk->ts);
} }
void write_name_to_dbt (DBT *dbt, const struct name_key *nk) { static void
write_name_to_dbt (DBT *dbt, const struct name_key *nk) {
int i; int i;
for (i=0; 1; i++) { for (i=0; 1; i++) {
write_uchar_to_dbt(dbt, nk->name[i]); write_uchar_to_dbt(dbt, nk->name[i]);
...@@ -75,18 +81,21 @@ void write_name_to_dbt (DBT *dbt, const struct name_key *nk) { ...@@ -75,18 +81,21 @@ void write_name_to_dbt (DBT *dbt, const struct name_key *nk) {
} }
} }
void write_pd_to_dbt (DBT *dbt, const struct primary_data *pd) { static void
write_pd_to_dbt (DBT *dbt, const struct primary_data *pd) {
write_timestamp_to_dbt(dbt, &pd->expiretime); write_timestamp_to_dbt(dbt, &pd->expiretime);
write_uchar_to_dbt(dbt, pd->doesexpire); write_uchar_to_dbt(dbt, pd->doesexpire);
write_name_to_dbt(dbt, &pd->name); write_name_to_dbt(dbt, &pd->name);
} }
void read_uchar_from_dbt (const DBT *dbt, unsigned int *off, unsigned char *uchar) { static void
read_uchar_from_dbt (const DBT *dbt, unsigned int *off, unsigned char *uchar) {
assert(*off < dbt->size); assert(*off < dbt->size);
*uchar = ((unsigned char *)dbt->data)[(*off)++]; *uchar = ((unsigned char *)dbt->data)[(*off)++];
} }
void read_uint_from_dbt (const DBT *dbt, unsigned int *off, unsigned int *uint) { static void
read_uint_from_dbt (const DBT *dbt, unsigned int *off, unsigned int *uint) {
unsigned char a,b,c,d; unsigned char a,b,c,d;
read_uchar_from_dbt(dbt, off, &a); read_uchar_from_dbt(dbt, off, &a);
read_uchar_from_dbt(dbt, off, &b); read_uchar_from_dbt(dbt, off, &b);
...@@ -95,12 +104,14 @@ void read_uint_from_dbt (const DBT *dbt, unsigned int *off, unsigned int *uint) ...@@ -95,12 +104,14 @@ void read_uint_from_dbt (const DBT *dbt, unsigned int *off, unsigned int *uint)
*uint = (a<<24)+(b<<16)+(c<<8)+d; *uint = (a<<24)+(b<<16)+(c<<8)+d;
} }
void read_timestamp_from_dbt (const DBT *dbt, unsigned int *off, struct timestamp *ts) { static void
read_timestamp_from_dbt (const DBT *dbt, unsigned int *off, struct timestamp *ts) {
read_uint_from_dbt(dbt, off, &ts->tv_sec); read_uint_from_dbt(dbt, off, &ts->tv_sec);
read_uint_from_dbt(dbt, off, &ts->tv_usec); read_uint_from_dbt(dbt, off, &ts->tv_usec);
} }
void read_name_from_dbt (const DBT *dbt, unsigned int *off, struct name_key *nk) { static void
read_name_from_dbt (const DBT *dbt, unsigned int *off, struct name_key *nk) {
unsigned char buf[1000]; unsigned char buf[1000];
int i; int i;
for (i=0; 1; i++) { for (i=0; 1; i++) {
...@@ -110,17 +121,20 @@ void read_name_from_dbt (const DBT *dbt, unsigned int *off, struct name_key *nk) ...@@ -110,17 +121,20 @@ void read_name_from_dbt (const DBT *dbt, unsigned int *off, struct name_key *nk)
nk->name=(unsigned char*)(strdup((char*)buf)); nk->name=(unsigned char*)(strdup((char*)buf));
} }
void read_pd_from_dbt (const DBT *dbt, unsigned int *off, struct primary_data *pd) { static void
read_pd_from_dbt (const DBT *dbt, unsigned int *off, struct primary_data *pd) {
read_timestamp_from_dbt(dbt, off, &pd->expiretime); read_timestamp_from_dbt(dbt, off, &pd->expiretime);
read_uchar_from_dbt(dbt, off, &pd->doesexpire); read_uchar_from_dbt(dbt, off, &pd->doesexpire);
read_name_from_dbt(dbt, off, &pd->name); read_name_from_dbt(dbt, off, &pd->name);
} }
int name_offset_in_pd_dbt (void) { static int
name_offset_in_pd_dbt (void) {
return 9; return 9;
} }
int name_callback (DB *UU(secondary), const DBT * UU(key), const DBT *data, DBT *result) { static int
name_callback (DB *UU(secondary), const DBT * UU(key), const DBT *data, DBT *result) {
struct primary_data *pd = malloc(sizeof(*pd)); struct primary_data *pd = malloc(sizeof(*pd));
unsigned int off=0; unsigned int off=0;
read_pd_from_dbt(data, &off, pd); read_pd_from_dbt(data, &off, pd);
...@@ -134,7 +148,8 @@ int name_callback (DB *UU(secondary), const DBT * UU(key), const DBT *data, DBT ...@@ -134,7 +148,8 @@ int name_callback (DB *UU(secondary), const DBT * UU(key), const DBT *data, DBT
return 0; return 0;
} }
int expire_callback (DB *UU(secondary), const DBT *UU(key), const DBT *data, DBT *result) { static int
expire_callback (DB *UU(secondary), const DBT *UU(key), const DBT *data, DBT *result) {
struct primary_data *d = data->data; struct primary_data *d = data->data;
if (d->doesexpire) { if (d->doesexpire) {
result->flags=0; result->flags=0;
...@@ -196,7 +211,8 @@ int count_all_items=0; // The total number of items ...@@ -196,7 +211,8 @@ int count_all_items=0; // The total number of items
DBT nc_key,nc_data; DBT nc_key,nc_data;
void create_databases (void) { static void
create_databases (void) {
int r; int r;
r = db_env_create(&dbenv, 0); CKERR(r); r = db_env_create(&dbenv, 0); CKERR(r);
...@@ -217,7 +233,8 @@ void create_databases (void) { ...@@ -217,7 +233,8 @@ void create_databases (void) {
r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r); r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r);
} }
void close_databases (void) { static void
close_databases (void) {
int r; int r;
if (delete_cursor) { if (delete_cursor) {
r = delete_cursor->c_close(delete_cursor); CKERR(r); r = delete_cursor->c_close(delete_cursor); CKERR(r);
...@@ -237,7 +254,8 @@ void close_databases (void) { ...@@ -237,7 +254,8 @@ void close_databases (void) {
static int tod_counter=0; static int tod_counter=0;
void gettod (struct timestamp *ts) { static void
gettod (struct timestamp *ts) {
#if 0 #if 0
struct timeval tv; struct timeval tv;
int r = gettimeofday(&tv, 0); int r = gettimeofday(&tv, 0);
...@@ -250,7 +268,8 @@ void gettod (struct timestamp *ts) { ...@@ -250,7 +268,8 @@ void gettod (struct timestamp *ts) {
#endif #endif
} }
void setup_for_db_create (void) { static void
setup_for_db_create (void) {
// Remove name.db and then rebuild it with associate(... DB_CREATE) // Remove name.db and then rebuild it with associate(... DB_CREATE)
...@@ -274,7 +293,8 @@ void setup_for_db_create (void) { ...@@ -274,7 +293,8 @@ void setup_for_db_create (void) {
} }
int count_entries (DB *db) { static int
count_entries (DB *db) {
DBC *dbc; DBC *dbc;
int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r); int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r);
DBT key,data; DBT key,data;
...@@ -291,7 +311,8 @@ int count_entries (DB *db) { ...@@ -291,7 +311,8 @@ int count_entries (DB *db) {
return n_found; return n_found;
} }
int count_entries_and_max_tod (DB *db, int *tod) { static int
count_entries_and_max_tod (DB *db, int *tod) {
DBC *dbc; DBC *dbc;
int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r); int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r);
DBT key,data; DBT key,data;
...@@ -305,7 +326,7 @@ int count_entries_and_max_tod (DB *db, int *tod) { ...@@ -305,7 +326,7 @@ int count_entries_and_max_tod (DB *db, int *tod) {
int thistod = ntohl(*(2+(unsigned int*)key.data)); int thistod = ntohl(*(2+(unsigned int*)key.data));
if (thistod>*tod) *tod=thistod; if (thistod>*tod) *tod=thistod;
n_found++; n_found++;
dbg_name_insert(name_offset_in_pd_dbt()+data.data); dbg_name_insert(name_offset_in_pd_dbt()+(unsigned char*)data.data);
} }
(*tod)++; (*tod)++;
assert(r==DB_NOTFOUND); assert(r==DB_NOTFOUND);
...@@ -313,7 +334,8 @@ int count_entries_and_max_tod (DB *db, int *tod) { ...@@ -313,7 +334,8 @@ int count_entries_and_max_tod (DB *db, int *tod) {
return n_found; return n_found;
} }
void do_create (void) { static void
do_create (void) {
setup_for_db_create(); setup_for_db_create();
// Now check to see if the number of names matches the number of associated things. // Now check to see if the number of names matches the number of associated things.
int n_named = count_entries(namedb); int n_named = count_entries(namedb);
...@@ -321,7 +343,8 @@ void do_create (void) { ...@@ -321,7 +343,8 @@ void do_create (void) {
assert(n_named==n_prim); assert(n_named==n_prim);
} }
void insert_person (void) { static void
insert_person (void) {
const int extrafortod = 20; const int extrafortod = 20;
int namelen = 5+extrafortod+myrandom()%245; int namelen = 5+extrafortod+myrandom()%245;
struct primary_key pk; struct primary_key pk;
...@@ -332,14 +355,14 @@ void insert_person (void) { ...@@ -332,14 +355,14 @@ void insert_person (void) {
gettod(&pk.ts); gettod(&pk.ts);
pd.expiretime = pk.ts; pd.expiretime = pk.ts;
pd.expiretime.tv_sec += 24*60*60*366; pd.expiretime.tv_sec += 24*60*60*366;
pd.doesexpire = (myrandom()%10==0); pd.doesexpire =(char)(myrandom()%10==0);
int i; int i;
pd.name.name = namearray; pd.name.name = namearray;
pd.name.name[0] = 'A'+myrandom()%26; pd.name.name[0] = (char)('A'+myrandom()%26);
for (i=1; i<namelen; i++) { for (i=1; i<namelen; i++) {
pd.name.name[i] = 'a'+myrandom()%26; pd.name.name[i] = (char)('a'+myrandom()%26);
} }
int count=snprintf((char*)&pd.name.name[i], extrafortod, "%d.%d", pk.ts.tv_sec, pk.ts.tv_usec); int count=snprintf((char*)&pd.name.name[i], extrafortod, "%u.%u", pk.ts.tv_sec, pk.ts.tv_usec);
assert(count<extrafortod); assert(count<extrafortod);
DBT key,data; DBT key,data;
memset(&key,0,sizeof(DBT)); memset(&key,0,sizeof(DBT));
...@@ -367,7 +390,8 @@ void insert_person (void) { ...@@ -367,7 +390,8 @@ void insert_person (void) {
} }
} }
void delete_oldest_expired (void) { static void
delete_oldest_expired (void) {
int r; int r;
int r3=myrandom()%3; int r3=myrandom()%3;
if (delete_cursor==0) { if (delete_cursor==0) {
...@@ -419,7 +443,8 @@ void delete_oldest_expired (void) { ...@@ -419,7 +443,8 @@ void delete_oldest_expired (void) {
} }
// Use a cursor to step through the names. // Use a cursor to step through the names.
void step_name (void) { static void
step_name (void) {
int r; int r;
if (name_cursor==0) { if (name_cursor==0) {
r = namedb->cursor(namedb, null_txn, &name_cursor, 0); CKERR(r); r = namedb->cursor(namedb, null_txn, &name_cursor, 0); CKERR(r);
...@@ -450,7 +475,8 @@ void step_name (void) { ...@@ -450,7 +475,8 @@ void step_name (void) {
int cursor_load=2; /* Set this to a higher number to do more cursor work for every insertion. Needed to get to the end. */ int cursor_load=2; /* Set this to a higher number to do more cursor work for every insertion. Needed to get to the end. */
void activity (void) { static void
activity (void) {
if (myrandom()%20==0) { if (myrandom()%20==0) {
// Delete the oldest expired one. Keep the cursor open // Delete the oldest expired one. Keep the cursor open
delete_oldest_expired(); delete_oldest_expired();
...@@ -463,13 +489,14 @@ void activity (void) { ...@@ -463,13 +489,14 @@ void activity (void) {
} }
void usage (const char*) __attribute__((__noreturn__)); static __attribute__((__noreturn__))
void usage (const char *argv1) { void usage (const char *argv1) {
fprintf(stderr, "Usage:\n %s [ --DB-CREATE | --more ] [ --tod=N ] [ --seed=SEED ] [ --count=count ] \n", argv1); fprintf(stderr, "Usage:\n %s [ --DB-CREATE | --more ] [ --tod=N ] [ --seed=SEED ] [ --count=count ] \n", argv1);
exit(1); exit(1);
} }
int maybe_parse_intarg (const char *progname, const char *arg, const char *cmdname, int *result) { static int
maybe_parse_intarg (const char *progname, const char *arg, const char *cmdname, int *result) {
int len = strlen(cmdname); int len = strlen(cmdname);
if (strncmp(arg, cmdname, len)==0) { if (strncmp(arg, cmdname, len)==0) {
errno=0; errno=0;
......
...@@ -33,14 +33,21 @@ struct primary_key { ...@@ -33,14 +33,21 @@ struct primary_key {
struct timestamp ts; struct timestamp ts;
}; };
void print_pkey (DBT *dbt) { static u_int32_t
int_from_chars (unsigned char *d) {
return (d[0]<<24)+(d[1]<<16)+(d[2]<<8)+d[3];
}
static __attribute__((__unused__))
void
print_pkey (DBT *dbt) {
unsigned char *d = dbt->data; unsigned char *d = dbt->data;
int i; int i;
assert(dbt->size==12); assert(dbt->size==12);
printf("pkey=%u.%u.%u {", printf("pkey=%u.%u.%u {",
(d[0]<<24)+(d[1]<<16)+(d[2]<<8)+d[3], int_from_chars(d),
(d[4]<<24)+(d[5]<<16)+(d[6]<<8)+d[7], int_from_chars(d+4),
(d[8]<<24)+(d[9]<<16)+(d[10]<<8)+d[11]); int_from_chars(d+8));
for (i=0; i<12; i++) { for (i=0; i<12; i++) {
if (i!=0) printf(","); if (i!=0) printf(",");
printf("%d", d[i]); printf("%d", d[i]);
...@@ -59,34 +66,40 @@ struct primary_data { ...@@ -59,34 +66,40 @@ struct primary_data {
struct name_key name; struct name_key name;
}; };
void free_pd (struct primary_data *pd) { static void
free_pd (struct primary_data *pd) {
free(pd->name.name); free(pd->name.name);
free(pd); free(pd);
} }
void write_uchar_to_dbt (DBT *dbt, const unsigned char c) { static void
write_uchar_to_dbt (DBT *dbt, const unsigned char c) {
assert(dbt->size+1 <= dbt->ulen); assert(dbt->size+1 <= dbt->ulen);
((char*)dbt->data)[dbt->size++]=c; ((char*)dbt->data)[dbt->size++]=c;
} }
void write_uint_to_dbt (DBT *dbt, const unsigned int v) { static void
write_uchar_to_dbt(dbt, (v>>24)&0xff); write_uint_to_dbt (DBT *dbt, const unsigned int v) {
write_uchar_to_dbt(dbt, (v>>16)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>>24)&0xff));
write_uchar_to_dbt(dbt, (v>> 8)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>>16)&0xff));
write_uchar_to_dbt(dbt, (v>> 0)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>> 8)&0xff));
write_uchar_to_dbt(dbt, (unsigned char)((v>> 0)&0xff));
} }
void write_timestamp_to_dbt (DBT *dbt, const struct timestamp *ts) { static void
write_timestamp_to_dbt (DBT *dbt, const struct timestamp *ts) {
write_uint_to_dbt(dbt, ts->tv_sec); write_uint_to_dbt(dbt, ts->tv_sec);
write_uint_to_dbt(dbt, ts->tv_usec); write_uint_to_dbt(dbt, ts->tv_usec);
} }
void write_pk_to_dbt (DBT *dbt, const struct primary_key *pk) { static void
write_pk_to_dbt (DBT *dbt, const struct primary_key *pk) {
write_uint_to_dbt(dbt, pk->rand); write_uint_to_dbt(dbt, pk->rand);
write_timestamp_to_dbt(dbt, &pk->ts); write_timestamp_to_dbt(dbt, &pk->ts);
} }
void write_name_to_dbt (DBT *dbt, const struct name_key *nk) { static void
write_name_to_dbt (DBT *dbt, const struct name_key *nk) {
int i; int i;
for (i=0; 1; i++) { for (i=0; 1; i++) {
write_uchar_to_dbt(dbt, nk->name[i]); write_uchar_to_dbt(dbt, nk->name[i]);
...@@ -94,19 +107,22 @@ void write_name_to_dbt (DBT *dbt, const struct name_key *nk) { ...@@ -94,19 +107,22 @@ void write_name_to_dbt (DBT *dbt, const struct name_key *nk) {
} }
} }
void write_pd_to_dbt (DBT *dbt, const struct primary_data *pd) { static void
write_pd_to_dbt (DBT *dbt, const struct primary_data *pd) {
write_timestamp_to_dbt(dbt, &pd->creationtime); write_timestamp_to_dbt(dbt, &pd->creationtime);
write_timestamp_to_dbt(dbt, &pd->expiretime); write_timestamp_to_dbt(dbt, &pd->expiretime);
write_uchar_to_dbt(dbt, pd->doesexpire); write_uchar_to_dbt(dbt, pd->doesexpire);
write_name_to_dbt(dbt, &pd->name); write_name_to_dbt(dbt, &pd->name);
} }
void read_uchar_from_dbt (const DBT *dbt, unsigned int *off, unsigned char *uchar) { static void
read_uchar_from_dbt (const DBT *dbt, unsigned int *off, unsigned char *uchar) {
assert(*off < dbt->size); assert(*off < dbt->size);
*uchar = ((unsigned char *)dbt->data)[(*off)++]; *uchar = ((unsigned char *)dbt->data)[(*off)++];
} }
void read_uint_from_dbt (const DBT *dbt, unsigned int *off, unsigned int *uint) { static void
read_uint_from_dbt (const DBT *dbt, unsigned int *off, unsigned int *uint) {
unsigned char a,b,c,d; unsigned char a,b,c,d;
read_uchar_from_dbt(dbt, off, &a); read_uchar_from_dbt(dbt, off, &a);
read_uchar_from_dbt(dbt, off, &b); read_uchar_from_dbt(dbt, off, &b);
...@@ -115,12 +131,14 @@ void read_uint_from_dbt (const DBT *dbt, unsigned int *off, unsigned int *uint) ...@@ -115,12 +131,14 @@ void read_uint_from_dbt (const DBT *dbt, unsigned int *off, unsigned int *uint)
*uint = (a<<24)+(b<<16)+(c<<8)+d; *uint = (a<<24)+(b<<16)+(c<<8)+d;
} }
void read_timestamp_from_dbt (const DBT *dbt, unsigned int *off, struct timestamp *ts) { static void
read_timestamp_from_dbt (const DBT *dbt, unsigned int *off, struct timestamp *ts) {
read_uint_from_dbt(dbt, off, &ts->tv_sec); read_uint_from_dbt(dbt, off, &ts->tv_sec);
read_uint_from_dbt(dbt, off, &ts->tv_usec); read_uint_from_dbt(dbt, off, &ts->tv_usec);
} }
void read_name_from_dbt (const DBT *dbt, unsigned int *off, struct name_key *nk) { static void
read_name_from_dbt (const DBT *dbt, unsigned int *off, struct name_key *nk) {
unsigned char buf[1000]; unsigned char buf[1000];
int i; int i;
for (i=0; 1; i++) { for (i=0; 1; i++) {
...@@ -130,18 +148,16 @@ void read_name_from_dbt (const DBT *dbt, unsigned int *off, struct name_key *nk) ...@@ -130,18 +148,16 @@ void read_name_from_dbt (const DBT *dbt, unsigned int *off, struct name_key *nk)
nk->name=(unsigned char*)(strdup((char*)buf)); nk->name=(unsigned char*)(strdup((char*)buf));
} }
void read_pd_from_dbt (const DBT *dbt, unsigned int *off, struct primary_data *pd) { static void
read_pd_from_dbt (const DBT *dbt, unsigned int *off, struct primary_data *pd) {
read_timestamp_from_dbt(dbt, off, &pd->creationtime); read_timestamp_from_dbt(dbt, off, &pd->creationtime);
read_timestamp_from_dbt(dbt, off, &pd->expiretime); read_timestamp_from_dbt(dbt, off, &pd->expiretime);
read_uchar_from_dbt(dbt, off, &pd->doesexpire); read_uchar_from_dbt(dbt, off, &pd->doesexpire);
read_name_from_dbt(dbt, off, &pd->name); read_name_from_dbt(dbt, off, &pd->name);
} }
int name_offset_in_pd_dbt (void) { static int
return 17; name_callback (DB *secondary __attribute__((__unused__)), const DBT * UU(key), const DBT *data, DBT *result) {
}
int name_callback (DB *secondary __attribute__((__unused__)), const DBT * UU(key), const DBT *data, DBT *result) {
struct primary_data *pd = malloc(sizeof(*pd)); struct primary_data *pd = malloc(sizeof(*pd));
unsigned int off=0; unsigned int off=0;
read_pd_from_dbt(data, &off, pd); read_pd_from_dbt(data, &off, pd);
...@@ -155,7 +171,8 @@ int name_callback (DB *secondary __attribute__((__unused__)), const DBT * UU(key ...@@ -155,7 +171,8 @@ int name_callback (DB *secondary __attribute__((__unused__)), const DBT * UU(key
return 0; return 0;
} }
int expire_callback (DB *UU(secondary), const DBT * UU(key), const DBT *data, DBT *result) { static int
expire_callback (DB *UU(secondary), const DBT * UU(key), const DBT *data, DBT *result) {
struct primary_data *d = data->data; struct primary_data *d = data->data;
if (d->doesexpire) { if (d->doesexpire) {
result->flags=0; result->flags=0;
...@@ -183,7 +200,8 @@ int count_all_items=0; // The total number of items ...@@ -183,7 +200,8 @@ int count_all_items=0; // The total number of items
DBT nc_key,nc_data; DBT nc_key,nc_data;
void create_databases (void) { static void
create_databases (void) {
int r; int r;
r = db_env_create(&dbenv, 0); CKERR(r); r = db_env_create(&dbenv, 0); CKERR(r);
...@@ -202,7 +220,8 @@ void create_databases (void) { ...@@ -202,7 +220,8 @@ void create_databases (void) {
r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r); r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r);
} }
void close_databases (void) { static void
close_databases (void) {
int r; int r;
if (delete_cursor) { if (delete_cursor) {
r = delete_cursor->c_close(delete_cursor); CKERR(r); r = delete_cursor->c_close(delete_cursor); CKERR(r);
...@@ -219,13 +238,15 @@ void close_databases (void) { ...@@ -219,13 +238,15 @@ void close_databases (void) {
} }
void gettod (struct timestamp *ts) { static void
gettod (struct timestamp *ts) {
static int counter=0; static int counter=0;
ts->tv_sec=0; ts->tv_sec=0;
ts->tv_usec=counter++; ts->tv_usec=counter++;
} }
void setup_for_db_create (void) { static void
setup_for_db_create (void) {
// Remove name.db and then rebuild it with associate(... DB_CREATE) // Remove name.db and then rebuild it with associate(... DB_CREATE)
...@@ -249,7 +270,8 @@ void setup_for_db_create (void) { ...@@ -249,7 +270,8 @@ void setup_for_db_create (void) {
} }
int count_entries (DB *db) { static int
count_entries (DB *db) {
DBC *dbc; DBC *dbc;
int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r); int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r);
DBT key,data; DBT key,data;
...@@ -266,7 +288,8 @@ int count_entries (DB *db) { ...@@ -266,7 +288,8 @@ int count_entries (DB *db) {
return n_found; return n_found;
} }
void do_create (void) { static void
do_create (void) {
setup_for_db_create(); setup_for_db_create();
// Now check to see if the number of names matches the number of associated things. // Now check to see if the number of names matches the number of associated things.
int n_named = count_entries(namedb); int n_named = count_entries(namedb);
...@@ -276,7 +299,8 @@ void do_create (void) { ...@@ -276,7 +299,8 @@ void do_create (void) {
int rcount=0; int rcount=0;
void insert_person (void) { static void
insert_person (void) {
int namelen = 5+random()%245; int namelen = 5+random()%245;
rcount++; rcount++;
struct primary_key pk; struct primary_key pk;
...@@ -347,16 +371,8 @@ void insert_person (void) { ...@@ -347,16 +371,8 @@ void insert_person (void) {
} }
} }
void print_dbt (DBT *dbt) { static void
unsigned int i; delete_oldest_expired (void) {
for (i=0; i<dbt->size; i++) {
unsigned char c = ((char*)dbt->data)[i];
if (c!='\\' && isprint(c)) printf("%c", c);
else printf("\\%02x", c);
}
}
void delete_oldest_expired (void) {
printf("%s:%d %d:%d delete\n", __FILE__, __LINE__, oppass, opnum); printf("%s:%d %d:%d delete\n", __FILE__, __LINE__, oppass, opnum);
int r; int r;
random(); random();
...@@ -411,7 +427,8 @@ void delete_oldest_expired (void) { ...@@ -411,7 +427,8 @@ void delete_oldest_expired (void) {
} }
// Use a cursor to step through the names. // Use a cursor to step through the names.
void step_name (void) { static void
step_name (void) {
int r; int r;
if (name_cursor==0) { if (name_cursor==0) {
r = namedb->cursor(namedb, null_txn, &name_cursor, 0); CKERR(r); r = namedb->cursor(namedb, null_txn, &name_cursor, 0); CKERR(r);
...@@ -437,7 +454,8 @@ void step_name (void) { ...@@ -437,7 +454,8 @@ void step_name (void) {
int cursor_load=2; /* Set this to a higher number to do more cursor work for every insertion. Needed to get to the end. */ int cursor_load=2; /* Set this to a higher number to do more cursor work for every insertion. Needed to get to the end. */
void activity (void) { static void
activity (void) {
random(); random();
rcount++; rcount++;
if (oppass==2 && (opnum==8 || opnum==53 || opnum==57 || opnum==65 || opnum==78 || opnum==97)) { if (oppass==2 && (opnum==8 || opnum==53 || opnum==57 || opnum==65 || opnum==78 || opnum==97)) {
...@@ -457,8 +475,9 @@ void activity (void) { ...@@ -457,8 +475,9 @@ void activity (void) {
} }
void usage (const char *argv1) __attribute__((__noreturn__)); static __attribute__((__noreturn__))
void usage (const char *argv1) { void
usage (const char *argv1) {
fprintf(stderr, "Usage:\n %s [ --DB-CREATE | --more ] [-v|-q] seed\n", argv1); fprintf(stderr, "Usage:\n %s [ --DB-CREATE | --more ] [-v|-q] seed\n", argv1);
exit(1); exit(1);
} }
......
...@@ -46,10 +46,10 @@ static void write_uchar_to_dbt (DBT *dbt, const unsigned char c) { ...@@ -46,10 +46,10 @@ static void write_uchar_to_dbt (DBT *dbt, const unsigned char c) {
} }
static void write_uint_to_dbt (DBT *dbt, const unsigned int v) { static void write_uint_to_dbt (DBT *dbt, const unsigned int v) {
write_uchar_to_dbt(dbt, (v>>24)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>>24)&0xff));
write_uchar_to_dbt(dbt, (v>>16)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>>16)&0xff));
write_uchar_to_dbt(dbt, (v>> 8)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>> 8)&0xff));
write_uchar_to_dbt(dbt, (v>> 0)&0xff); write_uchar_to_dbt(dbt, (unsigned char)((v>> 0)&0xff));
} }
static void write_timestamp_to_dbt (DBT *dbt, timestamp ts) { static void write_timestamp_to_dbt (DBT *dbt, timestamp ts) {
...@@ -125,18 +125,6 @@ static int name_callback (DB *secondary __attribute__((__unused__)), const DBT * ...@@ -125,18 +125,6 @@ static int name_callback (DB *secondary __attribute__((__unused__)), const DBT *
return 0; return 0;
} }
int expire_callback (DB *UU(secondary), const DBT * UU(key), const DBT *data, DBT *result) {
struct primary_data *d = data->data;
if (d->doesexpire) {
result->flags=0;
result->size=sizeof(timestamp);
result->data=&d->expiretime;
return 0;
} else {
return DB_DONOTINDEX;
}
}
// The expire_key is simply a timestamp. // The expire_key is simply a timestamp.
static DB_ENV *dbenv; static DB_ENV *dbenv;
...@@ -242,7 +230,7 @@ static void delete_oldest_expired (void) { ...@@ -242,7 +230,7 @@ static void delete_oldest_expired (void) {
assert(count==0); assert(count==0);
count++; count++;
int r; int r;
printf("%s:%d deleting %d\n", __FILE__, __LINE__, pkey_0); printf("%s:%d deleting %u\n", __FILE__, __LINE__, pkey_0);
DBT pkey; DBT pkey;
memset(&pkey, 0, sizeof(pkey)); memset(&pkey, 0, sizeof(pkey));
{ {
......
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