Skip to content

Commit 9e413bd

Browse files
committed
runtime: use _strdup on Windows
Windows prefers the `_strdup` extension over `strdup`. This avoids unnecessary warnings when building the standard library.
1 parent b748546 commit 9e413bd

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

include/swift/Demangling/TypeLookupError.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ class TypeLookupError {
8484
static char *getCString(char *str) { return str; }
8585

8686
static char *getCString(const std::string &str) {
87+
#if defined(_WIN32)
88+
return _strdup(str.c_str());
89+
#else
8790
return strdup(str.c_str());
91+
#endif
8892
}
8993

9094
public:

stdlib/public/runtime/Errors.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ reportOnCrash(uint32_t flags, const char *message)
330330
if (previous)
331331
swift_asprintf(&current, "%s%s", current, message);
332332
else
333+
#if defined(_WIN32)
334+
current = ::_strdup(message);
335+
#else
333336
current = ::strdup(message);
337+
#endif
334338
} while (!std::atomic_compare_exchange_strong_explicit(&kFatalErrorMessage,
335339
&previous,
336340
static_cast<const char *>(current),

stdlib/public/runtime/SymbolInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static Win32ModuleInfo moduleInfoFromAddress(const void *address) {
115115
if (pwszFileName != wszBuffer)
116116
::free(pwszFileName);
117117

118-
return { ::strdup("<unknown>"), mi.lpBaseOfDll };
118+
return { ::_strdup("<unknown>"), mi.lpBaseOfDll };
119119
}
120120

121121
const char *result = _swift_win32_copyUTF8FromWide(pwszFileName);
@@ -125,7 +125,7 @@ static Win32ModuleInfo moduleInfoFromAddress(const void *address) {
125125

126126
return { result, mi.lpBaseOfDll };
127127
} else {
128-
return { ::strdup("<unknown>"), nullptr };
128+
return { ::_strdup("<unknown>"), nullptr };
129129
}
130130
}
131131
#endif
@@ -156,7 +156,7 @@ std::optional<SymbolInfo> SymbolInfo::lookup(const void *address) {
156156

157157
if (bRet) {
158158
return SymbolInfo((const void *)package.si.Address,
159-
::strdup(package.si.Name),
159+
::_strdup(package.si.Name),
160160
moduleInfo.name,
161161
moduleInfo.base);
162162
} else {

stdlib/public/runtime/SymbolInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ struct SymbolInfo {
6464

6565
void initializeFrom(const SymbolInfo &other) {
6666
_symbolAddress = other._symbolAddress;
67-
_symbolName = ::strdup(other._symbolName);
68-
_moduleFileName = ::strdup(other._moduleFileName);
67+
_symbolName = ::_strdup(other._symbolName);
68+
_moduleFileName = ::_strdup(other._moduleFileName);
6969
_moduleBaseAddress = other._moduleBaseAddress;
7070
}
7171

0 commit comments

Comments
 (0)