[llvm-commits] [llvm] r66545 - in /llvm/trunk: include/llvm/Support/raw_ostream.h lib/Support/raw_ostream.cpp

Chris Lattner clattner at apple.com
Tue Mar 10 10:45:29 PDT 2009


On Mar 10, 2009, at 9:21 AM, Daniel Dunbar wrote:

> Author: ddunbar
> Date: Tue Mar 10 11:21:55 2009
> New Revision: 66545
>
> URL: http://llvm.org/viewvc/llvm-project?rev=66545&view=rev
> Log:
> PR3478: raw_ostream should not buffer stderr
> - Add unbuffered flag to raw_ostream, forwarded by raw_fd_ostream and
>   used by raw_stderr_ostream.

Hi Daniel,

I think this is useful, but not sufficient.  Check out how the  
operator<<(char) method works on raw_ostream for example.

-Chris

>
>
> Modified:
>    llvm/trunk/include/llvm/Support/raw_ostream.h
>    llvm/trunk/lib/Support/raw_ostream.cpp
>
> Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=66545&r1=66544&r2=66545&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
> +++ llvm/trunk/include/llvm/Support/raw_ostream.h Tue Mar 10  
> 11:21:55 2009
> @@ -32,8 +32,10 @@
> class raw_ostream {
> protected:
>   char *OutBufStart, *OutBufEnd, *OutBufCur;
> +  bool Unbuffered;
> +
> public:
> -  raw_ostream() {
> +  raw_ostream(bool unbuffered=false) : Unbuffered(unbuffered) {
>     // Start out ready to flush.
>     OutBufStart = OutBufEnd = OutBufCur = 0;
>   }
> @@ -59,6 +61,16 @@
>     OutBufCur = OutBufStart;
>   }
>
> +  /// SetUnbuffered - Set the streams buffering status. When
> +  /// unbuffered the stream will flush after every write. This  
> routine
> +  /// will also flush the buffer immediately when the stream is being
> +  /// set to unbuffered.
> +  void SetUnbuffered(bool unbuffered) {
> +    Unbuffered = unbuffered;
> +    if (Unbuffered)
> +      flush();
> +  }
> +
>   // 
> = 
> = 
> =-------------------------------------------------------------------- 
> ===//
>   // Data Output Interface
>   // 
> = 
> = 
> =-------------------------------------------------------------------- 
> ===//
> @@ -165,9 +177,11 @@
>   raw_fd_ostream(const char *Filename, bool Binary, std::string  
> &ErrorInfo);
>
>   /// raw_fd_ostream ctor - FD is the file descriptor that this  
> writes to.  If
> -  /// ShouldClose is true, this closes the file when
> -  raw_fd_ostream(int fd, bool shouldClose) : FD(fd),  
> ShouldClose(shouldClose) {}
> -
> +  /// ShouldClose is true, this closes the file when the stream is  
> destroyed.
> +  raw_fd_ostream(int fd, bool shouldClose,
> +                 bool unbuffered=false) : raw_ostream(unbuffered),  
> FD(fd),
> +                                          ShouldClose(shouldClose) {}
> +
>   ~raw_fd_ostream();
>
>   /// flush_impl - The is the piece of the class that is implemented  
> by
>
> Modified: llvm/trunk/lib/Support/raw_ostream.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=66545&r1=66544&r2=66545&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/Support/raw_ostream.cpp (original)
> +++ llvm/trunk/lib/Support/raw_ostream.cpp Tue Mar 10 11:21:55 2009
> @@ -141,6 +141,9 @@
>     break;
>   }
>   OutBufCur += Size;
> +
> +  if (Unbuffered)
> +    flush_impl();
>   return *this;
> }
>
> @@ -266,7 +269,8 @@
> // 
> = 
> = 
> = 
> ----------------------------------------------------------------------= 
> ==//
>
> raw_stdout_ostream 
> ::raw_stdout_ostream():raw_fd_ostream(STDOUT_FILENO, false) {}
> - 
> raw_stderr_ostream 
> ::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false) {}
> + 
> raw_stderr_ostream 
> ::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false,
> +                                                        true) {}
>
> // An out of line virtual method to provide a home for the class  
> vtable.
> void raw_stdout_ostream::handle() {}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list