Added docs for SPI_freeString, and used it to stop memory leak of strings
authorbillh <billh@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Fri, 30 Nov 2001 14:48:23 +0000 (14:48 +0000)
committerbillh <billh@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Fri, 30 Nov 2001 14:48:23 +0000 (14:48 +0000)
in simple-at.c.

git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@126 e2bd861d-eb25-0410-b326-f6ed22b6b98c

ChangeLog
cspi/spi-util.c
cspi/spi-util.h
cspi/spi.h
docs/reference/cspi/at-spi-cspi-sections.txt
docs/reference/cspi/tmpl/spi_event.sgml
docs/reference/cspi/tmpl/spi_main.sgml
docs/reference/cspi/tmpl/spi_registry.sgml
test/at.c
test/keysynth-demo.c
test/simple-at.c

index 81b5432..8f61c06 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2001-11-28  Bill Haneman  <bill.haneman@sun.com>
 
+       * docs/reference/cspi:
+       Included docs for SPI_freeString in generated documentation.
+
+       * cspi/spi-util.c:
+       Renamed spi_freeString to SPI_freeString, for consistency.  Added
+       documentation for this function.
+
+       * cspi/spi-util.h:
+       Renamed spi_freeString to SPI_freeString, for consistency.  
+       Removed obsolete method declaration string_from_corba_string.
+
+       * test/keysynth-demo.c:
+       Small tweak to comments.
+
+       * test/simple-at.c:
+       Stopped leaking the strings returned from CSPI. 
+
+2001-11-28  Bill Haneman  <bill.haneman@sun.com>
+
        Merged Michael's branch (see his ChangeLog entries below).
        
        * at-bridge/bridge.c: Explicitly hold a ref to the registry while
index 5b4714a..cc63fea 100644 (file)
@@ -1,8 +1,17 @@
 #include <stdlib.h>
 #include <cspi/spi-private.h>
 
+/**
+ * SPI_freeString:
+ * @s: a character string returned from another at-spi call.
+ *
+ * Free a character string returned from an at-spi call.  Clients of
+ * at-spi should use this function instead of free () or g_free().
+ * This API should not be used to free strings
+ * from other libraries or allocated by the client.
+ **/
 void
-spi_freeString (char *s)
+SPI_freeString (char *s)
 {
   CORBA_free (s);
 }
index 933225f..1154017 100644 (file)
@@ -1,8 +1,7 @@
 #ifndef __SPI_UTIL_H
 #define __SPI_UTIL_H
 
-char *
-string_from_corba_string (CORBA_char *string);
-
+void
+SPI_freeString (char *s);
 
 #endif /* __SPI_UTIL_H */
index 3e3e0bf..cfaa790 100644 (file)
@@ -1366,9 +1366,6 @@ boolean
 AccessibleValue_setCurrentValue (AccessibleValue *obj,
                                  float newValue);
 
-void
-spi_freeString (char *s);
-
 G_END_DECLS
 
 #endif
index a6bdd0e..b385029 100644 (file)
@@ -6,6 +6,8 @@ SPI_event_main
 SPI_eventIsReady
 SPI_nextEvent
 SPI_exit
+<SUBSECTION Utility Functions>
+SPI_freeString
 </SECTION>
 
 <SECTION>
index 79ddbcc..7ea77ca 100644 (file)
@@ -20,11 +20,13 @@ Event Listener Support
 </para>
 
 
-<!-- ##### TYPEDEF AccessibleEventListenerCB ##### -->
+<!-- ##### USER_FUNCTION AccessibleEventListenerCB ##### -->
 <para>
 
 </para>
 
+@event: 
+
 
 <!-- ##### FUNCTION createAccessibleEventListener ##### -->
 <para>
index e51c49c..98db998 100644 (file)
@@ -54,3 +54,11 @@ SPI main loop and initialization
 
 
 
+<!-- ##### FUNCTION SPI_freeString ##### -->
+<para>
+
+</para>
+
+@s: 
+
+
index 27ea221..cf984ce 100644 (file)
@@ -50,11 +50,14 @@ Registry queries
 @Returns: 
 
 
