Changed IDL for State, Component, and Image to reduce use of out params.
authorbillh <billh@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Tue, 4 Dec 2001 22:51:38 +0000 (22:51 +0000)
committerbillh <billh@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Tue, 4 Dec 2001 22:51:38 +0000 (22:51 +0000)
Fixed string memory leaks in registry.c.

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

15 files changed:
ChangeLog
cspi/spi.h
cspi/spi_component.c
cspi/spi_image.c
docs/reference/cspi/at-spi-cspi-sections.txt
idl/Accessibility_Accessible.idl
idl/Accessibility_Component.idl
idl/Accessibility_Image.idl
idl/Accessibility_State.idl
idl/Accessible.idl
idl/Component.idl
idl/Image.idl
idl/State.idl
libspi/registry.c
registryd/registry.c

index 046ab2f..5feeebe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,41 @@
+2001-12-04  Bill Haneman  <bill.haneman@sun.com>
+
+       * libspi/registry.c (_registry_notify_listeners):
+       Changed listener loop iteration to use preferred convention.
+       Got rid of string memory leaks caused be calling g_strconcat
+       inside function calls.
+
+       * libspi/registry.c (parse_event_type):
+       Stopped g_strconcat memory leaks, free the g_strsplit return,
+       g_strdup the split pieces when used, etc.
+
+2001-12-04  Bill Haneman  <bill.haneman@sun.com>
+
+       * idl/State.idl: 
+       Change method 'compare' to return a 'difference set' rather than
+       taking a StateSet as an out parameter (more Java-friendly).
+
+       * idl/Accessible.idl:
+       Added CORBA struct 'BoundingBox', to faciliate API changes below:
+       
+       * idl/Component.idl:
+       * idl/Image.idl:
+       Changed methods 'getExtents' and 'getImageExtents' in these
+       interfaces to return a BoundingBox structure.  
+       (getPosition and getSize are redundant and possibly should be
+       removed, rather than creating a corresponding Point struct.)
+
+       * cspi/spi_component.c:
+       Modify implementation of getExtents to reflect the above IDL
+       change.
+       
+       * cspi/spi_image.c:
+       * cspi/spi.h:
+       Add (missing) AccessibleImage_getExtents () API.
+
+       * docs/reference/cspi/at-spi-cspi-sections.txt:
+       Added AccessibleImage_getImageExtents () to docs.
+       
 2001-12-03  Bill Haneman  <bill.haneman@sun.com>
 
        * idl/Component.idl:
index a38cb1c..3bebd99 100644 (file)
@@ -1100,6 +1100,13 @@ AccessibleImage_getImagePosition (AccessibleImage *obj,
                                   long int *y,
                                   AccessibleCoordType ctype);
 
+void
+AccessibleImage_getImageExtents (AccessibleImage *obj,
+                                long int *x,
+                                long int *y,
+                                long int *width,
+                                long int *height,
+                                AccessibleCoordType ctype);
 /*
  *
  * AccessibleRelation function prototypes
index 103a69f..73f1556 100644 (file)
@@ -114,19 +114,15 @@ AccessibleComponent_getExtents (AccessibleComponent *obj,
                                 long int *height,
                                 AccessibleCoordType ctype)
 {
-  CORBA_long cx, cy, cw, ch;   
-  Accessibility_Component_getExtents (CSPI_OBJREF (obj),
-                                      &cx,
-                                      &cy,
-                                      &cw,
-                                      &ch,
-                                     ctype,
-                                     cspi_ev ());
+  Accessibility_BoundingBox bbox;
+  bbox = Accessibility_Component_getExtents (CSPI_OBJREF (obj),
+                                            ctype,
+                                            cspi_ev ());
   cspi_warn_ev (cspi_ev (), "AccessibleComponent_getExtents");
-  *x = (long) cx;
-  *y = (long) cy;
-  *width = (long) cw;
-  *height = (long) ch;
+  *x = bbox.x;
+  *y = bbox.y;
+  *width = bbox.width;
+  *height = bbox.height;
 }
 
 /**
index 2e0b5f3..c351ecf 100644 (file)
@@ -95,3 +95,35 @@ AccessibleImage_getImagePosition (AccessibleImage *obj,
                                        (CORBA_long *) x, (CORBA_long *) y, (CORBA_short) ctype,
                                        cspi_ev ());
 }
+
+/**
+ * AccessibleImage_getImageExtents:
+ * @obj: a pointer to the #AccessibleImage implementor to query.
+ * @x: a pointer to a #long into which the minimum x coordinate will be returned.
+ * @y: a pointer to a #long into which the minimum y coordinate will be returned.
+ * @width: a pointer to a #long into which the image x extent will be returned.
+ * @width: a pointer to a #long into which the image y extent will be returned.
+ * @ctype: the desired coordinate system into which to return the results,
+ *         (e.g. SPI_COORD_TYPE_WINDOW, SPI_COORD_TYPE_SCREEN).
+ *
+ * Get the bounding box of the image displayed in a
+ *         specified #AccessibleImage implementor.
+ *
+ **/
+void
+AccessibleImage_getImageExtents (AccessibleImage *obj,
+                                long *x,
+                                long *y,
+                                long *width,
+                                long *height,
+                                AccessibleCoordType ctype)
+{
+  Accessibility_BoundingBox bbox;      
+  bbox = Accessibility_Image_getImageExtents (CSPI_OBJREF (obj),
+                                             (CORBA_short) ctype,
+                                             cspi_ev ());
+  *x = bbox.x;
+  *y = bbox.y;
+  *width = bbox.width;
+  *height = bbox.height;
+}
index eae6b82..bac26c6 100644 (file)
@@ -154,6 +154,7 @@ AccessibleImage_unref
 AccessibleImage_getImageDescription
 AccessibleImage_getImageSize
 AccessibleImage_getImagePosition
