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

Make cxx compile. Addresses #1032, #1343, #1328.

git-svn-id: file:///svn/toku/tokudb.1032b+1343@8459 c7de825b-a66e-492c-adef-691d508d4ae1
parent a6de8872
#include <stdlib.h>
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
......@@ -55,8 +56,8 @@ static int dbdump(char *dbfile, char *dbname) {
// printf("%.*s\n", val.get_size(), (char *)val.get_data());
hexdump(&val);
}
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
r = db.close(0); assert(r == 0);
......
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
......@@ -51,8 +52,8 @@ static int dbdump(char *dbfile, char *dbname) {
} catch (DbException ) {
/* Nothing, that's just how we got out of the loop. */
}
free(key.get_data());
free(val.get_data());
toku_free(key.get_data());
toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
r = db.close(0); assert(r == 0);
......
#include <stdlib.h>
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
static inline void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
......@@ -17,7 +18,7 @@ static void hexput(Dbt *d, int c) {
int ulen = d->get_ulen();
if (n+1 >= ulen) {
int newulen = ulen == 0 ? 1 : ulen*2;
cp = (unsigned char *) realloc(cp, newulen); assert(cp);
cp = (unsigned char *) toku_realloc(cp, newulen); assert(cp);
d->set_data(cp);
d->set_ulen(newulen);
}
......@@ -77,8 +78,8 @@ static int dbload(char *dbfile, char *dbname) {
r = db.put(0, &key, &val, 0);
assert(r == 0);
}
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = db.close(0); assert(r == 0);
#if defined(USE_ENV) && USE_ENV
......
......@@ -3,6 +3,7 @@
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <memory.h>
#define FNAME __FILE__ ".tdb"
#define FNAME2 __FILE__ "2.tdb"
......@@ -162,8 +163,8 @@ static void test_dbc_exceptions () {
Dbt key; key.set_flags(DB_DBT_MALLOC);
Dbt val; val.set_flags(DB_DBT_MALLOC);
TC(curs->get(&key, &val, DB_FIRST), 0);
free(key.get_data());
free(val.get_data());
toku_free(key.get_data());
toku_free(val.get_data());
TC(curs->del(DB_DELETE_ANY), 0);
TCRET(curs->get(&key, &val, DB_CURRENT), DB_KEYEMPTY);
TCRET(curs->del(0), DB_KEYEMPTY);
......
......@@ -4,6 +4,7 @@
#include <arpa/inet.h>
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
int verbose;
......@@ -42,10 +43,10 @@ int my_cursor_count(Dbc *cursor, db_recno_t *count, Db *db) {
if (!keyeq(&key, &nkey)) break;
}
r = 0;
if (nkey.get_data()) free(nkey.get_data());
if (nval.get_data()) free(nval.get_data());
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
int rr = count_cursor->close(); assert(rr == 0);
return r;
}
......@@ -62,10 +63,10 @@ int my_next_nodup(Dbc *cursor, Dbt *key, Dbt *val) {
if (r != 0) break;
if (!keyeq(&currentkey, &nkey)) break;
}
if (nkey.get_data()) free(nkey.get_data());
if (nval.get_data()) free(nval.get_data());
if (currentkey.get_data()) free(currentkey.get_data());
if (currentval.get_data()) free(currentval.get_data());
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (currentkey.get_data()) toku_free(currentkey.get_data());
if (currentval.get_data()) toku_free(currentval.get_data());
if (r == 0) r = cursor->get(key, val, DB_CURRENT);
return r;
}
......@@ -82,10 +83,10 @@ int my_prev_nodup(Dbc *cursor, Dbt *key, Dbt *val) {
if (r != 0) break;
if (!keyeq(&currentkey, &nkey)) break;
}
if (nkey.get_data()) free(nkey.get_data());
if (nval.get_data()) free(nval.get_data());
if (currentkey.get_data()) free(currentkey.get_data());
if (currentval.get_data()) free(currentval.get_data());
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (currentkey.get_data()) toku_free(currentkey.get_data());
if (currentval.get_data()) toku_free(currentval.get_data());
if (r == 0) r = cursor->get(key, val, DB_CURRENT);
return r;
}
......@@ -99,10 +100,10 @@ int my_next_dup(Dbc *cursor, Dbt *key, Dbt *val) {
Dbt nval; nval.set_flags(DB_DBT_REALLOC);
r = cursor->get(&nkey, &nval, DB_NEXT);
if (r == 0 && !keyeq(&currentkey, &nkey)) r = DB_NOTFOUND;
if (nkey.get_data()) free(nkey.get_data());
if (nval.get_data()) free(nval.get_data());
if (currentkey.get_data()) free(currentkey.get_data());
if (currentval.get_data()) free(currentval.get_data());
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (currentkey.get_data()) toku_free(currentkey.get_data());
if (currentval.get_data()) toku_free(currentval.get_data());
if (r == 0) r = cursor->get(key, val, DB_CURRENT);
return r;
}
......@@ -116,10 +117,10 @@ int my_prev_dup(Dbc *cursor, Dbt *key, Dbt *val) {
Dbt nval; nval.set_flags(DB_DBT_REALLOC);
r = cursor->get(&nkey, &nval, DB_PREV);
if (r == 0 && !keyeq(&currentkey, &nkey)) r = DB_NOTFOUND;
if (nkey.get_data()) free(nkey.get_data());
if (nval.get_data()) free(nval.get_data());
if (currentkey.get_data()) free(currentkey.get_data());
if (currentval.get_data()) free(currentval.get_data());
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (currentkey.get_data()) toku_free(currentkey.get_data());
if (currentval.get_data()) toku_free(currentval.get_data());
if (r == 0) r = cursor->get(key, val, DB_CURRENT);
return r;
}
......@@ -153,8 +154,8 @@ void test_cursor_count_flags(Db *db) {
Dbt key; key.set_flags(DB_DBT_MALLOC);
Dbt val; val.set_flags(DB_DBT_MALLOC);
r = cursor->get(&key, &val, DB_FIRST); assert(r == 0);
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
db_recno_t n;
r = cursor->count(&n, 1); assert(r == EINVAL);
r = cursor->count(&n, 0); assert(r == 0);
......@@ -191,8 +192,8 @@ void walk(Db *db, int n) {
if (k == n/2) assert((int)count == n); else assert(count == 1);
}
assert(i == 2*n-1);
free(key.get_data());
free(val.get_data());
toku_free(key.get_data());
toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
......@@ -228,8 +229,8 @@ void test_zero_count(Db *db, int n) {
if (r != 0) break;
}
assert(i == n);
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
......@@ -253,8 +254,8 @@ void test_next_nodup(Db *db, int n) {
r = cursor->get(&key, &val, DB_NEXT_NODUP);
}
assert(i == n);
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
......@@ -278,8 +279,8 @@ void test_prev_nodup(Db *db, int n) {
r = cursor->get(&key, &val, DB_PREV_NODUP);
}
assert(i == -1);
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
......@@ -319,8 +320,8 @@ void test_next_dup(Db *db, int n) {
}
assert(i == 0);
#endif
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
......
......@@ -8,6 +8,7 @@
#include <toku_os.h>
#include <sys/time.h>
#include <unistd.h>
#include <memory.h>
#include "../../src/tests/test.h"
......@@ -41,8 +42,8 @@ struct primary_data {
};
void free_pd (struct primary_data *pd) {
free(pd->name.name);
free(pd);
toku_free(pd->name.name);
toku_free(pd);
}
void write_uchar_to_dbt (Dbt *dbt, const unsigned char c) {
......@@ -109,7 +110,7 @@ void read_name_from_dbt (const Dbt *dbt, int *off, struct name_key *nk) {
read_uchar_from_dbt(dbt, off, &buf[i]);
if (buf[i]==0) break;
}
nk->name=(unsigned char*)(strdup((char*)buf));
nk->name=(unsigned char*)(toku_strdup((char*)buf));
}
void read_pd_from_dbt (const Dbt *dbt, int *off, struct primary_data *pd) {
......@@ -123,7 +124,7 @@ int name_offset_in_pd_dbt (void) {
}
int name_callback (Db *secondary, const Dbt *key, const Dbt *data, Dbt *result) {
struct primary_data *pd = (struct primary_data *) malloc(sizeof(*pd));
struct primary_data *pd = (struct primary_data *) toku_malloc(sizeof(*pd));
int off=0;
read_pd_from_dbt(data, &off, pd);
static int buf[1000];
......@@ -158,9 +159,9 @@ static void dbg_name_insert (unsigned char *name) {
name = (unsigned char*)strdup((char*)name);
n_names++;
if (names==0) {
names=malloc(sizeof(*names));
names=toku_malloc(sizeof(*names));
} else {
names = realloc(names, n_names*sizeof(*names));
names = toku_realloc(names, n_names*sizeof(*names));
}
names[n_names-1]=name;
}
......@@ -228,8 +229,8 @@ void close_databases (void) {
if (name_cursor) {
r = name_cursor->close(); CKERR(r);
}
if (nc_key.get_data()) free(nc_key.get_data());
if (nc_data.get_data()) free(nc_data.get_data());
if (nc_key.get_data()) toku_free(nc_key.get_data());
if (nc_data.get_data()) toku_free(nc_data.get_data());
r = namedb->close(0); CKERR(r); delete namedb;
r = dbp->close(0); CKERR(r); delete dbp;
r = expiredb->close(0); CKERR(r); delete expiredb;
......@@ -388,7 +389,7 @@ void delete_oldest_expired (void) {
count_all_items--;
}
savepkey = pkey;
savepkey.set_data(malloc(pkey.get_size()));
savepkey.set_data(toku_malloc(pkey.get_size()));
memcpy(savepkey.get_data(), pkey.get_data(), pkey.get_size());
switch (r3) {
case 0:
......@@ -409,7 +410,7 @@ void delete_oldest_expired (void) {
assert(r==DB_KEYEMPTY);
r = dbp->get(null_txn, &savepkey, &data, 0);
assert(r==DB_NOTFOUND);
free(savepkey.get_data());
toku_free(savepkey.get_data());
}
// Use a cursor to step through the names.
......@@ -430,7 +431,7 @@ void step_name (void) {
assert(cursor_count_n_items==calc_n_items);
r = name_cursor->get(&nc_key, &nc_data, DB_FIRST);
if (r==DB_NOTFOUND) {
nc_key.set_data(realloc(nc_key.get_data(), 1));
nc_key.set_data(toku_realloc(nc_key.get_data(), 1));
((char*)nc_key.get_data())[0]=0;
cursor_count_n_items=0;
} else {
......@@ -490,10 +491,10 @@ int test_main (int argc, const char *argv[]) {
}
nc_key.set_flags(DB_DBT_REALLOC);
nc_key.set_data(malloc(1)); // Iniitalize it.
nc_key.set_data(toku_malloc(1)); // Iniitalize it.
((char*)nc_key.get_data())[0]=0;
nc_data.set_flags(DB_DBT_REALLOC);
nc_data.set_data(malloc(1)); // Iniitalize it.
nc_data.set_data(toku_malloc(1)); // Iniitalize it.
mode = MODE_DEFAULT;
......
......@@ -13,6 +13,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <memory.h>
#define DIR __FILE__ ".dir"
int verbose;
......@@ -48,8 +49,8 @@ void expect(Dbc *cursor, int k, int v) {
assert(kk == k);
assert(vv == v);
free(key.get_data());
free(val.get_data());
toku_free(key.get_data());
toku_free(val.get_data());
}
void test_reverse_compare(int n, int dup_flags) {
......
#ifndef MEMORY_H
#define MEMORY_H
#if defined __cplusplus
extern "C" {
#endif
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include <stdlib.h>
......@@ -99,4 +103,8 @@ extern int toku_realloc_counter;
extern int toku_calloc_counter;
extern int toku_free_counter;
#if defined __cplusplus
};
#endif
#endif
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