diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/eurephia_nullsafe.c | 10 | ||||
-rw-r--r-- | common/eurephia_nullsafe.h | 12 |
2 files changed, 14 insertions, 8 deletions
diff --git a/common/eurephia_nullsafe.c b/common/eurephia_nullsafe.c index bd78d6b..2536d4b 100644 --- a/common/eurephia_nullsafe.c +++ b/common/eurephia_nullsafe.c @@ -38,6 +38,12 @@ #include <eurephia_context.h> #include <eurephia_log.h> +#if __GNUC__ >= 3 +#define __malloc__ __attribute__((malloc)) +#else /* If not GCC 3 or newer, disable optimisations */ +#define __malloc__ +#endif + /** * Internal function, should be called via the malloc_nullsafe() macro. * This replaces the use of malloc() and memset(). This function uses calloc @@ -51,7 +57,7 @@ * * @return Returns a void pointer to the memory region on success, otherwise NULL */ -void *__malloc_nullsafe(eurephiaCTX *ctx, size_t sz, const char *file, int line) { +__malloc__ void *_malloc_nullsafe(eurephiaCTX *ctx, size_t sz, const char *file, int line) { void *buf = NULL; buf = calloc(1, sz); /* Using calloc, also gives a zero'd memory region */ @@ -83,7 +89,7 @@ void *__malloc_nullsafe(eurephiaCTX *ctx, size_t sz, const char *file, int line) * @param line debug info, which line in the file * */ -void inline __free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line) { +void inline _free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line) { if( ptr == NULL ) { return; } diff --git a/common/eurephia_nullsafe.h b/common/eurephia_nullsafe.h index 22d50ed..5249c19 100644 --- a/common/eurephia_nullsafe.h +++ b/common/eurephia_nullsafe.h @@ -80,10 +80,10 @@ -void *__malloc_nullsafe(eurephiaCTX *, size_t, const char *, int); +void *_malloc_nullsafe(eurephiaCTX *, size_t, const char *, int); /** - * Front-end macro for the __malloc_nullsafe() function. + * Front-end macro for the _malloc_nullsafe() function. * * @param ctx eurephiaCTX (used for debugg logging) * @param sz Size of the memory region wanted @@ -91,19 +91,19 @@ void *__malloc_nullsafe(eurephiaCTX *, size_t, const char *, int); * @return Returns a pointer to the memory region on success, otherwise NULL. * */ -#define malloc_nullsafe(ctx, sz) __malloc_nullsafe(ctx, sz, __FILE__, __LINE__) +#define malloc_nullsafe(ctx, sz) _malloc_nullsafe(ctx, sz, __FILE__, __LINE__) -void inline __free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line); +void inline _free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line); /** - * Front-end macro for the __free_nullsafe() function. + * Front-end macro for the __ree_nullsafe() function. * * @param ctx eurephiaCTX (used for debugg logging) * @param ptr Pointer to the memory region being freed. * */ -#define free_nullsafe(ctx, ptr) { __free_nullsafe(ctx, ptr, __FILE__, __LINE__); ptr = NULL; } +#define free_nullsafe(ctx, ptr) { _free_nullsafe(ctx, ptr, __FILE__, __LINE__); ptr = NULL; } /** |