From 8021528f5e8bdd84425f5df19c7c5485b3553113 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 29 Oct 2022 21:01:01 +0300 Subject: [PATCH] cleanup: reduce code duplication with a new function StatusCreateTerminatedMsg. This is not covered by current tests. --- src/libespeak-ng/speech.c | 57 +++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index ed704623..1c0130d3 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -63,6 +63,8 @@ #include "voice.h" // for FreeVoiceList, VoiceReset, current_... #include "wavegen.h" // for WavegenFill, WavegenInit, WcmdqUsed +static espeak_ng_STATUS StatusCreateTerminatedMsg(t_espeak_command *c1, unsigned int *unique_identifier, void *user_data); + unsigned char *outbuf = NULL; int outbuf_size = 0; unsigned char *out_start; @@ -686,22 +688,7 @@ espeak_ng_Synthesize(const void *text, size_t size, *unique_identifier = c1->u.my_text.unique_identifier; } - // Create the "terminated msg" command (same uid) - t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data); - - // Try to add these 2 commands (single transaction) - if (c1 && c2) { - espeak_ng_STATUS status = fifo_add_commands(c1, c2); - if (status != ENS_OK) { - delete_espeak_command(c1); - delete_espeak_command(c2); - } - return status; - } - - delete_espeak_command(c1); - delete_espeak_command(c2); - return ENOMEM; + return StatusCreateTerminatedMsg(c1, unique_identifier, user_data); #else return sync_espeak_Synth(0, text, position, position_type, end_position, flags, user_data); #endif @@ -736,22 +723,7 @@ espeak_ng_SynthesizeMark(const void *text, *unique_identifier = c1->u.my_mark.unique_identifier; } - // Create the "terminated msg" command (same uid) - t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data); - - // Try to add these 2 commands (single transaction) - if (c1 && c2) { - espeak_ng_STATUS status = fifo_add_commands(c1, c2); - if (status != ENS_OK) { - delete_espeak_command(c1); - delete_espeak_command(c2); - } - return status; - } - - delete_espeak_command(c1); - delete_espeak_command(c2); - return ENOMEM; + return StatusCreateTerminatedMsg(c1, unique_identifier, user_data); #else return sync_espeak_Synth_Mark(0, text, index_mark, end_position, flags, user_data); #endif @@ -964,4 +936,25 @@ ESPEAK_API const char *espeak_Info(const char **ptr) return version_string; } + #pragma GCC visibility pop + + +static espeak_ng_STATUS StatusCreateTerminatedMsg(t_espeak_command *c1, unsigned int *unique_identifier, void *user_data) { +// Create the "terminated msg" command (same uid) + t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data); + + // Try to add these 2 commands (single transaction) + if (c1 && c2) { + espeak_ng_STATUS status = fifo_add_commands(c1, c2); + if (status != ENS_OK) { + delete_espeak_command(c1); + delete_espeak_command(c2); + } + return status; + } + + delete_espeak_command(c1); + delete_espeak_command(c2); + return ENOMEM; +} \ No newline at end of file