Skip to content
Permalink
Browse files
Make sure internal symbols aren't polluting namespace.
This could be a problem if MojoShader is statically compiled into an app.
  • Loading branch information
icculus committed Feb 3, 2009
1 parent 7f6d425 commit 23bc5ec879459b94543c72acb94c044ed47f0561
Showing with 18 additions and 16 deletions.
  1. +10 −9 mojoshader.c
  2. +6 −6 mojoshader_assembler.c
  3. +2 −1 mojoshader_internal.h
@@ -238,9 +238,10 @@ struct Context

// Convenience functions for allocators...

static MOJOSHADER_error out_of_mem_error = { "Out of memory", NULL, -1 };
MOJOSHADER_parseData out_of_mem_data = {
1, &out_of_mem_error, 0, 0, 0, 0, MOJOSHADER_TYPE_UNKNOWN, 0, 0, 0, 0
MOJOSHADER_error MOJOSHADER_out_of_mem_error = { "Out of memory", NULL, -1 };
MOJOSHADER_parseData MOJOSHADER_out_of_mem_data = {
1, &MOJOSHADER_out_of_mem_error, 0, 0, 0, 0,
MOJOSHADER_TYPE_UNKNOWN, 0, 0, 0, 0
};

static inline void out_of_memory(Context *ctx)
@@ -7187,11 +7188,11 @@ static MOJOSHADER_parseData *build_parsedata(Context *ctx)
int attribute_count = 0;

if (ctx->out_of_memory)
return &out_of_mem_data;
return &MOJOSHADER_out_of_mem_data;

retval = (MOJOSHADER_parseData*) Malloc(ctx, sizeof(MOJOSHADER_parseData));
if (retval == NULL)
return &out_of_mem_data;
return &MOJOSHADER_out_of_mem_data;

memset(retval, '\0', sizeof (MOJOSHADER_parseData));

@@ -7262,7 +7263,7 @@ static MOJOSHADER_parseData *build_parsedata(Context *ctx)
} // for
Free(ctx, ctx->errors);
Free(ctx, retval);
return &out_of_mem_data;
return &MOJOSHADER_out_of_mem_data;
} // if
} // if
else
@@ -7469,11 +7470,11 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
int failed = 0;

if ( ((m == NULL) && (f != NULL)) || ((m != NULL) && (f == NULL)) )
return &out_of_mem_data; // supply both or neither.
return &MOJOSHADER_out_of_mem_data; // supply both or neither.

ctx = build_context(profile, tokenbuf, bufsize, swiz, swizcount, m, f, d);
if (ctx == NULL)
return &out_of_mem_data;
return &MOJOSHADER_out_of_mem_data;

verify_swizzles(ctx);

@@ -7535,7 +7536,7 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *_data)
{
MOJOSHADER_parseData *data = (MOJOSHADER_parseData *) _data;
if ((data == NULL) || (data == &out_of_mem_data))
if ((data == NULL) || (data == &MOJOSHADER_out_of_mem_data))
return; // no-op.

MOJOSHADER_free f = (data->free == NULL) ? internal_free : data->free;
@@ -1784,12 +1784,12 @@ static const MOJOSHADER_parseData *build_failed_assembly(Context *ctx)
assert(isfail(ctx));

if (ctx->out_of_memory)
return &out_of_mem_data;
return &MOJOSHADER_out_of_mem_data;

MOJOSHADER_parseData *retval = NULL;
retval = (MOJOSHADER_parseData*) Malloc(ctx, sizeof(MOJOSHADER_parseData));
if (retval == NULL)
return &out_of_mem_data;
return &MOJOSHADER_out_of_mem_data;

memset(retval, '\0', sizeof (MOJOSHADER_parseData));
retval->malloc = (ctx->malloc == internal_malloc) ? NULL : ctx->malloc;
@@ -1801,7 +1801,7 @@ static const MOJOSHADER_parseData *build_failed_assembly(Context *ctx)
if ((retval->errors == NULL) && (ctx->error_count > 0))
{
Free(ctx, retval);
return &out_of_mem_data;
return &MOJOSHADER_out_of_mem_data;
} // if

return retval;
@@ -1997,11 +1997,11 @@ const MOJOSHADER_parseData *MOJOSHADER_assemble(const char *source,
Context *ctx = NULL;

if ( ((m == NULL) && (f != NULL)) || ((m != NULL) && (f == NULL)) )
return &out_of_mem_data; // supply both or neither.
return &MOJOSHADER_out_of_mem_data; // supply both or neither.

ctx = build_context(source, m, f, d);
if (ctx == NULL)
return &out_of_mem_data;
return &MOJOSHADER_out_of_mem_data;

// Version token always comes first.
ctx->parse_phase = MOJOSHADER_PARSEPHASE_WORKING;
@@ -2054,7 +2054,7 @@ const MOJOSHADER_parseData *MOJOSHADER_assemble(const char *source,
MOJOSHADER_error *error = &retval->errors[i];
if (error->error_position >= 0)
{
assert(retval != &out_of_mem_data);
assert(retval != &MOJOSHADER_out_of_mem_data);
const int pos = error->error_position / sizeof (uint32);
if (pos >= ctx->output_len)
error->error_position = -1; // oh well.
@@ -263,7 +263,8 @@ typedef enum
MOJOSHADER_PARSEPHASE_DONE,
} MOJOSHADER_parsePhase;

extern MOJOSHADER_parseData out_of_mem_data;
extern MOJOSHADER_error MOJOSHADER_out_of_mem_error;
extern MOJOSHADER_parseData MOJOSHADER_out_of_mem_data;

typedef struct ErrorList
{

0 comments on commit 23bc5ec

Please sign in to comment.