Problems with including a second file

I've had some recent trouble with the library interface, which can be
reproduced via the following code (call this "test.c"):
/***** BEGIN CODE */
#include <stdio.h>
#include <library.h>
int main (int argc, char** argv) {
    void *lmp;
    lammps_open_no_mpi(argc, argv, &lmp);
    lammps_file (lmp, "in.test1");
    lammps_file (lmp, "in.test2");
    lammps_close (lmp);
}
/***** END CODE */

The contents of in.test1 and in.test2 are the single lines
   print "HELLO!"
and
   print "HELLO AGAIN!"
respectively.

I tested this on my SVN checkout and on a brand new build from today's
tarball (version from 22-Mar-2013); both segfault during the read of the
second file. I tried a version from 21-Nov-2013 and another from
14-Mar-2013, and didn't get the same problem, though those ARE using a
different machine and complier.

It only seems to be a problem when the SECOND file is read; I can do
other things through the library interface (lammps_command, for example)
without problems, and the first lammps_file call goes smoothly and doesn't
mess anything up.

Compiling steps:
   make stubs
   make makelib
   make -f Makefile.lib serial
   gcc -c -I$LAMMPS_SRC/STUBS test.c
   g++ test.o $LAMMPS_SRC/STUBS/libmpi_stubs.a \
     $LAMMPS_SRC/liblammps_serial.a -lfftw3

Suggestions are welcome!

Karl D. Hammond
University of Tennessee, Knoxville
[email protected]...

"You can never know everything, and part of what you know is always
   wrong. A portion of wisdom lies in knowing that. A portion of courage
   lies in going on anyway."
"Nothing ever goes as you expect. Expect nothing, and you will not be
   surprised."

Sounds like a bug - I'll check it out
when I'm back in the office next week.

Thanks for providing test code.

Steve

I think the problem is input.cpp, line 222, which closes the previous
input file, combined with line 170 of the same file, which also closes
the previous input file. It's the second closing that's causing the
segfault. I can't just comment out the second fclose, of course, because
that would mess up things for normal (non-library) runs, but I think the
fact that the library interface is replacing the usual route to an input
file is throwing something off.

Also, my earlier comments that it worked in the 21-Nov-2012 version were
erroneous; I get the same problem there, too.

-Karl

Fixed this - will be patched today.

Thanks,
Steve