[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] server - Use the GQueue data structure to remove hard-coded uppe
From: |
Luke Yelavich |
Subject: |
[PATCH] server - Use the GQueue data structure to remove hard-coded upper limits on voice lists |
Date: |
Wed, 3 Jun 2015 10:56:41 +1000 |
From: Luke Yelavich <address@hidden>
To: address@hidden
No synthesizer at this time provides more than 256 voices, but hard-coding
a maximum is not a good idea either.
---
src/server/output.c | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/src/server/output.c b/src/server/output.c
index 0313454..8d2cbae 100644
--- a/src/server/output.c
+++ b/src/server/output.c
@@ -278,11 +278,14 @@ int output_send_data(char *cmd, OutputModule * output,
int wfr)
static SPDVoice **output_get_voices(OutputModule * module)
{
SPDVoice **voice_dscr;
+ SPDVoice *voice;
GString *reply;
gchar **lines;
gchar **atoms;
+ GQueue *voices;
int i;
int ret = 0;
+ int numvoices = 0;
gboolean errors = FALSE;
output_lock();
@@ -298,10 +301,10 @@ static SPDVoice **output_get_voices(OutputModule * module)
output_unlock();
return NULL;
}
- //TODO: only 256 voices supported here
- lines = g_strsplit(reply->str, "\n", 256);
+
+ lines = g_strsplit(reply->str, "\n", -1);
g_string_free(reply, TRUE);
- voice_dscr = g_malloc(256 * sizeof(SPDVoice *));
+ voices = g_queue_new();
for (i = 0; !errors && (lines[i] != NULL); i++) {
MSG(1, "LINE here:|%s|", lines[i]);
if (strlen(lines[i]) <= 4) {
@@ -320,10 +323,11 @@ static SPDVoice **output_get_voices(OutputModule * module)
errors = TRUE;
} else {
//Fill in VoiceDescription
- voice_dscr[i] = g_malloc(sizeof(SPDVoice));
- voice_dscr[i]->name = g_strdup(atoms[0]);
- voice_dscr[i]->language = g_strdup(atoms[1]);
- voice_dscr[i]->variant = g_strdup(atoms[2]);
+ voice = g_malloc(sizeof(SPDVoice));
+ voice->name = g_strdup(atoms[0]);
+ voice->language = g_strdup(atoms[1]);
+ voice->variant = g_strdup(atoms[2]);
+ g_queue_push_tail(voices, voice);
}
if (atoms != NULL)
g_strfreev(atoms);
@@ -331,7 +335,24 @@ static SPDVoice **output_get_voices(OutputModule * module)
/* Should we do something in a final "else" branch? */
}
+
+ if (errors == TRUE) {
+ g_queue_free(voices);
+ g_strfreev(lines);
+ output_unlock();
+ return NULL;
+ }
+
+ numvoices = g_queue_get_length(voices);
+
+ voice_dscr = g_malloc((numvoices + 1) * sizeof(SPDVoice *));
+
+ for (i = 0; i < numvoices; i++) {
+ voice_dscr[i] = g_queue_pop_head(voices);
+ }
+
voice_dscr[i] = NULL;
+ g_queue_free(voices);
g_strfreev(lines);
output_unlock();
--
2.1.4
- [PATCH] server - Use the GQueue data structure to remove hard-coded upper limits on voice lists,
Luke Yelavich <=