[Scummvm-git-logs] scummvm master -> 30f2c2f3cdecc8536aed3f7d570876bc1f803d51
sev-
sev at scummvm.org
Thu Aug 20 22:02:18 UTC 2020
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
27a2b94687 WIN32: Remove unnecessary string conversion
30f2c2f3cd WIN32: Use malloc instead of new in string conversion functions
Commit: 27a2b94687e7cbd042a621ec6c645a973672d9c8
https://github.com/scummvm/scummvm/commit/27a2b94687e7cbd042a621ec6c645a973672d9c8
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2020-08-21T00:02:13+02:00
Commit Message:
WIN32: Remove unnecessary string conversion
Changed paths:
backends/text-to-speech/windows/windows-text-to-speech.cpp
backends/text-to-speech/windows/windows-text-to-speech.h
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.cpp b/backends/text-to-speech/windows/windows-text-to-speech.cpp
index 534759d0c3..b2e8851d04 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -389,9 +389,7 @@ void WindowsTextToSpeechManager::createVoice(void *cpVoiceToken) {
warning("Could not get the language attribute for voice: %s", desc.c_str());
return;
}
- buffer = Win32::unicodeToAnsi(data);
- Common::String language = lcidToLocale(buffer);
- delete[] buffer;
+ Common::String language = lcidToLocale(data);
CoTaskMemFree(data);
// only get the voices for the current language
@@ -407,9 +405,7 @@ void WindowsTextToSpeechManager::createVoice(void *cpVoiceToken) {
warning("Could not get the gender attribute for voice: %s", desc.c_str());
return;
}
- buffer = Win32::unicodeToAnsi(data);
- Common::TTSVoice::Gender gender = !strcmp(buffer, "Male") ? Common::TTSVoice::MALE : Common::TTSVoice::FEMALE;
- delete[] buffer;
+ Common::TTSVoice::Gender gender = !wcscmp(data, L"Male") ? Common::TTSVoice::MALE : Common::TTSVoice::FEMALE;
CoTaskMemFree(data);
// age
@@ -419,35 +415,31 @@ void WindowsTextToSpeechManager::createVoice(void *cpVoiceToken) {
warning("Could not get the age attribute for voice: %s", desc.c_str());
return;
}
- buffer = Win32::unicodeToAnsi(data);
- Common::TTSVoice::Age age = !strcmp(buffer, "Adult") ? Common::TTSVoice::ADULT : Common::TTSVoice::UNKNOWN_AGE;
- delete[] buffer;
+ Common::TTSVoice::Age age = !wcscmp(data, L"Adult") ? Common::TTSVoice::ADULT : Common::TTSVoice::UNKNOWN_AGE;
CoTaskMemFree(data);
_ttsState->_availableVoices.push_back(Common::TTSVoice(gender, age, (void *) voiceToken, desc));
}
-int strToInt(Common::String str) {
- str.toUppercase();
+int strToInt(WCHAR *str) {
int result = 0;
- for (unsigned i = 0; i < str.size(); i++) {
- if (str[i] < '0' || (str[i] > '9' && str[i] < 'A') || str[i] > 'F')
+ for (unsigned i = 0; i < wcslen(str); i++) {
+ WCHAR c = towupper(str[i]);
+ if (c < L'0' || (c > L'9' && c < L'A') || c > L'F')
break;
- int num = (str[i] <= '9') ? str[i] - '0' : str[i] - 55;
+ int num = (c <= L'9') ? c - L'0' : c - 55;
result = result * 16 + num;
}
return result;
}
-Common::String WindowsTextToSpeechManager::lcidToLocale(Common::String lcid) {
+Common::String WindowsTextToSpeechManager::lcidToLocale(WCHAR *lcid) {
LCID locale = strToInt(lcid);
- int nchars = GetLocaleInfoW(locale, LOCALE_SISO639LANGNAME, NULL, 0);
- wchar_t *languageCode = new wchar_t[nchars];
- GetLocaleInfoW(locale, LOCALE_SISO639LANGNAME, languageCode, nchars);
- char *resultTmp = Win32::unicodeToAnsi(languageCode);
- Common::String result = resultTmp;
+ int nchars = GetLocaleInfoA(locale, LOCALE_SISO639LANGNAME, NULL, 0);
+ char *languageCode = new char[nchars];
+ GetLocaleInfoA(locale, LOCALE_SISO639LANGNAME, languageCode, nchars);
+ Common::String result = languageCode;
delete[] languageCode;
- free(resultTmp);
return result;
}
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.h b/backends/text-to-speech/windows/windows-text-to-speech.h
index 3527f36fc6..7f52549a5f 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.h
+++ b/backends/text-to-speech/windows/windows-text-to-speech.h
@@ -77,7 +77,7 @@ private:
void init();
virtual void updateVoices() override;
void createVoice(void *cpVoiceToken);
- Common::String lcidToLocale(Common::String lcid);
+ Common::String lcidToLocale(WCHAR *lcid);
SpeechState _speechState;
Common::String _lastSaid;
HANDLE _thread;
Commit: 30f2c2f3cdecc8536aed3f7d570876bc1f803d51
https://github.com/scummvm/scummvm/commit/30f2c2f3cdecc8536aed3f7d570876bc1f803d51
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2020-08-21T00:02:13+02:00
Commit Message:
WIN32: Use malloc instead of new in string conversion functions
Changed paths:
backends/dialogs/win32/win32-dialogs.cpp
backends/platform/sdl/win32/win32.cpp
backends/platform/sdl/win32/win32_wrapper.cpp
backends/taskbar/win32/win32-taskbar.cpp
backends/text-to-speech/windows/windows-text-to-speech.cpp
diff --git a/backends/dialogs/win32/win32-dialogs.cpp b/backends/dialogs/win32/win32-dialogs.cpp
index bf4a79614a..a8217ba7e0 100644
--- a/backends/dialogs/win32/win32-dialogs.cpp
+++ b/backends/dialogs/win32/win32-dialogs.cpp
@@ -95,7 +95,7 @@ HRESULT getShellPath(IShellItem *item, Common::String &path) {
char *str = Win32::unicodeToAnsi(name);
path = Common::String(str);
CoTaskMemFree(name);
- delete[] str;
+ free(str);
}
return hr;
}
@@ -132,11 +132,11 @@ Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const ch
LPWSTR str = Win32::ansiToUnicode(title, Win32::getCurrentCharset());
hr = dialog->SetTitle(str);
- delete[] str;
+ free(str);
str = Win32::ansiToUnicode(_("Choose"), Win32::getCurrentCharset());
hr = dialog->SetOkButtonLabel(str);
- delete[] str;
+ free(str);
if (ConfMan.hasKey("browser_lastpath")) {
str = Win32::ansiToUnicode(ConfMan.get("browser_lastpath").c_str());
@@ -145,7 +145,7 @@ Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const ch
if (SUCCEEDED(hr)) {
hr = dialog->SetDefaultFolder(item);
}
- delete[] str;
+ free(str);
}
// Show dialog
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index 638174df55..1c67d0d601 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -474,18 +474,12 @@ char *OSystem_Win32::convertEncoding(const char* to, const char *from, const cha
}
memcpy(tmpStr, string, length);
} else {
- // Win32::ansiToUnicode uses new to allocate the memory. We need to copy it into an array
- // allocated with malloc as it is going to be freed using free.
- WCHAR *tmpStr2 = Win32::ansiToUnicode(string, Win32::getCodePageId(from));
- if (!tmpStr2) {
+ tmpStr = Win32::ansiToUnicode(string, Win32::getCodePageId(from));
+ if (!tmpStr) {
if (newString != nullptr)
free(newString);
return nullptr;
}
- size_t size = wcslen(tmpStr2) + 1; // +1 for the terminating null wchar
- tmpStr = (WCHAR *) malloc(sizeof(WCHAR) * size);
- memcpy(tmpStr, tmpStr2, sizeof(WCHAR) * size);
- delete[] tmpStr2;
}
if (newString != nullptr)
@@ -501,15 +495,7 @@ char *OSystem_Win32::convertEncoding(const char* to, const char *from, const cha
} else {
result = Win32::unicodeToAnsi(tmpStr, Win32::getCodePageId(to));
free(tmpStr);
- if (!result)
- return nullptr;
- // Win32::unicodeToAnsi uses new to allocate the memory. We need to copy it into an array
- // allocated with malloc as it is going to be freed using free.
- size_t size = strlen(result) + 1;
- char *resultCopy = (char *) malloc(sizeof(char) * size);
- memcpy(resultCopy, result, sizeof(char) * size);
- delete[] result;
- return resultCopy;
+ return result;
}
}
diff --git a/backends/platform/sdl/win32/win32_wrapper.cpp b/backends/platform/sdl/win32/win32_wrapper.cpp
index 7efcb00aa1..31663f1b57 100644
--- a/backends/platform/sdl/win32/win32_wrapper.cpp
+++ b/backends/platform/sdl/win32/win32_wrapper.cpp
@@ -85,7 +85,7 @@ wchar_t *ansiToUnicode(const char *s, uint codePage) {
DWORD size = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
if (size > 0) {
- LPWSTR result = new WCHAR[size];
+ LPWSTR result = (LPWSTR)calloc(size, sizeof(WCHAR));
if (MultiByteToWideChar(codePage, 0, s, -1, result, size) != 0)
return result;
}
@@ -97,7 +97,7 @@ char *unicodeToAnsi(const wchar_t *s, uint codePage) {
DWORD size = WideCharToMultiByte(codePage, 0, s, -1, NULL, 0, 0, 0);
if (size > 0) {
- char *result = new char[size];
+ char *result = (char *)calloc(size, sizeof(char));
if (WideCharToMultiByte(codePage, 0, s, -1, result, size, 0, 0) != 0)
return result;
}
diff --git a/backends/taskbar/win32/win32-taskbar.cpp b/backends/taskbar/win32/win32-taskbar.cpp
index 1a03bbd516..6542973716 100644
--- a/backends/taskbar/win32/win32-taskbar.cpp
+++ b/backends/taskbar/win32/win32-taskbar.cpp
@@ -136,7 +136,7 @@ void Win32TaskbarManager::setOverlayIcon(const Common::String &name, const Commo
DestroyIcon(pIcon);
- delete[] desc;
+ free(desc);
}
void Win32TaskbarManager::setProgressValue(int completed, int total) {
@@ -267,7 +267,7 @@ void Win32TaskbarManager::setCount(int count) {
// Sets the overlay icon
LPWSTR desc = Win32::ansiToUnicode(Common::String::format("Found games: %d", count).c_str());
_taskbar->SetOverlayIcon(_window->getHwnd(), _icon, desc);
- delete[] desc;
+ free(desc);
}
void Win32TaskbarManager::addRecent(const Common::String &name, const Common::String &description) {
@@ -301,7 +301,7 @@ void Win32TaskbarManager::addRecent(const Common::String &name, const Common::St
link->SetIconLocation(icon, 0);
- delete[] icon;
+ free(icon);
}
// The link's display name must be set via property store.
@@ -321,8 +321,8 @@ void Win32TaskbarManager::addRecent(const Common::String &name, const Common::St
// SHAddToRecentDocs will cause the games to be added to the Recent list, allowing the user to pin them.
SHAddToRecentDocs(SHARD_LINK, link);
link->Release();
- delete[] game;
- delete[] desc;
+ free(game);
+ free(desc);
}
}
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.cpp b/backends/text-to-speech/windows/windows-text-to-speech.cpp
index b2e8851d04..59eb599a55 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -362,7 +362,7 @@ void WindowsTextToSpeechManager::createVoice(void *cpVoiceToken) {
if (SUCCEEDED(hr)) {
buffer = Win32::unicodeToAnsi(descW);
desc = buffer;
- delete[] buffer;
+ free(buffer);
CoTaskMemFree(descW);
}
More information about the Scummvm-git-logs
mailing list