-<!-- ##### TYPEDEF AccessibleKeystrokeListenerCB ##### -->
+<!-- ##### USER_FUNCTION AccessibleKeystrokeListenerCB ##### -->
 <para>
 
 </para>
 
+@stroke: 
+@Returns: 
+
 
 <!-- ##### TYPEDEF AccessibleKeyEventMask ##### -->
 <para>
index e6f96d1..f65bc8c 100644 (file)
--- a/test/at.c
+++ b/test/at.c
@@ -50,6 +50,7 @@ main(int argc, char **argv)
         CORBA_short n_desktops;
         CORBA_long j;
         CORBA_long n_apps;
+       CORBA_string s;
         Accessibility_Desktop desktop;
         Accessibility_Application app;
         Accessibility_Registry registry;
@@ -105,8 +106,9 @@ main(int argc, char **argv)
             for (i=0; i<n_desktops; ++i)
               {
                 desktop = Accessibility_Registry_getDesktop (registry, i, &ev);
-                fprintf (stderr, "desktop %d name: %s\n", i,
-                         Accessibility_Desktop__get_name (desktop, &ev));
+               s = Accessibility_Desktop__get_name (desktop, &ev);
+                fprintf (stderr, "desktop %d name: %s\n", i, s);
+               CORBA_free (s);  
                 check_ev (&ev, "desktop:name");
                 n_apps = Accessibility_Desktop__get_childCount (desktop, &ev);
                 check_ev (&ev, "desktop:childCount");
@@ -115,8 +117,9 @@ main(int argc, char **argv)
                   {
                     app = (Accessibility_Application) Accessibility_Desktop_getChildAtIndex (desktop, j, &ev);
                     check_ev (&ev, "desktop:getChildAtIndex");
-                    fprintf (stderr, "app %d name: %s\n", j,
-                             Accessibility_Application__get_name (app, &ev));
+                    s = Accessibility_Application__get_name (app, &ev);
+                   fprintf (stderr, "app %d name: %s\n", j, s);
+                   CORBA_free (s);
                     check_ev (&ev, "app:getName");
                   }
               }
index a884437..59d0dc1 100644 (file)
@@ -482,7 +482,7 @@ main(int argc, char **argv)
    * Register a listener on an 'unused' key, to serve as a 'single switch'.
    * On most Intel boxes there is at least one 'special' system key that does not
    * have a non-zero keycode assigned in the Xserver, so we will intercept any keycode
-   * that is 'zero'.  Often these the "windows" key or the "menu" key.
+   * that is 'zero'.  Often these the are the "windows" or the "menu" keys.
    */
   switch_set.keysyms = g_new0 (unsigned long, 1);
   switch_set.keycodes = g_new0 (unsigned short, 1);
index 80f051c..09c7ac6 100644 (file)
@@ -57,6 +57,7 @@ main(int argc, char **argv)
   int n_apps;
   Accessible *desktop;
   Accessible *application;
