diff --git a/benchmarks/rose.cpp b/benchmarks/rose.cpp index 15e4c7e..5ea8db9 100644 --- a/benchmarks/rose.cpp +++ b/benchmarks/rose.cpp @@ -647,8 +647,7 @@ int main(int argc, char **argv) { assert(i < argc); column[column_count] = atoi(argv[i]); column_count++; - column = reinterpret_cast(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( - 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] diff --git a/src/apps/referential/algebra.c b/src/apps/referential/algebra.c index 00774d0..6e9008f 100644 --- a/src/apps/referential/algebra.c +++ b/src/apps/referential/algebra.c @@ -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++; diff --git a/src/apps/referential/tuple.c b/src/apps/referential/tuple.c index ae3b7c2..de9be58 100644 --- a/src/apps/referential/tuple.c +++ b/src/apps/referential/tuple.c @@ -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; diff --git a/src/stasis/allocationPolicy.c b/src/stasis/allocationPolicy.c index cb3675b..943cf8f 100644 --- a/src/stasis/allocationPolicy.c +++ b/src/stasis/allocationPolicy.c @@ -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); } diff --git a/src/stasis/bufferManager/pageArray.c b/src/stasis/bufferManager/pageArray.c index 8644582..a8cdc8f 100644 --- a/src/stasis/bufferManager/pageArray.c +++ b/src/stasis/bufferManager/pageArray.c @@ -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; } diff --git a/src/stasis/dirtyPageTable.c b/src/stasis/dirtyPageTable.c index 4847e36..ebc99ef 100644 --- a/src/stasis/dirtyPageTable.c +++ b/src/stasis/dirtyPageTable.c @@ -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); diff --git a/src/stasis/experimental/group.c b/src/stasis/experimental/group.c index 07e5d75..c0ec5ed 100644 --- a/src/stasis/experimental/group.c +++ b/src/stasis/experimental/group.c @@ -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])); diff --git a/src/stasis/experimental/logMemory.c b/src/stasis/experimental/logMemory.c index 8b297df..14b98f4 100644 --- a/src/stasis/experimental/logMemory.c +++ b/src/stasis/experimental/logMemory.c @@ -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)); diff --git a/src/stasis/io/memory.c b/src/stasis/io/memory.c index 7b8601f..ec94024 100644 --- a/src/stasis/io/memory.c +++ b/src/stasis/io/memory.c @@ -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); diff --git a/src/stasis/io/non_blocking.c b/src/stasis/io/non_blocking.c index f796b6f..76012d7 100644 --- a/src/stasis/io/non_blocking.c +++ b/src/stasis/io/non_blocking.c @@ -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++; } diff --git a/src/stasis/logger/inMemoryLog.c b/src/stasis/logger/inMemoryLog.c index 11c9879..58caabe 100644 --- a/src/stasis/logger/inMemoryLog.c +++ b/src/stasis/logger/inMemoryLog.c @@ -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; diff --git a/src/stasis/transactionTable.c b/src/stasis/transactionTable.c index 4c5b3bb..8648732 100644 --- a/src/stasis/transactionTable.c +++ b/src/stasis/transactionTable.c @@ -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; diff --git a/src/stasis/util/lhtable.c b/src/stasis/util/lhtable.c index b2db6cb..8045161 100644 --- a/src/stasis/util/lhtable.c +++ b/src/stasis/util/lhtable.c @@ -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; diff --git a/src/stasis/util/min.c b/src/stasis/util/min.c index d1c3ae1..338cc2b 100644 --- a/src/stasis/util/min.c +++ b/src/stasis/util/min.c @@ -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; diff --git a/src/stasis/util/multiset.c b/src/stasis/util/multiset.c index 718ded6..5662ab8 100644 --- a/src/stasis/util/multiset.c +++ b/src/stasis/util/multiset.c @@ -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)++; diff --git a/src/stasis/util/slab.c b/src/stasis/util/slab.c index 0047cae..669ae11 100644 --- a/src/stasis/util/slab.c +++ b/src/stasis/util/slab.c @@ -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]); diff --git a/stasis/util/hazard.h b/stasis/util/hazard.h index 4cab4a2..9a17c6e 100644 --- a/stasis/util/hazard.h +++ b/stasis/util/hazard.h @@ -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]; diff --git a/stasis/util/histogram.h b/stasis/util/histogram.h index 5982eb0..c34b3e1 100644 --- a/stasis/util/histogram.h +++ b/stasis/util/histogram.h @@ -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; \ } diff --git a/test/check_impl.h b/test/check_impl.h index fe9426e..2991eb7 100644 --- a/test/check_impl.h +++ b/test/check_impl.h @@ -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); } diff --git a/test/stasis/fault_injection/fisubject.c b/test/stasis/fault_injection/fisubject.c index d5bad22..4a31a5b 100644 --- a/test/stasis/fault_injection/fisubject.c +++ b/test/stasis/fault_injection/fisubject.c @@ -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; }