[llvm-commits] [llvm] r150120 - /llvm/trunk/lib/Support/DataStream.cpp

Benjamin Kramer benny.kra at googlemail.com
Thu Feb 9 02:02:19 PST 2012


On 09.02.2012, at 01:35, David Blaikie <dblaikie at gmail.com> wrote:

> Author: dblaikie
> Date: Wed Feb  8 18:29:19 2012
> New Revision: 150120
>
> URL: http://llvm.org/viewvc/llvm-project?rev=150120&view=rev
> Log:
> Remove static initializer from DataStream.cpp

Looks like PathV2.cpp and MemoryBuffer.cpp suffer from exactly the same problem.

- Ben
>
> If someone would prefer a clear name for the 'success' error_value we could
> come up with one - potentially just a 'named constructor' style
> 'error_value::success()' to make this expression more self-documenting. If
> I see this come up in other cases I'll certainly consider it.
>
> One step along the way to resolving PR11944.
>
> Modified:
>    llvm/trunk/lib/Support/DataStream.cpp
>
> Modified: llvm/trunk/lib/Support/DataStream.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DataStream.cpp?rev=150120&r1=150119&r2=150120&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/DataStream.cpp (original)
> +++ llvm/trunk/lib/Support/DataStream.cpp Wed Feb  8 18:29:19 2012
> @@ -49,8 +49,6 @@
>
> namespace {
>
> -const static error_code success;
> -
> // Very simple stream backed by a file. Mostly useful for stdin and debugging;
> // actual file access is probably still best done with mmap.
> class DataFileStreamer : public DataStreamer {
> @@ -66,18 +64,20 @@
>   }
>
>   error_code OpenFile(const std::string &Filename) {
> -    int OpenFlags = O_RDONLY;
> -#ifdef O_BINARY
> -    OpenFlags |= O_BINARY;  // Open input file in binary mode on win32.
> -#endif
>     if (Filename == "-") {
>       Fd = 0;
>       sys::Program::ChangeStdinToBinary();
> +      return error_code();
>     }
> -    else
> -      Fd = ::open(Filename.c_str(), OpenFlags);
> -    if (Fd == -1) return error_code(errno, posix_category());
> -      return success;
> +
> +    int OpenFlags = O_RDONLY;
> +#ifdef O_BINARY
> +    OpenFlags |= O_BINARY;  // Open input file in binary mode on win32.
> +#endif
> +    Fd = ::open(Filename.c_str(), OpenFlags);
> +    if (Fd == -1)
> +      return error_code(errno, posix_category());
> +    return error_code();
>   }
> };
>
> @@ -87,8 +87,7 @@
> DataStreamer *getDataFileStreamer(const std::string &Filename,
>                                   std::string *StrError) {
>   DataFileStreamer *s = new DataFileStreamer();
> -  error_code e = s->OpenFile(Filename);
> -  if (e != success) {
> +  if (error_code e = s->OpenFile(Filename)) {
>     *StrError = std::string("Could not open ") + Filename + ": " +
>         e.message() + "\n";
>     return NULL;
>
>
> _______________________________________________
> 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