[g-a-devel]Gnome Speech - fixups - (patch)
- From: Michael Meeks <michael ximian com>
- To: Marc Mulcahy <marc mulcahy sun com>
- Cc: accessibility mailing list <gnome-accessibility-devel gnome org>
- Subject: [g-a-devel]Gnome Speech - fixups - (patch)
- Date: 13 Sep 2002 05:07:33 +0100
Hi Marc,
As discussed, with this I get cleaner code, nicer output, several
theoretical segvs / leaks killed, clean exit, better exception handling
etc.
May I commit ?
Regards,
Michael.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-speech/ChangeLog,v
retrieving revision 1.7.2.18
diff -u -p -u -r1.7.2.18 ChangeLog
--- ChangeLog 12 Sep 2002 19:19:00 -0000 1.7.2.18
+++ ChangeLog 13 Sep 2002 03:10:36 -0000
@@ -1,3 +1,19 @@
+2002-09-13 Michael Meeks <michael ximian com>
+
+ * gnome-speech/synthesisdriver.c
+ (impl_getParameterValueDescription): don't use
+ uninitialized variable.
+
+ * test/test-speech.c (main): fix ev / select_server
+ (select_server): upd.
+ (driver_say_print): impl. helper.
+ (parameter_tests): use helper throught.
+ (do_test): don't double free, use helper.
+ include stdlib.h for atoi etc.
+ (parameter_tests): pass ev around more normally.
+ (main): free exceptions at end, do a debug
+ shutdown, so we can track ref leaks correctly.
+
2002-09-12 Marc Mulcahy <marc mulcahy sun com>
* configure.in drivers/Makefile.am drivers/festival: Added basic
Index: gnome-speech/synthesisdriver.c
===================================================================
RCS file: /cvs/gnome/gnome-speech/gnome-speech/Attic/synthesisdriver.c,v
retrieving revision 1.1.2.4
diff -u -p -u -r1.1.2.4 synthesisdriver.c
--- gnome-speech/synthesisdriver.c 12 Sep 2002 16:22:17 -0000 1.1.2.4
+++ gnome-speech/synthesisdriver.c 13 Sep 2002 03:10:36 -0000
@@ -157,7 +157,7 @@ impl_getParameterValueDescription (Porta
SynthesisDriver *driver = synthesis_driver_from_servant (servant);
ParameterPrivate *priv;
GSList *tmp;
- ValueDescription *d;
+ ValueDescription *d = NULL;
g_return_val_if_fail (driver, NULL);
priv = find_parameter (driver, name);
@@ -169,7 +169,7 @@ impl_getParameterValueDescription (Porta
if (d->value == value)
break;
}
- return CORBA_string_dup (d->description ? d->description : "");
+ return CORBA_string_dup (d && d->description ? d->description : "");
}
@@ -293,6 +293,7 @@ synthesis_driver_add_parameter_value_des
d->description = g_strdup (description);
priv->value_descriptions = g_slist_append (priv->value_descriptions, d);
}
+
BONOBO_TYPE_FUNC_FULL (SynthesisDriver,
GNOME_Speech_SynthesisDriver,
bonobo_object_get_type (),
Index: test/test-speech.c
===================================================================
RCS file: /cvs/gnome/gnome-speech/test/test-speech.c,v
retrieving revision 1.2.2.3
diff -u -p -u -r1.2.2.3 test-speech.c
--- test/test-speech.c 12 Sep 2002 16:22:17 -0000 1.2.2.3
+++ test/test-speech.c 13 Sep 2002 03:10:36 -0000
@@ -1,24 +1,51 @@
#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
#include <glib/gmain.h>
#include <libbonobo.h>
#include <gnome-speech/gnome-speech.h>
+static void
+driver_say_print (GNOME_Speech_SynthesisDriver driver,
+ const char *format,
+ ...)
+{
+ va_list args;
+ char *str;
+ CORBA_Environment ev;
+
+ va_start (args, format);
+
+ CORBA_exception_init (&ev);
+
+ str = g_strdup_vprintf (format, args);
+ GNOME_Speech_SynthesisDriver_say (driver, str, &ev);
+ if (BONOBO_EX (&ev))
+ printf ("Exception %s writing '%s'",
+ bonobo_exception_get_text (&ev), str);
+ else
+ printf ("%s", str);
+ g_free (str);
+ CORBA_exception_free (&ev);
+
+ va_end (args);
+}
static CORBA_Object
-select_server ()
+select_server (CORBA_Environment *ev)
{
- CORBA_Environment ev;
+
int i;
Bonobo_ServerInfoList *servers;
Bonobo_ServerInfo *info;
char input[81];
CORBA_Object rv;
- CORBA_exception_init (&ev);
- servers = bonobo_activation_query ("repo_ids.has ('IDL:GNOME/Speech/SynthesisDriver:1.0')",
- NULL, &ev);
- if (ev._major != CORBA_NO_EXCEPTION)
+ servers = bonobo_activation_query (
+ "repo_ids.has ('IDL:GNOME/Speech/SynthesisDriver:1.0')",
+ NULL, ev);
+ if (BONOBO_EX (ev))
{
return CORBA_OBJECT_NIL;
}
@@ -44,75 +71,52 @@ select_server ()
}
info = &servers->_buffer[i];
printf ("Atempting to activate %s.\n", info->iid);
- rv = bonobo_activation_activate_from_id (info->iid,
- 0, NULL, &ev);
+ rv = bonobo_activation_activate_from_id (
+ (const Bonobo_ActivationID) info->iid,
+ 0, NULL, ev);
CORBA_free (servers);
+
return rv;
}
-
-
static void
-parameter_tests (GNOME_Speech_SynthesisDriver driver)
+parameter_tests (GNOME_Speech_SynthesisDriver driver, CORBA_Environment *ev)
{
GNOME_Speech_ParameterList *list;
int i;
- gchar *text;
gboolean done = FALSE;
- CORBA_Environment ev;
- CORBA_exception_init (&ev);
- list = GNOME_Speech_SynthesisDriver_getSupportedParameters (driver, &ev);
- if (list->_length == 0)
+ list = GNOME_Speech_SynthesisDriver_getSupportedParameters (driver, ev);
+ if (BONOBO_EX (ev) || list->_length == 0)
{
CORBA_free (list);
- printf ("No parameters supported.\n\n");
- GNOME_Speech_SynthesisDriver_say (driver, "No parameters supported.",&ev);
+ driver_say_print (driver, "No parameters supported.\n");
return;
}
- text = g_strdup_printf ("%d parameters supported.\n", list->_length);
- printf (text);
- GNOME_Speech_SynthesisDriver_say (driver, text, &ev);
- g_free (text);
+
+ driver_say_print (driver, "%d parameters supported.\n", list->_length);
for (i = 0; i < list->_length; i++)
{
GNOME_Speech_Parameter *p = &(list->_buffer[i]);
- printf ("Name gotten is %s value is %p.\n", p->name, p->name);
- text = g_strdup_printf ("parameter %d: %s.\n", i+1, p->name);
- printf (text);
- g_free (text);
- text = g_strdup_printf (" minimum value: %.2lf.\n", p->min);
- printf (text);
- GNOME_Speech_SynthesisDriver_say (driver, text, &ev);
- g_free (text);
- text = g_strdup_printf (" current value: %.2lf.\n", p->current);
- printf (text);
- GNOME_Speech_SynthesisDriver_say (driver, text, &ev);
- g_free (text);
- text = g_strdup_printf (" maximum value: %.2lf.\n", p->max);
- printf (text);
- GNOME_Speech_SynthesisDriver_say (driver, text, &ev);
- g_free (text);
- text = g_strdup_printf (" %s\n",
- (p->enumerated)
- ? "Is enumerated."
- : "Is not enumerated.");
- printf (text);
- GNOME_Speech_SynthesisDriver_say (driver, text, &ev);
- g_free (text);
+
+ driver_say_print (driver, "parameter %d: %s.\n", i + 1, p->name);
+ driver_say_print (driver, " minimum value: %.2lf.\n", p->min);
+ driver_say_print (driver, " current value: %.2lf.\n", p->current);
+ driver_say_print (driver, " maximum value: %.2lf.\n", p->max);
+ driver_say_print (driver, " %s\n",
+ (p->enumerated) ? "Is enumerated."
+ : "Is not enumerated.");
}
+
while (!done)
{
gchar input[81];
gint choice;
gdouble new_value;
GNOME_Speech_Parameter *p;
- gchar *prompt;
- prompt = g_strdup_printf ("Parameter to change (1 through %d, 0 to exit): ", list->_length);
- printf (prompt);
- GNOME_Speech_SynthesisDriver_say (driver, prompt, &ev);
- g_free (prompt);
+ driver_say_print (driver, "Parameter to change (1 through %d, "
+ "0 to exit): ", list->_length);
fgets (input, 80, stdin);
choice = atoi(input);
if (choice == 0)
@@ -121,82 +125,70 @@ parameter_tests (GNOME_Speech_SynthesisD
break;
}
p = &(list->_buffer[choice-1]);
- prompt = g_strdup_printf ("new %s? %.2lf through %.2lf.", p->name, p->min, p->max);
- printf (prompt);
- GNOME_Speech_SynthesisDriver_say (driver, prompt, &ev);
- g_free (prompt);
- fgets (input, 80, stdin);
- new_value = atof (input);
- printf ("Setting to %lf.\n", new_value);
- GNOME_Speech_SynthesisDriver_setParameterValue (driver, p->name, new_value, &ev);
+ driver_say_print (driver, "new %s? %.2lf through %.2lf.",
+ p->name, p->min, p->max);
+ fgets (input, 80, stdin);
+ new_value = atof (input);
+ printf ("Setting to %lf.\n", new_value);
+ GNOME_Speech_SynthesisDriver_setParameterValue (driver, p->name, new_value, ev);
}
-
- CORBA_free (list);
+ CORBA_free (list);
}
-
-
static int
-do_test (GNOME_Speech_SynthesisDriver driver)
+do_test (GNOME_Speech_SynthesisDriver driver, CORBA_Environment *ev)
{
char input[81];
int choice;
CORBA_string driver_name, driver_version;
CORBA_string synth_name, synth_version;
- CORBA_Environment ev;
- CORBA_exception_init (&ev);
- driver_name = GNOME_Speech_SynthesisDriver__get_driverName (driver, &ev);
- if (driver_name)
+ driver_name = GNOME_Speech_SynthesisDriver__get_driverName (driver, ev);
+ if (!BONOBO_EX (ev))
{
- printf ("Driver naem: %s\n", driver_name);
+ printf ("Driver name: %s\n", driver_name);
CORBA_free (driver_name);
}
- driver_version = GNOME_Speech_SynthesisDriver__get_driverVersion (driver, &ev);
- if (driver_version)
+ driver_version = GNOME_Speech_SynthesisDriver__get_driverVersion (driver, ev);
+ if (!BONOBO_EX (ev))
{
printf ("Driver version: %s\n", driver_version);
CORBA_free (driver_version);
}
- synth_name = GNOME_Speech_SynthesisDriver__get_synthesizerName (driver, &ev);
- if (synth_name)
+ synth_name = GNOME_Speech_SynthesisDriver__get_synthesizerName (driver, ev);
+ if (!BONOBO_EX (ev))
{
- printf ("Synthesizer naem: %s\n", synth_name);
+ printf ("Synthesizer name: %s\n", synth_name);
CORBA_free (synth_name);
}
- synth_version = GNOME_Speech_SynthesisDriver__get_synthesizerVersion (driver, &ev);
- if (synth_version)
+ synth_version = GNOME_Speech_SynthesisDriver__get_synthesizerVersion (driver, ev);
+ if (!BONOBO_EX (ev))
{
printf ("Synthesizer Version: %s\n", synth_version);
- CORBA_free (synth_name);
+ CORBA_free (synth_version);
}
- printf ("\nPlease select a test.\n\n");
- GNOME_Speech_SynthesisDriver_say (driver, "Please select a test.", &ev);
- printf ("2: Parameter test.\n");
- GNOME_Speech_SynthesisDriver_say (driver, "1. Parameter test.", &ev);
- printf ("0: Exit\n");
- GNOME_Speech_SynthesisDriver_say (driver, "0. exit.", &ev);
+ driver_say_print (driver, "\nPlease select a test.\n\n");
+ driver_say_print (driver, "1. Parameter test.\n");
+ driver_say_print (driver, "0. Exit.\n");
printf ("\nSelect test: ");
fgets (input, 80, stdin);
choice = atoi (input);
switch (choice)
{
case 1:
- GNOME_Speech_SynthesisDriver_stop (driver, &ev);
- parameter_tests (driver);
+ GNOME_Speech_SynthesisDriver_stop (driver, ev);
+ parameter_tests (driver, ev);
break;
case 0:
- GNOME_Speech_SynthesisDriver_stop (driver, &ev);
- GNOME_Speech_SynthesisDriver_say (driver, "Goodbye.", &ev);
+ GNOME_Speech_SynthesisDriver_stop (driver, ev);
+ GNOME_Speech_SynthesisDriver_say (driver, "Goodbye.", ev);
return -1;
}
return 0;
}
-
-
int
main (int argc, char **argv)
{
@@ -209,15 +201,15 @@ main (int argc, char **argv)
{
g_error ("Can't initialize Bonobo...\n");
}
- o = select_server (ev);
- if (o == CORBA_OBJECT_NIL)
+
+ o = select_server (&ev);
+ if (BONOBO_EX (&ev) || o == CORBA_OBJECT_NIL)
{
printf ("No server selected.\n");
return 0;
}
-
- /* Atempt to initialize the driver */
+ /* Atempt to initialize the driver */
if (!GNOME_Speech_SynthesisDriver_isInitialized (o, &ev) &&
!GNOME_Speech_SynthesisDriver_driverInit (o, &ev))
{
@@ -228,10 +220,14 @@ main (int argc, char **argv)
{
while (!done)
{
- if (do_test ((GNOME_Speech_SynthesisDriver)o))
+ if (do_test (o, &ev))
done = 1;
}
- }
+ }
CORBA_Object_release (o, &ev);
- return 0;
+
+ CORBA_exception_free (&ev);
+
+ return bonobo_debug_shutdown ();
}
+
--
mmeeks gnu org <><, Pseudo Engineer, itinerant idiot
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]