| 21 | } |
| 22 | |
| 23 | UCChar* Memory::StringToCoTaskMemAuto(UCStringView InString) |
| 24 | { |
| 25 | size_t length = InString.length() + 1; |
| 26 | size_t size = length * sizeof(UCChar); |
| 27 | |
| 28 | // TODO(Emily): This (and a few other places) misuse the WC/MB split assuming Windows is the only WC platform. |
| 29 | // If we want to decide that is a general assumption we can entirely remove the `CORAL_WIDE_CHARS` |
| 30 | // Macro and its exclusive effects. |
| 31 | #ifdef CORAL_WINDOWS |
| 32 | auto* buffer = static_cast<UCChar*>(CoTaskMemAlloc(size)); |
| 33 | |
| 34 | if (buffer != nullptr) |
| 35 | { |
| 36 | memset(buffer, 0xCE, size); |
| 37 | wcscpy(buffer, InString.data()); |
| 38 | } |
| 39 | #else |
| 40 | UCChar* buffer; |
| 41 | |
| 42 | if ((buffer = static_cast<UCChar*>(calloc(length, sizeof(UCChar))))) |
| 43 | { |
| 44 | strcpy(buffer, InString.data()); |
| 45 | } |
| 46 | #endif |
| 47 | |
| 48 | return buffer; |
| 49 | } |
| 50 | |
| 51 | void Memory::FreeCoTaskMem(void* InMemory) |
| 52 | { |