News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Possible PipedProcess copy/paste err?

Started by Pecan, February 02, 2008, 06:25:33 PM

Previous topic - Next topic

Pecan

I was looking at PipedProcess today and ran across this.

Is the double "= GetErrorStream();" a result of the copy/paste imp again?

Should one of them be GetOutputSteam(); or the like?


void PipedProcess::ForfeitStreams()
{
    char buf[4096];
    if (IsErrorAvailable())
    {
        wxInputStream *in = GetErrorStream();
        while(in->Read(&buf, sizeof(buf)).LastRead())
            ;
    }
    if (IsInputAvailable())
    {
        wxInputStream *in = GetErrorStream();
        while(in->Read(&buf, sizeof(buf)).LastRead())
            ;
    }
}


MortenMacFly

Quote from: Pecan on February 02, 2008, 06:25:33 PM
Is the double "= GetErrorStream();" a result of the copy/paste imp again?
I'd say so, yes! Hence I wonder why it is working anyways... is the cout/cerr stream possibly combined?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

thomas

It works because only the error stream matters. But yes, it looks like a copy error.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

MortenMacFly

Quote from: thomas on February 02, 2008, 09:33:41 PM
It works because only the error stream matters. But yes, it looks like a copy error.
So Lieven... seems it's best if you fix this? ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

thomas

It really doesn't matter, even though it's wrong. But go ahead and fix it if you want :)
The HasInputStream branch won't be taken, since the stream is already closed. Only the error stream cannot be closed programmatically which is why it must be drained, else the program might hang if you kill a process that has more data in the error stream than will fit in the buffer. However, killing doesn't work under Windows anyway, and under Linux,  the buffer size should not be a problem.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."