Skip to content

Commit

Permalink
Make sure internal symbols aren't polluting namespace.
Browse files Browse the repository at this point in the history
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 23bc5ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
19 changes: 10 additions & 9 deletions mojoshader.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions mojoshader_assembler.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion mojoshader_internal.h
Expand Up @@ -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
{
Expand Down

0 comments on commit 23bc5ec

Please sign in to comment.