add type checking to 'ptr' argument for lammps() class constructor. raise exception if incompatible

This commit is contained in:
Axel Kohlmeyer
2016-07-18 23:12:59 -04:00
parent 4ac8af8bea
commit 0aebb2eabe

View File

@ -123,11 +123,14 @@ class lammps(object):
# self.lmp = self.lib.lammps_open_no_mpi(0,None)
else:
self.opened = 0
# magic to convert ptr to ctypes ptr
pythonapi.PyCObject_AsVoidPtr.restype = c_void_p
pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
self.lmp = c_void_p(pythonapi.PyCObject_AsVoidPtr(ptr))
if isinstance(ptr,lammps):
# magic to convert ptr to ctypes ptr
pythonapi.PyCObject_AsVoidPtr.restype = c_void_p
pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
self.lmp = c_void_p(pythonapi.PyCObject_AsVoidPtr(ptr))
else:
self.lmp = None
raise TypeError('Unsupported type passed as "ptr"')
def __del__(self):
if self.lmp and self.opened: self.lib.lammps_close(self.lmp)