realloc -> stasis_realloc

This commit is contained in:
Rusty Sears 2012-11-30 19:15:18 -08:00
parent 649f85d218
commit 286370a3f1
20 changed files with 41 additions and 44 deletions

View file

@ -647,8 +647,7 @@ int main(int argc, char **argv) {
assert(i < argc);
column[column_count] = atoi(argv[i]);
column_count++;
column = reinterpret_cast<int*>(realloc(column,
(column_count+1) * sizeof(int)));
column = stasis_realloc(column, column_count+1, int);
} else if (!strcmp(argv[i], "-m")) {
multicolumn = 1;
} else if (!strcmp(argv[i], "-t")) {
@ -703,7 +702,7 @@ int main(int argc, char **argv) {
val_t current = 0;
// dataset is managed by malloc so that it can be realloc()'ed
// dataset is managed by malloc so that it can be realloc'ed
val_t **dataset;
if(requested_column_count && file_mode) {
@ -802,8 +801,7 @@ int main(int argc, char **argv) {
} else {
inserts++;
for(int col = 0; col < column_count; col++) {
dataset[col] = reinterpret_cast<val_t*>(
realloc(dataset[col], sizeof(val_t) * (inserts + 1)));
dataset[col] = stasis_realloc(dataset[col], (inserts + 1), val_t);
errno = 0;
char * endptr;
dataset[col][inserts]

View file

@ -22,11 +22,11 @@ char ** split(char * in, char ** freeme, int* count, char * delim) {
char ** ret = 0;
while(tok) {
(*count)++;
ret = realloc(ret, sizeof(char*) * *count);
ret = stasis_realloc(ret, *count, char*);
ret[(*count)-1] = tok;
tok = strtok_r(NULL,delim,&strtoks);
}
ret = realloc(ret, sizeof(char*) * ((*count)+1));
ret = stasis_realloc(ret, (*count)+1, char*);
ret[*count]=0;
return ret;
}
@ -685,7 +685,7 @@ lladdIterator_t* ReferentialAlgebra_Join(int xid,
while(Titerator_next(xid, inner_it)) {
byte * in_val;
Titerator_value(xid, inner_it, (byte**)&in_val);
j->inner_tpls = realloc(j->inner_tpls, sizeof(tuple_t)*(i+1));
j->inner_tpls = stasis_realloc(j->inner_tpls, i+1, tuple_t);
j->inner_tpls[i] = tupleDup(*(tuple_t*)in_val);
Titerator_tupleDone(xid, inner_it);
i++;

View file

@ -113,16 +113,16 @@ tuple_t tupleAlloc() {
tuple_t tupleCatInt64(tuple_t t, int64_t i) {
t.count++;
t.type = realloc(t.type,t.count * sizeof(t.type[0]));
t.col = realloc(t.col,t.count * sizeof(t.col[0]));
t.type = stasis_realloc(t.type,t.count, datatype_t);
t.col = stasis_realloc(t.col, t.count, tuplecol_t);
t.type[t.count-1] = int64_typ;
t.col[t.count-1].int64 = i;
return t;
}
tuple_t tupleCatString(tuple_t t, const char * str) {
t.count++;
t.type = realloc(t.type,t.count * sizeof(t.type[0]));
t.col = realloc(t.col,t.count * sizeof(t.col[0]));
t.type = stasis_realloc(t.type,t.count,datatype_t);
t.col = stasis_realloc(t.col,t.count,tuplecol_t);
t.type[t.count-1] = string_typ;
t.col[t.count-1].string = strdup(str);
return t;

View file

@ -257,7 +257,7 @@ static int xidAllocedDealloced_helper_lookup_by_xid(struct rbtree *t, int xid, p
ret = 1;
// add pageid to ret value
(*count)++;
*pages = realloc(*pages, *count * sizeof(*pages[0]));
*pages = stasis_realloc(*pages, *count, pageid_t);
// printf("pages %x count %x *pages %x len %lld \n", pages, count, *pages, *count * sizeof(*pages[0]));
fflush(stdout);
(*pages)[(*count) - 1] = tup->pageid;
@ -275,7 +275,7 @@ static int xidAllocedDealloced_helper_lookup_by_pageid(struct rbtree *t, pageid_
ret = 1;
// add xid to ret value.
(*count)++;
*xids = realloc(*xids, *count * sizeof(*xids[0]));
*xids = stasis_realloc(*xids, *count, int);
(*xids)[(*count) - 1] = tup->xid;
tup = rblookup(RB_LUGREAT, tup, t);
}

View file

@ -15,7 +15,7 @@ static Page * paLoadPage(stasis_buffer_manager_t *bm, stasis_buffer_manager_hand
stasis_buffer_manager_page_array_t *pa = bm->impl;
pthread_mutex_lock(&pa->mut);
if(pageid >= pa->pageCount) {
pa->pageMap = realloc(pa->pageMap, (1+pageid) * sizeof(Page*));
pa->pageMap = stasis_realloc(pa->pageMap, 1+pageid, Page*);
for(pageid_t i = pa->pageCount; i <= pageid; i++) {
pa->pageMap[i] = 0;
}

View file

@ -323,7 +323,7 @@ void stasis_dirty_page_table_flush_range(stasis_dirty_page_table_t * dirtyPages,
e && (stop == 0 || e->p < stop);
e = rblookup(RB_LUGREAT, e, dirtyPages->tableByPage)) {
n++;
staleDirtyPages = realloc(staleDirtyPages, sizeof(pageid_t) * n);
staleDirtyPages = stasis_realloc(staleDirtyPages, n, pageid_t);
staleDirtyPages[n-1] = e->p;
}
pthread_mutex_unlock(&dirtyPages->mutex);

View file

@ -40,8 +40,8 @@ static int stasis_log_structured_group_put(struct stasis_group_t* impl,
stasis_log_structured_group_entry_t * entry;
if((entry = LH_ENTRY(find)(g->table, k,keylen))) {
entry->count++;
entry->val = realloc(entry->val, sizeof(entry->val[0])*entry->count);
entry->vallen = realloc(entry->vallen, sizeof(entry->vallen[0])*entry->count);
entry->val = stasis_realloc(entry->val, entry->count, byte*);
entry->vallen = stasis_realloc(entry->vallen, entry->count, size_t);
} else {
entry = malloc(sizeof(*entry));
entry->val = malloc(sizeof(entry->val[0]));

View file

@ -100,7 +100,7 @@ int logMemory_Iterator_next (int xid, void * impl) {
byte * tmp;
tmp = realloc(fifo->cached_value, size);
tmp = stasis_realloc(fifo->cached_value, size, byte);
if(tmp == NULL) {
pthread_mutex_unlock(&(fifo->mutex));
pthread_mutex_unlock(&(fifo->readerMutex));
@ -167,7 +167,7 @@ int logMemory_Iterator_tryNext (int xid, void * impl) {
byte * tmp;
tmp = realloc(fifo->cached_value, size);
tmp = stasis_realloc(fifo->cached_value, size, byte);
if(tmp == NULL) {
pthread_mutex_unlock(&(fifo->mutex));
pthread_mutex_unlock(&(fifo->readerMutex));
@ -254,7 +254,7 @@ int logMemory_Iterator_nextOrEmpty (int xid, void * impl) {
byte * tmp;
tmp = realloc(fifo->cached_value, size);
tmp = stasis_realloc(fifo->cached_value, size, byte);
if(tmp == NULL) {
pthread_mutex_unlock(&(fifo->mutex));
pthread_mutex_unlock(&(fifo->readerMutex));

View file

@ -59,7 +59,7 @@ static stasis_write_buffer_t * mem_write_buffer(stasis_handle_t * h,
} else {
byte * newbuf;
if(off+len) {
newbuf = realloc(impl->buf, off+len);
newbuf = stasis_realloc(impl->buf, off+len, byte);
} else {
free(impl->buf);
newbuf = stasis_malloc(0, byte);

View file

@ -195,9 +195,8 @@ static stasis_handle_t * getSlowHandle(nbw_impl * impl) {
slow = impl->slow_factory(impl->slow_factory_arg);
pthread_mutex_lock(&impl->mut);
impl->all_slow_handle_count++;
impl->all_slow_handles
= realloc(impl->all_slow_handles,
(impl->all_slow_handle_count) * sizeof(stasis_handle_t*));
impl->all_slow_handles = stasis_realloc(impl->all_slow_handles,
impl->all_slow_handle_count, stasis_handle_t*);
impl->all_slow_handles[(impl->all_slow_handle_count)-1] = slow;
pthread_mutex_unlock(&impl->mut);
} else {
@ -670,9 +669,9 @@ static void * nbw_worker(void * handle) {
dummy_count = 1;
first = 0;
} else {
buf = realloc(buf, len);
buf = stasis_realloc(buf, len, byte);
dummies = realloc(dummies, sizeof(tree_node) * (dummy_count+1));
dummies = stasis_realloc(dummies, dummy_count+1, tree_node);
dummies[dummy_count] = dummy;
dummy_count++;
}

View file

@ -72,7 +72,7 @@ LogEntry* stasis_log_impl_in_memory_reserve_entry(struct stasis_log_t* log, size
writelock(impl->globalOffset_lock, 0);
} else {
impl->bufferLen *= 2;
impl->buffer = realloc(impl->buffer, impl->bufferLen * sizeof(LogEntry *));
impl->buffer = stasis_realloc(impl->buffer, impl->bufferLen, LogEntry *);
}
} else {
done = 1;

View file

@ -133,12 +133,12 @@ int stasis_transaction_table_register_callback(stasis_transaction_table_t *tbl,
stasis_transaction_table_callback_t **list = &tbl->commitCallbacks[type];
int *count = &tbl->commitCallbackCount[type];
*list = realloc(*list, (1+*count) * sizeof(*list[0]));
*list = stasis_realloc(*list, 1+*count, stasis_transaction_table_callback_t);
(*list)[*count] = cb;
for(int i = 0; i < MAX_TRANSACTIONS; i++) {
void *** args;
args = &tbl->table[i].commitArgs[type];
*args = realloc(*args, (1+*count) * sizeof(*args[0]));
*args = stasis_realloc(*args, 1+*count, void*);
(*args)[*count] = 0;
}
return (*count)++;
@ -180,7 +180,7 @@ int* stasis_transaction_table_list_active(stasis_transaction_table_t *tbl, int *
if(e_xid >= 0) {
ret[*count] = e_xid;
(*count)++;
ret = realloc(ret, ((*count)+1) * sizeof(*ret));
ret = stasis_realloc(ret, (*count)+1, int);
ret[*count] = INVALID_XID;
}
}
@ -343,9 +343,9 @@ stasis_transaction_table_entry_t * stasis_transaction_table_begin(stasis_transac
if(test_and_set_entry(&tbl->table[i], INVALID_XTABLE_XID, PENDING_XTABLE_XID)) {
index = i;
tls->num_entries++;
tls->entries = realloc(tls->entries, sizeof(sizeof(ret)) * tls->num_entries);
tls->entries = stasis_realloc(tls->entries, tls->num_entries, stasis_transaction_table_entry_t*);
tls->entries[tls->num_entries-1] = &tbl->table[index];
tls->indexes = realloc(tls->indexes, sizeof(int) * tls->num_entries);
tls->indexes = stasis_realloc(tls->indexes, tls->num_entries, int);
tls->indexes[tls->num_entries-1] = index;
tbl->table[index].xidWhenFree = RESERVED_XTABLE_XID;
tbl->table[index].tid = tls->tid;

View file

@ -164,8 +164,8 @@ static void extendHashTable(struct LH_ENTRY(table) * table) {
// Assumes realloc is reasonably fast... This seems to be a good
// assumption under linux.
table->bucketList = realloc(table->bucketList,
(1+newBucket) * sizeof(struct LH_ENTRY(pair_t)));
table->bucketList = stasis_realloc(table->bucketList, 1+newBucket,
struct LH_ENTRY(pair_t));
table->bucketListLength = 1+newBucket;
table->bucketList[newBucket].key = 0;
table->bucketList[newBucket].keyLength = 0;

View file

@ -73,7 +73,7 @@ void stasis_aggregate_min_add(stasis_aggregate_min_t * min, lsn_t * a) {
}
}
min->num_entries++;
min->vals = realloc(min->vals, min->num_entries * sizeof(lsn_t**));
min->vals = stasis_realloc(min->vals, min->num_entries, lsn_t*);
*p = min->num_entries-1;
min->vals[*p] = a;
return;

View file

@ -19,7 +19,7 @@ void stasis_util_multiset_destroy(stasis_util_multiset_t * set) {
}
void stasis_util_multiset_insert(stasis_util_multiset_t * set, lsn_t item) {
set->items = realloc(set->items, (set->item_count+1)*sizeof(lsn_t));
set->items = stasis_realloc(set->items, set->item_count+1, lsn_t);
assert(set->items);
set->items[set->item_count] = item;
(set->item_count)++;

View file

@ -70,7 +70,7 @@ void* stasis_util_slab_malloc(stasis_util_slab_t * slab) {
} else if(slab->this_block_count == slab->objs_per_block) {
(slab->this_block_count) = 0;
(slab->this_block) ++;
slab->blocks = realloc(slab->blocks, (slab->this_block+1) * sizeof(slab->blocks[0]));
slab->blocks = stasis_realloc(slab->blocks, slab->this_block+1, byte*);
assert(slab->blocks);
slab->blocks[slab->this_block] = stasis_malloc(slab->block_sz, byte);
assert(slab->blocks[slab->this_block]);

View file

@ -48,7 +48,7 @@ static inline void hazard_scan(hazard_t * h, hazard_ptr_rec_t * rec) {
pthread_mutex_lock(&h->tls_list_mut);
hazard_ptr_rec_t * list = h->tls_list;
while(list != NULL) {
ptrs = realloc(ptrs, sizeof(hazard_ptr) * (ptrs_len+h->num_slots));
ptrs = stasis_realloc(ptrs, ptrs_len+h->num_slots, hazard_ptr);
// int would_stop = 0;
for(int i = 0; i < h->num_slots; i++) {
ptrs[ptrs_len] = list->hp[i];

View file

@ -23,8 +23,8 @@ static inline void stasis_histogram_thread_destroy(void * p) { free (p); }
void stasis_histogram_ctor_##x(void) { stasis_histogram_64_clear(&x); \
pthread_key_create(&(x.tls), stasis_histogram_thread_destroy); \
stasis_auto_histogram_count++; \
stasis_auto_histograms = realloc(stasis_auto_histograms, sizeof(void*)*stasis_auto_histogram_count); \
stasis_auto_histogram_names = realloc(stasis_auto_histogram_names, sizeof(void*)*stasis_auto_histogram_count); \
stasis_auto_histograms = stasis_realloc(stasis_auto_histograms, stasis_auto_histogram_count, stasis_histogram_64_t*); \
stasis_auto_histogram_names = stasis_realloc(stasis_auto_histogram_names, stasis_auto_histogram_count, char*); \
stasis_auto_histograms[stasis_auto_histogram_count - 1] = &x; \
stasis_auto_histogram_names[stasis_auto_histogram_count - 1] = __FILE__":"#x; \
}

View file

@ -85,8 +85,8 @@ static inline void tcase_add_checked_fixture(TCase * tc, void(*setup)(void), voi
#define tcase_add_test(tc, fcn) tcase_add_test_(tc, fcn, #fcn)
static void tcase_add_test_(TCase * tc, void(*fcn)(void), const char* name) {
(tc->count)++;
tc->tests = realloc(tc->tests, sizeof(tc->tests[0])*tc->count);
tc->names = realloc(tc->names, sizeof(tc->names[0])*tc->count);
tc->tests = (void(**)(void)) stasis_realloc(tc->tests, tc->count, void*);
tc->names = stasis_realloc(tc->names, tc->count, char*);
tc->tests[tc->count-1] = fcn;
tc->names[tc->count-1] = strdup(name);
}

View file

@ -200,7 +200,7 @@ writeKeyToBuffer(char** insertBuffer, int* bufferCurrentLength,
*/
if ((curLength + 15) > totalSize) {
totalSize *= 2;
*insertBuffer = (char*) realloc(*insertBuffer, totalSize);
*insertBuffer = stasis_realloc(*insertBuffer, totalSize, char);
*bufferTotalSize = totalSize;
}