Handling of multiple Redirection RAII's
This commit is contained in:
parent
768254099f
commit
d2953ff9a6
@ -68,6 +68,9 @@ namespace cling {
|
||||
///\brief Stores the stack for the redirect file paths for err.
|
||||
llvm::SmallVector<llvm::SmallString<128>, 2> m_PrevStderrFileName;
|
||||
|
||||
//Counter to handle more than one redirection RAAI's
|
||||
int m_RedirectionRAIILevel = 0;
|
||||
|
||||
public:
|
||||
enum RedirectionScope {
|
||||
kSTDOUT = 1,
|
||||
@ -85,7 +88,14 @@ namespace cling {
|
||||
|
||||
public:
|
||||
MaybeRedirectOutputRAII(MetaProcessor* p);
|
||||
~MaybeRedirectOutputRAII() { pop(); }
|
||||
~MaybeRedirectOutputRAII();
|
||||
|
||||
// Don't mess with m_RedirectionRAIILevel
|
||||
MaybeRedirectOutputRAII(const MaybeRedirectOutputRAII&) = delete;
|
||||
MaybeRedirectOutputRAII(MaybeRedirectOutputRAII&&) = delete;
|
||||
MaybeRedirectOutputRAII& operator=(const MaybeRedirectOutputRAII&) = delete;
|
||||
MaybeRedirectOutputRAII& operator=(MaybeRedirectOutputRAII&&) = delete;
|
||||
|
||||
private:
|
||||
void pop();
|
||||
void redirect(FILE* file, const std::string& fileName,
|
||||
@ -114,6 +124,11 @@ namespace cling {
|
||||
m_Outs = &outs;
|
||||
return prev;
|
||||
}
|
||||
void increaseRedirectionRAIILevel() { m_RedirectionRAIILevel++; }
|
||||
|
||||
void decreaseRedirectionRAIILevel() { m_RedirectionRAIILevel--; }
|
||||
|
||||
int getRedirectionRAIILevel() { return m_RedirectionRAIILevel; }
|
||||
|
||||
///\brief Process the input coming from the prompt and possibli returns
|
||||
/// result of the execution of the last statement
|
||||
|
@ -44,6 +44,7 @@ namespace cling {
|
||||
MetaProcessor* p)
|
||||
:m_MetaProcessor(p), m_isCurrentlyRedirecting(0) {
|
||||
StringRef redirectionFile;
|
||||
m_MetaProcessor->increaseRedirectionRAIILevel();
|
||||
if (!m_MetaProcessor->m_PrevStdoutFileName.empty()) {
|
||||
redirectionFile = m_MetaProcessor->m_PrevStdoutFileName.back();
|
||||
redirect(stdout, redirectionFile.str(), kSTDOUT);
|
||||
@ -63,6 +64,11 @@ namespace cling {
|
||||
}
|
||||
}
|
||||
|
||||
MetaProcessor::MaybeRedirectOutputRAII::~MaybeRedirectOutputRAII() {
|
||||
pop();
|
||||
m_MetaProcessor->decreaseRedirectionRAIILevel();
|
||||
}
|
||||
|
||||
void MetaProcessor::MaybeRedirectOutputRAII::redirect(FILE* file,
|
||||
const std::string& fileName,
|
||||
MetaProcessor::RedirectionScope scope) {
|
||||
@ -79,6 +85,11 @@ namespace cling {
|
||||
}
|
||||
|
||||
void MetaProcessor::MaybeRedirectOutputRAII::pop() {
|
||||
//If we have only one redirection RAII
|
||||
//only then do the unredirection.
|
||||
if (m_MetaProcessor->getRedirectionRAIILevel() != 1)
|
||||
return;
|
||||
|
||||
if (m_isCurrentlyRedirecting & kSTDOUT) {
|
||||
unredirect(m_MetaProcessor->m_backupFDStdout, STDOUT_FILENO, stdout);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user