Commit 983fa9da authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

change my_malloc to toku_malloc. It all works

git-svn-id: file:///svn/tokudb@26 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9cf0dd72
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage # GCOV_FLAGS = -fprofile-arcs -ftest-coverage
#PROF_FLAGS = -pg #PROF_FLAGS = -pg
#OPTFLAGS = -O2 #OPTFLAGS = -O2
CFLAGS = -Wall -W $(OPTFLAGS) -g $(GCOV_FLAGS) $(PROF_FLAGS) -Werror CFLAGS = -Wall -W $(OPTFLAGS) -g $(GCOV_FLAGS) $(PROF_FLAGS) -Werror -fPIC
LDFLAGS = $(OPTFLAGS) -g $(GCOV_FLAGS) $(PROF_FLAGS) LDFLAGS = $(OPTFLAGS) -g $(GCOV_FLAGS) $(PROF_FLAGS)
default: bins default: bins
......
...@@ -138,7 +138,7 @@ void serialize_brtnode_to(int fd, diskoff off, diskoff size, BRTNODE node) { ...@@ -138,7 +138,7 @@ void serialize_brtnode_to(int fd, diskoff off, diskoff size, BRTNODE node) {
int i; int i;
unsigned int calculated_size = serialize_brtnode_size(node); unsigned int calculated_size = serialize_brtnode_size(node);
assert(size>0); assert(size>0);
w.buf=my_malloc(size); w.buf=toku_malloc(size);
w.size=size; w.size=size;
w.ndone=0; w.ndone=0;
//printf("%s:%d serializing %lld w height=%d p0=%p\n", __FILE__, __LINE__, off, node->height, node->mdicts[0]); //printf("%s:%d serializing %lld w height=%d p0=%p\n", __FILE__, __LINE__, off, node->height, node->mdicts[0]);
...@@ -190,7 +190,7 @@ void serialize_brtnode_to(int fd, diskoff off, diskoff size, BRTNODE node) { ...@@ -190,7 +190,7 @@ void serialize_brtnode_to(int fd, diskoff off, diskoff size, BRTNODE node) {
//printf("%s:%d wrote %d bytes for %lld size=%lld\n", __FILE__, __LINE__, w.ndone, off, size); //printf("%s:%d wrote %d bytes for %lld size=%lld\n", __FILE__, __LINE__, w.ndone, off, size);
assert(w.ndone<=size); assert(w.ndone<=size);
my_free(w.buf); toku_free(w.buf);
} }
int deserialize_brtnode_from (int fd, diskoff off, BRTNODE *brtnode, int nodesize) { int deserialize_brtnode_from (int fd, diskoff off, BRTNODE *brtnode, int nodesize) {
...@@ -201,7 +201,7 @@ int deserialize_brtnode_from (int fd, diskoff off, BRTNODE *brtnode, int nodesiz ...@@ -201,7 +201,7 @@ int deserialize_brtnode_from (int fd, diskoff off, BRTNODE *brtnode, int nodesiz
int r; int r;
if (errno!=0) { if (errno!=0) {
r=errno; r=errno;
if (0) { died0: my_free(result); } if (0) { died0: toku_free(result); }
return r; return r;
} }
{ {
...@@ -216,9 +216,9 @@ int deserialize_brtnode_from (int fd, diskoff off, BRTNODE *brtnode, int nodesiz ...@@ -216,9 +216,9 @@ int deserialize_brtnode_from (int fd, diskoff off, BRTNODE *brtnode, int nodesiz
datasize = ntohl(datasize_n); datasize = ntohl(datasize_n);
if (datasize<=0 || datasize>(1<<30)) { r = DB_BADFORMAT; goto died0; } if (datasize<=0 || datasize>(1<<30)) { r = DB_BADFORMAT; goto died0; }
} }
rc.buf=my_malloc(datasize); rc.buf=toku_malloc(datasize);
if (errno!=0) { if (errno!=0) {
if (0) { died1: my_free(rc.buf); } if (0) { died1: toku_free(rc.buf); }
r=errno; r=errno;
goto died0; goto died0;
} }
...@@ -316,7 +316,7 @@ int deserialize_brtnode_from (int fd, diskoff off, BRTNODE *brtnode, int nodesiz ...@@ -316,7 +316,7 @@ int deserialize_brtnode_from (int fd, diskoff off, BRTNODE *brtnode, int nodesiz
} }
} }
//printf("%s:%d Ok got %lld n_children=%d\n", __FILE__, __LINE__, result->thisnodename, result->n_children); //printf("%s:%d Ok got %lld n_children=%d\n", __FILE__, __LINE__, result->thisnodename, result->n_children);
my_free(rc.buf); toku_free(rc.buf);
*brtnode = result; *brtnode = result;
verify_counts(result); verify_counts(result);
return 0; return 0;
...@@ -360,7 +360,7 @@ int serialize_brt_header_to (int fd, struct brt_header *h) { ...@@ -360,7 +360,7 @@ int serialize_brt_header_to (int fd, struct brt_header *h) {
size+=12 + 1 + strlen(h->names[i]); size+=12 + 1 + strlen(h->names[i]);
} }
} }
w.buf = my_malloc(size); w.buf = toku_malloc(size);
w.size = size; w.size = size;
w.ndone = 0; w.ndone = 0;
wbuf_int (&w, size); wbuf_int (&w, size);
...@@ -384,24 +384,26 @@ int serialize_brt_header_to (int fd, struct brt_header *h) { ...@@ -384,24 +384,26 @@ int serialize_brt_header_to (int fd, struct brt_header *h) {
ssize_t r = pwrite(fd, w.buf, w.ndone, 0); ssize_t r = pwrite(fd, w.buf, w.ndone, 0);
assert((size_t)r==w.ndone); assert((size_t)r==w.ndone);
} }
my_free(w.buf); toku_free(w.buf);
return 0; return 0;
} }
int deserialize_brtheader_from (int fd, diskoff off, struct brt_header **brth) { int deserialize_brtheader_from (int fd, diskoff off, struct brt_header **brth) {
printf("%s:%d calling MALLOC\n", __FILE__, __LINE__);
struct brt_header *MALLOC(h); struct brt_header *MALLOC(h);
struct cursor rc; struct cursor rc;
int size; int size;
int sizeagain; int sizeagain;
assert(off==0); assert(off==0);
printf("%s:%d malloced %p\n", __FILE__, __LINE__, h);
{ {
uint32_t size_n; uint32_t size_n;
ssize_t r = pread(fd, &size_n, sizeof(size_n), off); ssize_t r = pread(fd, &size_n, sizeof(size_n), off);
if (r==0) { my_free(h); return -1; } if (r==0) { toku_free(h); return -1; }
assert(r==sizeof(size_n)); assert(r==sizeof(size_n));
size = ntohl(size_n); size = ntohl(size_n);
} }
rc.buf = my_malloc(size); rc.buf = toku_malloc(size);
rc.size=size; rc.size=size;
assert(rc.size>0); assert(rc.size>0);
rc.ndone=0; rc.ndone=0;
...@@ -435,7 +437,7 @@ int deserialize_brtheader_from (int fd, diskoff off, struct brt_header **brth) { ...@@ -435,7 +437,7 @@ int deserialize_brtheader_from (int fd, diskoff off, struct brt_header **brth) {
h->unnamed_root = rbuf_diskoff(&rc); h->unnamed_root = rbuf_diskoff(&rc);
} }
assert(rc.ndone==rc.size); assert(rc.ndone==rc.size);
my_free(rc.buf); toku_free(rc.buf);
*brth = h; *brth = h;
return 0; return 0;
} }
...@@ -198,7 +198,7 @@ static void test5 (void) { ...@@ -198,7 +198,7 @@ static void test5 (void) {
} }
} }
printf("\n"); printf("\n");
my_free(values); toku_free(values);
r = close_brt(t); assert(r==0); r = close_brt(t); assert(r==0);
r = cachetable_close(ct); assert(r==0); r = cachetable_close(ct); assert(r==0);
memory_check_all_free(); memory_check_all_free();
......
...@@ -43,7 +43,7 @@ void brtnode_free (BRTNODE node) { ...@@ -43,7 +43,7 @@ void brtnode_free (BRTNODE node) {
//printf("%s:%d %p->mdict[0]=%p\n", __FILE__, __LINE__, node, node->mdicts[0]); //printf("%s:%d %p->mdict[0]=%p\n", __FILE__, __LINE__, node, node->mdicts[0]);
if (node->height>0) { if (node->height>0) {
for (i=0; i<node->u.n.n_children-1; i++) { for (i=0; i<node->u.n.n_children-1; i++) {
my_free((void*)node->u.n.childkeys[i]); toku_free((void*)node->u.n.childkeys[i]);
} }
for (i=0; i<node->u.n.n_children; i++) { for (i=0; i<node->u.n.n_children; i++) {
if (node->u.n.htables[i]) { if (node->u.n.htables[i]) {
...@@ -54,7 +54,7 @@ void brtnode_free (BRTNODE node) { ...@@ -54,7 +54,7 @@ void brtnode_free (BRTNODE node) {
if (node->u.l.buffer) // The buffer may have been freed already, in some cases. if (node->u.l.buffer) // The buffer may have been freed already, in some cases.
pma_free(&node->u.l.buffer); pma_free(&node->u.l.buffer);
} }
my_free(node); toku_free(node);
} }
void brtnode_flush_callback (CACHEFILE cachefile, diskoff nodename, void *brtnode_v, int write_me, int keep_me) { void brtnode_flush_callback (CACHEFILE cachefile, diskoff nodename, void *brtnode_v, int write_me, int keep_me) {
...@@ -93,12 +93,12 @@ void brtheader_flush_callback (CACHEFILE cachefile, diskoff nodename, void *head ...@@ -93,12 +93,12 @@ void brtheader_flush_callback (CACHEFILE cachefile, diskoff nodename, void *head
if (h->n_named_roots>0) { if (h->n_named_roots>0) {
int i; int i;
for (i=0; i<h->n_named_roots; i++) { for (i=0; i<h->n_named_roots; i++) {
my_free(h->names[i]); toku_free(h->names[i]);
} }
my_free(h->names); toku_free(h->names);
my_free(h->roots); toku_free(h->roots);
} }
my_free(h); toku_free(h);
} }
} }
...@@ -869,14 +869,14 @@ static int setup_brt_root_node (BRT t, diskoff offset) { ...@@ -869,14 +869,14 @@ static int setup_brt_root_node (BRT t, diskoff offset) {
r=cachetable_put(t->cf, offset, node, r=cachetable_put(t->cf, offset, node,
brtnode_flush_callback, brtnode_fetch_callback, (void*)t->h->nodesize); brtnode_flush_callback, brtnode_fetch_callback, (void*)t->h->nodesize);
if (r!=0) { if (r!=0) {
my_free(node); toku_free(node);
return r; return r;
} }
//printf("%s:%d created %lld\n", __FILE__, __LINE__, node->thisnodename); //printf("%s:%d created %lld\n", __FILE__, __LINE__, node->thisnodename);
verify_counts(node); verify_counts(node);
r=cachetable_unpin(t->cf, node->thisnodename, 1); r=cachetable_unpin(t->cf, node->thisnodename, 1);
if (r!=0) { if (r!=0) {
my_free(node); toku_free(node);
return r; return r;
} }
return 0; return 0;
...@@ -900,14 +900,14 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, ...@@ -900,14 +900,14 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
if ((MALLOC(t))==0) { if ((MALLOC(t))==0) {
assert(errno==ENOMEM); assert(errno==ENOMEM);
r = ENOMEM; r = ENOMEM;
if (0) { died0: my_free(t); } if (0) { died0: toku_free(t); }
return r; return r;
} }
if (dbname) { if (dbname) {
malloced_name = mystrdup(dbname); malloced_name = mystrdup(dbname);
if (malloced_name==0) { if (malloced_name==0) {
r = ENOMEM; r = ENOMEM;
if (0) { died0a: if(malloced_name) my_free(malloced_name); } if (0) { died0a: if(malloced_name) toku_free(malloced_name); }
goto died0; goto died0;
} }
} }
...@@ -926,7 +926,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, ...@@ -926,7 +926,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
if ((MALLOC(t->h))==0) { if ((MALLOC(t->h))==0) {
assert(errno==ENOMEM); assert(errno==ENOMEM);
r = ENOMEM; r = ENOMEM;
if (0) { died2: my_free(t->h); } if (0) { died2: toku_free(t->h); }
goto died1; goto died1;
} }
t->h->nodesize=nodesize; t->h->nodesize=nodesize;
...@@ -935,9 +935,9 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, ...@@ -935,9 +935,9 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
if (dbname) { if (dbname) {
t->h->unnamed_root = -1; t->h->unnamed_root = -1;
t->h->n_named_roots = 1; t->h->n_named_roots = 1;
if ((MALLOC_N(1, t->h->names))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died3: my_free(t->h->names); } goto died2; } if ((MALLOC_N(1, t->h->names))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died3: toku_free(t->h->names); } goto died2; }
if ((MALLOC_N(1, t->h->roots))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died4: my_free(t->h->roots); } goto died3; } if ((MALLOC_N(1, t->h->roots))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died4: toku_free(t->h->roots); } goto died3; }
if ((t->h->names[0] = mystrdup(dbname))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died5: my_free(t->h->names[0]); } goto died4; } if ((t->h->names[0] = mystrdup(dbname))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died5: toku_free(t->h->names[0]); } goto died4; }
t->h->roots[0] = nodesize; t->h->roots[0] = nodesize;
} else { } else {
t->h->unnamed_root = nodesize; t->h->unnamed_root = nodesize;
...@@ -958,8 +958,8 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, ...@@ -958,8 +958,8 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
goto died1; /* deallocate everything. */ goto died1; /* deallocate everything. */
} }
} }
if ((t->h->names = my_realloc(t->h->names, (1+t->h->n_named_roots)*sizeof(*t->h->names))) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; } if ((t->h->names = toku_realloc(t->h->names, (1+t->h->n_named_roots)*sizeof(*t->h->names))) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; }
if ((t->h->roots = my_realloc(t->h->roots, (1+t->h->n_named_roots)*sizeof(*t->h->roots))) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; } if ((t->h->roots = toku_realloc(t->h->roots, (1+t->h->n_named_roots)*sizeof(*t->h->roots))) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; }
t->h->n_named_roots++; t->h->n_named_roots++;
if ((t->h->names[t->h->n_named_roots-1] = mystrdup(dbname)) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; } if ((t->h->names[t->h->n_named_roots-1] = mystrdup(dbname)) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; }
printf("%s:%d t=%p\n", __FILE__, __LINE__, t); printf("%s:%d t=%p\n", __FILE__, __LINE__, t);
...@@ -1002,8 +1002,8 @@ int close_brt (BRT brt) { ...@@ -1002,8 +1002,8 @@ int close_brt (BRT brt) {
assert(0==cachefile_count_pinned(brt->cf, 1)); assert(0==cachefile_count_pinned(brt->cf, 1));
//printf("%s:%d closing cachetable\n", __FILE__, __LINE__); //printf("%s:%d closing cachetable\n", __FILE__, __LINE__);
if ((r = cachefile_close(brt->cf))!=0) return r; if ((r = cachefile_close(brt->cf))!=0) return r;
if (brt->database_name) my_free(brt->database_name); if (brt->database_name) toku_free(brt->database_name);
my_free(brt); toku_free(brt);
return 0; return 0;
} }
...@@ -1409,7 +1409,7 @@ int brt_cursor_close (BRT_CURSOR curs) { ...@@ -1409,7 +1409,7 @@ int brt_cursor_close (BRT_CURSOR curs) {
int r2=pma_cursor_free(&curs->pmacurs); int r2=pma_cursor_free(&curs->pmacurs);
if (r==0) r=r2; if (r==0) r=r2;
} }
my_free(curs); toku_free(curs);
return r; return r;
} }
......
...@@ -46,7 +46,7 @@ static void flush (CACHEFILE f, CACHEKEY key, void*value, int write_me __attribu ...@@ -46,7 +46,7 @@ static void flush (CACHEFILE f, CACHEKEY key, void*value, int write_me __attribu
printf("%lld was flushed, but I didn't expect it\n", key); printf("%lld was flushed, but I didn't expect it\n", key);
abort(); abort();
found_flush: found_flush:
my_free(value); toku_free(value);
} }
struct item *make_item (CACHEKEY key) { struct item *make_item (CACHEKEY key) {
......
...@@ -56,7 +56,7 @@ int create_cachetable (CACHETABLE *result, int n_entries) { ...@@ -56,7 +56,7 @@ int create_cachetable (CACHETABLE *result, int n_entries) {
int i; int i;
t->n_in_table = 0; t->n_in_table = 0;
t->table_size = n_entries; t->table_size = n_entries;
t->table = my_calloc(t->table_size, sizeof(struct ctpair)); t->table = toku_calloc(t->table_size, sizeof(struct ctpair));
assert(t->table); assert(t->table);
t->head = t->tail = 0; t->head = t->tail = 0;
for (i=0; i<t->table_size; i++) { for (i=0; i<t->table_size; i++) {
...@@ -120,7 +120,7 @@ int cachefile_close (CACHEFILE cf) { ...@@ -120,7 +120,7 @@ int cachefile_close (CACHEFILE cf) {
if ((r = cachefile_flush(cf))) return r; if ((r = cachefile_flush(cf))) return r;
r = close(cf->fd); r = close(cf->fd);
cf->cachetable->cachefiles = remove_cf_from_list(cf, cf->cachetable->cachefiles); cf->cachetable->cachefiles = remove_cf_from_list(cf, cf->cachetable->cachefiles);
my_free(cf); toku_free(cf);
return r; return r;
} else { } else {
return 0; return 0;
...@@ -228,7 +228,7 @@ static void flush_and_remove (CACHETABLE t, PAIR remove_me, int write_me) { ...@@ -228,7 +228,7 @@ static void flush_and_remove (CACHETABLE t, PAIR remove_me, int write_me) {
t->n_in_table--; t->n_in_table--;
// Remove it from the hash chain. // Remove it from the hash chain.
t->table[h] = remove_from_hash_chain (remove_me, t->table[h]); t->table[h] = remove_from_hash_chain (remove_me, t->table[h]);
my_free(remove_me); toku_free(remove_me);
} }
static void flush_and_keep (PAIR flush_me) { static void flush_and_keep (PAIR flush_me) {
...@@ -312,12 +312,12 @@ int cachetable_get_and_pin (CACHEFILE cachefile, CACHEKEY key, void**value, ...@@ -312,12 +312,12 @@ int cachetable_get_and_pin (CACHEFILE cachefile, CACHEKEY key, void**value,
} }
if (maybe_flush_some(t)) return -2; if (maybe_flush_some(t)) return -2;
{ {
void *my_value; void *toku_value;
int r; int r;
WHEN_TRACE_CT(printf("%s:%d CT: fetch_callback(%lld...)\n", __FILE__, __LINE__, key)); WHEN_TRACE_CT(printf("%s:%d CT: fetch_callback(%lld...)\n", __FILE__, __LINE__, key));
if ((r=fetch_callback(cachefile, key, &my_value,extraargs))) return r; if ((r=fetch_callback(cachefile, key, &toku_value,extraargs))) return r;
cachetable_put(cachefile, key, my_value, flush_callback, fetch_callback,extraargs); cachetable_put(cachefile, key, toku_value, flush_callback, fetch_callback,extraargs);
*value = my_value; *value = toku_value;
} }
WHEN_TRACE_CT(printf("%s:%d did fetch: cachtable_get_and_pin(%lld)--> %p\n", __FILE__, __LINE__, key, *value)); WHEN_TRACE_CT(printf("%s:%d did fetch: cachtable_get_and_pin(%lld)--> %p\n", __FILE__, __LINE__, key, *value));
return 0; return 0;
...@@ -396,8 +396,8 @@ int cachetable_close (CACHETABLE t) { ...@@ -396,8 +396,8 @@ int cachetable_close (CACHETABLE t) {
for (i=0; i<t->table_size; i++) { for (i=0; i<t->table_size; i++) {
if (t->table[i]) return -1; if (t->table[i]) return -1;
} }
my_free(t->table); toku_free(t->table);
my_free(t); toku_free(t);
return 0; return 0;
} }
......
...@@ -17,7 +17,7 @@ int hashtable_create (HASHTABLE *h) { ...@@ -17,7 +17,7 @@ int hashtable_create (HASHTABLE *h) {
tab->n_keys=0; tab->n_keys=0;
tab->arraysize=128; tab->arraysize=128;
assert(sizeof(*tab->array)==sizeof(void*)); assert(sizeof(*tab->array)==sizeof(void*));
tab->array = my_calloc(tab->arraysize, sizeof(*tab->array)); tab->array = toku_calloc(tab->arraysize, sizeof(*tab->array));
for (i=0; i<tab->arraysize; i++) tab->array[i]=0; for (i=0; i<tab->arraysize; i++) tab->array[i]=0;
*h=tab; *h=tab;
return 0; return 0;
...@@ -86,7 +86,7 @@ int hash_insert (HASHTABLE tab, const char *key, ITEMLEN keylen, const char *val ...@@ -86,7 +86,7 @@ int hash_insert (HASHTABLE tab, const char *key, ITEMLEN keylen, const char *val
tab->n_keys++; tab->n_keys++;
if (tab->n_keys > tab->arraysize) { if (tab->n_keys > tab->arraysize) {
int newarraysize = tab->arraysize*2; int newarraysize = tab->arraysize*2;
HASHELT *newarray = my_calloc(newarraysize, sizeof(*tab->array)); HASHELT *newarray = toku_calloc(newarraysize, sizeof(*tab->array));
int i; int i;
assert(newarray!=0); assert(newarray!=0);
for (i=0; i<newarraysize; i++) newarray[i]=0; for (i=0; i<newarraysize; i++) newarray[i]=0;
...@@ -98,7 +98,7 @@ int hash_insert (HASHTABLE tab, const char *key, ITEMLEN keylen, const char *val ...@@ -98,7 +98,7 @@ int hash_insert (HASHTABLE tab, const char *key, ITEMLEN keylen, const char *val
newarray[h] = he; newarray[h] = he;
} }
} }
my_free(tab->array); toku_free(tab->array);
// printf("Freed\n"); // printf("Freed\n");
tab->array=newarray; tab->array=newarray;
tab->arraysize=newarraysize; tab->arraysize=newarraysize;
...@@ -118,9 +118,9 @@ int hash_delete (HASHTABLE tab, const char *key, ITEMLEN keylen) { ...@@ -118,9 +118,9 @@ int hash_delete (HASHTABLE tab, const char *key, ITEMLEN keylen) {
assert(*prev_ptr==he); assert(*prev_ptr==he);
*prev_ptr = he->next; *prev_ptr = he->next;
//printf("Freeing %s %s\n", he->key, he->val); //printf("Freeing %s %s\n", he->key, he->val);
my_free(he->key); toku_free(he->key);
my_free(he->val); toku_free(he->val);
my_free(he); toku_free(he);
tab->n_keys--; tab->n_keys--;
return BRT_OK; return BRT_OK;
} }
...@@ -189,9 +189,9 @@ static void hasheltlist_free (HASHELT elt) { ...@@ -189,9 +189,9 @@ static void hasheltlist_free (HASHELT elt) {
if (elt==0) return; if (elt==0) return;
else { else {
hasheltlist_free(elt->next); hasheltlist_free(elt->next);
my_free(elt->key); toku_free(elt->key);
my_free(elt->val); toku_free(elt->val);
my_free(elt); toku_free(elt);
} }
} }
...@@ -200,8 +200,8 @@ void hashtable_free(HASHTABLE *tab) { ...@@ -200,8 +200,8 @@ void hashtable_free(HASHTABLE *tab) {
//printf("%s:%d free hashtable %p\n", __FILE__, __LINE__, tab); //printf("%s:%d free hashtable %p\n", __FILE__, __LINE__, tab);
hashtable_clear(*tab); hashtable_clear(*tab);
//printf("%s:%d free %p\n", __FILE__, __LINE__, tab);n //printf("%s:%d free %p\n", __FILE__, __LINE__, tab);n
my_free((*tab)->array); toku_free((*tab)->array);
my_free(*tab); toku_free(*tab);
*tab=0; *tab=0;
} }
......
...@@ -22,7 +22,7 @@ void note_did_malloc (void *p, long size) { ...@@ -22,7 +22,7 @@ void note_did_malloc (void *p, long size) {
WHEN_MEM_DEBUG( WHEN_MEM_DEBUG(
if (n_items_malloced<items_limit) { items[n_items_malloced]=p; sizes[n_items_malloced]=size; } if (n_items_malloced<items_limit) { items[n_items_malloced]=p; sizes[n_items_malloced]=size; }
else overflowed=1; else overflowed=1;
//printf("%s:%d %p=malloc(%ld)\n", __FILE__, __LINE__, r, size); printf("%s:%d %p=malloc(%ld)\n", __FILE__, __LINE__, p, size);
); );
n_items_malloced++; n_items_malloced++;
} }
...@@ -44,7 +44,7 @@ void note_did_free(void *p) { ...@@ -44,7 +44,7 @@ void note_did_free(void *p) {
abort(); abort();
ok:; ok:;
} }
//printf("%s:%d free(%p)\n", __FILE__, __LINE__, p); printf("%s:%d free(%p)\n", __FILE__, __LINE__, p);
); );
n_items_malloced--; n_items_malloced--;
} }
...@@ -123,7 +123,7 @@ void do_memory_check (void) { ...@@ -123,7 +123,7 @@ void do_memory_check (void) {
#endif #endif
void *my_calloc(long nmemb, long size) { void *toku_calloc(long nmemb, long size) {
void *r; void *r;
errno=0; errno=0;
r = actual_calloc(nmemb, size); r = actual_calloc(nmemb, size);
...@@ -132,23 +132,24 @@ void *my_calloc(long nmemb, long size) { ...@@ -132,23 +132,24 @@ void *my_calloc(long nmemb, long size) {
//if ((long)r==0x80523f8) { printf("%s:%d %p\n", __FILE__, __LINE__, r); } //if ((long)r==0x80523f8) { printf("%s:%d %p\n", __FILE__, __LINE__, r); }
return r; return r;
} }
void *my_malloc(long size) { void *toku_malloc(long size) {
void * r; void * r;
errno=0; errno=0;
r=actual_malloc(size); r=actual_malloc(size);
//printf("%s:%d malloc(%ld)->%p\n", __FILE__, __LINE__, size,r); printf("%s:%d malloc(%ld)->%p\n", __FILE__, __LINE__, size,r);
note_did_malloc(r, size); note_did_malloc(r, size);
//if ((long)r==0x80523f8) { printf("%s:%d %p size=%ld\n", __FILE__, __LINE__, r, size); } //if ((long)r==0x80523f8) { printf("%s:%d %p size=%ld\n", __FILE__, __LINE__, r, size); }
return r; return r;
} }
void *tagmalloc(unsigned long size, int typtag) { void *tagmalloc(unsigned long size, int typtag) {
void *r = my_malloc(size); printf("%s:%d tagmalloc\n", __FILE__, __LINE__);
void *r = toku_malloc(size);
assert(size>sizeof(int)); assert(size>sizeof(int));
((int*)r)[0] = typtag; ((int*)r)[0] = typtag;
return r; return r;
} }
void *my_realloc(void *p, long size) { void *toku_realloc(void *p, long size) {
void *newp; void *newp;
note_did_free(p); note_did_free(p);
errno=0; errno=0;
...@@ -158,14 +159,14 @@ void *my_realloc(void *p, long size) { ...@@ -158,14 +159,14 @@ void *my_realloc(void *p, long size) {
return newp; return newp;
} }
void my_free(void* p) { void toku_free(void* p) {
//printf("%s:%d free(%p)\n", __FILE__, __LINE__, p); //printf("%s:%d free(%p)\n", __FILE__, __LINE__, p);
note_did_free(p); note_did_free(p);
actual_free(p); actual_free(p);
} }
void *memdup (const void *v, unsigned int len) { void *memdup (const void *v, unsigned int len) {
void *r=my_malloc(len); void *r=toku_malloc(len);
memcpy(r,v,len); memcpy(r,v,len);
return r; return r;
} }
......
//#include <stdlib.h> //#include <stdlib.h>
/* errno is set to 0 or a value to indicate problems. */ /* errno is set to 0 or a value to indicate problems. */
void *my_calloc(long nmemb, long size); void *toku_calloc(long nmemb, long size);
void *my_malloc(long size); void *toku_malloc(long size);
void *tagmalloc(unsigned long size, int typ); void *tagmalloc(unsigned long size, int typ);
void my_free(void*); void toku_free(void*);
void *my_realloc(void *, long size); void *toku_realloc(void *, long size);
#define MALLOC(v) v = my_malloc(sizeof(*v)) #define MALLOC(v) v = toku_malloc(sizeof(*v))
#define MALLOC_N(n,v) v = my_malloc((n)*sizeof(*v)) #define MALLOC_N(n,v) v = toku_malloc((n)*sizeof(*v))
#define TAGMALLOC(t,v) t v = tagmalloc(sizeof(*v), TYP_ ## t); #define TAGMALLOC(t,v) t v = tagmalloc(sizeof(*v), TYP_ ## t);
......
...@@ -102,8 +102,8 @@ static void test_pma_find (void) { ...@@ -102,8 +102,8 @@ static void test_pma_find (void) {
assert(r==6); assert(r==6);
r=pmainternal_find(pma, "zzz", 3); r=pmainternal_find(pma, "zzz", 3);
assert(r==N); assert(r==N);
my_free(pma->pairs); toku_free(pma->pairs);
my_free(pma); toku_free(pma);
} }
void test_smooth_region_N (int N) { void test_smooth_region_N (int N) {
...@@ -455,8 +455,8 @@ void test_pma_cursor_3 (void) { ...@@ -455,8 +455,8 @@ void test_pma_cursor_3 (void) {
r=pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND); r=pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND);
my_free(key.data); toku_free(key.data);
my_free(val.data); toku_free(val.data);
r=pma_cursor_free(&c); assert(r==0); r=pma_cursor_free(&c); assert(r==0);
r=pma_free(&pma); assert(r==0); r=pma_free(&pma); assert(r==0);
......
...@@ -220,7 +220,7 @@ int pmainternal_smooth_region (struct pair *pairs, int n, int idx) { ...@@ -220,7 +220,7 @@ int pmainternal_smooth_region (struct pair *pairs, int n, int idx) {
/* Now the tricky part. Distribute the data. */ /* Now the tricky part. Distribute the data. */
r=distribute_data (pairs, n, r=distribute_data (pairs, n,
tmppairs, n_saved); tmppairs, n_saved);
my_free(tmppairs); toku_free(tmppairs);
return r; return r;
} }
} }
...@@ -271,7 +271,7 @@ int pma_create (PMA *pma) { ...@@ -271,7 +271,7 @@ int pma_create (PMA *pma) {
result->pairs[result->N].key = (void*)0xdeadbeef; result->pairs[result->N].key = (void*)0xdeadbeef;
//printf("pairs=%p (size=%d)\n", result->pairs,result->N*sizeof(*result->pairs)); //printf("pairs=%p (size=%d)\n", result->pairs,result->N*sizeof(*result->pairs));
if (result->pairs==0) { if (result->pairs==0) {
my_free(result); toku_free(result);
return -1; return -1;
} }
for (i=0; i<result->N; i++) { for (i=0; i<result->N; i++) {
...@@ -382,9 +382,9 @@ int pma_cursor_free (PMA_CURSOR *cursp) { ...@@ -382,9 +382,9 @@ int pma_cursor_free (PMA_CURSOR *cursp) {
} else { } else {
curs->next->prev = curs->prev; curs->next->prev = curs->prev;
} }
if (curs->skey) my_free(curs->skey); if (curs->skey) toku_free(curs->skey);
if (curs->sval) my_free(curs->sval); if (curs->sval) toku_free(curs->sval);
my_free(curs); toku_free(curs);
*cursp=0; *cursp=0;
return 0; return 0;
} }
...@@ -424,7 +424,7 @@ int pmainternal_make_space_at (PMA pma, int idx) { ...@@ -424,7 +424,7 @@ int pmainternal_make_space_at (PMA pma, int idx) {
assert(size==pma_index_limit(pma)); assert(size==pma_index_limit(pma));
size*=2; size*=2;
//printf("realloc %p to %d\n", pma->pairs, size*sizeof(*pma->pairs)); //printf("realloc %p to %d\n", pma->pairs, size*sizeof(*pma->pairs));
pma->pairs = my_realloc(pma->pairs, (1+size)*sizeof(*pma->pairs)); pma->pairs = toku_realloc(pma->pairs, (1+size)*sizeof(*pma->pairs));
for (i=hi; i<size; i++) pma->pairs[i].key=0; for (i=hi; i<size; i++) pma->pairs[i].key=0;
pma->pairs[size].key = (void*)0xdeadbeefL; pma->pairs[size].key = (void*)0xdeadbeefL;
pma->N=size; pma->N=size;
...@@ -461,7 +461,7 @@ enum pma_errors pma_lookup (PMA pma, bytevec key, ITEMLEN keylen, bytevec*val, I ...@@ -461,7 +461,7 @@ enum pma_errors pma_lookup (PMA pma, bytevec key, ITEMLEN keylen, bytevec*val, I
} }
void maybe_free (const void *p) { void maybe_free (const void *p) {
if (p) my_free((void*)p); if (p) toku_free((void*)p);
} }
/* returns 0 if OK. /* returns 0 if OK.
...@@ -478,8 +478,8 @@ int pma_free (PMA *pmap) { ...@@ -478,8 +478,8 @@ int pma_free (PMA *pmap) {
pma->pairs[i].val=0; pma->pairs[i].val=0;
} }
} }
my_free(pma->pairs); toku_free(pma->pairs);
my_free(pma); toku_free(pma);
*pmap=0; *pmap=0;
return 0; return 0;
} }
...@@ -535,8 +535,8 @@ int pma_delete (PMA pma, bytevec key, ITEMLEN keylen) { ...@@ -535,8 +535,8 @@ int pma_delete (PMA pma, bytevec key, ITEMLEN keylen) {
return DB_NOTFOUND; return DB_NOTFOUND;
} }
assert(pma->pairs[l].val!=0); assert(pma->pairs[l].val!=0);
my_free((void*)pma->pairs[l].key); toku_free((void*)pma->pairs[l].key);
my_free((void*)pma->pairs[l].val); toku_free((void*)pma->pairs[l].val);
pma->pairs[l].key = 0; pma->pairs[l].key = 0;
pma->pairs[l].val = 0; pma->pairs[l].val = 0;
pma->pairs[l].keylen = 0; pma->pairs[l].keylen = 0;
......
...@@ -21,7 +21,7 @@ void ybt_test0 (void) { ...@@ -21,7 +21,7 @@ void ybt_test0 (void) {
assert(strcmp(t0.data, "byebye")==0); /* t0's data should be changed too, since it used v0 */ assert(strcmp(t0.data, "byebye")==0); /* t0's data should be changed too, since it used v0 */
assert(strcmp(t1.data, "byebye")==0); assert(strcmp(t1.data, "byebye")==0);
my_free(v0); my_free(v1); toku_free(v0); toku_free(v1);
memory_check_all_free(); memory_check_all_free();
/* See if we can probe to find out how big something is by setting ulen=0 with YBT_USERMEM */ /* See if we can probe to find out how big something is by setting ulen=0 with YBT_USERMEM */
...@@ -45,7 +45,7 @@ void ybt_test0 (void) { ...@@ -45,7 +45,7 @@ void ybt_test0 (void) {
assert(t0.size==11); assert(t0.size==11);
assert(strcmp(t0.data, "provincial")==0); assert(strcmp(t0.data, "provincial")==0);
my_free(t0.data); toku_free(t0.data);
memory_check_all_free(); memory_check_all_free();
} }
......
...@@ -12,12 +12,12 @@ int ybt_init (DBT *ybt) { ...@@ -12,12 +12,12 @@ int ybt_init (DBT *ybt) {
int ybt_set_value (DBT *ybt, bytevec val, ITEMLEN vallen, void **staticptrp) { int ybt_set_value (DBT *ybt, bytevec val, ITEMLEN vallen, void **staticptrp) {
if (ybt->flags==DB_DBT_MALLOC) { if (ybt->flags==DB_DBT_MALLOC) {
domalloc: domalloc:
ybt->data = my_malloc(vallen); ybt->data = toku_malloc(vallen);
if (errno!=0) return errno; if (errno!=0) return errno;
ybt->ulen = vallen; ybt->ulen = vallen;
} else if (ybt->flags==DB_DBT_REALLOC) { } else if (ybt->flags==DB_DBT_REALLOC) {
if (ybt->data==0) goto domalloc; if (ybt->data==0) goto domalloc;
ybt->data = my_realloc(ybt->data, vallen); ybt->data = toku_realloc(ybt->data, vallen);
if (errno!=0) return errno; if (errno!=0) return errno;
ybt->ulen = vallen; ybt->ulen = vallen;
...@@ -27,9 +27,9 @@ int ybt_set_value (DBT *ybt, bytevec val, ITEMLEN vallen, void **staticptrp) { ...@@ -27,9 +27,9 @@ int ybt_set_value (DBT *ybt, bytevec val, ITEMLEN vallen, void **staticptrp) {
if (staticptrp==0) return -1; if (staticptrp==0) return -1;
void *staticptr=*staticptrp; void *staticptr=*staticptrp;
if (staticptr==0) if (staticptr==0)
staticptr = my_malloc(vallen); staticptr = toku_malloc(vallen);
else else
staticptr = my_realloc(staticptr, vallen); staticptr = toku_realloc(staticptr, vallen);
if (errno!=0) return errno; if (errno!=0) return errno;
*staticptrp = staticptr; *staticptrp = staticptr;
ybt->data = staticptr; ybt->data = staticptr;
......
CFLAGS = -W -Wall -Wno-unused -g CFLAGS = -W -Wall -Wno-unused -g -fPIC
CPPFLAGS = -I../include -I../newbrt CPPFLAGS = -I../include -I../newbrt
install: libdb.so
cp libdb.so ../src-bdbwrap/
ydb.o: ../include/db.h ../newbrt/cachetable.h ydb.o: ../include/db.h ../newbrt/cachetable.h
libdb.so: ydb.c DBBINS = ydb.o ../newbrt/brt.o ../newbrt/brt-serialize.o ../newbrt/cachetable.o ../newbrt/hashtable.o ../newbrt/header-io.o ../newbrt/key.o ../newbrt/memory.o ../newbrt/pma.o ../newbrt/ybt.o
cc $(CPPFLAGS) ydb.c -shared -fPIC -o libdb.so $(CFLAGS) libdb.so: $(DBBINS)
cc $(CPPFLAGS) $(DBBINS) -shared -o libdb.so $(CFLAGS)
libdb.a(ydb.o): ydb.o libdb.a(ydb.o): ydb.o
...@@ -237,8 +237,7 @@ int txn_abort (DB_TXN *txn) { ...@@ -237,8 +237,7 @@ int txn_abort (DB_TXN *txn) {
} }
int txn_commit (DB_TXN *txn, u_int32_t flags) { int txn_commit (DB_TXN *txn, u_int32_t flags) {
fprintf(stderr, "%s:%d txn_commit(%p,%ud)\n", __FILE__, __LINE__, txn, flags); return 0;
abort();
} }
int log_compare (const DB_LSN *a, const DB_LSN *b) { int log_compare (const DB_LSN *a, const DB_LSN *b) {
......
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