From a31b958e89b901eec190109be30183a8afc6989d Mon Sep 17 00:00:00 2001 From: billh Date: Tue, 4 Dec 2001 22:51:38 +0000 Subject: [PATCH] Changed IDL for State, Component, and Image to reduce use of out params. Fixed string memory leaks in registry.c. git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@135 e2bd861d-eb25-0410-b326-f6ed22b6b98c --- ChangeLog | 38 +++++++++++++++++++++++++++ cspi/spi.h | 7 +++++ cspi/spi_component.c | 20 ++++++-------- cspi/spi_image.c | 32 +++++++++++++++++++++++ docs/reference/cspi/at-spi-cspi-sections.txt | 1 + idl/Accessibility_Accessible.idl | 7 +++++ idl/Accessibility_Component.idl | 2 +- idl/Accessibility_Image.idl | 2 +- idl/Accessibility_State.idl | 3 ++- idl/Accessible.idl | 7 +++++ idl/Component.idl | 2 +- idl/Image.idl | 2 +- idl/State.idl | 3 ++- libspi/registry.c | 39 +++++++++++++++++----------- registryd/registry.c | 39 +++++++++++++++++----------- 15 files changed, 156 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 046ab2f..5feeebe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,41 @@ +2001-12-04 Bill Haneman + + * 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 + + * 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 * idl/Component.idl: diff --git a/cspi/spi.h b/cspi/spi.h index a38cb1c..3bebd99 100644 --- a/cspi/spi.h +++ b/cspi/spi.h @@ -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 diff --git a/cspi/spi_component.c b/cspi/spi_component.c index 103a69f..73f1556 100644 --- a/cspi/spi_component.c +++ b/cspi/spi_component.c @@ -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; } /** diff --git a/cspi/spi_image.c b/cspi/spi_image.c index 2e0b5f3..c351ecf 100644 --- a/cspi/spi_image.c +++ b/cspi/spi_image.c @@ -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; +} diff --git a/docs/reference/cspi/at-spi-cspi-sections.txt b/docs/reference/cspi/at-spi-cspi-sections.txt index eae6b82..bac26c6 100644 --- a/docs/reference/cspi/at-spi-cspi-sections.txt +++ b/docs/reference/cspi/at-spi-cspi-sections.txt @@ -154,6 +154,7 @@ AccessibleImage_unref AccessibleImage_getImageDescription AccessibleImage_getImageSize AccessibleImage_getImagePosition +AccessibleImage_getImageExtents
diff --git a/idl/Accessibility_Accessible.idl b/idl/Accessibility_Accessible.idl index dae5ed1..cfebaa9 100644 --- a/idl/Accessibility_Accessible.idl +++ b/idl/Accessibility_Accessible.idl @@ -33,6 +33,13 @@ module Accessibility { typedef sequence RelationSet; + struct BoundingBox { + long x; + long y; + long width; + long height; + }; + interface Accessible : Bonobo::Unknown { /** diff --git a/idl/Accessibility_Component.idl b/idl/Accessibility_Component.idl index 4900684..8044557 100644 --- a/idl/Accessibility_Component.idl +++ b/idl/Accessibility_Component.idl @@ -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 (); diff --git a/idl/Accessibility_Image.idl b/idl/Accessibility_Image.idl index f1ea4d3..d819172 100644 --- a/idl/Accessibility_Image.idl +++ b/idl/Accessibility_Image.idl @@ -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); }; }; diff --git a/idl/Accessibility_State.idl b/idl/Accessibility_State.idl index 732c177..7e37256 100644 --- a/idl/Accessibility_State.idl +++ b/idl/Accessibility_State.idl @@ -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 (); }; }; diff --git a/idl/Accessible.idl b/idl/Accessible.idl index dae5ed1..cfebaa9 100644 --- a/idl/Accessible.idl +++ b/idl/Accessible.idl @@ -33,6 +33,13 @@ module Accessibility { typedef sequence RelationSet; + struct BoundingBox { + long x; + long y; + long width; + long height; + }; + interface Accessible : Bonobo::Unknown { /** diff --git a/idl/Component.idl b/idl/Component.idl index 4900684..8044557 100644 --- a/idl/Component.idl +++ b/idl/Component.idl @@ -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 (); diff --git a/idl/Image.idl b/idl/Image.idl index f1ea4d3..d819172 100644 --- a/idl/Image.idl +++ b/idl/Image.idl @@ -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); }; }; diff --git a/idl/State.idl b/idl/State.idl index 732c177..7e37256 100644 --- a/idl/State.idl +++ b/idl/State.idl @@ -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 (); }; }; diff --git a/libspi/registry.c b/libspi/registry.c index 62d4178..956e088 100644 --- a/libspi/registry.c +++ b/libspi/registry.c @@ -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; nnext) { - 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); diff --git a/registryd/registry.c b/registryd/registry.c index 62d4178..956e088 100644 --- a/registryd/registry.c +++ b/registryd/registry.c @@ -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; nnext) { - 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); -- 2.7.4