diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-08 01:46:00 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-08 21:34:37 +0800 |
commit | 593b658eb1491d4b3103971aba6592aff2765f0e (patch) | |
tree | 526bc88c6a895c215015926c90ff38c106a94604 /src/base | |
parent | df550874cd546a85074edc35bebeb3cd0530622b (diff) | |
download | cru-593b658eb1491d4b3103971aba6592aff2765f0e.tar.gz cru-593b658eb1491d4b3103971aba6592aff2765f0e.tar.bz2 cru-593b658eb1491d4b3103971aba6592aff2765f0e.zip |
Fix some compile errors on Windows.
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/SubProcess.cpp | 13 | ||||
-rw-r--r-- | src/base/io/Stream.cpp | 4 | ||||
-rw-r--r-- | src/base/log/StdioLogTarget.cpp | 4 | ||||
-rw-r--r-- | src/base/platform/win/DebugLogTarget.cpp | 6 | ||||
-rw-r--r-- | src/base/platform/win/Exception.cpp | 6 | ||||
-rw-r--r-- | src/base/platform/win/Win32FileStream.cpp | 37 |
6 files changed, 29 insertions, 41 deletions
diff --git a/src/base/SubProcess.cpp b/src/base/SubProcess.cpp index 1133b848..9a6ee64f 100644 --- a/src/base/SubProcess.cpp +++ b/src/base/SubProcess.cpp @@ -7,11 +7,6 @@ #endif namespace cru { - -#ifdef CRU_PLATFORM_UNIX -using ThisPlatformSubProcessImpl = platform::unix::PosixSpawnSubProcessImpl; -#endif - PlatformSubProcess::PlatformSubProcess( SubProcessStartInfo start_info, std::shared_ptr<IPlatformSubProcessImpl> impl) @@ -156,8 +151,14 @@ SubProcessExitResult SubProcess::Call( } SubProcess::SubProcess(SubProcessStartInfo start_info) { + +#ifdef CRU_PLATFORM_UNIX platform_process_.reset(new PlatformSubProcess( - std::move(start_info), std::make_shared<ThisPlatformSubProcessImpl>())); + std::move(start_info), + std::make_shared<platform::unix::PosixSpawnSubProcessImpl>())); +#else + NotImplemented(); +#endif platform_process_->Start(); } diff --git a/src/base/io/Stream.cpp b/src/base/io/Stream.cpp index 9b7ef856..4cb58eca 100644 --- a/src/base/io/Stream.cpp +++ b/src/base/io/Stream.cpp @@ -171,11 +171,11 @@ Index Stream::DoGetSize() { } Index Stream::DoRead(std::byte* buffer, Index offset, Index size) { - throw Exception(u"Stream is readable but DoSeek is not implemented."); + throw Exception(u"Stream is readable but DoRead is not implemented."); } Index Stream::DoWrite(const std::byte* buffer, Index offset, Index size) { - throw Exception(u"Stream is writable but DoSeek is not implemented."); + throw Exception(u"Stream is writable but DoWrite is not implemented."); } void Stream::DoFlush() {} diff --git a/src/base/log/StdioLogTarget.cpp b/src/base/log/StdioLogTarget.cpp index 45203f2c..a17e91b6 100644 --- a/src/base/log/StdioLogTarget.cpp +++ b/src/base/log/StdioLogTarget.cpp @@ -1,5 +1,9 @@ #include "cru/base/log/StdioLogTarget.h" +#ifdef _WIN32 +#include "cru/base/String.h" +#endif + #include <iostream> namespace cru::log { diff --git a/src/base/platform/win/DebugLogTarget.cpp b/src/base/platform/win/DebugLogTarget.cpp index 89bd3d19..afbab620 100644 --- a/src/base/platform/win/DebugLogTarget.cpp +++ b/src/base/platform/win/DebugLogTarget.cpp @@ -1,10 +1,12 @@ #include "cru/base/platform/win/DebugLogTarget.h" +#include "cru/base/String.h" + namespace cru::platform::win { -void WinDebugLogTarget::Write(::cru::log::LogLevel level, StringView s) { +void WinDebugLogTarget::Write(::cru::log::LogLevel level, std::string s) { CRU_UNUSED(level) - String m = s.ToString(); + String m = String::FromUtf8(s); ::OutputDebugStringW(reinterpret_cast<const wchar_t*>(m.c_str())); } } // namespace cru::platform::win diff --git a/src/base/platform/win/Exception.cpp b/src/base/platform/win/Exception.cpp index 5ff6146b..941875f7 100644 --- a/src/base/platform/win/Exception.cpp +++ b/src/base/platform/win/Exception.cpp @@ -14,12 +14,12 @@ inline String HResultMakeMessage(HRESULT h_result, } HResultError::HResultError(HRESULT h_result) - : PlatformException(HResultMakeMessage(h_result, std::nullopt)), + : Exception(HResultMakeMessage(h_result, std::nullopt)), h_result_(h_result) {} HResultError::HResultError(HRESULT h_result, std::string_view additional_message) - : PlatformException(HResultMakeMessage( + : Exception(HResultMakeMessage( h_result, String::FromUtf8(additional_message.data(), additional_message.size()))), h_result_(h_result) {} @@ -33,6 +33,6 @@ Win32Error::Win32Error(String message) : Win32Error(::GetLastError(), message) {} Win32Error::Win32Error(DWORD error_code, String message) - : PlatformException(Win32MakeMessage(error_code, message)), + : Exception(Win32MakeMessage(error_code, message)), error_code_(error_code) {} } // namespace cru::platform::win diff --git a/src/base/platform/win/Win32FileStream.cpp b/src/base/platform/win/Win32FileStream.cpp index 54e6ae45..f3809b3e 100644 --- a/src/base/platform/win/Win32FileStream.cpp +++ b/src/base/platform/win/Win32FileStream.cpp @@ -14,7 +14,8 @@ namespace cru::platform::win { using namespace cru::io; Win32FileStream::Win32FileStream(String path, OpenFileFlag flags) - : path_(std::move(path)), + : Stream(true, true, true), + path_(std::move(path)), flags_(flags), p_(new details::Win32FileStreamPrivate()) { DWORD grfMode = STGM_SHARE_DENY_NONE; @@ -46,15 +47,11 @@ Win32FileStream::Win32FileStream(String path, OpenFileFlag flags) } Win32FileStream::~Win32FileStream() { - Close(); + DoClose(); delete p_; } -bool Win32FileStream::CanSeek() { return true; } - -Index Win32FileStream::Seek(Index offset, SeekOrigin origin) { - CheckClosed(); - +Index Win32FileStream::DoSeek(Index offset, SeekOrigin origin) { DWORD dwOrigin = 0; if (origin == SeekOrigin::Current) { @@ -74,23 +71,13 @@ Index Win32FileStream::Seek(Index offset, SeekOrigin origin) { return n_new_offset.QuadPart; } -bool Win32FileStream::CanRead() { return true; } - -Index Win32FileStream::Read(std::byte* buffer, Index offset, Index size) { - if (size < 0) { - throw Exception(u"Size must be greater than 0."); - } - - CheckClosed(); - +Index Win32FileStream::DoRead(std::byte* buffer, Index offset, Index size) { ULONG n_read; ThrowIfFailed(p_->stream_->Read(buffer + offset, size, &n_read)); return n_read; } -bool Win32FileStream::CanWrite() { return true; } - -Index Win32FileStream::Write(const std::byte* buffer, Index offset, +Index Win32FileStream::DoWrite(const std::byte* buffer, Index offset, Index size) { if (size < 0) { throw Exception(u"Size must be greater than 0."); @@ -104,19 +91,13 @@ Index Win32FileStream::Write(const std::byte* buffer, Index offset, return n_written; } -void Win32FileStream::Close() { - if (closed_) return; +void Win32FileStream::DoClose() { + CRU_STREAM_BEGIN_CLOSE - if (p_->stream_) { + if (p_->stream_) { p_->stream_->Release(); p_->stream_ = nullptr; } - closed_ = true; } - -void Win32FileStream::CheckClosed() { - if (closed_) throw Exception(u"Stream is closed."); -} - } // namespace cru::platform::win |