error handling when calling SimInspiralChooseTDWaveform from python with empty params dict
@riccardo-sturani @jolien-creighton @maria.haney @harald.pfeiffer @sebastian-khan In somebody else's waveform plotting python script, I noticed segfaults when calling SimInspiralChooseTDWaveform()
for aligned approximants but with in-plane spin components and an empty parameters dictionary (passed as params=lal.CreateDict()
as it was coded up). That should indeed fail, but it doesn't do so cleanly. I've condensed it down to the minimal example below. This gives me all sorts of funny errors in different installations.
There is an easy fix: use params=None
instead of params=lal.CreateDict()
. However, I believe something is going wrong with the error handling here.
example errors:
- on my Debian laptop using lalsuite 6.70 from pip:
XLAL Error - XLALSimInspiralChooseTDWaveform: Non-zero transverse spins were given, but this is a non-precessing approximant.
XLAL Error - XLALSimInspiralChooseTDWaveform (LALSimInspiral.c:1094): Invalid argument
Segmentation fault
- on my Debian laptop using lalsuite built from today's master:
XLAL Error - XLALSimInspiralChooseTDWaveform: Non-zero transverse spins were given, but this is a non-precessing approximant.
XLAL Error - XLALSimInspiralChooseTDWaveform (LALSimInspiral.c:741): Invalid argument
free(): double free detected in tcache 2
Aborted
- on LDAS or Arcca using system installs:
XLAL Error - XLALSimInspiralChooseTDWaveform: Non-zero transverse spins were given, but this is a non-precessing approximant.
XLAL Error - XLALSimInspiralChooseTDWaveform (LALSimInspiral.c:737): Invalid argument
*** Error in `python': free(): invalid pointer: 0x00002b28a4eaf7b8 ***
======= Backtrace: =========
[...]
======= Memory map: ========
[...]
What I think may be going on is that the ABORT_NONZERO_TRANSVERSE_SPINS
macro defined in check_waveform_macros.h
, which contains a XLALDestroyDict(LALparams)
line, somehow confuses the SWIG wrapping...? cc @karl-wette
To reproduce:
import lal
import lalsimulation
hp, hc = lalsimulation.SimInspiralChooseTDWaveform(
m1=30*lal.MSUN_SI,
m2=30*lal.MSUN_SI,
s1x=1,
s1y=0,
s1z=0,
s2x=0,
s2y=0,
s2z=0,
distance=1e6*lal.PC_SI,
inclination=0,
phiRef=0,
longAscNodes=0,
eccentricity=0,
meanPerAno=0,
deltaT=1./4096,
f_min=20,
f_ref=20,
params=lal.CreateDict(),
approximant=lalsimulation.IMRPhenomD
)
I was hoping to check if creating+destroying a dict without lalsimulation ever getting involved would work,
params=lal.CreateDict()
lal.DestroyDict(params)
but XLALDestroyDict does not seem to be SWIG-exported, so I couldn't test that.