Commit f24fa9e6 authored by marko's avatar marko

branches/zip: Define mem_heap_calloc() and mem_calloc(). Use them

when allocating zero-filled memory.
parent b3b01c1c
......@@ -727,8 +727,9 @@ skip_field:
/* Set the extern field reference in dfield to zero */
dfield->len = BTR_EXTERN_FIELD_REF_SIZE;
dfield->data = mem_heap_alloc(heap, BTR_EXTERN_FIELD_REF_SIZE);
memset(dfield->data, 0, BTR_EXTERN_FIELD_REF_SIZE);
dfield->data = mem_heap_calloc(heap,
BTR_EXTERN_FIELD_REF_SIZE);
UNIV_MEM_ALLOC(dfield->data, BTR_EXTERN_FIELD_REF_SIZE);
n_fields++;
ut_ad(n_fields < dtuple_get_n_fields(entry));
}
......
......@@ -88,16 +88,14 @@ dict_create_sys_tables_tuple(
/* 6: MIX_ID (obsolete) ---------------------------*/
dfield = dtuple_get_nth_field(entry, 4);
ptr = mem_heap_alloc(heap, 8);
memset(ptr, 0, 8);
ptr = mem_heap_calloc(heap, 8);
dfield_set_data(dfield, ptr, 8);
/* 7: MIX_LEN (obsolete) --------------------------*/
dfield = dtuple_get_nth_field(entry, 5);
ptr = mem_heap_alloc(heap, 4);
memset(ptr, 0, 4);
ptr = mem_heap_calloc(heap, 4);
dfield_set_data(dfield, ptr, 4);
/* 8: CLUSTER_NAME ---------------------*/
......
......@@ -1742,8 +1742,7 @@ dict_index_build_internal_clust(
}
/* Remember the table columns already contained in new_index */
indexed = mem_alloc(table->n_cols * sizeof *indexed);
memset(indexed, 0, table->n_cols * sizeof *indexed);
indexed = mem_calloc(table->n_cols * sizeof *indexed);
/* Mark with 0 the table columns already contained in new_index */
for (i = 0; i < new_index->n_def; i++) {
......@@ -1828,8 +1827,7 @@ dict_index_build_internal_non_clust(
dict_index_copy(new_index, index, table, 0, index->n_fields);
/* Remember the table columns already contained in new_index */
indexed = mem_alloc(table->n_cols * sizeof *indexed);
memset(indexed, 0, table->n_cols * sizeof *indexed);
indexed = mem_calloc(table->n_cols * sizeof *indexed);
/* Mark with 0 table columns already contained in new_index */
for (i = 0; i < new_index->n_def; i++) {
......@@ -4653,8 +4651,7 @@ dict_undo_create_element(
ut_a(trx->dict_undo_list);
dict_undo = mem_alloc(sizeof(*dict_undo));
memset(dict_undo, '\0', sizeof(*dict_undo));
dict_undo = mem_calloc(sizeof *dict_undo);
UT_LIST_ADD_LAST(node, *trx->dict_undo_list, dict_undo);
......@@ -4716,8 +4713,7 @@ dict_redo_create_element(
ut_a(trx->dict_redo_list);
dict_redo = mem_alloc(sizeof(*dict_redo));
memset(dict_redo, '\0', sizeof(*dict_redo));
dict_redo = mem_calloc(sizeof *dict_redo);
UT_LIST_ADD_LAST(node, *trx->dict_redo_list, dict_redo);
......
......@@ -191,8 +191,7 @@ dict_mem_table_add_col(
}
if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {
/* All preceding column names are empty. */
char* s = mem_heap_alloc(heap, table->n_def);
memset(s, 0, table->n_def);
char* s = mem_heap_calloc(heap, table->n_def);
table->col_names = s;
}
......
......@@ -162,6 +162,19 @@ mem_heap_free_func_noninline(
const char* file_name, /* in: file name where freed */
ulint line); /* in: line where freed */
/*******************************************************************
Allocates and zero-fills n bytes of memory from a memory heap. */
UNIV_INLINE
void*
mem_heap_calloc(
/*============*/
/* out: allocated storage, NULL if did not
succeed (only possible for
MEM_HEAP_BTR_SEARCH type heaps) */
mem_heap_t* heap, /* in: memory heap */
ulint n); /* in: number of bytes; if the heap is allowed
to grow into the buffer pool, this must be
<= MEM_MAX_ALLOC_IN_BUF */
/*******************************************************************
Allocates n bytes of memory from a memory heap. */
UNIV_INLINE
void*
......@@ -249,6 +262,8 @@ mem_heap_get_size(
Use this macro instead of the corresponding function!
Macro for memory buffer allocation */
#define mem_calloc(N) memset(mem_alloc(N), 0, (N));
#define mem_alloc(N) mem_alloc_func((N), __FILE__, __LINE__)
/******************************************************************
Use this macro instead of the corresponding function!
......
......@@ -119,6 +119,23 @@ mem_block_get_start(mem_block_t* block)
return(block->start);
}
/*******************************************************************
Allocates and zero-fills n bytes of memory from a memory heap. */
UNIV_INLINE
void*
mem_heap_calloc(
/*============*/
/* out: allocated storage, NULL if did not
succeed (only possible for
MEM_HEAP_BTR_SEARCH type heaps) */
mem_heap_t* heap, /* in: memory heap */
ulint n) /* in: number of bytes; if the heap is allowed
to grow into the buffer pool, this must be
<= MEM_MAX_ALLOC_IN_BUF */
{
return(memset(mem_heap_alloc(heap, n), 0, n));
}
/*******************************************************************
Allocates n bytes of memory from a memory heap. */
UNIV_INLINE
......
......@@ -2259,8 +2259,7 @@ page_validate(
/* The following buffer is used to check that the
records in the page record heap do not overlap */
buf = mem_heap_alloc(heap, UNIV_PAGE_SIZE);
memset(buf, 0, UNIV_PAGE_SIZE);
buf = mem_heap_calloc(heap, UNIV_PAGE_SIZE);
/* Check first that the record heap and the directory do not
overlap. */
......
......@@ -1082,8 +1082,7 @@ page_zip_compress(
+ UNIV_PAGE_SIZE * 4
+ (512 << MAX_MEM_LEVEL));
recs = mem_heap_alloc(heap, n_dense * sizeof *recs);
memset(recs, 0, n_dense * sizeof *recs);
recs = mem_heap_calloc(heap, n_dense * sizeof *recs);
fields = mem_heap_alloc(heap, (n_fields + 1) * 2);
......
......@@ -103,8 +103,7 @@ row_merge_buf_create_low(
{
row_merge_buf_t* buf;
buf = mem_heap_alloc(heap, buf_size);
memset(buf, 0, buf_size);
buf = mem_heap_calloc(heap, buf_size);
buf->heap = heap;
buf->index = index;
buf->max_tuples = max_tuples;
......
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