diff options
| author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-11 12:23:02 -0300 |
|---|---|---|
| committer | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-11 20:22:25 -0300 |
| commit | b603404487e0daa101deacbe346aa2fc9ee255c7 (patch) | |
| tree | b0bc4000de3c1754a400e43665fbcd7731df4dab /src/nvim/spell.c | |
| parent | 951d00a492c58449d3c241fa710a83051f45dcb7 (diff) | |
| download | rneovim-b603404487e0daa101deacbe346aa2fc9ee255c7.tar.gz rneovim-b603404487e0daa101deacbe346aa2fc9ee255c7.tar.bz2 rneovim-b603404487e0daa101deacbe346aa2fc9ee255c7.zip | |
GA_DEEP_CLEAR macro for garray memory deallocation
Used to free garrays of `salitem_T` and `fromto_T` in spell.c, and
garray `wcmd_T` in ex_docmd.c.
Helped-by: Jiaqi Li
Diffstat (limited to 'src/nvim/spell.c')
| -rw-r--r-- | src/nvim/spell.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c index fa786fdd74..fbdd58f4d3 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2379,13 +2379,26 @@ static void slang_free(slang_T *lp) free(lp); } +/// Frees a salitem_T +static void free_salitem(salitem_T *smp) { + free(smp->sm_lead); + // Don't free sm_oneof and sm_rules, they point into sm_lead. + free(smp->sm_to); + free(smp->sm_lead_w); + free(smp->sm_oneof_w); + free(smp->sm_to_w); +} + +/// Frees a fromto_T +static void free_fromto(fromto_T *ftp) { + free(ftp->ft_from); + free(ftp->ft_to); +} + // Clear an slang_T so that the file can be reloaded. static void slang_clear(slang_T *lp) { garray_T *gap; - fromto_T *ftp; - salitem_T *smp; - int round; free(lp->sl_fbyts); lp->sl_fbyts = NULL; @@ -2401,36 +2414,23 @@ static void slang_clear(slang_T *lp) free(lp->sl_pidxs); lp->sl_pidxs = NULL; - for (round = 1; round <= 2; ++round) { - gap = round == 1 ? &lp->sl_rep : &lp->sl_repsal; - while (!GA_EMPTY(gap)) { - ftp = &((fromto_T *)gap->ga_data)[--gap->ga_len]; - free(ftp->ft_from); - free(ftp->ft_to); - } - ga_clear(gap); - } + GA_DEEP_CLEAR(&lp->sl_rep, fromto_T, free_fromto); + GA_DEEP_CLEAR(&lp->sl_repsal, fromto_T, free_fromto); gap = &lp->sl_sal; if (lp->sl_sofo) { // "ga_len" is set to 1 without adding an item for latin1 - if (gap->ga_data != NULL) + if (gap->ga_data != NULL) { // SOFOFROM and SOFOTO items: free lists of wide characters. for (int i = 0; i < gap->ga_len; ++i) { free(((int **)gap->ga_data)[i]); } - } else - // SAL items: free salitem_T items - while (!GA_EMPTY(gap)) { - smp = &((salitem_T *)gap->ga_data)[--gap->ga_len]; - free(smp->sm_lead); - // Don't free sm_oneof and sm_rules, they point into sm_lead. - free(smp->sm_to); - free(smp->sm_lead_w); - free(smp->sm_oneof_w); - free(smp->sm_to_w); } - ga_clear(gap); + ga_clear(gap); + } else { + // SAL items: free salitem_T items + GA_DEEP_CLEAR(gap, salitem_T, free_salitem); + } for (int i = 0; i < lp->sl_prefixcnt; ++i) { vim_regfree(lp->sl_prefprog[i]); |