Index: gobject/gclosure.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gclosure.c,v
retrieving revision 1.15
diff -u -p -r1.15 gclosure.c
--- gobject/gclosure.c	16 Sep 2004 18:52:40 -0000	1.15
+++ gobject/gclosure.c	10 Mar 2005 05:00:28 -0000
@@ -26,7 +26,6 @@
 /* FIXME: need caching allocators
  */
 
-#define	CLOSURE_MAX_REF_COUNT		((1 << 15) - 1)
 #define	CLOSURE_MAX_N_GUARDS		((1 << 1) - 1)
 #define	CLOSURE_MAX_N_FNOTIFIERS	((1 << 2) - 1)
 #define	CLOSURE_MAX_N_INOTIFIERS	((1 << 8) - 1)
@@ -54,7 +53,6 @@ g_closure_new_simple (guint           si
   g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
 
   closure = g_malloc (sizeof_closure);
-  closure->ref_count = 1;
   closure->meta_marshal = 0;
   closure->n_guards = 0;
   closure->n_fnotifiers = 0;
@@ -66,7 +64,9 @@ g_closure_new_simple (guint           si
   closure->is_invalid = FALSE;
   closure->marshal = NULL;
   closure->data = data;
-  closure->notifiers = NULL;
+  closure->priv = g_malloc (sizeof (GClosurePrivate));
+  closure->priv->ref_count = 1;
+  closure->priv->notifiers = NULL;
   memset (G_STRUCT_MEMBER_P (closure, sizeof (*closure)), 0, sizeof_closure - sizeof (*closure));
 
   return closure;
@@ -84,7 +84,7 @@ closure_invoke_notifiers (GClosure *clos
    * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
    *
    * constrains/catches:
-   * - closure->notifiers may be reloacted during callback
+   * - closure->priv->notifiers may be reloacted during callback
    * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
    * - i.e. callbacks can be removed/added during invocation
    * - have to prepare for callback removal during invocation (->marshal & ->data)
@@ -103,7 +103,7 @@ closure_invoke_notifiers (GClosure *clos
 	{
 	  register guint n = --closure->n_fnotifiers;
 
-	  ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
+	  ndata = closure->priv->notifiers + CLOSURE_N_MFUNCS (closure) + n;
 	  closure->marshal = (GClosureMarshal) ndata->notify;
 	  closure->data = ndata->data;
 	  ndata->notify (ndata->data, closure);
@@ -117,7 +117,7 @@ closure_invoke_notifiers (GClosure *clos
 	{
           register guint n = --closure->n_inotifiers;
 
-	  ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
+	  ndata = closure->priv->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
 	  closure->marshal = (GClosureMarshal) ndata->notify;
 	  closure->data = ndata->data;
 	  ndata->notify (ndata->data, closure);
@@ -131,7 +131,7 @@ closure_invoke_notifiers (GClosure *clos
       offs = closure->meta_marshal;
       while (i--)
 	{
-	  ndata = closure->notifiers + offs + i;
+	  ndata = closure->priv->notifiers + offs + i;
 	  ndata->notify (ndata->data, closure);
 	}
       break;
@@ -140,7 +140,7 @@ closure_invoke_notifiers (GClosure *clos
       offs = closure->meta_marshal + i;
       while (i--)
 	{
-	  ndata = closure->notifiers + offs + i;
+	  ndata = closure->priv->notifiers + offs + i;
 	  ndata->notify (ndata->data, closure);
 	}
       break;
@@ -162,18 +162,18 @@ g_closure_set_meta_marshal (GClosure    
   g_return_if_fail (closure->meta_marshal == 0);
 
   n = CLOSURE_N_NOTIFIERS (closure);
-  notifiers = closure->notifiers;
-  closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
+  notifiers = closure->priv->notifiers;
+  closure->priv->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
   if (notifiers)
     {
       /* usually the meta marshal will be setup right after creation, so the
        * g_memmove() should be rare-case scenario
        */
-      g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
+      g_memmove (closure->priv->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
       g_free (notifiers);
     }
-  closure->notifiers[0].data = marshal_data;
-  closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
+  closure->priv->notifiers[0].data = marshal_data;
+  closure->priv->notifiers[0].notify = (GClosureNotify) meta_marshal;
   closure->meta_marshal = 1;
 }
 
@@ -193,32 +193,32 @@ g_closure_add_marshal_guards (GClosure  
   g_return_if_fail (closure->in_marshal == FALSE);
   g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
 
-  closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
+  closure->priv->notifiers = g_renew (GClosureNotifyData, closure->priv->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
   if (closure->n_inotifiers)
-    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
+    closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
 			closure->n_fnotifiers +
-			closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
-									  closure->n_fnotifiers + 0)];
+			closure->n_inotifiers + 1)] = closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
+										closure->n_fnotifiers + 0)];
   if (closure->n_inotifiers > 1)
-    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
-			closure->n_fnotifiers +
-			closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
-								      closure->n_fnotifiers + 1)];
+    closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
+			      closure->n_fnotifiers +
+			      closure->n_inotifiers)] = closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
+										  closure->n_fnotifiers + 1)];
   if (closure->n_fnotifiers)
