Testing for empty input files: streambuf::in_avail() isn't robust accross platforms
In ./src/macro/Driver.cc
, streambuf::in_avail() == 0
is used to test whether the input file is empty.
Using the cross-compiler of Julia infrastructure https://github.com/JuliaPackaging/Yggdrasil and BinaryBuilder.jl
, under macOS
, in_avail()
return 0 just after the opening of the file even if the file isn't empty. This behavior can be demonstated with the attached example test.cc[test.cc]
It isn't completely clear to me whether the cross-compiler used by BinaryBuilder.jl
is buggy or whether one shouldn't rely on in_avail()
to test whether a file is empty.
For DynareJulia, I patch the current source code with modfile.peek() == std::istream::traits_type::eof()
but to do so I have to remove const
on modfile
. Here is the patch file patches.patch
Furthermore, testing for an empty input file shouldn't be done in Driver.cc
but higher up in DynareMain.cc
. Currently if the user supplies an empty *.mod file, macroExpandModFile()
returns without attempting to parse the file for macros, but the preprocessor fails with a cryptic error when the second stage lexer
attempts to read an empty string.