Commit 81f79a50 authored by osku's avatar osku

Fix comments for memory allocation functions and add some extra checks.

Adapt callers.
parent 1a77f1c5
......@@ -40,9 +40,13 @@ ha_create(
table->adaptive = FALSE;
}
/* Creating MEM_HEAP_BTR_SEARCH type heaps can potentially fail,
but in practise it never should in this case, hence the asserts. */
if (n_mutexes == 0) {
if (in_btr_search) {
table->heap = mem_heap_create_in_btr_search(4096);
ut_a(table->heap);
} else {
table->heap = mem_heap_create_in_buffer(4096);
}
......@@ -57,6 +61,7 @@ ha_create(
for (i = 0; i < n_mutexes; i++) {
if (in_btr_search) {
table->heaps[i] = mem_heap_create_in_btr_search(4096);
ut_a(table->heaps[i]);
} else {
table->heaps[i] = mem_heap_create_in_buffer(4096);
}
......
......@@ -68,21 +68,6 @@ ha_insert_for_fold(
node is created! */
void* data); /* in: data, must not be NULL */
/*****************************************************************
Reserves the necessary hash table mutex and inserts an entry into the hash
table. */
UNIV_INLINE
ibool
ha_insert_for_fold_mutex(
/*=====================*/
/* out: TRUE if succeed, FALSE if no more
memory could be allocated */
hash_table_t* table, /* in: hash table */
ulint fold, /* in: folded value of data; if a node with
the same fold value already exists, it is
updated to point to the same data, and no new
node is created! */
void* data); /* in: data, must not be NULL */
/*****************************************************************
Deletes an entry from a hash table. */
void
......
......@@ -191,30 +191,3 @@ ha_search_and_delete_if_found(
return(FALSE);
}
/*****************************************************************
Reserves the necessary hash table mutex and inserts an entry into the hash
table. */
UNIV_INLINE
ibool
ha_insert_for_fold_mutex(
/*=====================*/
/* out: TRUE if succeed, FALSE if no more
memory could be allocated */
hash_table_t* table, /* in: hash table */
ulint fold, /* in: folded value of data; if a node with
the same fold value already exists, it is
updated to point to the same data, and no new
node is created! */
void* data) /* in: data, must not be NULL */
{
ibool ret;
hash_mutex_enter(table, fold);
ret = ha_insert_for_fold(table, fold, data);
hash_mutex_exit(table, fold);
return(ret);
}
......@@ -31,13 +31,18 @@ typedef mem_block_info_t mem_block_t;
typedef mem_block_t mem_heap_t;
/* Types of allocation for memory heaps: DYNAMIC means allocation from the
dynamic memory pool of the C compiler, BUFFER means allocation from the index
page buffer pool; the latter method is used for very big heaps */
dynamic memory pool of the C compiler, BUFFER means allocation from the
buffer pool; the latter method is used for very big heaps */
#define MEM_HEAP_DYNAMIC 0 /* the most common type */
#define MEM_HEAP_BUFFER 1
#define MEM_HEAP_BTR_SEARCH 2 /* this flag can be ORed to the
previous */
#define MEM_HEAP_BTR_SEARCH 2 /* this flag can optionally be
ORed to MEM_HEAP_BUFFER, in which
case heap->free_block is used in
some cases for memory allocations,
and if it's NULL, the memory
allocation functions can return
NULL. */
/* The following start size is used for the first block in the memory heap if
the size is not specified, i.e., 0 is given as the parameter in the call of
......@@ -98,13 +103,15 @@ heap freeing. */
(heap), __FILE__, __LINE__)
/*********************************************************************
NOTE: Use the corresponding macros instead of this function. Creates a
memory heap which allocates memory from dynamic space. For debugging
purposes, takes also the file name and line as argument. */
memory heap. For debugging purposes, takes also the file name and line as
arguments. */
UNIV_INLINE
mem_heap_t*
mem_heap_create_func(
/*=================*/
/* out, own: memory heap */
/* out, own: memory heap, NULL if
did not succeed (only possible for
MEM_HEAP_BTR_SEARCH type heaps)*/
ulint n, /* in: desired start block size,
this means that a single user buffer
of size n will fit in the block,
......@@ -121,11 +128,9 @@ mem_heap_create_func(
block is not unintentionally erased
(if allocated in the stack), before
the memory heap is explicitly freed. */
ulint type, /* in: MEM_HEAP_DYNAMIC
or MEM_HEAP_BUFFER */
ulint type, /* in: heap type */
const char* file_name, /* in: file name where created */
ulint line /* in: line where created */
);
ulint line); /* in: line where created */
/*********************************************************************
NOTE: Use the corresponding macro instead of this function. Frees the space
occupied by a memory heap. In the debug version erases the heap memory
......@@ -143,8 +148,9 @@ UNIV_INLINE
void*
mem_heap_alloc(
/*===========*/
/* out: allocated storage, NULL if
did not succeed */
/* 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
......@@ -220,8 +226,7 @@ UNIV_INLINE
void*
mem_alloc_func(
/*===========*/
/* out, own: free storage, NULL
if did not succeed */
/* out, own: free storage */
ulint n, /* in: desired number of bytes */
const char* file_name, /* in: file name where created */
ulint line /* in: line where created */
......@@ -235,8 +240,7 @@ with mem_free. */
void*
mem_alloc_func_noninline(
/*=====================*/
/* out, own: free storage,
NULL if did not succeed */
/* out, own: free storage */
ulint n, /* in: desired number of bytes */
const char* file_name, /* in: file name where created */
ulint line /* in: line where created */
......
......@@ -16,8 +16,9 @@ Creates a memory heap block where data can be allocated. */
mem_block_t*
mem_heap_create_block(
/*==================*/
/* out, own: memory heap block,
NULL if did not succeed */
/* out, own: memory heap block, NULL if
did not succeed (only possible for
MEM_HEAP_BTR_SEARCH type heaps) */
mem_heap_t* heap, /* in: memory heap or NULL if first block
should be created */
ulint n, /* in: number of bytes needed for user data, or
......@@ -50,7 +51,8 @@ mem_block_t*
mem_heap_add_block(
/*===============*/
/* out: created block, NULL if did not
succeed */
succeed (only possible for
MEM_HEAP_BTR_SEARCH type heaps)*/
mem_heap_t* heap, /* in: memory heap */
ulint n); /* in: number of bytes user needs */
......@@ -126,7 +128,9 @@ UNIV_INLINE
void*
mem_heap_alloc(
/*===========*/
/* out: allocated storage */
/* 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
......@@ -370,13 +374,15 @@ mem_heap_free_top(
/*********************************************************************
NOTE: Use the corresponding macros instead of this function. Creates a
memory heap which allocates memory from dynamic space. For debugging
purposes, takes also the file name and line as argument. */
memory heap. For debugging purposes, takes also the file name and line as
argument. */
UNIV_INLINE
mem_heap_t*
mem_heap_create_func(
/*=================*/
/* out, own: memory heap */
/* out, own: memory heap, NULL if
did not succeed (only possible for
MEM_HEAP_BTR_SEARCH type heaps)*/
ulint n, /* in: desired start block size,
this means that a single user buffer
of size n will fit in the block,
......@@ -393,11 +399,9 @@ mem_heap_create_func(
block is not unintentionally erased
(if allocated in the stack), before
the memory heap is explicitly freed. */
ulint type, /* in: MEM_HEAP_DYNAMIC
or MEM_HEAP_BUFFER */
ulint type, /* in: heap type */
const char* file_name, /* in: file name where created */
ulint line /* in: line where created */
)
ulint line) /* in: line where created */
{
mem_block_t* block;
......@@ -409,7 +413,10 @@ mem_heap_create_func(
init_block, type, file_name, line);
}
ut_ad(block);
if (block == NULL) {
return(NULL);
}
UT_LIST_INIT(block->base);
......@@ -418,11 +425,6 @@ mem_heap_create_func(
#ifdef UNIV_MEM_DEBUG
if (block == NULL) {
return(block);
}
mem_hash_insert(block, file_name, line);
#endif
......@@ -484,8 +486,7 @@ UNIV_INLINE
void*
mem_alloc_func(
/*===========*/
/* out, own: free storage, NULL
if did not succeed */
/* out, own: free storage */
ulint n, /* in: desired number of bytes */
const char* file_name, /* in: file name where created */
ulint line /* in: line where created */
......@@ -496,10 +497,6 @@ mem_alloc_func(
heap = mem_heap_create_func(n, NULL, MEM_HEAP_DYNAMIC, file_name,
line);
if (heap == NULL) {
return(NULL);
}
/* Note that as we created the first block in the heap big enough
for the buffer requested by the caller, the buffer will be in the
......
......@@ -1705,7 +1705,7 @@ static
lock_t*
lock_rec_create(
/*============*/
/* out: created lock, NULL if out of memory */
/* out: created lock */
ulint type_mode,/* in: lock mode and wait flag, type is
ignored and replaced by LOCK_REC */
rec_t* rec, /* in: record on page */
......@@ -1747,11 +1747,6 @@ lock_rec_create(
lock = mem_heap_alloc(trx->lock_heap, sizeof(lock_t) + n_bytes);
if (UNIV_UNLIKELY(lock == NULL)) {
return(NULL);
}
UT_LIST_ADD_LAST(trx_locks, trx->trx_locks, lock);
lock->trx = trx;
......@@ -1886,8 +1881,7 @@ static
lock_t*
lock_rec_add_to_queue(
/*==================*/
/* out: lock where the bit was set, NULL if out
of memory */
/* out: lock where the bit was set */
ulint type_mode,/* in: lock mode, wait, gap etc. flags;
type is ignored and replaced by LOCK_REC */
rec_t* rec, /* in: record on page */
......@@ -3405,8 +3399,7 @@ UNIV_INLINE
lock_t*
lock_table_create(
/*==============*/
/* out, own: new lock object, or NULL if
out of memory */
/* out, own: new lock object */
dict_table_t* table, /* in: database table in dictionary cache */
ulint type_mode,/* in: lock mode possibly ORed with
LOCK_WAIT */
......@@ -3432,11 +3425,6 @@ lock_table_create(
lock = mem_heap_alloc(trx->lock_heap, sizeof(lock_t));
}
if (lock == NULL) {
return(NULL);
}
UT_LIST_ADD_LAST(trx_locks, trx->trx_locks, lock);
lock->type_mode = type_mode | LOCK_TABLE;
......
......@@ -92,12 +92,10 @@ with mem_free. */
void*
mem_alloc_func_noninline(
/*=====================*/
/* out, own: free storage,
NULL if did not succeed */
/* out, own: free storage */
ulint n, /* in: desired number of bytes */
const char* file_name, /* in: file name where created */
ulint line /* in: line where created */
)
ulint line) /* in: line where created */
{
return(mem_alloc_func(n, file_name, line));
}
......@@ -122,8 +120,9 @@ Creates a memory heap block where data can be allocated. */
mem_block_t*
mem_heap_create_block(
/*==================*/
/* out, own: memory heap block,
NULL if did not succeed */
/* out, own: memory heap block, NULL if
did not succeed (only possible for
MEM_HEAP_BTR_SEARCH type heaps) */
mem_heap_t* heap, /* in: memory heap or NULL if first block
should be created */
ulint n, /* in: number of bytes needed for user data, or
......@@ -182,6 +181,8 @@ mem_heap_create_block(
}
if (block == NULL) {
/* Only MEM_HEAP_BTR_SEARCH allocation should ever fail. */
ut_a(type & MEM_HEAP_BTR_SEARCH);
return(NULL);
}
......@@ -222,7 +223,8 @@ mem_block_t*
mem_heap_add_block(
/*===============*/
/* out: created block, NULL if did not
succeed */
succeed (only possible for
MEM_HEAP_BTR_SEARCH type heaps)*/
mem_heap_t* heap, /* in: memory heap */
ulint n) /* in: number of bytes user needs */
{
......
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