Add jerryscript-compiler.h public header to cover compiler incompatibilities (#2313)
In general, public headers should not have compiler-specific constructs but both the core and the port headers have attributes, which are non-standard. It's better to factor out such constructs to a common place (a new header) and hide them behind macros, which can then be defined on a per-compiler basis. This patch moves the existing definitions of function attributes and likely/unlikely builtins to the new header. At the same time, it unifies the names of these attribute defines and where they are used. Moreover, it touches on jerry-main and removes the uses of `__attribute__((unused))` entirely and replaces them with the elsewhere used `(void) ...` pattern. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -56,7 +56,7 @@ jmem_finalize (void)
|
||||
*
|
||||
* @return packed pointer
|
||||
*/
|
||||
inline jmem_cpointer_t __attr_pure___ __attr_always_inline___
|
||||
inline jmem_cpointer_t JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
|
||||
jmem_compress_pointer (const void *pointer_p) /**< pointer to compress */
|
||||
{
|
||||
JERRY_ASSERT (pointer_p != NULL);
|
||||
@@ -90,7 +90,7 @@ jmem_compress_pointer (const void *pointer_p) /**< pointer to compress */
|
||||
*
|
||||
* @return unpacked pointer
|
||||
*/
|
||||
inline void * __attr_pure___ __attr_always_inline___
|
||||
inline void * JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
|
||||
jmem_decompress_pointer (uintptr_t compressed_pointer) /**< pointer to decompress */
|
||||
{
|
||||
JERRY_ASSERT (compressed_pointer != JMEM_CP_NULL);
|
||||
|
||||
+11
-11
@@ -96,7 +96,7 @@
|
||||
/**
|
||||
* Get end of region
|
||||
*/
|
||||
static inline jmem_heap_free_t * __attr_always_inline___ __attr_pure___
|
||||
static inline jmem_heap_free_t * JERRY_ATTR_ALWAYS_INLINE JERRY_ATTR_PURE
|
||||
jmem_heap_get_region_end (jmem_heap_free_t *curr_p) /**< current region */
|
||||
{
|
||||
return (jmem_heap_free_t *)((uint8_t *) curr_p + curr_p->size);
|
||||
@@ -193,7 +193,7 @@ jmem_heap_finalize (void)
|
||||
* @return pointer to allocated memory block - if allocation is successful,
|
||||
* NULL - if there is not enough memory.
|
||||
*/
|
||||
static __attr_hot___ void *
|
||||
static void * JERRY_ATTR_HOT
|
||||
jmem_heap_alloc_block_internal (const size_t size)
|
||||
{
|
||||
#ifndef JERRY_SYSTEM_ALLOCATOR
|
||||
@@ -205,7 +205,7 @@ jmem_heap_alloc_block_internal (const size_t size)
|
||||
|
||||
/* Fast path for 8 byte chunks, first region is guaranteed to be sufficient. */
|
||||
if (required_size == JMEM_ALIGNMENT
|
||||
&& likely (JERRY_HEAP_CONTEXT (first).next_offset != JMEM_HEAP_END_OF_LIST))
|
||||
&& JERRY_LIKELY (JERRY_HEAP_CONTEXT (first).next_offset != JMEM_HEAP_END_OF_LIST))
|
||||
{
|
||||
data_space_p = JMEM_HEAP_GET_ADDR_FROM_OFFSET (JERRY_HEAP_CONTEXT (first).next_offset);
|
||||
JERRY_ASSERT (jmem_is_heap_pointer (data_space_p));
|
||||
@@ -235,7 +235,7 @@ jmem_heap_alloc_block_internal (const size_t size)
|
||||
|
||||
VALGRIND_UNDEFINED_SPACE (data_space_p, sizeof (jmem_heap_free_t));
|
||||
|
||||
if (unlikely (data_space_p == JERRY_CONTEXT (jmem_heap_list_skip_p)))
|
||||
if (JERRY_UNLIKELY (data_space_p == JERRY_CONTEXT (jmem_heap_list_skip_p)))
|
||||
{
|
||||
JERRY_CONTEXT (jmem_heap_list_skip_p) = JMEM_HEAP_GET_ADDR_FROM_OFFSET (JERRY_HEAP_CONTEXT (first).next_offset);
|
||||
}
|
||||
@@ -309,7 +309,7 @@ jmem_heap_alloc_block_internal (const size_t size)
|
||||
|
||||
VALGRIND_NOACCESS_SPACE (&JERRY_HEAP_CONTEXT (first), sizeof (jmem_heap_free_t));
|
||||
|
||||
if (unlikely (!data_space_p))
|
||||
if (JERRY_UNLIKELY (!data_space_p))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ jmem_heap_gc_and_alloc_block (const size_t size, /**< required memory size
|
||||
bool ret_null_on_error) /**< indicates whether return null or terminate
|
||||
with ERR_OUT_OF_MEMORY on out of memory */
|
||||
{
|
||||
if (unlikely (size == 0))
|
||||
if (JERRY_UNLIKELY (size == 0))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -359,7 +359,7 @@ jmem_heap_gc_and_alloc_block (const size_t size, /**< required memory size
|
||||
|
||||
void *data_space_p = jmem_heap_alloc_block_internal (size);
|
||||
|
||||
if (likely (data_space_p != NULL))
|
||||
if (JERRY_LIKELY (data_space_p != NULL))
|
||||
{
|
||||
VALGRIND_FREYA_MALLOCLIKE_SPACE (data_space_p, size);
|
||||
return data_space_p;
|
||||
@@ -373,7 +373,7 @@ jmem_heap_gc_and_alloc_block (const size_t size, /**< required memory size
|
||||
|
||||
data_space_p = jmem_heap_alloc_block_internal (size);
|
||||
|
||||
if (likely (data_space_p != NULL))
|
||||
if (JERRY_LIKELY (data_space_p != NULL))
|
||||
{
|
||||
VALGRIND_FREYA_MALLOCLIKE_SPACE (data_space_p, size);
|
||||
return data_space_p;
|
||||
@@ -400,7 +400,7 @@ jmem_heap_gc_and_alloc_block (const size_t size, /**< required memory size
|
||||
* @return NULL, if the required memory is 0
|
||||
* pointer to allocated memory block, otherwise
|
||||
*/
|
||||
inline void * __attr_hot___ __attr_always_inline___
|
||||
inline void * JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
|
||||
jmem_heap_alloc_block (const size_t size) /**< required memory size */
|
||||
{
|
||||
return jmem_heap_gc_and_alloc_block (size, false);
|
||||
@@ -416,7 +416,7 @@ jmem_heap_alloc_block (const size_t size) /**< required memory size */
|
||||
* also NULL, if the allocation has failed
|
||||
* pointer to the allocated memory block, otherwise
|
||||
*/
|
||||
inline void * __attr_hot___ __attr_always_inline___
|
||||
inline void * JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
|
||||
jmem_heap_alloc_block_null_on_error (const size_t size) /**< required memory size */
|
||||
{
|
||||
return jmem_heap_gc_and_alloc_block (size, true);
|
||||
@@ -425,7 +425,7 @@ jmem_heap_alloc_block_null_on_error (const size_t size) /**< required memory siz
|
||||
/**
|
||||
* Free the memory block.
|
||||
*/
|
||||
void __attr_hot___
|
||||
void JERRY_ATTR_HOT
|
||||
jmem_heap_free_block (void *ptr, /**< pointer to beginning of data space of the block */
|
||||
const size_t size) /**< size of allocated region */
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ jmem_pools_finalize (void)
|
||||
* @return pointer to allocated chunk, if allocation was successful,
|
||||
* or NULL - if not enough memory.
|
||||
*/
|
||||
inline void * __attr_hot___ __attr_always_inline___
|
||||
inline void * JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
|
||||
jmem_pools_alloc (size_t size) /**< size of the chunk */
|
||||
{
|
||||
#ifdef JMEM_GC_BEFORE_EACH_ALLOC
|
||||
@@ -131,7 +131,7 @@ jmem_pools_alloc (size_t size) /**< size of the chunk */
|
||||
/**
|
||||
* Free the chunk
|
||||
*/
|
||||
inline void __attr_hot___ __attr_always_inline___
|
||||
inline void JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
|
||||
jmem_pools_free (void *chunk_p, /**< pointer to the chunk */
|
||||
size_t size) /**< size of the chunk */
|
||||
{
|
||||
|
||||
@@ -164,8 +164,8 @@ void jmem_stats_free_property_bytes (size_t property_size);
|
||||
void jmem_heap_get_stats (jmem_heap_stats_t *);
|
||||
#endif /* JMEM_STATS */
|
||||
|
||||
jmem_cpointer_t jmem_compress_pointer (const void *pointer_p) __attr_pure___;
|
||||
void *jmem_decompress_pointer (uintptr_t compressed_pointer) __attr_pure___;
|
||||
jmem_cpointer_t JERRY_ATTR_PURE jmem_compress_pointer (const void *pointer_p);
|
||||
void * JERRY_ATTR_PURE jmem_decompress_pointer (uintptr_t compressed_pointer);
|
||||
|
||||
/**
|
||||
* A free memory callback routine type.
|
||||
@@ -217,7 +217,7 @@ void jmem_run_free_unused_memory_callbacks (jmem_free_unused_memory_severity_t s
|
||||
* Get value of pointer from specified compressed pointer value
|
||||
*/
|
||||
#define JMEM_CP_GET_POINTER(type, cp_value) \
|
||||
(((unlikely ((cp_value) == JMEM_CP_NULL)) ? NULL : JMEM_CP_GET_NON_NULL_POINTER (type, cp_value)))
|
||||
(((JERRY_UNLIKELY ((cp_value) == JMEM_CP_NULL)) ? NULL : JMEM_CP_GET_NON_NULL_POINTER (type, cp_value)))
|
||||
|
||||
/**
|
||||
* Set value of non-null compressed pointer so that it will correspond
|
||||
@@ -235,7 +235,7 @@ void jmem_run_free_unused_memory_callbacks (jmem_free_unused_memory_severity_t s
|
||||
{ \
|
||||
void *ptr_value = (void *) non_compressed_pointer; \
|
||||
\
|
||||
if (unlikely ((ptr_value) == NULL)) \
|
||||
if (JERRY_UNLIKELY ((ptr_value) == NULL)) \
|
||||
{ \
|
||||
(cp_value) = JMEM_CP_NULL; \
|
||||
} \
|
||||
|
||||
Reference in New Issue
Block a user