diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-10-17 08:37:30 +0800 | 
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-10-17 08:37:30 +0800 | 
| commit | 3c8d5c8f732239a8b50418be27464e30b9dddeae (patch) | |
| tree | 8ffb46c18e48c8463c1fb16fcacf216f296b8a1f /src/base/platform | |
| parent | 37943858b3b260589b5dc222bb5184d2846fb6dc (diff) | |
| download | cru-3c8d5c8f732239a8b50418be27464e30b9dddeae.tar.gz cru-3c8d5c8f732239a8b50418be27464e30b9dddeae.tar.bz2 cru-3c8d5c8f732239a8b50418be27464e30b9dddeae.zip | |
Exception remove string.
Diffstat (limited to 'src/base/platform')
| -rw-r--r-- | src/base/platform/unix/PosixSpawnSubProcess.cpp | 34 | ||||
| -rw-r--r-- | src/base/platform/unix/UnixFileStream.cpp | 8 | ||||
| -rw-r--r-- | src/base/platform/win/Win32FileStream.cpp | 4 | 
3 files changed, 24 insertions, 22 deletions
| diff --git a/src/base/platform/unix/PosixSpawnSubProcess.cpp b/src/base/platform/unix/PosixSpawnSubProcess.cpp index f99d3224..7362175f 100644 --- a/src/base/platform/unix/PosixSpawnSubProcess.cpp +++ b/src/base/platform/unix/PosixSpawnSubProcess.cpp @@ -1,7 +1,6 @@  #include "cru/base/platform/unix/PosixSpawnSubProcess.h"  #include "cru/base/Exception.h"  #include "cru/base/Guard.h" -#include "cru/base/String.h"  #include "cru/base/SubProcess.h"  #include "cru/base/log/Logger.h" @@ -9,6 +8,7 @@  #include <spawn.h>  #include <sys/wait.h>  #include <unistd.h> +#include <cstring>  #include <format>  #include <memory>  #include <string_view> @@ -20,23 +20,25 @@ PosixSpawnSubProcessImpl::PosixSpawnSubProcessImpl() : pid_(0), exit_code_(0) {}  PosixSpawnSubProcessImpl::~PosixSpawnSubProcessImpl() {}  namespace { -char** CreateCstrArray(const std::vector<String>& argv) { -  std::vector<Buffer> utf8_argv; -  for (const auto& arg : argv) { -    utf8_argv.push_back(arg.ToUtf8Buffer()); +char** CreateCstrArray(const std::vector<std::string>& argv) { +  auto argv_len = argv.size(); +  char** result = new char*[argv_len + 1]; +  for (int i = 0; i < argv.size(); i++) { +    auto len = argv[i].size(); +    char* str = new char[len + 1]; +    result[i] = str; +    std::memcpy(str, argv[i].data(), len); +    str[len] = 0;    } -  char** result = new char*[utf8_argv.size() + 1]; -  for (int i = 0; i < utf8_argv.size(); i++) { -    result[i] = reinterpret_cast<char*>(utf8_argv[i].Detach()); -  } -  result[utf8_argv.size()] = nullptr; +  result[argv_len] = nullptr;    return result;  } -char** CreateCstrArray(const std::unordered_map<String, String>& envp) { -  std::vector<String> str_array; +char** CreateCstrArray( +    const std::unordered_map<std::string, std::string>& envp) { +  std::vector<std::string> str_array;    for (auto& [key, value] : envp) { -    str_array.push_back(key + u"=" + value); +    str_array.push_back(key + "=" + value);    }    return CreateCstrArray(str_array);  } @@ -112,8 +114,8 @@ void PosixSpawnSubProcessImpl::PlatformCreateProcess(                "Failed to set flag POSIX_SPAWN_CLOEXEC_DEFAULT (osx).");  #endif -  auto exe = start_info.program.ToUtf8(); -  std::vector<String> arguments{start_info.program}; +  auto exe = start_info.program; +  std::vector<std::string> arguments{start_info.program};    arguments.insert(arguments.cend(), start_info.arguments.cbegin(),                     start_info.arguments.cend()); @@ -168,7 +170,7 @@ void PosixSpawnSubProcessImpl::PlatformKillProcess() {    int error = kill(pid_, SIGKILL);    if (error != 0) {      std::unique_ptr<ErrnoException> inner(new ErrnoException(errno)); -    throw SubProcessInternalException(u"Failed to call kill on a subprocess.", +    throw SubProcessInternalException("Failed to call kill on a subprocess.",                                        std::move(inner));    }  } diff --git a/src/base/platform/unix/UnixFileStream.cpp b/src/base/platform/unix/UnixFileStream.cpp index 0772c279..43ff2244 100644 --- a/src/base/platform/unix/UnixFileStream.cpp +++ b/src/base/platform/unix/UnixFileStream.cpp @@ -33,7 +33,7 @@ int MapSeekOrigin(Stream::SeekOrigin origin) {      case Stream::SeekOrigin::End:        return SEEK_END;      default: -      throw Exception(u"Invalid seek origin."); +      throw Exception("Invalid seek origin.");    }  }  }  // namespace @@ -58,7 +58,7 @@ UnixFileStream::~UnixFileStream() { DoClose(); }  Index UnixFileStream::DoSeek(Index offset, SeekOrigin origin) {    off_t result = ::lseek(file_descriptor_, offset, MapSeekOrigin(origin));    if (result == -1) { -    throw ErrnoException(u"Failed to seek file."); +    throw ErrnoException("Failed to seek file.");    }    return result;  } @@ -66,7 +66,7 @@ Index UnixFileStream::DoSeek(Index offset, SeekOrigin origin) {  Index UnixFileStream::DoRead(std::byte *buffer, Index offset, Index size) {    auto result = ::read(file_descriptor_, buffer + offset, size);    if (result == -1) { -    throw ErrnoException(u"Failed to read file."); +    throw ErrnoException("Failed to read file.");    }    return result;  } @@ -75,7 +75,7 @@ Index UnixFileStream::DoWrite(const std::byte *buffer, Index offset,                                Index size) {    auto result = ::write(file_descriptor_, buffer + offset, size);    if (result == -1) { -    throw ErrnoException(u"Failed to write file."); +    throw ErrnoException("Failed to write file.");    }    return result;  } diff --git a/src/base/platform/win/Win32FileStream.cpp b/src/base/platform/win/Win32FileStream.cpp index f3809b3e..341fe9d3 100644 --- a/src/base/platform/win/Win32FileStream.cpp +++ b/src/base/platform/win/Win32FileStream.cpp @@ -29,7 +29,7 @@ Win32FileStream::Win32FileStream(String path, OpenFileFlag flags)      if (flags & io::OpenFileFlags::Write) {        grfMode |= STGM_WRITE;      } else { -      throw Exception(u"Stream must be readable or writable."); +      throw Exception("Stream must be readable or writable.");      }    } @@ -80,7 +80,7 @@ Index Win32FileStream::DoRead(std::byte* buffer, Index offset, Index size) {  Index Win32FileStream::DoWrite(const std::byte* buffer, Index offset,                               Index size) {    if (size < 0) { -    throw Exception(u"Size must be greater than 0."); +    throw Exception("Size must be greater than 0.");    }    CheckClosed(); | 
