Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an actual global dbgout for compilers that don't fully optimize it away. #1314

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion galsim/phase_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/SBProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

//#define DEBUGLOGGING

#include <fstream>
#include "SBProfile.h"
#include "SBTransform.h"
#include "SBProfileImpl.h"
Expand All @@ -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() {}
Expand Down
Loading