Assigning MultiTimestampsVector to structure doesn't properly disown memory
Following our last discussions, it looks like the problem is related to assigning the multiTimestamps member of CWMFDataParams.
This code should not fail and the result of make_array_at_once
should be copied (as in "deep copy") into the structure;
that's not the case, only the top array is properly copied.
import lal
import lalpulsar
class FaultyClass:
def __init__(self):
self.cwmf = lalpulsar.CWMFDataParams()
self.cwmf.multiTimestamps = make_array_at_once()
class FaultyClass2:
def __init__(self):
multi_timestamps = lalpulsar.CreateMultiLIGOTimeGPSVector(1)
time_gps_vector = lalpulsar.CreateTimestampVector(10)
for ind in range(time_gps_vector.length):
time_gps_vector.data[ind] = lal.LIGOTimeGPS(
ind, ind
)
time_gps_vector.deltaT = 0
multi_timestamps.data[0] = time_gps_vector
self.cwmf = lalpulsar.CWMFDataParams()
self.cwmf.multiTimestamps = multi_timestamps
def make_array_at_once():
multi_timestamps = lalpulsar.CreateMultiLIGOTimeGPSVector(1)
time_gps_vector = lalpulsar.CreateTimestampVector(10)
for ind in range(time_gps_vector.length):
time_gps_vector.data[ind] = lal.LIGOTimeGPS(
ind, ind
)
time_gps_vector.deltaT = 0
multi_timestamps.data[0] = time_gps_vector
return multi_timestamps
# Either of these fails
print(FaultyClass2().cwmf.multiTimestamps.data[0].data[0])
print(FaultyClass().cwmf.multiTimestamps.data[0].data[0])
Edited by Rodrigo Tenorio