Remove allocator functions which stores size.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -408,26 +408,6 @@ jmem_heap_alloc_block_null_on_error (const size_t size) /**< required memory siz
|
||||
return jmem_heap_gc_and_alloc_block (size, true);
|
||||
} /* jmem_heap_alloc_block_null_on_error */
|
||||
|
||||
/**
|
||||
* Allocate block and store block size.
|
||||
*
|
||||
* Note: block will only be aligned to 4 bytes.
|
||||
*/
|
||||
inline void * __attr_always_inline___
|
||||
jmem_heap_alloc_block_store_size (size_t size) /**< required size */
|
||||
{
|
||||
if (unlikely (size == 0))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size += sizeof (jmem_heap_free_t);
|
||||
|
||||
jmem_heap_free_t *const data_space_p = (jmem_heap_free_t *) jmem_heap_alloc_block (size);
|
||||
data_space_p->size = (uint32_t) size;
|
||||
return (void *) (data_space_p + 1);
|
||||
} /* jmem_heap_alloc_block_store_size */
|
||||
|
||||
/**
|
||||
* Free the memory block.
|
||||
*/
|
||||
@@ -540,17 +520,6 @@ jmem_heap_free_block (void *ptr, /**< pointer to beginning of data space of the
|
||||
JMEM_HEAP_STAT_FREE (size);
|
||||
} /* jmem_heap_free_block */
|
||||
|
||||
/**
|
||||
* Free block with stored size
|
||||
*/
|
||||
inline void __attr_always_inline___
|
||||
jmem_heap_free_block_size_stored (void *ptr) /**< pointer to the memory block */
|
||||
{
|
||||
jmem_heap_free_t *const original_p = ((jmem_heap_free_t *) ptr) - 1;
|
||||
JERRY_ASSERT (original_p + 1 == ptr);
|
||||
jmem_heap_free_block (original_p, original_p->size);
|
||||
} /* jmem_heap_free_block_size_stored */
|
||||
|
||||
/**
|
||||
* Compress pointer
|
||||
*
|
||||
|
||||
@@ -34,8 +34,6 @@ extern void jmem_heap_finalize (void);
|
||||
extern void *jmem_heap_alloc_block (const size_t);
|
||||
extern void *jmem_heap_alloc_block_null_on_error (const size_t);
|
||||
extern void jmem_heap_free_block (void *, const size_t);
|
||||
extern void *jmem_heap_alloc_block_store_size (size_t);
|
||||
extern void jmem_heap_free_block_size_stored (void *);
|
||||
extern uintptr_t jmem_heap_compress_pointer (const void *);
|
||||
extern void *jmem_heap_decompress_pointer (uintptr_t);
|
||||
extern bool jmem_is_heap_pointer (const void *);
|
||||
|
||||
@@ -38,7 +38,7 @@ util_free_literal (lexer_literal_t *literal_p) /**< literal */
|
||||
{
|
||||
if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
|
||||
{
|
||||
jmem_heap_free_block_size_stored ((void *) literal_p->u.char_p);
|
||||
jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length);
|
||||
}
|
||||
}
|
||||
else if ((literal_p->type == LEXER_FUNCTION_LITERAL)
|
||||
|
||||
@@ -1202,7 +1202,7 @@ lexer_process_char_literal (parser_context_t *context_p, /**< context */
|
||||
|
||||
if (has_escape)
|
||||
{
|
||||
literal_p->u.char_p = (uint8_t *) jmem_heap_alloc_block_store_size (length);
|
||||
literal_p->u.char_p = (uint8_t *) jmem_heap_alloc_block (length);
|
||||
memcpy ((uint8_t *) literal_p->u.char_p, char_p, length);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -100,7 +100,7 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
|
||||
|
||||
if (!(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
|
||||
{
|
||||
jmem_heap_free_block_size_stored ((void *) char_p);
|
||||
jmem_heap_free_block ((void *) char_p, literal_p->prop.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -522,7 +522,7 @@ parser_generate_initializers (parser_context_t *context_p, /**< context */
|
||||
if (!context_p->is_show_opcodes
|
||||
&& !(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
|
||||
{
|
||||
jmem_heap_free_block_size_stored ((void *) literal_p->u.char_p);
|
||||
jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length);
|
||||
}
|
||||
#else /* !PARSER_DUMP_BYTE_CODE */
|
||||
literal_pool_p[literal_p->prop.index] = literal_p->u.value;
|
||||
@@ -1693,7 +1693,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
if ((literal_p->type == LEXER_IDENT_LITERAL || literal_p->type == LEXER_STRING_LITERAL)
|
||||
&& !(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
|
||||
{
|
||||
jmem_heap_free_block_size_stored ((void *) literal_p->u.char_p);
|
||||
jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ test_heap_give_some_memory_back (jmem_free_unused_memory_severity_t severity)
|
||||
TEST_ASSERT (ptrs[i][k] == 0);
|
||||
}
|
||||
|
||||
jmem_heap_free_block_size_stored (ptrs[i]);
|
||||
jmem_heap_free_block (ptrs[i], sizes[i]);
|
||||
ptrs[i] = NULL;
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ main ()
|
||||
for (uint32_t j = 0; j < test_sub_iters; j++)
|
||||
{
|
||||
size_t size = (size_t) rand () % test_threshold_block_size;
|
||||
ptrs[j] = (uint8_t *) jmem_heap_alloc_block_store_size (size);
|
||||
ptrs[j] = (uint8_t *) jmem_heap_alloc_block (size);
|
||||
sizes[j] = size;
|
||||
|
||||
TEST_ASSERT (sizes[j] == 0 || ptrs[j] != NULL);
|
||||
@@ -104,7 +104,7 @@ main ()
|
||||
TEST_ASSERT (ptrs[j][k] == 0);
|
||||
}
|
||||
|
||||
jmem_heap_free_block_size_stored (ptrs[j]);
|
||||
jmem_heap_free_block (ptrs[j], sizes[j]);
|
||||
|
||||
ptrs[j] = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user