From 1e0e75c810450bbb3d91a41a1fde9e421e4209a8 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Wed, 15 Jan 2014 18:02:33 +0100 Subject: [PATCH] Clean up after gmxcpp Using grompp in integration tests with potentially multiple different calls to gmx_grompp per executable requires that we start from a clean state every time we do such a call. Old code was re-using -I paths, and both -D and #defines, which was breaking some tests I am working on. Also added some other done_* calls on the general theory of trying not to be evil. Change-Id: I6016bc1786c8ecc9303eeee2ad4a83975117ca5f --- src/gromacs/gmxpreprocess/gmxcpp.c | 33 ++++++++++++++++++++++++++++++++- src/gromacs/gmxpreprocess/gmxcpp.h | 8 +++++++- src/gromacs/gmxpreprocess/topio.c | 1 + src/programs/gmx/grompp.c | 2 ++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/gromacs/gmxpreprocess/gmxcpp.c b/src/gromacs/gmxpreprocess/gmxcpp.c index cb93732416..f66f0d1838 100644 --- a/src/gromacs/gmxpreprocess/gmxcpp.c +++ b/src/gromacs/gmxpreprocess/gmxcpp.c @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013, by the GROMACS development team, led by + * Copyright (c) 2013,2014, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -173,6 +173,18 @@ static void add_include(const char *include) } } +static void done_includes() +{ + int i; + for (i = 0; (i < nincl); i++) + { + sfree(incl[i]); + } + sfree(incl); + incl = NULL; + nincl = 0; +} + static void add_define(const char *name, const char *value) { int i; @@ -209,6 +221,19 @@ static void add_define(const char *name, const char *value) } } +static void done_defines() +{ + int i; + for (i = 0; (i < ndef); i++) + { + sfree(defs[i].name); + sfree(defs[i].def); + } + sfree(defs); + defs = NULL; + ndef = 0; +} + /* Open the file to be processed. The handle variable holds internal info for the cpp emulator. Return integer status */ int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts) @@ -750,6 +775,12 @@ int cpp_close_file(gmx_cpp_t *handlep) return eCPP_OK; } +void cpp_done() +{ + done_includes(); + done_defines(); +} + /* Return a string containing the error message coresponding to status variable */ char *cpp_error(gmx_cpp_t *handlep, int status) diff --git a/src/gromacs/gmxpreprocess/gmxcpp.h b/src/gromacs/gmxpreprocess/gmxcpp.h index b42a80db98..785f3acf46 100644 --- a/src/gromacs/gmxpreprocess/gmxcpp.h +++ b/src/gromacs/gmxpreprocess/gmxcpp.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2008, The GROMACS development team. - * Copyright (c) 2012, by the GROMACS development team, led by + * Copyright (c) 2012,2014, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -81,6 +81,12 @@ int cpp_cur_linenr(const gmx_cpp_t *handlep); */ int cpp_close_file(gmx_cpp_t *handlep); +/* Clean up file static data structures + + NOT THREAD SAFE + */ +void cpp_done(); + /* Return a string containing the error message coresponding to status variable. diff --git a/src/gromacs/gmxpreprocess/topio.c b/src/gromacs/gmxpreprocess/topio.c index c21679d71e..8fa85c5123 100644 --- a/src/gromacs/gmxpreprocess/topio.c +++ b/src/gromacs/gmxpreprocess/topio.c @@ -1014,6 +1014,7 @@ static char **read_topol(const char *infile, const char *outfile, { gmx_fatal(FARGS, cpp_error(&handle, status)); } + cpp_done(); if (out) { gmx_fio_fclose(out); diff --git a/src/programs/gmx/grompp.c b/src/programs/gmx/grompp.c index 8f0e671cbd..b1e77afdb6 100644 --- a/src/programs/gmx/grompp.c +++ b/src/programs/gmx/grompp.c @@ -1944,6 +1944,8 @@ int gmx_grompp(int argc, char *argv[]) done_warning(wi, FARGS); write_tpx_state(ftp2fn(efTPX, NFILE, fnm), ir, &state, sys); + done_atomtype(atype); + done_mtop(sys, TRUE); done_inputrec_strings(); return 0; -- 2.11.4.GIT