From 85e84ce291f0ae02778955ba8fc4cc7c48b1d4ad Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 7 Feb 2009 00:35:17 -0500 Subject: [PATCH] Renamed internal_malloc() and internal_free(). This is to prevent namespace clash if we statically link MojoShader to an app. --- mojoshader.c | 14 ++++++++------ mojoshader_assembler.c | 10 +++++----- mojoshader_internal.h | 8 ++++---- mojoshader_opengl.c | 4 ++-- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 0e94bc2e..e2e9f6b5 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -237,6 +237,8 @@ struct Context // Convenience functions for allocators... +void *MOJOSHADER_internal_malloc(int bytes, void *d) { return malloc(bytes); } +void MOJOSHADER_internal_free(void *ptr, void *d) { free(ptr); } MOJOSHADER_error MOJOSHADER_out_of_mem_error = { "Out of memory", NULL, -1 }; MOJOSHADER_parseData MOJOSHADER_out_of_mem_data = { @@ -6745,8 +6747,8 @@ static Context *build_context(const char *profile, const unsigned int swizcount, MOJOSHADER_malloc m, MOJOSHADER_free f, void *d) { - if (m == NULL) m = internal_malloc; - if (f == NULL) f = internal_free; + if (m == NULL) m = MOJOSHADER_internal_malloc; + if (f == NULL) f = MOJOSHADER_internal_free; Context *ctx = (Context *) m(sizeof (Context), d); if (ctx == NULL) @@ -6836,7 +6838,7 @@ static void destroy_context(Context *ctx) { if (ctx != NULL) { - MOJOSHADER_free f = ((ctx->free != NULL) ? ctx->free : internal_free); + MOJOSHADER_free f = ((ctx->free != NULL) ? ctx->free : MOJOSHADER_internal_free); void *d = ctx->malloc_data; if (ctx->output_bytes != NULL) f(d, ctx->output_bytes); @@ -7289,8 +7291,8 @@ static MOJOSHADER_parseData *build_parsedata(Context *ctx) retval->error_count = ctx->error_count; retval->errors = errors; - retval->malloc = (ctx->malloc == internal_malloc) ? NULL : ctx->malloc; - retval->free = (ctx->free == internal_free) ? NULL : ctx->free; + retval->malloc = (ctx->malloc == MOJOSHADER_internal_malloc) ? NULL : ctx->malloc; + retval->free = (ctx->free == MOJOSHADER_internal_free) ? NULL : ctx->free; retval->malloc_data = ctx->malloc_data; return retval; @@ -7539,7 +7541,7 @@ void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *_data) if ((data == NULL) || (data == &MOJOSHADER_out_of_mem_data)) return; // no-op. - MOJOSHADER_free f = (data->free == NULL) ? internal_free : data->free; + MOJOSHADER_free f = (data->free == NULL) ? MOJOSHADER_internal_free : data->free; void *d = data->malloc_data; int i; diff --git a/mojoshader_assembler.c b/mojoshader_assembler.c index 3573165f..0bda4fa5 100644 --- a/mojoshader_assembler.c +++ b/mojoshader_assembler.c @@ -1704,8 +1704,8 @@ static void parse_token(Context *ctx) static Context *build_context(const char *source, MOJOSHADER_malloc m, MOJOSHADER_free f, void *d) { - if (m == NULL) m = internal_malloc; - if (f == NULL) f = internal_free; + if (m == NULL) m = MOJOSHADER_internal_malloc; + if (f == NULL) f = MOJOSHADER_internal_free; Context *ctx = (Context *) m(sizeof (Context), d); if (ctx == NULL) @@ -1740,7 +1740,7 @@ static void destroy_context(Context *ctx) { if (ctx != NULL) { - MOJOSHADER_free f = ((ctx->free != NULL) ? ctx->free : internal_free); + MOJOSHADER_free f = ((ctx->free != NULL) ? ctx->free : MOJOSHADER_internal_free); void *d = ctx->malloc_data; free_error_list(f, d, ctx->errors); if (ctx->output != NULL) @@ -1792,8 +1792,8 @@ static const MOJOSHADER_parseData *build_failed_assembly(Context *ctx) return &MOJOSHADER_out_of_mem_data; memset(retval, '\0', sizeof (MOJOSHADER_parseData)); - retval->malloc = (ctx->malloc == internal_malloc) ? NULL : ctx->malloc; - retval->free = (ctx->free == internal_free) ? NULL : ctx->free; + retval->malloc = (ctx->malloc == MOJOSHADER_internal_malloc) ? NULL : ctx->malloc; + retval->free = (ctx->free == MOJOSHADER_internal_free) ? NULL : ctx->free; retval->malloc_data = ctx->malloc_data; retval->error_count = ctx->error_count; diff --git a/mojoshader_internal.h b/mojoshader_internal.h index e6e5e23d..c98892d2 100644 --- a/mojoshader_internal.h +++ b/mojoshader_internal.h @@ -132,11 +132,11 @@ typedef int32_t int32; // #define this to force app to supply an allocator, so there's no reference // to the C runtime's malloc() and free()... #if MOJOSHADER_FORCE_ALLOCATOR -#define internal_malloc NULL -#define internal_free NULL +#define MOJOSHADER_internal_malloc NULL +#define MOJOSHADER_internal_free NULL #else -static void *internal_malloc(int bytes, void *d) { return malloc(bytes); } -static void internal_free(void *ptr, void *d) { free(ptr); } +void *MOJOSHADER_internal_malloc(int bytes, void *d); +void MOJOSHADER_internal_free(void *ptr, void *d); #endif // result modifiers. diff --git a/mojoshader_opengl.c b/mojoshader_opengl.c index 71aa7d7c..7fed967b 100644 --- a/mojoshader_opengl.c +++ b/mojoshader_opengl.c @@ -939,8 +939,8 @@ MOJOSHADER_glContext *MOJOSHADER_glCreateContext(const char *profile, MOJOSHADER_glContext *current_ctx = ctx; ctx = NULL; - if (m == NULL) m = internal_malloc; - if (f == NULL) f = internal_free; + if (m == NULL) m = MOJOSHADER_internal_malloc; + if (f == NULL) f = MOJOSHADER_internal_free; ctx = (MOJOSHADER_glContext *) m(sizeof (MOJOSHADER_glContext), d); if (ctx == NULL)