+  char *s;
 
   if ((argc > 1) && (!strncmp(argv[1],"-h",2)))
   {
@@ -78,13 +79,17 @@ main(int argc, char **argv)
   for (i=0; i<n_desktops; ++i)
     {
       desktop = getDesktop (i);
-      fprintf (stderr, "desktop %d name: %s\n", i, Accessible_getName (desktop));
+      s = Accessible_getName (desktop);
+      fprintf (stderr, "desktop %d name: %s\n", i, s);
+      SPI_freeString (s);
       n_apps = Accessible_getChildCount (desktop);
       for (j=0; j<n_apps; ++j)
         {
           application = Accessible_getChildAtIndex (desktop, j);
-          fprintf (stderr, "app %d name: %s\n", j, Accessible_getName (application));
-         Accessible_unref (application);
+         s = Accessible_getName (application);
+          fprintf (stderr, "app %d name: %s\n", j, s);
+          SPI_freeString (s);
+          Accessible_unref (application);
         }
       Accessible_unref (desktop);
     }
@@ -139,6 +144,8 @@ get_environment_vars()
 void
 report_focussed_accessible (Accessible *obj, boolean shutup_previous_speech)
 {
+  char *s;
+  int len;
   if (use_festival)
     {
     if (festival_chatty)           
@@ -146,8 +153,10 @@ report_focussed_accessible (Accessible *obj, boolean shutup_previous_speech)
         _festival_say (Accessible_getRole (obj), "voice_don_diphone", shutup_previous_speech);
       }
       fprintf (stderr, "getting Name\n");
-      _festival_say (Accessible_getName (obj), "voice_kal_diphone",
+      s = Accessible_getName (obj);
+      _festival_say (s, "voice_kal_diphone",
                     shutup_previous_speech || festival_chatty);
+      SPI_freeString (s);
     }
   
   if (Accessible_isComponent (obj))
@@ -171,29 +180,37 @@ report_focussed_accessible (Accessible *obj, boolean shutup_previous_speech)
      long start_offset, end_offset;
      char *first_sentence = "empty";
      text_interface = Accessible_getText (obj);
-     fprintf (stderr, "isText...%p\n", text_interface);
      first_sentence = AccessibleText_getTextAtOffset (
               text_interface, (long) 0, SPI_TEXT_BOUNDARY_SENTENCE_START, &start_offset, &end_offset);
-     if (first_sentence) _festival_say(first_sentence, "voice_don_diphone", FALSE);
-     fprintf (stderr, "done reporting on focussed object\n");
+     if (first_sentence)
+       {
+        _festival_say(first_sentence, "voice_don_diphone", FALSE);
+        SPI_freeString (first_sentence);
+       }
+     len = AccessibleText_getCharacterCount (text_interface);
+     s = AccessibleText_getText (text_interface, 0, len);
+     fprintf (stderr, "done reporting on focussed object, text=%s\n", s);
   }
 }
 
 void
 report_focus_event (AccessibleEvent *event)
 {
-  fprintf (stderr, "%s event from %s\n", event->type,
-           Accessible_getName (event->source));
+  char *s = Accessible_getName (event->source);
+  fprintf (stderr, "%s event from %s\n", event->type, s);
+  SPI_freeString (s);
   report_focussed_accessible (event->source, TRUE);
 }
 
 void
 report_button_press (AccessibleEvent *event)
 {
-  fprintf (stderr, "%s event from %s\n", event->type,
-           Accessible_getName (event->source));
-  fprintf (stderr, "Object description %s\n",
-           Accessible_getDescription (event->source));
+  char *s = Accessible_getName (event->source);
+  fprintf (stderr, "%s event from %s\n", event->type, s);
+  SPI_freeString (s);
+  s = Accessible_getDescription (event->source);
+  fprintf (stderr, "Object description %s\n", s);
+  SPI_freeString (s);
 }
 
 
@@ -203,17 +220,22 @@ check_property_change (AccessibleEvent *event)
   AccessibleSelection *selection = Accessible_getSelection (event->source);
   int n_selections;
   int i;
+  char *s;
   if (selection)
   {
     n_selections = (int) AccessibleSelection_getNSelectedChildren (selection);
+    s = Accessible_getName (event->source);
     fprintf (stderr, "(Property) %s event from %s, %d selected children\n",
-            event->type, Accessible_getName (event->source), n_selections);
+            event->type, s, n_selections);
+    SPI_freeString (s);
   /* for now, speak entire selection set */
     for (i=0; i<n_selections; ++i)
       {
         Accessible *obj = AccessibleSelection_getSelectedChild (selection, (long) i);
        g_return_if_fail (obj);
-       fprintf (stderr, "Child %d, name=%s\n", i, Accessible_getName (obj));
+       s = Accessible_getName (obj);
+       fprintf (stderr, "Child %d, name=%s\n", i, s);
+       SPI_freeString (s);
        report_focussed_accessible (obj, i==0);
     }
   }