+AccessibleImage_getImageExtents
 </SECTION>
 
 <SECTION>
index dae5ed1..cfebaa9 100644 (file)
@@ -33,6 +33,13 @@ module Accessibility {
   
   typedef sequence<Relation> RelationSet;
 
+  struct BoundingBox {
+         long x;
+         long y;
+         long width;
+         long height;
+  };
+
   interface Accessible : Bonobo::Unknown {
 
     /**
index 4900684..8044557 100644 (file)
@@ -39,7 +39,7 @@ module Accessibility {
 
         boolean contains (in long x, in long y, in short coord_type);
         Accessible getAccessibleAtPoint (in long x, in long y, in short coord_type);
-        void getExtents (out long x, out long y, out long width, out long height, in short coord_type);
+        BoundingBox getExtents (in short coord_type);
         void getPosition (out long x, out long y, in short coord_type);
         void getSize (out long width, out long height);
        ComponentLayer getLayer ();
index f1ea4d3..d819172 100644 (file)
@@ -24,8 +24,8 @@ module Accessibility {
 
   interface Image : Bonobo::Unknown  {
     readonly attribute string imageDescription;
+    BoundingBox getImageExtents (in short coordType);
     void getImagePosition (out long x, out long y, in short coordType);
-    void getImageExtents (out long x, out long y, out long width, out long height, in short coodrType);
     void getImageSize (out long width, out long height);
   };
 };
index 732c177..7e37256 100644 (file)
@@ -110,7 +110,8 @@ module Accessibility {
     void               add (in StateType state);
     void               remove (in StateType state);
     boolean            equals (in StateSet stateSet);
-    void               compare (in StateSet compareState, out StateSet differenceSet);
+    /* returns a 'difference set' */
+    StateSet            compare (in StateSet compareState);
     boolean            isEmpty ();
   };
 };
index dae5ed1..cfebaa9 100644 (file)
@@ -33,6 +33,13 @@ module Accessibility {
   
   typedef sequence<Relation> RelationSet;
 
+  struct BoundingBox {
+         long x;
+         long y;
+         long width;
+         long height;
+  };
+
   interface Accessible : Bonobo::Unknown {
 
     /**
index 4900684..8044557 100644 (file)
@@ -39,7 +39,7 @@ module Accessibility {
 
         boolean contains (in long x, in long y, in short coord_type);
         Accessible getAccessibleAtPoint (in long x, in long y, in short coord_type);
-        void getExtents (out long x, out long y, out long width, out long height, in short coord_type);
+        BoundingBox getExtents (in short coord_type);
         void getPosition (out long x, out long y, in short coord_type);
         void getSize (out long width, out long height);
        ComponentLayer getLayer ();
index f1ea4d3..d819172 100644 (file)
@@ -24,8 +24,8 @@ module Accessibility {
 
   interface Image : Bonobo::Unknown  {
     readonly attribute string imageDescription;
+    BoundingBox getImageExtents (in short coordType);
     void getImagePosition (out long x, out long y, in short coordType);
-    void getImageExtents (out long x, out long y, out long width, out long height, in short coodrType);
     void getImageSize (out long width, out long height);
   };
 };
index 732c177..7e37256 100644 (file)
@@ -110,7 +110,8 @@ module Accessibility {
     void               add (in StateType state);
     void               remove (in StateType state);
     boolean            equals (in StateSet stateSet);
-    void               compare (in StateSet compareState, out StateSet differenceSet);
+    /* returns a 'difference set' */
+    StateSet            compare (in StateSet compareState);
     boolean            isEmpty ();
   };
 };
