[-- Attachment #1: Type: text/plain, Size: 685 bytes --]
I wrote:
>
> I think gtk-container-children might be leaking memory.
I propose to free the returned list with the following change.
* gtk-support.c (_sgtk_helper_toscm_copy_GtkWidget): New function.
* gtk-support.c, guile-gtk.h (gtk_container_children_interp): New
function.
* gdk-1.2.defs (gtk_container_children): Use it.
This change fixes a memory leak in gtk-container-children, the GList
returned by gtk_container_children must be freed by the caller.
I suppose I could use _sgtk_helper_toscm_copy_GtkWidget from the glue
file if it wasn't static. The name would be ok to be a global. Easy
enough to duplicate for now though.
[-- Attachment #2: gtk-support.c.container-children.diff --]
[-- Type: text/plain, Size: 1029 bytes --]
--- gtk-support.c.~1.6.~ 2003-05-08 08:03:54.000000000 +1000
+++ gtk-support.c 2003-06-15 16:10:38.000000000 +1000
@@ -160,6 +160,30 @@
gtk_selection_data_data (GtkSelectionData* data)
{ return (data->length >= 0) ? scm_mem2string (data->data, data->length) : SCM_BOOL_F; }
+
+/* Same as in gtk-glue.c, could share with that file if it exported this. */
+static SCM
+_sgtk_helper_toscm_copy_GtkWidget (void *mem)
+{
+ return sgtk_wrap_gtkobj ((GtkObject*)(*(GtkWidget**)mem));
+}
+
+/* The list returned by gtk_container_children must be freed by the caller.
+ Could do this sort of thing with a .defs file option, but easy enough to
+ have explicit code while there's only a few such. */
+SCM
+gtk_container_children_interp (GtkContainer *container)
+{
+ GList* children;
+ SCM ret;
+ children = gtk_container_children (container);
+ ret = sgtk_list2scm (children, _sgtk_helper_toscm_copy_GtkWidget);
+ g_list_free (children);
+ return ret;
+}
+
+
+
\f
/* These SCM_PROCs are here to have them initialized in
[-- Attachment #3: guile-gtk.h.container-children.diff --]
[-- Type: text/plain, Size: 363 bytes --]
--- guile-gtk.h.~1.25.~ 2003-06-15 09:08:11.000000000 +1000
+++ guile-gtk.h 2003-06-15 16:11:10.000000000 +1000
@@ -322,6 +322,7 @@
typedef int GtkWidgetFlags;
#endif
+SCM gtk_container_children_interp (GtkContainer *container);
gchar *gtk_label_get_interp (GtkLabel *label);
void gtk_menu_popup_interp (GtkMenu *menu,
GtkWidget *parent_menu_shell,
[-- Attachment #4: gtk-1.2.defs.container-children.diff --]
[-- Type: text/plain, Size: 398 bytes --]
--- gtk-1.2.defs.~1.10.~ 2003-04-04 08:07:41.000000000 +1000
+++ gtk-1.2.defs 2003-06-15 16:08:51.000000000 +1000
@@ -888,8 +888,8 @@
(scm-name "gtk-container-foreach-full")
(protection #t))
-(define-func gtk_container_children
- ((list GtkWidget))
+(define-func gtk_container_children_interp
+ SCM ;; list of GtkWidget
((GtkContainer container)))
(define-func gtk_container_focus