Export symbol information for preshaders.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 01 Jun 2011 02:14:12 -0400
changeset 1042 cb6659f80bb9
parent 1041 200cde29af83
child 1043 6227066350b4
Export symbol information for preshaders.
mojoshader.c
mojoshader.h
--- a/mojoshader.c	Wed Jun 01 02:11:57 2011 -0400
+++ b/mojoshader.c	Wed Jun 01 02:14:12 2011 -0400
@@ -7232,10 +7232,15 @@
     CtabData ctabdata = { 0, 0, 0 };
     parse_constant_table(ctx, ctab.tokens - 1, ctab.tokcount * 4,
                          okay_version, 0, &ctabdata);
+
+    // preshader owns this now. Don't free it in this function.
+    preshader->symbol_count = ctabdata.symbol_count;
+    preshader->symbols = ctabdata.symbols;
+
     if (!ctabdata.have_ctab)
     {
         fail(ctx, "Bogus preshader CTAB data");
-        goto parse_preshader_cleanup;
+        return;
     } // if
 
     // The FXLC block has the actual instructions...
@@ -7246,7 +7251,7 @@
     preshader->instructions = (MOJOSHADER_preshaderInstruction *)
                                 Malloc(ctx, len);
     if (preshader->instructions == NULL)
-        goto parse_preshader_cleanup;
+        return;
     memset(preshader->instructions, '\0', len);
 
     fxlc.tokens += 2;
@@ -7254,7 +7259,7 @@
     if (opcode_count > (fxlc.tokcount / 2))
     {
         fail(ctx, "Bogus preshader FXLC block.");
-        goto parse_preshader_cleanup;
+        return;
     } // if
 
     MOJOSHADER_preshaderInstruction *inst = preshader->instructions;
@@ -7312,7 +7317,7 @@
         if ((operand_count * 3) > fxlc.tokcount)
         {
             fail(ctx, "Bogus preshader FXLC block.");
-            goto parse_preshader_cleanup;
+            return;
         } // if
 
         MOJOSHADER_preshaderOperand *operand = &inst->operands[1];
@@ -7396,10 +7401,6 @@
 
         inst++;
     } // while
-
-parse_preshader_cleanup:
-    free_symbols(ctx->free, ctx->malloc_data,
-                 ctabdata.symbols, ctabdata.symbol_count);
 #endif
 } // parse_preshader
 
@@ -7616,6 +7617,7 @@
     {
         f((void *) preshader->literals, d);
         f((void *) preshader->instructions, d);
+        free_symbols(f, d, preshader->symbols, preshader->symbol_count);
         f((void *) preshader, d);
     } // if
 } // free_preshader
--- a/mojoshader.h	Wed Jun 01 02:11:57 2011 -0400
+++ b/mojoshader.h	Wed Jun 01 02:14:12 2011 -0400
@@ -422,6 +422,8 @@
     unsigned int literal_count;
     double *literals;
     unsigned int temp_count;  /* scalar, not vector! */
+    unsigned int symbol_count;
+    MOJOSHADER_symbol *symbols;
     unsigned int instruction_count;
     MOJOSHADER_preshaderInstruction *instructions;
 } MOJOSHADER_preshader;