[Scummvm-git-logs] scummvm master -> 6886ae0dae3bbc418e6fac5467de830b9f7225c4

criezy criezy at scummvm.org
Fri Sep 6 00:52:50 CEST 2019


This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8f930126e7 COMMON: Add string size computation to Encoding.
ba859f1eed TTS: Minimize the time needed for stop() on Win32
26bf329b95 TTS: Fix possible deadlock
6886ae0dae SDL: Copy result of SDL_iconv_string()


Commit: 8f930126e7de6db9c22ff9f02d52564c4c99a9a8
    https://github.com/scummvm/scummvm/commit/8f930126e7de6db9c22ff9f02d52564c4c99a9a8
Author: Jaromir Wysoglad (jaromirwysoglad at gmail.com)
Date: 2019-09-05T23:52:46+01:00

Commit Message:
COMMON: Add string size computation to Encoding.

Changed paths:
    common/encoding.cpp
    common/encoding.h


diff --git a/common/encoding.cpp b/common/encoding.cpp
index fc743e5..3c70f19 100644
--- a/common/encoding.cpp
+++ b/common/encoding.cpp
@@ -499,4 +499,20 @@ uint32 *Encoding::transliterateUTF32(const uint32 *string, size_t length) {
 	return result;
 }
 
+size_t Encoding::stringLength(const char *string, const String &encoding) {
+	if (encoding.hasPrefixIgnoreCase("UTF-16")) {
+		const uint16 *i = (const uint16 *) string;
+		for (;*i != 0; i++) {}
+		return (const char *) i - string;
+	} else if (encoding.hasPrefixIgnoreCase("UTF-32")) {
+		const uint32 *i = (const uint32 *) string;
+		for (;*i != 0; i++) {}
+		return (const char *) i - string;
+	} else {
+		const char *i = string;
+		for (;*i != 0; i++) {}
+		return i - string;
+	}
+}
+
 }