index 62d4178..956e088 100644 (file)
@@ -80,7 +80,7 @@ static long _get_unique_id();
 static gboolean _device_event_controller_hook (gpointer source);
 
 SpiListenerStruct *
-spi_listener_struct_new (Accessibility_EventListener *listener, CORBA_Environment *ev)
+spi_listener_struct_new (Accessibility_EventListener listener, CORBA_Environment *ev)
 {
   SpiListenerStruct *retval = g_malloc (sizeof (SpiListenerStruct));
   retval->listener = bonobo_object_dup_ref (listener, ev);
@@ -201,6 +201,7 @@ static void
 parse_event_type (EventTypeStruct *etype, char *event_name)
 {
   gchar **split_string;
+  gchar *s;
 
   split_string = g_strsplit(event_name, ":", 4);
   etype->event_name = g_strndup(event_name, 255);
@@ -224,19 +225,23 @@ parse_event_type (EventTypeStruct *etype, char *event_name)
 
   if (split_string[1])
     {
-      etype->major = split_string[1];
+      etype->major = g_strdup (split_string[1]);
       if (split_string[2])
         {
-          etype->minor = split_string[2];
+          etype->minor = g_strdup (split_string[2]);
           if (split_string[3])
             {
-              etype->detail = split_string[3];
-              etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], split_string[3], NULL));
+              etype->detail = g_strdup (split_string[3]);
+             s = g_strconcat (split_string[1], split_string[2], split_string[3], NULL);
+              etype->hash = g_str_hash (s);
+             g_free (s);
             }
           else
             {
               etype->detail = g_strdup ("");
-              etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], NULL));
+             s = g_strconcat (split_string[1], split_string[2], NULL);
+             etype->hash = g_str_hash (s);
+             g_free (s);
             }
         }
       else
@@ -253,7 +258,7 @@ parse_event_type (EventTypeStruct *etype, char *event_name)
       etype->hash = g_str_hash ("");
     }
 
