diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-31 20:38:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 20:38:09 +0000 |
commit | 4b13e27087a4c68824c281b2f980a7561dc39407 (patch) | |
tree | 6e488a2a3e61e34c4e1be217e2cb836adb9eed3b | |
parent | 75de60e68b46c555a87822a78d20c7197bddffb5 (diff) | |
parent | 5b0433b4beaee7adf59ad6ff79c83f4285a995b0 (diff) | |
download | gcc-4b13e27087a4c68824c281b2f980a7561dc39407.zip gcc-4b13e27087a4c68824c281b2f980a7561dc39407.tar.gz gcc-4b13e27087a4c68824c281b2f980a7561dc39407.tar.bz2 |
Merge #458
458: stdin: Allow compilation from standard input r=philberty a=CohenArthur
Fixes #457
I'm not really sure how to test it with `dejagnu` or if it is even possible.
This PR adds a check for the `-` filename in the `RAIIFile` class. In that case, the inner pointer should simply be `stdin`. We also have to be careful not to `fclose(stdin)` upon deallocation.
Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
-rw-r--r-- | gcc/rust/lex/rust-lex.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h index 5ac3a4b..8a9640e 100644 --- a/gcc/rust/lex/rust-lex.h +++ b/gcc/rust/lex/rust-lex.h @@ -16,7 +16,14 @@ private: FILE *file; public: - RAIIFile (const char *filename) : file (fopen (filename, "r")) {} + RAIIFile (const char *filename) + { + if (strncmp (filename, "-", 1) == 0) + file = stdin; + else + file = fopen (filename, "r"); + } + RAIIFile (const RAIIFile &other) = delete; RAIIFile &operator= (const RAIIFile &other) = delete; @@ -32,7 +39,7 @@ public: ~RAIIFile () { - if (file != nullptr) + if (file != nullptr && file != stdin) fclose (file); } |