Author Topic: Possible PipedProcess copy/paste err?  (Read 5998 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2875
Possible PipedProcess copy/paste err?
« on: February 02, 2008, 06:25:33 pm »
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?

Code
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())
            ;
    }
}


Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Possible PipedProcess copy/paste err?
« Reply #1 on: February 02, 2008, 07:39:14 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: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Possible PipedProcess copy/paste err?
« Reply #2 on: February 02, 2008, 09:33:41 pm »
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."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Possible PipedProcess copy/paste err?
« Reply #3 on: February 02, 2008, 10:02:56 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: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Possible PipedProcess copy/paste err?
« Reply #4 on: February 03, 2008, 01:18:35 pm »
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."