-  /* TODO: don't forget to free the strings from caller when done ! */
+  g_strfreev (split_string);
 }
 
 /**
@@ -545,19 +550,21 @@ _registry_notify_listeners (GList *listeners,
                             const Accessibility_Event *e_in,
                             CORBA_Environment *ev)
 {
-  int n;
-  int len;
+  gint n = 0;
   SpiListenerStruct *ls;
+  GList *list;
   EventTypeStruct etype;
   Accessibility_Event *e_out;
+  gchar *s;
   guint minor_hash;
   parse_event_type (&etype, e_in->type);
-  minor_hash = g_str_hash (g_strconcat (etype.major, etype.minor, NULL));
-  len = g_list_length (listeners);
+  s = g_strconcat (etype.major, etype.minor, NULL);
+  minor_hash = g_str_hash (s);
+  g_free (s);
 
-  for (n=0; n<len; ++n)
+  for (list = listeners; list; list = list->next)
     {
-      ls =  (SpiListenerStruct *) g_list_nth_data (listeners, n);
+      ls =  (SpiListenerStruct *) list->data;
 #ifdef SPI_SPI_LISTENER_DEBUG
       fprintf(stderr, "event hashes: %lx %lx %lx\n", ls->event_type_hash, etype.hash, minor_hash);
       fprintf(stderr, "event name: %s\n", etype.event_name);
@@ -565,8 +572,10 @@ _registry_notify_listeners (GList *listeners,
       if ((ls->event_type_hash == etype.hash) || (ls->event_type_hash == minor_hash))
         {
 #ifdef SPI_DEBUG
-          fprintf(stderr, "notifying listener #%d\n", n);
-          fprintf(stderr, "event source name %s\n", Accessibility_Accessible__get_name(e_in->source, ev));
+          fprintf(stderr, "notifying listener #%d\n", n++);
+         s = Accessibility_Accessible__get_name(e_in->source, ev);
+          fprintf(stderr, "event source name %s\n", s);
+         g_free (s);
 #endif
          e_out = ORBit_copy_value (e_in, TC_Accessibility_Event);
          e_out->source = bonobo_object_dup_ref (e_in->source, ev);
index 62d4178..956e088 100644 (file)
@@ -80,7 +80,7 @@ static long _get_unique_id();
 static gboolean _device_event_controller_hook (gpointer source);
 
 SpiListenerStruct *
-spi_listener_struct_new (Accessibility_EventListener *listener, CORBA_Environment *ev)
+spi_listener_struct_new (Accessibility_EventListener listener, CORBA_Environment *ev)
 {
   SpiListenerStruct *retval = g_malloc (sizeof (SpiListenerStruct));
   retval->listener = bonobo_object_dup_ref (listener, ev);
@@ -201,6 +201,7 @@ static void
 parse_event_type (EventTypeStruct *etype, char *event_name)
 {
   gchar **split_string;
+  gchar *s;
 
   split_string = g_strsplit(event_name, ":", 4);
   etype->event_name = g_strndup(event_name, 255);
@@ -224,19 +225,23 @@ parse_event_type (EventTypeStruct *etype, char *event_name)
 
   if (split_string[1])
     {
-      etype->major = split_string[1];
+      etype->major = g_strdup (split_string[1]);
       if (split_string[2])
         {
-          etype->minor = split_string[2];
+          etype->minor = g_strdup (split_string[2]);
           if (split_string[3])
             {
-              etype->detail = split_string[3];
-              etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], split_string[3], NULL));
+              etype->detail = g_strdup (split_string[3]);
+             s = g_strconcat (split_string[1], split_string[2], split_string[3], NULL);
+              etype->hash = g_str_hash (s);
+             g_free (s);
             }
           else
             {
               etype->detail = g_strdup ("");
-              etype->hash = g_str_hash ( g_strconcat (split_string[1], split_string[2], NULL));
+             s = g_strconcat (split_string[1], split_string[2], NULL);
+             etype->hash = g_str_hash (s);
+             g_free (s);
             }
         }
       else
@@ -253,7 +258,7 @@ parse_event_type (EventTypeStruct *etype, char *event_name)
       etype->hash = g_str_hash ("");
     }
 
-  /* TODO: don't forget to free the strings from caller when done ! */
+  g_strfreev (split_string);
 }
 
 /**
@@ -545,19 +550,21 @@ _registry_notify_listeners (GList *listeners,
                             const Accessibility_Event *e_in,
                             CORBA_Environment *ev)
 {
-  int n;
-  int len;
+  gint n = 0;
   SpiListenerStruct *ls;
+  GList *list;
   EventTypeStruct etype;
   Accessibility_Event *e_out;
+  gchar *s;
   guint minor_hash;
   parse_event_type (&etype, e_in->type);
-  minor_hash = g_str_hash (g_strconcat (etype.major, etype.minor, NULL));
-  len = g_list_length (listeners);
+  s = g_strconcat (etype.major, etype.minor, NULL);
+  minor_hash = g_str_hash (s);
+  g_free (s);
 
-  for (n=0; n<len; ++n)
+  for (list = listeners; list; list = list->next)
     {
-      ls =  (SpiListenerStruct *) g_list_nth_data (listeners, n);
+      ls =  (SpiListenerStruct *) list->data;
 #ifdef SPI_SPI_LISTENER_DEBUG
       fprintf(stderr, "event hashes: %lx %lx %lx\n", ls->event_type_hash, etype.hash, minor_hash);
       fprintf(stderr, "event name: %s\n", etype.event_name);
@@ -565,8 +572,10 @@ _registry_notify_listeners (GList *listeners,
       if ((ls->event_type_hash == etype.hash) || (ls->event_type_hash == minor_hash))
         {
 #ifdef SPI_DEBUG
-          fprintf(stderr, "notifying listener #%d\n", n);
-          fprintf(stderr, "event source name %s\n", Accessibility_Accessible__get_name(e_in->source, ev));
+          fprintf(stderr, "notifying listener #%d\n", n++);
+         s = Accessibility_Accessible__get_name(e_in->source, ev);
+          fprintf(stderr, "event source name %s\n", s);
+         g_free (s);
 #endif
          e_out = ORBit_copy_value (e_in, TC_Accessibility_Event);
          e_out->source = bonobo_object_dup_ref (e_in->source, ev);