runtime: use _strdup on Windows

Windows prefers the `_strdup` extension over `strdup`. This avoids
unnecessary warnings when building the standard library.
This commit is contained in:
Saleem Abdulrasool
2024-12-12 10:32:28 -08:00
parent b7485467e9
commit 9e413bd3d2
4 changed files with 13 additions and 5 deletions

View File

@@ -84,7 +84,11 @@ private:
static char *getCString(char *str) { return str; } static char *getCString(char *str) { return str; }
static char *getCString(const std::string &str) { static char *getCString(const std::string &str) {
#if defined(_WIN32)
return _strdup(str.c_str());
#else
return strdup(str.c_str()); return strdup(str.c_str());
#endif
} }
public: public:

View File

@@ -330,7 +330,11 @@ reportOnCrash(uint32_t flags, const char *message)
if (previous) if (previous)
swift_asprintf(&current, "%s%s", current, message); swift_asprintf(&current, "%s%s", current, message);
else else
#if defined(_WIN32)
current = ::_strdup(message);
#else
current = ::strdup(message); current = ::strdup(message);
#endif
} while (!std::atomic_compare_exchange_strong_explicit(&kFatalErrorMessage, } while (!std::atomic_compare_exchange_strong_explicit(&kFatalErrorMessage,
&previous, &previous,
static_cast<const char *>(current), static_cast<const char *>(current),

View File

@@ -115,7 +115,7 @@ static Win32ModuleInfo moduleInfoFromAddress(const void *address) {
if (pwszFileName != wszBuffer) if (pwszFileName != wszBuffer)
::free(pwszFileName); ::free(pwszFileName);
return { ::strdup("<unknown>"), mi.lpBaseOfDll }; return { ::_strdup("<unknown>"), mi.lpBaseOfDll };
} }
const char *result = _swift_win32_copyUTF8FromWide(pwszFileName); const char *result = _swift_win32_copyUTF8FromWide(pwszFileName);
@@ -125,7 +125,7 @@ static Win32ModuleInfo moduleInfoFromAddress(const void *address) {
return { result, mi.lpBaseOfDll }; return { result, mi.lpBaseOfDll };
} else { } else {
return { ::strdup("<unknown>"), nullptr }; return { ::_strdup("<unknown>"), nullptr };
} }
} }
#endif #endif
@@ -156,7 +156,7 @@ std::optional<SymbolInfo> SymbolInfo::lookup(const void *address) {
if (bRet) { if (bRet) {
return SymbolInfo((const void *)package.si.Address, return SymbolInfo((const void *)package.si.Address,
::strdup(package.si.Name), ::_strdup(package.si.Name),
moduleInfo.name, moduleInfo.name,
moduleInfo.base); moduleInfo.base);
} else { } else {

View File

@@ -64,8 +64,8 @@ private:
void initializeFrom(const SymbolInfo &other) { void initializeFrom(const SymbolInfo &other) {
_symbolAddress = other._symbolAddress; _symbolAddress = other._symbolAddress;
_symbolName = ::strdup(other._symbolName); _symbolName = ::_strdup(other._symbolName);
_moduleFileName = ::strdup(other._moduleFileName); _moduleFileName = ::_strdup(other._moduleFileName);
_moduleBaseAddress = other._moduleBaseAddress; _moduleBaseAddress = other._moduleBaseAddress;
} }