Clean up after gmxcpp
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 15 Jan 2014 17:02:33 +0000 (18:02 +0100)
committerDavid van der Spoel <davidvanderspoel@gmail.com>
Sun, 19 Jan 2014 08:45:22 +0000 (09:45 +0100)
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
src/gromacs/gmxpreprocess/gmxcpp.h
src/gromacs/gmxpreprocess/topio.c
src/programs/gmx/grompp.c

index cb93732416369cbed11deffd72dc43c26b658540..f66f0d1838a3fadeee260114c3d1ce70120ca734 100644 (file)
@@ -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)
index b42a80db988d551e278781e8a85d8cceafac0a8e..785f3acf4618081da42ae01b916251b037a314dd 100644 (file)
@@ -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.
 
index c21679d71e1528183018c93e059c12c8a0dad1c4..8fa85c5123c5ad582ac5d90456deb9c46d60f829 100644 (file)
@@ -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);
index 8f0e671cbd353feb75eef5b71750fd5920d29d7b..b1e77afdb65bba9a0a3e9ae21966513307a24565 100644 (file)
@@ -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;