From b03290ea50db1674ee8be73a2a4c90ddb3a93a42 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 18 Feb 2009 19:50:37 -0500 Subject: [PATCH] Let there be different close callbacks per IncludeState. --- mojoshader_internal.h | 1 + mojoshader_preprocessor.c | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mojoshader_internal.h b/mojoshader_internal.h index 0e01580d..0b3ac5fd 100644 --- a/mojoshader_internal.h +++ b/mojoshader_internal.h @@ -403,6 +403,7 @@ typedef struct IncludeState unsigned int bytes_left; unsigned int line; Conditional *conditional_stack; + MOJOSHADER_includeClose close_callback; struct IncludeState *next; } IncludeState; diff --git a/mojoshader_preprocessor.c b/mojoshader_preprocessor.c index 80250ffd..734000ee 100644 --- a/mojoshader_preprocessor.c +++ b/mojoshader_preprocessor.c @@ -541,7 +541,8 @@ static void free_filename_cache(Context *ctx) 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 @@ static int push_source(Context *ctx, const char *fname, const char *source, } // if } // if - state->included = included; + state->close_callback = close_callback; state->source_base = source; state->source = source; state->token = source; @@ -578,10 +579,10 @@ static void pop_source(Context *ctx) 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 @@ Preprocessor *preprocessor_start(const char *fname, const char *source, } // 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 @@ static void handle_pp_include(Context *ctx) 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);