Fix/support build with msvc (#214)

This commit is contained in:
sora-mono
2025-09-03 22:21:49 +08:00
committed by GitHub
parent cb3bfd54f9
commit bd0ead226b
6 changed files with 43 additions and 10 deletions

View File

@@ -134,12 +134,24 @@ Result<handle> open(std::string path, Mode mode) {
};
}
// MSVC seems to have a bug that it will try to optimize the function with tail call
// but it leads to "C4737: Unable to perform required tail call. Performance may be degraded."
// Discovered in MSVC 14.44.35207
// Adding /EHa won't help.
// Related:
// https://developercommunity.visualstudio.com/t/coroutine-compilation-resulting-in-error-c4737-una/1510427
#ifdef _MSC_VER
#pragma optimize("g", off)
#endif
Result<ssize_t> read(const handle& handle, char* buffer, std::size_t size) {
co_return co_await awaiter::read{
.file = handle.value(),
.bufs = {uv_buf_init(buffer, size)},
};
}
#ifdef _MSC_VER
#pragma optimize("g", on)
#endif
Result<std::string> read(std::string path, Mode mode) {
/// First stat the file to check if it exists, and to get the size
@@ -180,12 +192,24 @@ Result<std::string> read(std::string path, Mode mode) {
co_return content;
}
// MSVC seems to have a bug that it will try to optimize the function with tail call
// but it leads to "C4737: Unable to perform required tail call. Performance may be degraded."
// Discovered in MSVC 14.44.35207
// Adding /EHa won't help.
// Related:
// https://developercommunity.visualstudio.com/t/coroutine-compilation-resulting-in-error-c4737-una/1510427
#ifdef _MSC_VER
#pragma optimize("g", off)
#endif
Result<void> write(const handle& handle, char* buffer, std::size_t size) {
co_return co_await awaiter::write{
.file = handle.value(),
.bufs = {uv_buf_init(buffer, size)},
};
}
#ifdef _MSC_VER
#pragma optimize("g", on)
#endif
Result<void> write(std::string path, char* buffer, std::size_t size, Mode mode) {
auto file = co_await open(path, mode);