To prepare for the need to release resources when we're done with xdiff_outf, make a new function pair to initialize and release a struct xdiff_emit_state. Since we can roll the two lines always required to use xdiff_outf into one, the net number of lines at the call site remains constant. Old: ecb.outf = xdiff_outf; ecb.priv = &state; ... xdi_diff(file_p, file_o, &xpp, &xecfg, &ecb); New: xdiff_outf_init(&ecb, &state); ... xdi_diff(file_p, file_o, &xpp, &xecfg, &ecb); xdiff_outf_release(&state); Signed-off-by: Brian Downing <bdowning@xxxxxxxxx> --- builtin-blame.c | 4 ++-- combine-diff.c | 4 ++-- diff.c | 20 ++++++++++---------- xdiff-interface.c | 11 +++++++++++ xdiff-interface.h | 2 ++ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/builtin-blame.c b/builtin-blame.c index 4ea3431..b52eff4 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -528,15 +528,15 @@ static struct patch *compare_buffer(mmfile_t *file_p, mmfile_t *file_o, xpp.flags = xdl_opts; memset(&xecfg, 0, sizeof(xecfg)); xecfg.ctxlen = context; - ecb.outf = xdiff_outf; - ecb.priv = &state; memset(&state, 0, sizeof(state)); + xdiff_outf_init(&ecb, &state); state.xm.consume = process_u_diff; state.ret = xmalloc(sizeof(struct patch)); state.ret->chunks = NULL; state.ret->num = 0; xdi_diff(file_p, file_o, &xpp, &xecfg, &ecb); + xdiff_outf_release(&state); if (state.ret->num) { struct chunk *chunk; diff --git a/combine-diff.c b/combine-diff.c index 9f80a1c..887c315 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -217,9 +217,8 @@ static void combine_diff(const unsigned char *parent, mmfile_t *result_file, parent_file.size = sz; xpp.flags = XDF_NEED_MINIMAL; memset(&xecfg, 0, sizeof(xecfg)); - ecb.outf = xdiff_outf; - ecb.priv = &state; memset(&state, 0, sizeof(state)); + xdiff_outf_init(&ecb, &state); state.xm.consume = consume_line; state.nmask = nmask; state.sline = sline; @@ -228,6 +227,7 @@ static void combine_diff(const unsigned char *parent, mmfile_t *result_file, state.n = n; xdi_diff(&parent_file, result_file, &xpp, &xecfg, &ecb); + xdiff_outf_release(&state); free(parent_file.ptr); /* Assign line numbers for this parent. diff --git a/diff.c b/diff.c index 6954f99..222646d 100644 --- a/diff.c +++ b/diff.c @@ -459,10 +459,10 @@ static void diff_words_show(struct diff_words_data *diff_words) xpp.flags = XDF_NEED_MINIMAL; xecfg.ctxlen = diff_words->minus.alloc + diff_words->plus.alloc; - ecb.outf = xdiff_outf; - ecb.priv = diff_words; + xdiff_outf_init(&ecb, diff_words); diff_words->xm.consume = fn_out_diff_words_aux; xdi_diff(&minus, &plus, &xpp, &xecfg, &ecb); + xdiff_outf_release(diff_words); free(minus.ptr); free(plus.ptr); @@ -1520,8 +1520,7 @@ static void builtin_diff(const char *name_a, xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10); else if (!prefixcmp(diffopts, "-u")) xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10); - ecb.outf = xdiff_outf; - ecb.priv = &ecbdata; + xdiff_outf_init(&ecb, &ecbdata); ecbdata.xm.consume = fn_out_consume; if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS)) { ecbdata.diff_words = @@ -1529,6 +1528,7 @@ static void builtin_diff(const char *name_a, ecbdata.diff_words->file = o->file; } xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb); + xdiff_outf_release(&ecbdata); if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS)) free_diff_words_data(&ecbdata); } @@ -1579,9 +1579,9 @@ static void builtin_diffstat(const char *name_a, const char *name_b, memset(&xecfg, 0, sizeof(xecfg)); xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts; - ecb.outf = xdiff_outf; - ecb.priv = diffstat; + xdiff_outf_init(&ecb, diffstat); xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb); + xdiff_outf_release(diffstat); } free_and_return: @@ -1627,9 +1627,9 @@ static void builtin_checkdiff(const char *name_a, const char *name_b, memset(&xecfg, 0, sizeof(xecfg)); xpp.flags = XDF_NEED_MINIMAL; - ecb.outf = xdiff_outf; - ecb.priv = &data; + xdiff_outf_init(&ecb, &data); xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb); + xdiff_outf_release(&data); if ((data.ws_rule & WS_TRAILING_SPACE) && data.trailing_blanks_start) { @@ -3127,9 +3127,9 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1) xpp.flags = XDF_NEED_MINIMAL; xecfg.ctxlen = 3; xecfg.flags = XDL_EMIT_FUNCNAMES; - ecb.outf = xdiff_outf; - ecb.priv = &data; + xdiff_outf_init(&ecb, &data); xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb); + xdiff_outf_release(&data); } SHA1_Final(sha1, &ctx); diff --git a/xdiff-interface.c b/xdiff-interface.c index 61dc5c5..9c5e277 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -61,6 +61,13 @@ static void consume_one(void *priv_, char *s, unsigned long size) } } +void xdiff_outf_init(xdemitcb_t *ecb, void *priv_) +{ + struct xdiff_emit_state *priv = priv_; + ecb->outf = xdiff_outf; + ecb->priv = priv; +} + int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf) { struct xdiff_emit_state *priv = priv_; @@ -103,6 +110,10 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf) return 0; } +void xdiff_outf_release(void *priv_) +{ +} + /* * Trim down common substring at the end of the buffers, * but leave at least ctx lines at the end. diff --git a/xdiff-interface.h b/xdiff-interface.h index f7f791d..fca6200 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -14,7 +14,9 @@ struct xdiff_emit_state { }; int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb); +void xdiff_outf_init(xdemitcb_t *ecb, void *priv_); int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf); +void xdiff_outf_release(void *priv_); int parse_hunk_header(char *line, int len, int *ob, int *on, int *nb, int *nn); -- 1.5.6.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html