/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, 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.
%Include definitions.sip
%Include analysissettings.sip
+%Include analysisdata.sip
%Include analysismodule.sip
+%Include modules.sip
+
%ModuleCode
#include "gromacs/trajectoryanalysis/analysismodule.h"
#include "gromacs/trajectoryanalysis/cmdlinerunner.h"
#include "gromacs/utility/exceptions.h"
-class PyFactory {
+class PyFactory : public gmx::TrajectoryAnalysisCommandLineRunner::ModuleFactoryFunctor {
public:
PyFactory(PyObject *mod) : mod(mod) {} ;
gmx::TrajectoryAnalysisModulePointer operator () () {
int argc = PyList_GET_SIZE(py_argv);
char **argv = new char *[argc + 1];
+ bool to_free[argc];
+ std::fill(to_free, to_free+argc, false);
// Convert the list.
+ // TODO: Use something better than AsLatin1String to avoid unicode errors
for (int a = 0; a < argc; ++a)
{
PyObject *arg_obj = PyList_GET_ITEM(py_argv, a);
{
arg = strdup(arg);
Py_DECREF(arg_obj);
+ to_free[a] = true;
}
else
{
argv[argc] = NULL;
- TrajectoryAnalysisCommandLineRunner::runAsMain(argc, argv, PyFactory(mod));
+ PyFactory factory(mod);
+ TrajectoryAnalysisCommandLineRunner::runAsMain(argc, argv, &factory);
+
+ for (int i = 0; i < argc; i++)
+ if (to_free[i])
+ free(argv[i]);
+ delete[] argv;
}
%End