diff --git a/src/tests/Makefile b/src/tests/Makefile index 97404341746..58eef536599 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -47,7 +47,7 @@ LIBNAME=libdb.$(LIBEXT) # GCOV_FLAGS = -fprofile-arcs -ftest-coverage CFLAGS += -Wall $(OPTFLAGS) $(GCOV_FLAGS) ifneq ($(CC),icc) - CFLAGS += -Werror -g3 -ggdb3 + CFLAGS += -Werror -g3 -ggdb3 else 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. diff --git a/src/tests/test_cursor_delete_next.c b/src/tests/test_cursor_delete_next.c index 1e88776d2c6..1982e7673b6 100644 --- a/src/tests/test_cursor_delete_next.c +++ b/src/tests/test_cursor_delete_next.c @@ -19,7 +19,8 @@ DBT value; DBC *dbc; DB_TXN *const null_txn = 0; -void setup_db(char* name) { +static void +setup_db (char* name) { int r; system("rm -rf " ENVDIR); @@ -33,14 +34,16 @@ void setup_db(char* name) { 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; r = db->close(db, 0); CKERR(r); r = env->close(env, 0); CKERR(r); } -void insert() { +static void +insert (void) { int r; dbt_init(&key, "key", sizeof("key")); @@ -52,7 +55,8 @@ void insert() { 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; r = db->cursor(db, null_txn, &dbc, 0); CKERR(r); diff --git a/src/tests/test_cursor_flags.c b/src/tests/test_cursor_flags.c index e1d8bb968e8..41136c2d448 100644 --- a/src/tests/test_cursor_flags.c +++ b/src/tests/test_cursor_flags.c @@ -13,7 +13,8 @@ #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); DB_ENV * const null_env = 0; diff --git a/src/tests/test_cursor_nonleaf_expand.c b/src/tests/test_cursor_nonleaf_expand.c index 1fb0dd22519..b79397ffdbd 100644 --- a/src/tests/test_cursor_nonleaf_expand.c +++ b/src/tests/test_cursor_nonleaf_expand.c @@ -12,9 +12,8 @@ #include "test.h" - - -void expect_cursor_get(DBC *cursor, int k, int v, int op) { +static void +expect_cursor_get (DBC *cursor, int k, int v, int op) { int kk, vv; DBT key, val; 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) { 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; int r; 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) { return cursor; } -int db_put(DB *db, int k, int v) { +static int +db_put (DB *db, int k, int v) { DBT key, val; int r = db->put(db, 0, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0); return r; @@ -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 <, =, > 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); DB_ENV * const null_env = 0; diff --git a/src/tests/test_cursor_null.c b/src/tests/test_cursor_null.c index 967ff11793f..b5a0af79faa 100644 --- a/src/tests/test_cursor_null.c +++ b/src/tests/test_cursor_null.c @@ -11,19 +11,13 @@ // 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_ENV* dbenv; DBC* cursors[(int)256]; DB_TXN* null_txn = NULL; -void put(int _key, int _data) { +static void +put (int _key, int _data) { int r; DBT key; DBT data; @@ -42,7 +36,8 @@ void put(int _key, int _data) { 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]); int r; @@ -90,7 +85,8 @@ void cget(u_int32_t flag, BOOL find, char txn, int _key, int _data) { else CKERR2(r, DB_NOTFOUND); } -void init_dbc(char name) { +static void +init_dbc (char name) { int r; assert(!cursors[(int)name]); @@ -99,7 +95,8 @@ void init_dbc(char name) { assert(cursors[(int)name]); } -void close_dbc(char name) { +static void +close_dbc (char name) { int r; assert(cursors[(int)name]); @@ -108,7 +105,8 @@ void close_dbc(char name) { cursors[(int)name] = NULL; } -void setup_dbs(u_int32_t dup_flags) { +static void +setup_dbs (u_int32_t dup_flags) { int r; system("rm -rf " ENVDIR); @@ -136,7 +134,8 @@ void setup_dbs(u_int32_t dup_flags) { for (a = 'a'; a <= 'z'; a++) init_dbc(a); } -void close_dbs(void) { +static void +close_dbs (void) { char a; for (a = 'a'; a <= 'z'; a++) { if (cursors[(int)a]) close_dbc(a); @@ -151,7 +150,8 @@ void close_dbs(void) { dbenv = NULL; } -void test(u_int32_t dup_flags) { +static void +test (u_int32_t dup_flags) { /* ********************************************************************** */ int key; int data; diff --git a/src/tests/test_cursor_stickyness.c b/src/tests/test_cursor_stickyness.c index 2bbb347ba0e..0b759d99c23 100644 --- a/src/tests/test_cursor_stickyness.c +++ b/src/tests/test_cursor_stickyness.c @@ -13,46 +13,16 @@ #include "test.h" - -void db_put(DB *db, int k, int v) { +static void +db_put (DB *db, int k, int v) { DB_TXN * const null_txn = 0; DBT key, val; int r = db->put(db, null_txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0); assert(r == 0); } -void db_get(DB *db, int k) { - 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); - 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) { +static int +cursor_get (DBC *cursor, unsigned int *k, unsigned int *v, int op) { DBT key, val; int r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), op); if (r == 0) { @@ -64,49 +34,8 @@ int cursor_get(DBC *cursor, unsigned int *k, unsigned int *v, int op) { return r; } -void expect_cursor_get(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_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) { +static void +test_cursor_sticky (int n, int dup_mode) { if (verbose) printf("test_cursor_sticky:%d %d\n", n, dup_mode); DB_ENV * const null_env = 0; diff --git a/src/tests/test_db_assoc3.c b/src/tests/test_db_assoc3.c index 370a970c305..12f4c63c72a 100644 --- a/src/tests/test_db_assoc3.c +++ b/src/tests/test_db_assoc3.c @@ -40,34 +40,40 @@ struct primary_data { 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); } -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); ((char*)dbt->data)[dbt->size++]=c; } -void write_uint_to_dbt (DBT *dbt, const unsigned int v) { - write_uchar_to_dbt(dbt, (v>>24)&0xff); - write_uchar_to_dbt(dbt, (v>>16)&0xff); - write_uchar_to_dbt(dbt, (v>> 8)&0xff); - write_uchar_to_dbt(dbt, (v>> 0)&0xff); +static void +write_uint_to_dbt (DBT *dbt, const unsigned int v) { + write_uchar_to_dbt(dbt, (unsigned char)((v>>24)&0xff)); + write_uchar_to_dbt(dbt, (unsigned char)((v>>16)&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_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_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; for (i=0; 1; 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) { } } -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_uchar_to_dbt(dbt, pd->doesexpire); 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); *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; read_uchar_from_dbt(dbt, off, &a); 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) *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_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]; int 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) 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_uchar_from_dbt(dbt, off, &pd->doesexpire); 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; } -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)); unsigned int off=0; 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 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; if (d->doesexpire) { result->flags=0; @@ -196,7 +211,8 @@ int count_all_items=0; // The total number of items DBT nc_key,nc_data; -void create_databases (void) { +static void +create_databases (void) { int r; r = db_env_create(&dbenv, 0); CKERR(r); @@ -217,7 +233,8 @@ void create_databases (void) { r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r); } -void close_databases (void) { +static void +close_databases (void) { int r; if (delete_cursor) { r = delete_cursor->c_close(delete_cursor); CKERR(r); @@ -237,7 +254,8 @@ void close_databases (void) { static int tod_counter=0; -void gettod (struct timestamp *ts) { +static void +gettod (struct timestamp *ts) { #if 0 struct timeval tv; int r = gettimeofday(&tv, 0); @@ -250,7 +268,8 @@ void gettod (struct timestamp *ts) { #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) @@ -274,7 +293,8 @@ void setup_for_db_create (void) { } -int count_entries (DB *db) { +static int +count_entries (DB *db) { DBC *dbc; int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r); DBT key,data; @@ -291,7 +311,8 @@ int count_entries (DB *db) { 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; int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r); DBT key,data; @@ -305,7 +326,7 @@ int count_entries_and_max_tod (DB *db, int *tod) { int thistod = ntohl(*(2+(unsigned int*)key.data)); if (thistod>*tod) *tod=thistod; 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)++; assert(r==DB_NOTFOUND); @@ -313,7 +334,8 @@ int count_entries_and_max_tod (DB *db, int *tod) { return n_found; } -void do_create (void) { +static void +do_create (void) { setup_for_db_create(); // Now check to see if the number of names matches the number of associated things. int n_named = count_entries(namedb); @@ -321,7 +343,8 @@ void do_create (void) { assert(n_named==n_prim); } -void insert_person (void) { +static void +insert_person (void) { const int extrafortod = 20; int namelen = 5+extrafortod+myrandom()%245; struct primary_key pk; @@ -332,14 +355,14 @@ void insert_person (void) { gettod(&pk.ts); pd.expiretime = pk.ts; pd.expiretime.tv_sec += 24*60*60*366; - pd.doesexpire = (myrandom()%10==0); + pd.doesexpire =(char)(myrandom()%10==0); int i; pd.name.name = namearray; - pd.name.name[0] = 'A'+myrandom()%26; + pd.name.name[0] = (char)('A'+myrandom()%26); for (i=1; icursor(namedb, null_txn, &name_cursor, 0); CKERR(r); @@ -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. */ -void activity (void) { +static void +activity (void) { if (myrandom()%20==0) { // Delete the oldest expired one. Keep the cursor open delete_oldest_expired(); @@ -463,13 +489,14 @@ void activity (void) { } -void usage (const char*) __attribute__((__noreturn__)); +static __attribute__((__noreturn__)) void usage (const char *argv1) { fprintf(stderr, "Usage:\n %s [ --DB-CREATE | --more ] [ --tod=N ] [ --seed=SEED ] [ --count=count ] \n", argv1); 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); if (strncmp(arg, cmdname, len)==0) { errno=0; diff --git a/src/tests/test_db_curs2.c b/src/tests/test_db_curs2.c index edeb7348c78..6c0b1d240c5 100644 --- a/src/tests/test_db_curs2.c +++ b/src/tests/test_db_curs2.c @@ -33,14 +33,21 @@ struct primary_key { 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; int i; assert(dbt->size==12); printf("pkey=%u.%u.%u {", - (d[0]<<24)+(d[1]<<16)+(d[2]<<8)+d[3], - (d[4]<<24)+(d[5]<<16)+(d[6]<<8)+d[7], - (d[8]<<24)+(d[9]<<16)+(d[10]<<8)+d[11]); + int_from_chars(d), + int_from_chars(d+4), + int_from_chars(d+8)); for (i=0; i<12; i++) { if (i!=0) printf(","); printf("%d", d[i]); @@ -59,34 +66,40 @@ struct primary_data { 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); } -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); ((char*)dbt->data)[dbt->size++]=c; } -void write_uint_to_dbt (DBT *dbt, const unsigned int v) { - write_uchar_to_dbt(dbt, (v>>24)&0xff); - write_uchar_to_dbt(dbt, (v>>16)&0xff); - write_uchar_to_dbt(dbt, (v>> 8)&0xff); - write_uchar_to_dbt(dbt, (v>> 0)&0xff); +static void +write_uint_to_dbt (DBT *dbt, const unsigned int v) { + write_uchar_to_dbt(dbt, (unsigned char)((v>>24)&0xff)); + write_uchar_to_dbt(dbt, (unsigned char)((v>>16)&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_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_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; for (i=0; 1; 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) { } } -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->expiretime); write_uchar_to_dbt(dbt, pd->doesexpire); 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); *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; read_uchar_from_dbt(dbt, off, &a); 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) *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_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]; int 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) 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->expiretime); read_uchar_from_dbt(dbt, off, &pd->doesexpire); read_name_from_dbt(dbt, off, &pd->name); } -int name_offset_in_pd_dbt (void) { - return 17; -} - -int name_callback (DB *secondary __attribute__((__unused__)), const DBT * UU(key), const DBT *data, DBT *result) { +static int +name_callback (DB *secondary __attribute__((__unused__)), const DBT * UU(key), const DBT *data, DBT *result) { struct primary_data *pd = malloc(sizeof(*pd)); unsigned int off=0; read_pd_from_dbt(data, &off, pd); @@ -155,7 +171,8 @@ int name_callback (DB *secondary __attribute__((__unused__)), const DBT * UU(key 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; if (d->doesexpire) { result->flags=0; @@ -183,7 +200,8 @@ int count_all_items=0; // The total number of items DBT nc_key,nc_data; -void create_databases (void) { +static void +create_databases (void) { int r; r = db_env_create(&dbenv, 0); CKERR(r); @@ -202,7 +220,8 @@ void create_databases (void) { r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r); } -void close_databases (void) { +static void +close_databases (void) { int r; if (delete_cursor) { r = delete_cursor->c_close(delete_cursor); CKERR(r); @@ -219,13 +238,15 @@ void close_databases (void) { } -void gettod (struct timestamp *ts) { +static void +gettod (struct timestamp *ts) { static int counter=0; ts->tv_sec=0; 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) @@ -249,7 +270,8 @@ void setup_for_db_create (void) { } -int count_entries (DB *db) { +static int +count_entries (DB *db) { DBC *dbc; int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r); DBT key,data; @@ -266,7 +288,8 @@ int count_entries (DB *db) { return n_found; } -void do_create (void) { +static void +do_create (void) { setup_for_db_create(); // Now check to see if the number of names matches the number of associated things. int n_named = count_entries(namedb); @@ -276,7 +299,8 @@ void do_create (void) { int rcount=0; -void insert_person (void) { +static void +insert_person (void) { int namelen = 5+random()%245; rcount++; struct primary_key pk; @@ -347,16 +371,8 @@ void insert_person (void) { } } -void print_dbt (DBT *dbt) { - unsigned int i; - for (i=0; isize; i++) { - unsigned char c = ((char*)dbt->data)[i]; - if (c!='\\' && isprint(c)) printf("%c", c); - else printf("\\%02x", c); - } -} - -void delete_oldest_expired (void) { +static void +delete_oldest_expired (void) { printf("%s:%d %d:%d delete\n", __FILE__, __LINE__, oppass, opnum); int r; random(); @@ -411,7 +427,8 @@ void delete_oldest_expired (void) { } // Use a cursor to step through the names. -void step_name (void) { +static void +step_name (void) { int r; if (name_cursor==0) { r = namedb->cursor(namedb, null_txn, &name_cursor, 0); CKERR(r); @@ -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. */ -void activity (void) { +static void +activity (void) { random(); rcount++; if (oppass==2 && (opnum==8 || opnum==53 || opnum==57 || opnum==65 || opnum==78 || opnum==97)) { @@ -457,8 +475,9 @@ void activity (void) { } -void usage (const char *argv1) __attribute__((__noreturn__)); -void usage (const char *argv1) { +static __attribute__((__noreturn__)) +void +usage (const char *argv1) { fprintf(stderr, "Usage:\n %s [ --DB-CREATE | --more ] [-v|-q] seed\n", argv1); exit(1); } diff --git a/src/tests/test_db_cursor.c b/src/tests/test_db_cursor.c index ac1e5558aab..40a5d7cf12d 100644 --- a/src/tests/test_db_cursor.c +++ b/src/tests/test_db_cursor.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) { - write_uchar_to_dbt(dbt, (v>>24)&0xff); - write_uchar_to_dbt(dbt, (v>>16)&0xff); - write_uchar_to_dbt(dbt, (v>> 8)&0xff); - write_uchar_to_dbt(dbt, (v>> 0)&0xff); + write_uchar_to_dbt(dbt, (unsigned char)((v>>24)&0xff)); + write_uchar_to_dbt(dbt, (unsigned char)((v>>16)&0xff)); + write_uchar_to_dbt(dbt, (unsigned char)((v>> 8)&0xff)); + write_uchar_to_dbt(dbt, (unsigned char)((v>> 0)&0xff)); } static void write_timestamp_to_dbt (DBT *dbt, timestamp ts) { @@ -125,18 +125,6 @@ static int name_callback (DB *secondary __attribute__((__unused__)), const DBT * 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. static DB_ENV *dbenv; @@ -242,7 +230,7 @@ static void delete_oldest_expired (void) { assert(count==0); count++; int r; - printf("%s:%d deleting %d\n", __FILE__, __LINE__, pkey_0); + printf("%s:%d deleting %u\n", __FILE__, __LINE__, pkey_0); DBT pkey; memset(&pkey, 0, sizeof(pkey)); {