Let there be different close callbacks per IncludeState.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 18 Feb 2009 19:50:37 -0500
changeset 656 ddb1a0b4c443
parent 655 0b82fdeebf86
child 657 1268d95644f0
Let there be different close callbacks per IncludeState.
mojoshader_internal.h
mojoshader_preprocessor.c
--- a/mojoshader_internal.h	Wed Feb 18 19:30:04 2009 -0500
+++ b/mojoshader_internal.h	Wed Feb 18 19:50:37 2009 -0500
@@ -403,6 +403,7 @@
     unsigned int bytes_left;
     unsigned int line;
     Conditional *conditional_stack;
+    MOJOSHADER_includeClose close_callback;
     struct IncludeState *next;
 } IncludeState;
 
--- a/mojoshader_preprocessor.c	Wed Feb 18 19:30:04 2009 -0500
+++ b/mojoshader_preprocessor.c	Wed Feb 18 19:50:37 2009 -0500
@@ -541,7 +541,8 @@
 
 
 static int push_source(Context *ctx, const char *fname, const char *source,
-                       unsigned int srclen, unsigned int linenum, int included)
+                       unsigned int srclen, unsigned int linenum,
+                       MOJOSHADER_includeClose close_callback)
 {
     IncludeState *state = get_include(ctx);
     if (state == NULL)
@@ -557,7 +558,7 @@
         } // if
     } // if
 
-    state->included = included;
+    state->close_callback = close_callback;
     state->source_base = source;
     state->source = source;
     state->token = source;
@@ -578,10 +579,10 @@
     if (state == NULL)
         return;
 
-    if (state->included)
+    if (state->close_callback)
     {
-        ctx->close_callback(state->source_base, ctx->malloc,
-                            ctx->free, ctx->malloc_data);
+        state->close_callback(state->source_base, ctx->malloc,
+                              ctx->free, ctx->malloc_data);
     } // if
 
     // state->filename is a pointer to the filename cache; don't free it here!
@@ -631,7 +632,7 @@
         } // if
     } // for
 
-    if ((okay) && (!push_source(ctx, fname, source, sourcelen, 1, 0)))
+    if ((okay) && (!push_source(ctx, fname, source, sourcelen, 1, NULL)))
         okay = 0;
 
     if (!okay)
@@ -762,7 +763,7 @@
         return;
     } // if
 
-    if (!push_source(ctx, filename, newdata, newbytes, 1, 1))
+    if (!push_source(ctx, filename, newdata, newbytes, 1, ctx->close_callback))
     {
         assert(ctx->out_of_memory);
         ctx->close_callback(newdata, ctx->malloc, ctx->free, ctx->malloc_data);