Skip to content
Snippets Groups Projects
Commit cb867ea9 authored by sjplimp's avatar sjplimp Committed by GitHub
Browse files

Merge pull request #450 from rbberger/python_destruction_fix

Prevent segfault if Python was never initialized
parents 4da8c1c4 961096f9
No related branches found
No related tags found
No related merge requests found
......@@ -45,23 +45,25 @@ Python::Python(LAMMPS *lmp) : Pointers(lmp)
Python::~Python()
{
// clean up
PyGILState_STATE gstate = PyGILState_Ensure();
for (int i = 0; i < nfunc; i++) {
delete [] pfuncs[i].name;
deallocate(i);
PyObject *pFunc = (PyObject *) pfuncs[i].pFunc;
Py_XDECREF(pFunc);
}
if(pyMain) {
// clean up
PyGILState_STATE gstate = PyGILState_Ensure();
for (int i = 0; i < nfunc; i++) {
delete [] pfuncs[i].name;
deallocate(i);
PyObject *pFunc = (PyObject *) pfuncs[i].pFunc;
Py_XDECREF(pFunc);
}
// shutdown Python interpreter
// shutdown Python interpreter
if (pyMain && !external_interpreter) {
Py_Finalize();
}
else {
PyGILState_Release(gstate);
if (!external_interpreter) {
Py_Finalize();
}
else {
PyGILState_Release(gstate);
}
}
memory->sfree(pfuncs);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment