Changing uint8_t* to void* in arguments and return values of mem_heap_alloc_block, mem_heap_free_block and mem_heap_try_resize_block operations.
This commit is contained in:
+17
-13
@@ -412,7 +412,7 @@ mem_init_block_header (uint8_t *first_chunk_p, /**< address of the first
|
|||||||
* @return pointer to allocated memory block - if allocation is successful,\n
|
* @return pointer to allocated memory block - if allocation is successful,\n
|
||||||
* NULL - if there is not enough memory.
|
* NULL - if there is not enough memory.
|
||||||
*/
|
*/
|
||||||
uint8_t*
|
void*
|
||||||
mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to allocate in bytes */
|
mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to allocate in bytes */
|
||||||
mem_heap_alloc_term_t alloc_term) /**< expected allocation term */
|
mem_heap_alloc_term_t alloc_term) /**< expected allocation term */
|
||||||
{
|
{
|
||||||
@@ -566,16 +566,18 @@ mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to all
|
|||||||
* false - if there is not enough memory in front of the block.
|
* false - if there is not enough memory in front of the block.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
mem_heap_try_resize_block (uint8_t *ptr, /**< pointer to beginning of data space of the block to resize */
|
mem_heap_try_resize_block (void *ptr, /**< pointer to beginning of data space of the block to resize */
|
||||||
size_t size_in_bytes) /**< new block size */
|
size_t size_in_bytes) /**< new block size */
|
||||||
{
|
{
|
||||||
/* checking that ptr points to the heap */
|
uint8_t *uint8_ptr = (uint8_t*) ptr;
|
||||||
JERRY_ASSERT(ptr >= mem_heap.heap_start
|
|
||||||
&& ptr <= mem_heap.heap_start + mem_heap.heap_size);
|
/* checking that uint8_ptr points to the heap */
|
||||||
|
JERRY_ASSERT(uint8_ptr >= mem_heap.heap_start
|
||||||
|
&& uint8_ptr <= mem_heap.heap_start + mem_heap.heap_size);
|
||||||
|
|
||||||
mem_check_heap ();
|
mem_check_heap ();
|
||||||
|
|
||||||
mem_block_header_t *block_p = (mem_block_header_t*) ptr - 1;
|
mem_block_header_t *block_p = (mem_block_header_t*) uint8_ptr - 1;
|
||||||
|
|
||||||
VALGRIND_DEFINED_STRUCT(block_p);
|
VALGRIND_DEFINED_STRUCT(block_p);
|
||||||
|
|
||||||
@@ -681,7 +683,7 @@ mem_heap_try_resize_block (uint8_t *ptr, /**< pointer to beginning of data space
|
|||||||
|
|
||||||
if (size_in_bytes >= block_p->allocated_bytes)
|
if (size_in_bytes >= block_p->allocated_bytes)
|
||||||
{
|
{
|
||||||
VALGRIND_UNDEFINED_SPACE (ptr + block_p->allocated_bytes, size_in_bytes - block_p->allocated_bytes);
|
VALGRIND_UNDEFINED_SPACE (uint8_ptr + block_p->allocated_bytes, size_in_bytes - block_p->allocated_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
block_p->allocated_bytes = (mem_heap_offset_t) size_in_bytes;
|
block_p->allocated_bytes = (mem_heap_offset_t) size_in_bytes;
|
||||||
@@ -700,15 +702,17 @@ mem_heap_try_resize_block (uint8_t *ptr, /**< pointer to beginning of data space
|
|||||||
* Free the memory block.
|
* Free the memory block.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
mem_heap_free_block (uint8_t *ptr) /**< pointer to beginning of data space of the block */
|
mem_heap_free_block (void *ptr) /**< pointer to beginning of data space of the block */
|
||||||
{
|
{
|
||||||
/* checking that ptr points to the heap */
|
uint8_t *uint8_ptr = (uint8_t*) ptr;
|
||||||
JERRY_ASSERT(ptr >= mem_heap.heap_start
|
|
||||||
&& ptr <= mem_heap.heap_start + mem_heap.heap_size);
|
/* checking that uint8_ptr points to the heap */
|
||||||
|
JERRY_ASSERT(uint8_ptr >= mem_heap.heap_start
|
||||||
|
&& uint8_ptr <= mem_heap.heap_start + mem_heap.heap_size);
|
||||||
|
|
||||||
mem_check_heap ();
|
mem_check_heap ();
|
||||||
|
|
||||||
mem_block_header_t *block_p = (mem_block_header_t*) ptr - 1;
|
mem_block_header_t *block_p = (mem_block_header_t*) uint8_ptr - 1;
|
||||||
|
|
||||||
VALGRIND_DEFINED_STRUCT(block_p);
|
VALGRIND_DEFINED_STRUCT(block_p);
|
||||||
|
|
||||||
@@ -717,7 +721,7 @@ mem_heap_free_block (uint8_t *ptr) /**< pointer to beginning of data space of th
|
|||||||
|
|
||||||
MEM_HEAP_STAT_FREE_BLOCK (block_p);
|
MEM_HEAP_STAT_FREE_BLOCK (block_p);
|
||||||
|
|
||||||
VALGRIND_NOACCESS_SPACE(ptr, block_p->allocated_bytes);
|
VALGRIND_NOACCESS_SPACE(uint8_ptr, block_p->allocated_bytes);
|
||||||
|
|
||||||
/* checking magic nums that are neighbour to data space */
|
/* checking magic nums that are neighbour to data space */
|
||||||
JERRY_ASSERT(block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
|
JERRY_ASSERT(block_p->magic_num == MEM_MAGIC_NUM_OF_ALLOCATED_BLOCK);
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ typedef enum
|
|||||||
|
|
||||||
extern void mem_heap_init (uint8_t *heap_start, size_t heap_size);
|
extern void mem_heap_init (uint8_t *heap_start, size_t heap_size);
|
||||||
extern void mem_heap_finalize (void);
|
extern void mem_heap_finalize (void);
|
||||||
extern uint8_t* mem_heap_alloc_block (size_t size_in_bytes, mem_heap_alloc_term_t alloc_term);
|
extern void* mem_heap_alloc_block (size_t size_in_bytes, mem_heap_alloc_term_t alloc_term);
|
||||||
extern bool mem_heap_try_resize_block (uint8_t *ptr, size_t size_in_bytes);
|
extern bool mem_heap_try_resize_block (void *ptr, size_t size_in_bytes);
|
||||||
extern void mem_heap_free_block (uint8_t *ptr);
|
extern void mem_heap_free_block (void *ptr);
|
||||||
extern size_t __attribute_pure__ mem_heap_recommend_allocation_size (size_t minimum_allocation_size);
|
extern size_t __attribute_pure__ mem_heap_recommend_allocation_size (size_t minimum_allocation_size);
|
||||||
extern void mem_heap_print (bool dump_block_headers, bool dump_block_data, bool dump_stats);
|
extern void mem_heap_print (bool dump_block_headers, bool dump_block_data, bool dump_stats);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user