From 3a044d6fafb9dc904ee9e6e9a2b25944caeb0e33 Mon Sep 17 00:00:00 2001 From: Michael Hutchinson Date: Wed, 19 Sep 2012 19:39:47 -0400 Subject: [PATCH] Fix stack overflow in subclasses of managed containers --- gtk/glue/container.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gtk/glue/container.c b/gtk/glue/container.c index b9c7b75b2..2e0d40737 100644 --- a/gtk/glue/container.c +++ b/gtk/glue/container.c @@ -20,15 +20,24 @@ */ #include +#include void gtksharp_container_base_forall (GtkContainer *container, gboolean include_internals, GtkCallback cb, gpointer data); void gtksharp_container_base_forall (GtkContainer *container, gboolean include_internals, GtkCallback cb, gpointer data) { - GtkContainerClass *parent = g_type_class_peek_parent (G_OBJECT_GET_CLASS (container)); - if (parent->forall) - (*parent->forall) (container, include_internals, cb, data); + // Find and call the first base callback that's not the GTK# callback. The GTK# callback calls down the whole + // managed override chain, so calling it on a subclass-of-a-managed-container-subclass causes a stack overflow. + GtkContainerClass *parent = (GtkContainerClass *) G_OBJECT_GET_CLASS (container); + while ((parent = g_type_class_peek_parent (parent))) { + if (strncmp (G_OBJECT_CLASS_NAME (parent), "__gtksharp_", 11) != 0) { + if (parent->forall) { + (*parent->forall) (container, include_internals, cb, data); + } + return; + } + } } void gtksharp_container_override_forall (GType gtype, gpointer cb);