correct memory leak and incorrect access to global vectors and arrays for fixes from python

This commit is contained in:
Axel Kohlmeyer
2015-11-11 18:25:26 -05:00
parent b3aec4ebd8
commit a7c5dfeefe

View File

@ -121,21 +121,22 @@ class lammps:
# double was allocated by library interface function # double was allocated by library interface function
def extract_fix(self,id,style,type,i=0,j=0): def extract_fix(self,id,style,type,i=0,j=0):
if type == 0: if style == 0:
if style > 0: return None
self.lib.lammps_extract_fix.restype = POINTER(c_double) self.lib.lammps_extract_fix.restype = POINTER(c_double)
ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,i,j) ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,i,j)
result = ptr[0] result = ptr[0]
self.lib.lammps_free(ptr) self.lib.lammps_free(ptr)
return result return result
elif (style == 1) || (style == 2):
if type == 1: if type == 1:
self.lib.lammps_extract_fix.restype = POINTER(c_double) self.lib.lammps_extract_fix.restype = POINTER(c_double)
ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,i,j) elif type == 2:
return ptr
if type == 2:
self.lib.lammps_extract_fix.restype = POINTER(POINTER(c_double)) self.lib.lammps_extract_fix.restype = POINTER(POINTER(c_double))
else:
return None
ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,i,j) ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,i,j)
return ptr return ptr
else:
return None return None
# free memory for 1 double or 1 vector of doubles via lammps_free() # free memory for 1 double or 1 vector of doubles via lammps_free()