-    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
-			closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
+    closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
+			      closure->n_fnotifiers + 1)] = closure->priv->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
   if (closure->n_fnotifiers > 1)
-    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
-			closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
+    closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
+			closure->n_fnotifiers)] = closure->priv->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
   if (closure->n_guards)
-    closure->notifiers[(closure->meta_marshal +
+    closure->priv->notifiers[(closure->meta_marshal +
 			closure->n_guards +
-			closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
+			closure->n_guards + 1)] = closure->priv->notifiers[closure->meta_marshal + closure->n_guards];
   i = closure->n_guards++;
-  closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
-  closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
-  closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
-  closure->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
+  closure->priv->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
+  closure->priv->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
+  closure->priv->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
+  closure->priv->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
 }
 
 void
@@ -232,15 +232,15 @@ g_closure_add_finalize_notifier (GClosur
   g_return_if_fail (notify_func != NULL);
   g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
 
-  closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
+  closure->priv->notifiers = g_renew (GClosureNotifyData, closure->priv->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
   if (closure->n_inotifiers)
-    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
+    closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
 			closure->n_fnotifiers +
-			closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
-								      closure->n_fnotifiers + 0)];
+			closure->n_inotifiers)] = closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
+									    closure->n_fnotifiers + 0)];
   i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers++;
-  closure->notifiers[i].data = notify_data;
-  closure->notifiers[i].notify = notify_func;
+  closure->priv->notifiers[i].data = notify_data;
+  closure->priv->notifiers[i].notify = notify_func;
 }
 
 void
