Skip to content

Commit fb1211e

Browse files
committed
Rename the functions as they're exported as C APIs.
`SWIFT_RUNTIME_STDLIB_INTERNAL` does `extern "C"`, so we can't put these in a namespace and have to use a C-style prefix instead. Also slightly rearrange the code in `CommandLine.cpp`. rdar://103397975
1 parent ca771c4 commit fb1211e

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

include/swift/Runtime/Win32.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
#include <wchar.h>
2525

26-
namespace swift {
27-
namespace win32 {
28-
2926
/// Convert a wide string to UTF-8.
3027
///
3128
/// @param str The string to convert.
@@ -35,7 +32,7 @@ namespace win32 {
3532
///
3633
/// If @a str cannot be converted to UTF-8, @c nullptr is returned.
3734
SWIFT_RUNTIME_STDLIB_INTERNAL
38-
char *copyUTF8FromWide(const wchar_t *str);
35+
char *_swift_win32_copyUTF8FromWide(const wchar_t *str);
3936

4037
/// Convert a UTF-8 string to a wide string.
4138
///
@@ -46,10 +43,8 @@ char *copyUTF8FromWide(const wchar_t *str);
4643
///
4744
/// If @a str cannot be converted to UTF-16, @c nullptr is returned.
4845
SWIFT_RUNTIME_STDLIB_INTERNAL
49-
wchar_t *copyWideFromUTF8(const char *str);
46+
wchar_t *_swift_win32_copyWideFromUTF8(const char *str);
5047

51-
}
52-
}
5348
#endif // defined(_WIN32)
5449

5550
#endif // SWIFT_RUNTIME_WIN32_H

stdlib/public/CommandLineSupport/CommandLine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ static void swift::enumerateUnsafeArgv(const F& body) {
203203
int argc = 0;
204204
if (LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &argc)) {
205205
std::for_each(wargv, wargv + argc, [=] (wchar_t *warg) {
206-
auto arg = swift::win32::copyUTF8FromWide(warg);
207-
if (!arg) {
206+
if (char *arg = _swift_win32_copyUTF8FromWide(warg)) {
207+
body(argc, arg);
208+
free(arg);
209+
} else {
208210
// Note that GetLastError() and errno may not be so useful here,
209211
// as in the error case we may have called free(), which might reset
210212
// either or both of them.
@@ -213,8 +215,6 @@ static void swift::enumerateUnsafeArgv(const F& body) {
213215
"UTF-8: %lx, %d.\n",
214216
warg, ::GetLastError(), errno);
215217
}
216-
body(argc, arg);
217-
free(arg);
218218
});
219219

220220
LocalFree(wargv);

stdlib/public/runtime/Win32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <windows.h>
2323

2424
char *
25-
swift::win32::copyUTF8FromWide(const wchar_t *str) {
25+
_swift_win32_copyUTF8FromWide(const wchar_t *str) {
2626
char *result = nullptr;
2727
int len = ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS,
2828
str, -1,
@@ -48,7 +48,7 @@ swift::win32::copyUTF8FromWide(const wchar_t *str) {
4848
}
4949

5050
wchar_t *
51-
swift::win32::copyWideFromUTF8(const char *str) {
51+
_swift_win32_copyWideFromUTF8(const char *str) {
5252
wchar_t *result = nullptr;
5353
int len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
5454
str, -1,

0 commit comments

Comments
 (0)