From 58e3bdd34c62d613593b8ba61f3ffd0f912a38d8 Mon Sep 17 00:00:00 2001 From: Nick P Date: Wed, 7 Aug 2024 19:45:59 -0600 Subject: [PATCH] fixed ifstream::readsome() returning empty in LLVM18 OSX std::basic_istream::readsome is very implementation specific and was returning empty in LLVM18 OSX. stringstream was used as a in memory stream to allow readsome() to return non-empty --- tool/schema_compiler/src/Main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tool/schema_compiler/src/Main.cpp b/tool/schema_compiler/src/Main.cpp index 070757b5..7bf9b44b 100644 --- a/tool/schema_compiler/src/Main.cpp +++ b/tool/schema_compiler/src/Main.cpp @@ -89,8 +89,19 @@ int main(int argc, char **argv) std::ifstream stream(file); if (not stream.is_open()) return 1; - - auto tokens = minecpp::tool::schema_compiler::lex_input(stream); + /** + * Internal parser uses std::basic_istream::readsome to read from the stream + * which is highly implementation specific and was returning empty on LLVM18 in OSX. + * + * Therefore we create a stringstream to read from the file into memory, where readsome() + * function will then return non-empty, as the contents are in memory. + * + * https://en.cppreference.com/w/cpp/io/basic_istream/readsome + */ + std::stringstream in_memory_stream; + in_memory_stream << stream.rdbuf(); + in_memory_stream.seekg(0); + auto tokens = minecpp::tool::schema_compiler::lex_input(in_memory_stream); minecpp::tool::schema_compiler::Parser parser(tokens); try {