diff --git a/galsim/phase_screens.py b/galsim/phase_screens.py index dc4ac25a59..fa00df4b84 100644 --- a/galsim/phase_screens.py +++ b/galsim/phase_screens.py @@ -386,7 +386,8 @@ def __del__(self): with acquire_lock(self._objDict['lock'], timeout=3) as acquired: # If this can't acquire the lock, just timeout and return -- don't hang. # (This seems to happen occasionally, but apparently only here in __del__.) - if not acquired: return + if not acquired: # pragma: no cover + return self._objDict['refcount'].value -= 1 # Normally, shareKey is present, but on final cleanup, we have no control over diff --git a/src/SBProfile.cpp b/src/SBProfile.cpp index caa31a33f3..cfce28e1f4 100644 --- a/src/SBProfile.cpp +++ b/src/SBProfile.cpp @@ -19,6 +19,7 @@ //#define DEBUGLOGGING +#include #include "SBProfile.h" #include "SBTransform.h" #include "SBProfileImpl.h" @@ -35,10 +36,22 @@ // xdbg requires verbose_level >= 2 // xxdbg requires verbose_level >= 3 // -// If DEBUGLOGGING is not defined, the all three becomes just `if (false) std::cerr`, +// If DEBUGLOGGING is not defined, the all three becomes just `if (false) (*dbgout)`, // so the compiler parses the statement fine, but trivially optimizes the code away, // so there is no efficiency hit from leaving them in the code. +#ifndef DEBUGLOGGING +// Apparently not all compilers optimize away the if (false) (*dbgout) lines. +// That can cause errors when linking. cf. #1313. +// This fixes the problem by providing an actual dbgout object that doesn't write anything. +std::ostream* make_global_dbgout() { + static std::ofstream dbgout_ofstream; + dbgout_ofstream.setstate(std::ios_base::badbit); + return &dbgout_ofstream; +} +std::ostream* dbgout = make_global_dbgout(); +#endif + namespace galsim { SBProfile::SBProfile() {}