Skip to content
Permalink
Browse files
Renamed internal_malloc() and internal_free().
This is to prevent namespace clash if we statically link MojoShader to an app.
  • Loading branch information
icculus committed Feb 7, 2009
1 parent 0f57738 commit 85e84ce291f0ae02778955ba8fc4cc7c48b1d4ad
Showing with 19 additions and 17 deletions.
  1. +8 −6 mojoshader.c
  2. +5 −5 mojoshader_assembler.c
  3. +4 −4 mojoshader_internal.h
  4. +2 −2 mojoshader_opengl.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;

@@ -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;
@@ -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.
@@ -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)

0 comments on commit 85e84ce

Please sign in to comment.