Skip to content
Open
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
7 changes: 6 additions & 1 deletion include/cling/Utils/Output.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
namespace cling {
namespace utils {
///\brief The 'stdout' stream. llvm::raw_ostream wrapper of std::cout
///
/// Can be redirected via setOuts().
llvm::raw_ostream& outs();

///\brief Redirect cling::outs() to a custom stream.
/// Pass nullptr to restore the default (std::cout).
void setOuts(llvm::raw_ostream* s);

///\brief The 'stderr' stream. llvm::raw_ostream wrapper of std::cerr
///
llvm::raw_ostream& errs();
Expand Down Expand Up @@ -69,6 +73,7 @@ namespace cling {
typedef outstring<0> stdstrstream;
}
using utils::outs;
using utils::setOuts;
using utils::errs;
using utils::log;

Expand Down
2 changes: 2 additions & 0 deletions lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ namespace cling {
}
}

if (!NoRuntime) {
// Intercept all atexit calls, as the Interpreter and functions will be long
// gone when the -native- versions invoke them.
#if defined(__GLIBC__)
Expand Down Expand Up @@ -533,6 +534,7 @@ namespace cling {
Strm << ";\n";
#endif
#endif
} // !NoRuntime (atexit interception)

if (!SyntaxOnly) {
// Override the helper symbols injected by GenericLLVMIRPlatformSupport,
Expand Down
8 changes: 8 additions & 0 deletions lib/Utils/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@

namespace cling {
namespace utils {
static llvm::raw_ostream* sOutOverride = nullptr;

llvm::raw_ostream& outs() {
if (sOutOverride)
return *sOutOverride;
static llvm::raw_os_ostream sOut(std::cout);
sOut.SetUnbuffered();
if (llvm::sys::Process::StandardOutIsDisplayed())
sOut.enable_colors(true);
return sOut;
}

void setOuts(llvm::raw_ostream* s) {
sOutOverride = s;
}

llvm::raw_ostream& errs() {
static llvm::raw_os_ostream sErr(std::cerr);
sErr.SetUnbuffered();
Expand Down