[LLVMdev] raw_ostream behavior
Dan Gohman
dan433584 at gmail.com
Wed Aug 14 12:02:13 PDT 2013
The high-level answer is that library code shouldn't hardcode output paths,
including "-" and including using llvm::outs(). Library code should (in
general) instead accept an ostream in its API and write to wherever it is
being asked to write. If this is followed, the only place in any program
using llvm::outs() is code which is not part of a "library" -- i.e. it is
the "main" code, and it should only do so if it is a program which doesn't
open file names which could be "-".
Do you have a use-case where this restriction is too restrictive?
As a random aside, a more aggressive answer could be that "-" is a kind of
hack, and that it would be a better approach to use /dev/stdout and
/dev/stdin instead of "-", because they wouldn't require special-case
logic. Unfortunately, this may not be sufficiently portable.
Dan
On Wed, Aug 14, 2013 at 8:28 AM, Shankar Easwaran
<shankare at codeaurora.org>wrote:
>
> Hi,
>
> When I run the below example, it results in :-
>
> hello
> world
> LLVM ERROR: IO failure on output stream.
>
> Testcase :-
>
> #include <llvm/Support/raw_ostream.h>
>
> int fn() {
> std::string errorInfo;
> llvm::raw_fd_ostream out("-", errorInfo);
> out << "world\n";
> return 0;
> }
> int main(int argc, char **argv) {
> llvm::outs() << "hello\n";
> fn();
> return 0;
> }
>
> I tried to fix this by making llvm::outs(), not close the stdout
> descriptor, but I think its wrong. Recommendations ?
>
> Thanks
>
> Shankar Easwaran
>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted
> by the Linux Foundation
>
>
>
> ______________________________**_________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/**mailman/listinfo/llvmdev<http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130814/7dd6a287/attachment.html>
More information about the llvm-dev
mailing list