[llvm-commits] [llvm] r167407 - /llvm/trunk/lib/Support/MemoryBuffer.cpp

Daniel Dunbar daniel.dunbar at gmail.com
Tue Nov 6 08:15:41 PST 2012


Thanks, will fix shortly.

 - Daniel


On Nov 6, 2012, at 0:42, Alexey Samsonov <samsonov at google.com> wrote:

This change breaks our Windows buildbot:

1>Compiling...
1>MemoryBuffer.cpp
1>..\..\..\llvm\lib\Support\MemoryBuffer.cpp(324) : error C2065:
'S_IFIFO' : undeclared identifier


On Tue, Nov 6, 2012 at 1:55 AM, Daniel Dunbar <daniel at zuster.org> wrote:

> Author: ddunbar
> Date: Mon Nov  5 15:55:40 2012
> New Revision: 167407
>
> URL: http://llvm.org/viewvc/llvm-project?rev=167407&view=rev
> Log:
> MemoryBuffer: Support reading named pipes in getFile().
>
>  - We only support this when the client didn't claim to know the file size.
>
> Modified:
>     llvm/trunk/lib/Support/MemoryBuffer.cpp
>
> Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=167407&r1=167406&r2=167407&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
> +++ llvm/trunk/lib/Support/MemoryBuffer.cpp Mon Nov  5 15:55:40 2012
> @@ -201,6 +201,27 @@
>  };
>  }
>
> +static error_code getMemoryBufferForStream(int FD,
> +                                           StringRef BufferName,
> +                                           OwningPtr<MemoryBuffer>
> &result) {
> +  const ssize_t ChunkSize = 4096*4;
> +  SmallString<ChunkSize> Buffer;
> +  ssize_t ReadBytes;
> +  // Read into Buffer until we hit EOF.
> +  do {
> +    Buffer.reserve(Buffer.size() + ChunkSize);
> +    ReadBytes = read(FD, Buffer.end(), ChunkSize);
> +    if (ReadBytes == -1) {
> +      if (errno == EINTR) continue;
> +      return error_code(errno, posix_category());
> +    }
> +    Buffer.set_size(Buffer.size() + ReadBytes);
> +  } while (ReadBytes != 0);
> +
> +  result.reset(MemoryBuffer::getMemBufferCopy(Buffer, BufferName));
> +  return error_code::success();
> +}
> +
>  error_code MemoryBuffer::getFile(StringRef Filename,
>                                   OwningPtr<MemoryBuffer> &result,
>                                   int64_t FileSize,
> @@ -297,6 +318,13 @@
>        if (fstat(FD, &FileInfo) == -1) {
>          return error_code(errno, posix_category());
>        }
> +
> +      // If this is a named pipe, we can't trust the size. Create the
> memory
> +      // buffer by copying off the stream.
> +      if (FileInfo.st_mode & S_IFIFO) {
> +        return getMemoryBufferForStream(FD, Filename, result);
> +      }
> +
>        FileSize = FileInfo.st_size;
>      }
>      MapSize = FileSize;
> @@ -370,20 +398,5 @@
>    // fallback if it fails.
>    sys::Program::ChangeStdinToBinary();
>
> -  const ssize_t ChunkSize = 4096*4;
> -  SmallString<ChunkSize> Buffer;
> -  ssize_t ReadBytes;
> -  // Read into Buffer until we hit EOF.
> -  do {
> -    Buffer.reserve(Buffer.size() + ChunkSize);
> -    ReadBytes = read(0, Buffer.end(), ChunkSize);
> -    if (ReadBytes == -1) {
> -      if (errno == EINTR) continue;
> -      return error_code(errno, posix_category());
> -    }
> -    Buffer.set_size(Buffer.size() + ReadBytes);
> -  } while (ReadBytes != 0);
> -
> -  result.reset(getMemBufferCopy(Buffer, "<stdin>"));
> -  return error_code::success();
> +  return getMemoryBufferForStream(0, "<stdin>", result);
>  }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



-- 
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121106/8e41145e/attachment.html>


More information about the llvm-commits mailing list