@@ -255,10 +255,10 @@ g_closure_add_invalidate_notifier (GClos
   g_return_if_fail (closure->is_invalid == FALSE);
   g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
 
-  closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
+  closure->priv->notifiers = g_renew (GClosureNotifyData, closure->priv->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
   i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers++;
-  closure->notifiers[i].data = notify_data;
-  closure->notifiers[i].notify = notify_func;
+  closure->priv->notifiers[i].data = notify_data;
+  closure->priv->notifiers[i].notify = notify_func;
 }
 
 static inline gboolean
@@ -268,7 +268,7 @@ closure_try_remove_inotify (GClosure    
 {
   GClosureNotifyData *ndata, *nlast;
 
-  nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
+  nlast = closure->priv->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
   for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
     if (ndata->notify == notify_func && ndata->data == notify_data)
       {
@@ -288,7 +288,7 @@ closure_try_remove_fnotify (GClosure    
 {
   GClosureNotifyData *ndata, *nlast;
 
-  nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
+  nlast = closure->priv->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
   for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
     if (ndata->notify == notify_func && ndata->data == notify_data)
       {
@@ -296,8 +296,8 @@ closure_try_remove_fnotify (GClosure    
 	if (ndata < nlast)
 	  *ndata = *nlast;
 	if (closure->n_inotifiers)
-	  closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
-			      closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
+	  closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
+				    closure->n_fnotifiers)] = closure->priv->notifiers[(CLOSURE_N_MFUNCS (closure) +
 									    closure->n_fnotifiers +
 									    closure->n_inotifiers)];
 	return TRUE;
@@ -309,10 +309,9 @@ GClosure*
 g_closure_ref (GClosure *closure)
 {
   g_return_val_if_fail (closure != NULL, NULL);
-  g_return_val_if_fail (closure->ref_count > 0, NULL);
-  g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
+  g_return_val_if_fail (closure->priv->ref_count > 0, NULL);
 
-  closure->ref_count += 1;
+  closure->priv->ref_count += 1;
 
   return closure;
 }
@@ -324,7 +323,7 @@ g_closure_invalidate (GClosure *closure)
 
   if (!closure->is_invalid)
     {
-      closure->ref_count += 1;	/* preserve floating flag */
+      closure->priv->ref_count += 1;	/* preserve floating flag */
       closure->is_invalid = TRUE;
       closure_invoke_notifiers (closure, INOTIFY);
       g_closure_unref (closure);
@@ -335,17 +334,18 @@ void
 g_closure_unref (GClosure *closure)
 {
   g_return_if_fail (closure != NULL);
-  g_return_if_fail (closure->ref_count > 0);
+  g_return_if_fail (closure->priv->ref_count > 0);
 
-  if (closure->ref_count == 1)	/* last unref, invalidate first */
+  if (closure->priv->ref_count == 1)	/* last unref, invalidate first */
     g_closure_invalidate (closure);
 
-  closure->ref_count -= 1;
+  closure->priv->ref_count -= 1;
 
-  if (closure->ref_count == 0)
+  if (closure->priv->ref_count == 0)
     {
       closure_invoke_notifiers (closure, FNOTIFY);
-      g_free (closure->notifiers);
+      g_free (closure->priv->notifiers);
+      g_free (closure->priv);
       g_free (closure);
     }
 }
@@ -354,7 +354,7 @@ void
 g_closure_sink (GClosure *closure)
 {
   g_return_if_fail (closure != NULL);
-  g_return_if_fail (closure->ref_count > 0);
+  g_return_if_fail (closure->priv->ref_count > 0);
 
   /* floating is basically a kludge to avoid creating closures
    * with a ref_count of 0. so the intial ref_count a closure has
@@ -364,8 +364,8 @@ g_closure_sink (GClosure *closure)
   if (closure->floating)
     {
       closure->floating = FALSE;
-      if (closure->ref_count > 1)
-	closure->ref_count -= 1;
+      if (closure->priv->ref_count > 1)
+	closure->priv->ref_count -= 1;
       else
 	g_closure_unref (closure);
     }
@@ -420,12 +420,12 @@ g_closure_invoke (GClosure       *closur
 
       g_return_if_fail (closure->marshal || closure->meta_marshal);
 
-      closure->ref_count += 1;	/* preserve floating flag */
+      closure->priv->ref_count += 1;	/* preserve floating flag */
       closure->in_marshal = TRUE;
       if (closure->meta_marshal)
 	{
-	  marshal_data = closure->notifiers[0].data;
-	  marshal = (GClosureMarshal) closure->notifiers[0].notify;
+	  marshal_data = closure->priv->notifiers[0].data;
+	  marshal = (GClosureMarshal) closure->priv->notifiers[0].notify;
 	}
       else
 	{
Index: gobject/gclosure.h
===================================================================
RCS file: /cvs/gnome/glib/gobject/gclosure.h,v
retrieving revision 1.14
diff -u -p -r1.14 gclosure.h
--- gobject/gclosure.h	23 Feb 2002 20:08:13 -0000	1.14
+++ gobject/gclosure.h	10 Mar 2005 05:00:28 -0000
@@ -37,6 +37,7 @@ G_BEGIN_DECLS
 
 /* -- typedefs --- */
 typedef struct _GClosure		 GClosure;
+typedef struct _GClosurePrivate		 GClosurePrivate;
 typedef struct _GClosureNotifyData	 GClosureNotifyData;
 typedef void  (*GCallback)              (void);
 typedef void  (*GClosureNotify)		(gpointer	 data,
@@ -56,9 +57,14 @@ struct _GClosureNotifyData
   gpointer       data;
   GClosureNotify notify;
 };
+struct _GClosurePrivate
+{
+  guint               ref_count;
+  GClosureNotifyData *notifiers;
+};
 struct _GClosure
 {
-  /*< private >*/	guint	 ref_count : 15;
+  /*< private >*/	guint	 reserved : 15;
   /*< private >*/	guint	 meta_marshal : 1;
   /*< private >*/	guint	 n_guards : 1;
   /*< private >*/	guint	 n_fnotifiers : 2;	/* finalization notifiers */
@@ -77,7 +83,7 @@ struct _GClosure
 					    gpointer	    marshal_data);
   /*< protected >*/	gpointer data;
 
-  /*< private >*/	GClosureNotifyData *notifiers;
+  /*< private >*/	GClosurePrivate *priv;
 
   /* invariants/constrains:
    * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE
