Promote dynamic memory management from debugger transport to core API (#2503)
Under the cover of the debugger transport layer, allocation on the engine's heap has been made available to the public. As there are actually no restrictions on what the allocated memory can be used for, the memory management functions better fit in the core part of the API. Closes #1805 JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -29,28 +29,6 @@
|
||||
*/
|
||||
#define JERRY_DEBUGGER_TRANSPORT_TIMEOUT 100
|
||||
|
||||
/**
|
||||
* Allocate memory for a connection.
|
||||
*
|
||||
* @return allocated memory on success
|
||||
* NULL otherwise
|
||||
*/
|
||||
void *
|
||||
jerry_debugger_transport_malloc (size_t size) /**< size of the memory block */
|
||||
{
|
||||
return jmem_heap_alloc_block_null_on_error (size);
|
||||
} /* jerry_debugger_transport_malloc */
|
||||
|
||||
/**
|
||||
* Free memory allocated for a connection.
|
||||
*/
|
||||
void
|
||||
jerry_debugger_transport_free (void *mem_p, /**< value returned by jerry_debugger_transport_malloc() */
|
||||
size_t size) /**< same size passed to jerry_debugger_transport_malloc() */
|
||||
{
|
||||
jmem_heap_free_block (mem_p, size);
|
||||
} /* jerry_debugger_transport_free */
|
||||
|
||||
/**
|
||||
* Add a new transport layer.
|
||||
*/
|
||||
|
||||
@@ -2621,6 +2621,37 @@ jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, /**< CESU-8 string
|
||||
(lit_utf8_size_t) buf_size);
|
||||
} /* jerry_is_valid_cesu8_string */
|
||||
|
||||
/**
|
||||
* Allocate memory on the engine's heap.
|
||||
*
|
||||
* Note:
|
||||
* This function may take away memory from the executed JavaScript code.
|
||||
* If any other dynamic memory allocation API is available (e.g., libc
|
||||
* malloc), it should be used instead.
|
||||
*
|
||||
* @return allocated memory on success
|
||||
* NULL otherwise
|
||||
*/
|
||||
void *
|
||||
jerry_heap_alloc (size_t size) /**< size of the memory block */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
return jmem_heap_alloc_block_null_on_error (size);
|
||||
} /* jerry_heap_alloc */
|
||||
|
||||
/**
|
||||
* Free memory allocated on the engine's heap.
|
||||
*/
|
||||
void
|
||||
jerry_heap_free (void *mem_p, /**< value returned by jerry_heap_alloc */
|
||||
size_t size) /**< same size as passed to jerry_heap_alloc */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
jmem_heap_free_block (mem_p, size);
|
||||
} /* jerry_heap_free */
|
||||
|
||||
/**
|
||||
* Create an external engine context.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user