Make sure internal symbols aren't polluting namespace.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 03 Feb 2009 17:51:13 -0500
changeset 551 217200672d64
parent 550 2f977a75d2b5
child 552 40ca33bd5f88
Make sure internal symbols aren't polluting namespace. This could be a problem if MojoShader is statically compiled into an app.
mojoshader.c
mojoshader_assembler.c
mojoshader_internal.h
--- a/mojoshader.c	Tue Feb 03 17:31:37 2009 -0500
+++ b/mojoshader.c	Tue Feb 03 17:51:13 2009 -0500
@@ -238,9 +238,10 @@
 
 // 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 @@
     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 @@
             } // 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 @@
     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 @@
 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;
--- a/mojoshader_assembler.c	Tue Feb 03 17:31:37 2009 -0500
+++ b/mojoshader_assembler.c	Tue Feb 03 17:51:13 2009 -0500
@@ -1784,12 +1784,12 @@
     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 @@
     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 @@
     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 @@
             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.
--- a/mojoshader_internal.h	Tue Feb 03 17:31:37 2009 -0500
+++ b/mojoshader_internal.h	Tue Feb 03 17:51:13 2009 -0500
@@ -263,7 +263,8 @@
     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
 {