diff --git a/common/encoding.h b/common/encoding.h
index 2b079ad..adb6119 100644
--- a/common/encoding.h
+++ b/common/encoding.h
@@ -108,6 +108,18 @@ class Encoding {
 		 * @return Array of characters with the opposite endianity
 		 */
 		static char *switchEndian(const char *string, int length, int bitCount);
+
+		/**
+		 * Computes length (in bytes) of a string in a given encoding. 
+		 * The string must be zero ended. Similar to strlen
+		 * (could be used instead of strlen).
+		 *
+		 * @param string String, which size should be computed.
+		 * @param encoding Encoding of the string.
+		 *
+		 * @return Size of the string in bytes.
+		 */
+		static size_t stringLength(const char *string, const String &encoding);
 	
 	private:
 		/** The encoding, which is currently being converted to */


Commit: ba859f1eeda287214e90358b71728c594e2be652
    https://github.com/scummvm/scummvm/commit/ba859f1eeda287214e90358b71728c594e2be652
Author: Jaromir Wysoglad (jaromirwysoglad at gmail.com)
Date: 2019-09-05T23:52:46+01:00

Commit Message:
TTS: Minimize the time needed for stop() on Win32

This gets rid of freezes when using TTS on Windows.

Changed paths:
    backends/text-to-speech/windows/windows-text-to-speech.cpp


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 a59f219..ceca3e4 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -231,18 +231,16 @@ bool WindowsTextToSpeechManager::stop() {
 		resume();
 	_audio->SetState(SPAS_STOP, 0);
 	WaitForSingleObject(_speechMutex, INFINITE);
+	// Delete the speech queue
 	while (!_speechQueue.empty()) {
 		if (_speechQueue.front() != NULL)
 			free(_speechQueue.front());
 		_speechQueue.pop_front();
 	}
-	_speechQueue.push_back(NULL);
+	// Stop the current speech
+	_voice->Speak(NULL, SPF_PURGEBEFORESPEAK | SPF_ASYNC, 0);
+	_speechState = READY;
 	ReleaseMutex(_speechMutex);
-	if (_thread != NULL) {
-		WaitForSingleObject(_thread, INFINITE);
-		CloseHandle(_thread);
-		_thread = NULL;
-	}
 	_audio->SetState(SPAS_RUN, 0);
 	return false;
 }


Commit: 26bf329b9581985f04ccb26f41370a13836363ff
    https://github.com/scummvm/scummvm/commit/26bf329b9581985f04ccb26f41370a13836363ff
Author: Jaromir Wysoglad (jaromirwysoglad at gmail.com)
Date: 2019-09-05T23:52:46+01:00

Commit Message:
TTS: Fix possible deadlock

Changed paths:
    backends/text-to-speech/windows/windows-text-to-speech.cpp


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 ceca3e4..9e6d30c 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -128,6 +128,7 @@ DWORD WINAPI startSpeech(LPVOID parameters) {
 		WaitForSingleObject(*params->mutex, INFINITE);
 		// check again, when we have exclusive access to the queue
 		if (params->queue->empty() || *(params->state) == WindowsTextToSpeechManager::PAUSED) {
+			ReleaseMutex(*params->mutex);
 			break;
 		}
 		WCHAR *currentSpeech = params->queue->front();


Commit: 6886ae0dae3bbc418e6fac5467de830b9f7225c4
    https://github.com/scummvm/scummvm/commit/6886ae0dae3bbc418e6fac5467de830b9f7225c4
Author: Jaromir Wysoglad (jaromirwysoglad at gmail.com)
Date: 2019-09-05T23:52:46+01:00

Commit Message:
SDL: Copy result of SDL_iconv_string()

Changed paths:
    backends/platform/sdl/sdl.cpp


diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index c89a560..39933cc 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -28,6 +28,7 @@
 #include "common/taskbar.h"
 #include "common/textconsole.h"
 #include "common/translation.h"
+#include "common/encoding.h"
 
 #include "backends/saves/default/default-saves.h"
 
@@ -772,19 +773,42 @@ char *OSystem_SDL::convertEncoding(const char *to, const char *from, const char
 	int zeroBytes = 1;
 	if (Common::String(from).hasPrefixIgnoreCase("utf-16"))
 		zeroBytes = 2;
-	if (Common::String(from).hasPrefixIgnoreCase("utf-32"))
+	else if (Common::String(from).hasPrefixIgnoreCase("utf-32"))
 		zeroBytes = 4;
 
+	char *result;
 	// SDL_iconv_string() takes char * instead of const char * as it's third parameter
 	// with some older versions of SDL.
 #if SDL_VERSION_ATLEAST(2, 0, 0)
-	return SDL_iconv_string(to, from, string, length + zeroBytes);
+	result = SDL_iconv_string(to, from, string, length + zeroBytes);
 #else
 	char *stringCopy = (char *) calloc(sizeof(char), length + zeroBytes);
 	memcpy(stringCopy, string, length);
-	char *result = SDL_iconv_string(to, from, stringCopy, length + zeroBytes);
+	result = SDL_iconv_string(to, from, stringCopy, length + zeroBytes);
 	free(stringCopy);
-	return result;
 #endif
+	if (result == nullptr)
+		return nullptr;
+
+	// We need to copy the result, so that we can use SDL_free()
+	// on the string returned by SDL_iconv_string() and free()
+	// can then be used on the copyed and returned string.
+	// Sometimes free() and SDL_free() aren't compatible and
+	// using free() instead of SDL_free() can cause crashes.
+	size_t newLength = Common::Encoding::stringLength(result, to);
+	zeroBytes = 1;
+	if (Common::String(to).hasPrefixIgnoreCase("utf-16"))
+		zeroBytes = 2;
+	else if (Common::String(to).hasPrefixIgnoreCase("utf-32"))
+		zeroBytes = 4;
+	char *finalResult = (char *) malloc(newLength + zeroBytes);
+	if (!finalResult) {
+		warning("Could not allocate memory for encoding conversion");
+		SDL_free(result);
+		return nullptr;
+	}
+	memcpy(finalResult, result, newLength + zeroBytes);
+	SDL_free(result);
+	return finalResult;
 }
 





More information about the Scummvm-git-logs mailing list