Hi This series of patches fixes incompatibilities with the c99 inlining rules and sets default C dialect to gnu99.
I think it would make sense to use the c99 inlining rules as they are standardized and the gnu99 C dialect enables use of c99 features and may future proof the code slightly. These patches also allows monkey to be compiled using clang without adding anything to CFLAGS. These patches works on Debian Sid with clang-3.1-8 (based on LLVM 3.1) and gcc-4.7.1 and under Debian Squeeze with clang-1.1 (based on LLVM 2.7) and gcc-4.4.5. Some alignment warnings are issued when compiling with clang-1.1 but the binary works as expected. Benchmarking suggest performance is unaffected. These patches rely on previously submitted "[PATCH] configure: Fix accept4() check" and "[PATCH] mimetype: Make mk_mimetype_lookup static". -- Sonny Karlsson
>From a54381b70633b0b21ae6617c0b1bb6ad6b5ca992 Mon Sep 17 00:00:00 2001 From: Sonny Karlsson <[email protected]> Date: Mon, 13 Aug 2012 19:57:17 +0200 Subject: [PATCH 1/4] mk_memory: Make mem_ functions static inline. Use static inline for mem_malloc, mem_malloc_z, mem_realloc and mem_free. This will assure that calls to these functions from monkey core is inlined. Fixes incompatibilities with C99 inlining rules. Signed-off-by: Sonny Karlsson <[email protected]> --- src/include/mk_memory.h | 48 ++++++++++++++++++++++++++++++++++++++++++++--- src/mk_memory.c | 42 ----------------------------------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/include/mk_memory.h b/src/include/mk_memory.h index 41b6cb9..785dca4 100644 --- a/src/include/mk_memory.h +++ b/src/include/mk_memory.h @@ -22,6 +22,9 @@ #ifndef MK_MEM_H #define MK_MEM_H +#include <stdio.h> +#include "mk_macros.h" + typedef struct { char *data; @@ -34,9 +37,48 @@ typedef struct # define ALLOCSZ_ATTR(x,...) #endif -inline void *mk_mem_malloc(const size_t size); -inline void *mk_mem_malloc_z(const size_t size); -inline void *mk_mem_realloc(void *ptr, const size_t size); +static inline ALLOCSZ_ATTR(1) +void *mk_mem_malloc(const size_t size) +{ + void *aux = malloc(size); + + if (mk_unlikely(!aux && size)) { + perror("malloc"); + return NULL; + } + + return aux; +} + +static inline ALLOCSZ_ATTR(1) +void *mk_mem_malloc_z(const size_t size) +{ + void *buf = calloc(1, size); + if (mk_unlikely(!buf)) { + return NULL; + } + + return buf; +} + +static inline ALLOCSZ_ATTR(2) +void *mk_mem_realloc(void *ptr, const size_t size) +{ + void *aux = realloc(ptr, size); + + if (mk_unlikely(!aux && size)) { + perror("realloc"); + return NULL; + } + + return aux; +} + +static inline void mk_mem_free(void *ptr) +{ + free(ptr); +} + void mk_mem_free(void *ptr); void mk_mem_pointers_init(void); diff --git a/src/mk_memory.c b/src/mk_memory.c index a5332ea..20a9210 100644 --- a/src/mk_memory.c +++ b/src/mk_memory.c @@ -35,48 +35,6 @@ #include "mk_user.h" #include "mk_macros.h" -inline ALLOCSZ_ATTR(1) -void *mk_mem_malloc(const size_t size) -{ - void *aux = malloc(size); - - if (mk_unlikely(!aux && size)) { - perror("malloc"); - return NULL; - } - - return aux; -} - -inline ALLOCSZ_ATTR(1) -void *mk_mem_malloc_z(const size_t size) -{ - void *buf = calloc(1, size); - if (mk_unlikely(!buf)) { - return NULL; - } - - return buf; -} - -inline ALLOCSZ_ATTR(2) -void *mk_mem_realloc(void *ptr, const size_t size) -{ - void *aux = realloc(ptr, size); - - if (mk_unlikely(!aux && size)) { - perror("realloc"); - return NULL; - } - - return aux; -} - -void mk_mem_free(void *ptr) -{ - free(ptr); -} - mk_pointer mk_pointer_create(char *buf, long init, long end) { mk_pointer p; -- 1.7.10.4
_______________________________________________ Monkey mailing list [email protected] http://lists.monkey-project.com/listinfo/monkey
