Remove C++ comment
[platform/upstream/glib.git] / gobject / gclosure.c
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 2000-2001 Red Hat, Inc.
3  * Copyright (C) 2005 Imendio AB
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 #include        "gclosure.h"
21
22 /*
23  * MT safe with regards to reference counting.
24  */
25
26 #include        "gvalue.h"
27 #include        "gobjectalias.h"
28 #include        <string.h>
29
30
31 #define CLOSURE_MAX_REF_COUNT           ((1 << 15) - 1)
32 #define CLOSURE_MAX_N_GUARDS            ((1 << 1) - 1)
33 #define CLOSURE_MAX_N_FNOTIFIERS        ((1 << 2) - 1)
34 #define CLOSURE_MAX_N_INOTIFIERS        ((1 << 8) - 1)
35 #define CLOSURE_N_MFUNCS(cl)            ((cl)->meta_marshal + \
36                                          ((cl)->n_guards << 1L))
37 /* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */
38 #define CLOSURE_N_NOTIFIERS(cl)         (CLOSURE_N_MFUNCS (cl) + \
39                                          (cl)->n_fnotifiers + \
40                                          (cl)->n_inotifiers)
41
42 typedef union {
43   GClosure closure;
44   volatile gint vint;
45 } ClosureInt;
46
47 #define CHANGE_FIELD(_closure, _field, _OP, _value, _must_set, _SET_OLD, _SET_NEW)      \
48 G_STMT_START {                                                                          \
49   ClosureInt *cunion = (ClosureInt*) _closure;                                          \
50   gint new_int, old_int, success;                                                       \
51   do                                                                                    \
52     {                                                                                   \
53       ClosureInt tmp;                                                                   \
54       tmp.vint = old_int = cunion->vint;                                                \
55       _SET_OLD tmp.closure._field;                                                      \
56       tmp.closure._field _OP _value;                                                    \
57       _SET_NEW tmp.closure._field;                                                      \
58       new_int = tmp.vint;                                                               \
59       success = g_atomic_int_compare_and_exchange (&cunion->vint, old_int, new_int);    \
60     }                                                                                   \
61   while (!success && _must_set);                                                        \
62 } G_STMT_END
63
64 #define SWAP(_closure, _field, _value, _oldv)   CHANGE_FIELD (_closure, _field, =, _value, TRUE, *(_oldv) =,     (void) )
65 #define SET(_closure, _field, _value)           CHANGE_FIELD (_closure, _field, =, _value, TRUE,     (void),     (void) )
66 #define INC(_closure, _field)                   CHANGE_FIELD (_closure, _field, +=,     1, TRUE,     (void),     (void) )
67 #define INC_ASSIGN(_closure, _field, _newv)     CHANGE_FIELD (_closure, _field, +=,     1, TRUE,     (void), *(_newv) = )
68 #define DEC(_closure, _field)                   CHANGE_FIELD (_closure, _field, -=,     1, TRUE,     (void),     (void) )
69 #define DEC_ASSIGN(_closure, _field, _newv)     CHANGE_FIELD (_closure, _field, -=,     1, TRUE,     (void), *(_newv) = )
70
71 #if 0   /* for non-thread-safe closures */
72 #define SWAP(cl,f,v,o)     (void) (*(o) = cl->f, cl->f = v)
73 #define SET(cl,f,v)        (void) (cl->f = v)
74 #define INC(cl,f)          (void) (cl->f += 1)
75 #define INC_ASSIGN(cl,f,n) (void) (cl->f += 1, *(n) = cl->f)
76 #define DEC(cl,f)          (void) (cl->f -= 1)
77 #define DEC_ASSIGN(cl,f,n) (void) (cl->f -= 1, *(n) = cl->f)
78 #endif
79
80 enum {
81   FNOTIFY,
82   INOTIFY,
83   PRE_NOTIFY,
84   POST_NOTIFY
85 };
86
87
88 /* --- functions --- */
89 GClosure*
90 g_closure_new_simple (guint           sizeof_closure,
91                       gpointer        data)
92 {
93   GClosure *closure;
94
95   g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
96
97   closure = g_malloc0 (sizeof_closure);
98   SET (closure, ref_count, 1);
99   SET (closure, meta_marshal, 0);
100   SET (closure, n_guards, 0);
101   SET (closure, n_fnotifiers, 0);
102   SET (closure, n_inotifiers, 0);
103   SET (closure, in_inotify, FALSE);
104   SET (closure, floating, TRUE);
105   SET (closure, derivative_flag, 0);
106   SET (closure, in_marshal, FALSE);
107   SET (closure, is_invalid, FALSE);
108   closure->marshal = NULL;
109   closure->data = data;
110   closure->notifiers = NULL;
111   memset (G_STRUCT_MEMBER_P (closure, sizeof (*closure)), 0, sizeof_closure - sizeof (*closure));
112
113   return closure;
114 }
115
116 static inline void
117 closure_invoke_notifiers (GClosure *closure,
118                           guint     notify_type)
119 {
120   /* notifier layout:
121    *     meta_marshal  n_guards    n_guards     n_fnotif.  n_inotifiers
122    * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]]
123    *
124    * CLOSURE_N_MFUNCS(cl)    = meta_marshal + n_guards + n_guards;
125    * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
126    *
127    * constrains/catches:
128    * - closure->notifiers may be reloacted during callback
129    * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
130    * - i.e. callbacks can be removed/added during invocation
131    * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=)
132    * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify)
133    * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY
134    * + closure->meta_marshal is const for all cases
135    * + none of the callbacks can cause recursion
136    * + closure->n_inotifiers is const 0 during FNOTIFY
137    */
138   switch (notify_type)
139     {
140       GClosureNotifyData *ndata;
141       guint i, offs;
142     case FNOTIFY:
143       while (closure->n_fnotifiers)
144         {
145           guint n;
146           DEC_ASSIGN (closure, n_fnotifiers, &n);
147
148           ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
149           closure->marshal = (GClosureMarshal) ndata->notify;
150           closure->data = ndata->data;
151           ndata->notify (ndata->data, closure);
152         }
153       closure->marshal = NULL;
154       closure->data = NULL;
155       break;
156     case INOTIFY:
157       SET (closure, in_inotify, TRUE);
158       while (closure->n_inotifiers)
159         {
160           guint n;
161           DEC_ASSIGN (closure, n_inotifiers, &n);
162
163           ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
164           closure->marshal = (GClosureMarshal) ndata->notify;
165           closure->data = ndata->data;
166           ndata->notify (ndata->data, closure);
167         }
168       closure->marshal = NULL;
169       closure->data = NULL;
170       SET (closure, in_inotify, FALSE);
171       break;
172     case PRE_NOTIFY:
173       i = closure->n_guards;
174       offs = closure->meta_marshal;
175       while (i--)
176         {
177           ndata = closure->notifiers + offs + i;
178           ndata->notify (ndata->data, closure);
179         }
180       break;
181     case POST_NOTIFY:
182       i = closure->n_guards;
183       offs = closure->meta_marshal + i;
184       while (i--)
185         {
186           ndata = closure->notifiers + offs + i;
187           ndata->notify (ndata->data, closure);
188         }
189       break;
190     }
191 }
192
193 void
194 g_closure_set_meta_marshal (GClosure       *closure,
195                             gpointer        marshal_data,
196                             GClosureMarshal meta_marshal)
197 {
198   GClosureNotifyData *notifiers;
199
200   g_return_if_fail (closure != NULL);
201   g_return_if_fail (meta_marshal != NULL);
202   g_return_if_fail (closure->is_invalid == FALSE);
203   g_return_if_fail (closure->in_marshal == FALSE);
204   g_return_if_fail (closure->meta_marshal == 0);
205
206   notifiers = closure->notifiers;
207   closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
208   if (notifiers)
209     {
210       /* usually the meta marshal will be setup right after creation, so the
211        * g_memmove() should be rare-case scenario
212        */
213       g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
214       g_free (notifiers);
215     }
216   closure->notifiers[0].data = marshal_data;
217   closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
218   SET (closure, meta_marshal, 1);
219 }
220
221 void
222 g_closure_add_marshal_guards (GClosure      *closure,
223                               gpointer       pre_marshal_data,
224                               GClosureNotify pre_marshal_notify,
225                               gpointer       post_marshal_data,
226                               GClosureNotify post_marshal_notify)
227 {
228   guint i;
229
230   g_return_if_fail (closure != NULL);
231   g_return_if_fail (pre_marshal_notify != NULL);
232   g_return_if_fail (post_marshal_notify != NULL);
233   g_return_if_fail (closure->is_invalid == FALSE);
234   g_return_if_fail (closure->in_marshal == FALSE);
235   g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
236
237   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
238   if (closure->n_inotifiers)
239     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
240                         closure->n_fnotifiers +
241                         closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
242                                                                           closure->n_fnotifiers + 0)];
243   if (closure->n_inotifiers > 1)
244     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
245                         closure->n_fnotifiers +
246                         closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
247                                                                       closure->n_fnotifiers + 1)];
248   if (closure->n_fnotifiers)
249     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
250                         closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
251   if (closure->n_fnotifiers > 1)
252     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
253                         closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
254   if (closure->n_guards)
255     closure->notifiers[(closure->meta_marshal +
256                         closure->n_guards +
257                         closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
258   i = closure->n_guards;
259   closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
260   closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
261   closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
262   closure->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
263   INC (closure, n_guards);
264 }
265
266 void
267 g_closure_add_finalize_notifier (GClosure      *closure,
268                                  gpointer       notify_data,
269                                  GClosureNotify notify_func)
270 {
271   guint i;
272
273   g_return_if_fail (closure != NULL);
274   g_return_if_fail (notify_func != NULL);
275   g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
276
277   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
278   if (closure->n_inotifiers)
279     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
280                         closure->n_fnotifiers +
281                         closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
282                                                                       closure->n_fnotifiers + 0)];
283   i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers;
284   closure->notifiers[i].data = notify_data;
285   closure->notifiers[i].notify = notify_func;
286   INC (closure, n_fnotifiers);
287 }
288
289 void
290 g_closure_add_invalidate_notifier (GClosure      *closure,
291                                    gpointer       notify_data,
292                                    GClosureNotify notify_func)
293 {
294   guint i;
295
296   g_return_if_fail (closure != NULL);
297   g_return_if_fail (notify_func != NULL);
298   g_return_if_fail (closure->is_invalid == FALSE);
299   g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
300
301   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
302   i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers;
303   closure->notifiers[i].data = notify_data;
304   closure->notifiers[i].notify = notify_func;
305   INC (closure, n_inotifiers);
306 }
307
308 static inline gboolean
309 closure_try_remove_inotify (GClosure       *closure,
310                             gpointer       notify_data,
311                             GClosureNotify notify_func)
312 {
313   GClosureNotifyData *ndata, *nlast;
314
315   nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
316   for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
317     if (ndata->notify == notify_func && ndata->data == notify_data)
318       {
319         DEC (closure, n_inotifiers);
320         if (ndata < nlast)
321           *ndata = *nlast;
322
323         return TRUE;
324       }
325   return FALSE;
326 }
327
328 static inline gboolean
329 closure_try_remove_fnotify (GClosure       *closure,
330                             gpointer       notify_data,
331                             GClosureNotify notify_func)
332 {
333   GClosureNotifyData *ndata, *nlast;
334
335   nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
336   for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
337     if (ndata->notify == notify_func && ndata->data == notify_data)
338       {
339         DEC (closure, n_fnotifiers);
340         if (ndata < nlast)
341           *ndata = *nlast;
342         if (closure->n_inotifiers)
343           closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
344                               closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
345                                                                             closure->n_fnotifiers +
346                                                                             closure->n_inotifiers)];
347         return TRUE;
348       }
349   return FALSE;
350 }
351
352 GClosure*
353 g_closure_ref (GClosure *closure)
354 {
355   guint new_ref_count;
356   g_return_val_if_fail (closure != NULL, NULL);
357   g_return_val_if_fail (closure->ref_count > 0, NULL);
358   g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
359
360   INC_ASSIGN (closure, ref_count, &new_ref_count);
361   g_return_val_if_fail (new_ref_count > 1, NULL);
362
363   return closure;
364 }
365
366 void
367 g_closure_invalidate (GClosure *closure)
368 {
369   g_return_if_fail (closure != NULL);
370
371   if (!closure->is_invalid)
372     {
373       gboolean was_invalid;
374       g_closure_ref (closure);           /* preserve floating flag */
375       SWAP (closure, is_invalid, TRUE, &was_invalid);
376       /* invalidate only once */
377       if (!was_invalid)
378         closure_invoke_notifiers (closure, INOTIFY);
379       g_closure_unref (closure);
380     }
381 }
382
383 void
384 g_closure_unref (GClosure *closure)
385 {
386   guint new_ref_count;
387
388   g_return_if_fail (closure != NULL);
389   g_return_if_fail (closure->ref_count > 0);
390
391   if (closure->ref_count == 1)  /* last unref, invalidate first */
392     g_closure_invalidate (closure);
393
394   DEC_ASSIGN (closure, ref_count, &new_ref_count);
395
396   if (new_ref_count == 0)
397     {
398       closure_invoke_notifiers (closure, FNOTIFY);
399       g_free (closure->notifiers);
400       g_free (closure);
401     }
402 }
403
404 void
405 g_closure_sink (GClosure *closure)
406 {
407   g_return_if_fail (closure != NULL);
408   g_return_if_fail (closure->ref_count > 0);
409
410   /* floating is basically a kludge to avoid creating closures
411    * with a ref_count of 0. so the intial ref_count a closure has
412    * is unowned. with invoking g_closure_sink() code may
413    * indicate that it takes over that intiial ref_count.
414    */
415   if (closure->floating)
416     {
417       gboolean was_floating;
418       SWAP (closure, floating, FALSE, &was_floating);
419       /* unref floating flag only once */
420       if (was_floating)
421         g_closure_unref (closure);
422     }
423 }
424
425 void
426 g_closure_remove_invalidate_notifier (GClosure      *closure,
427                                       gpointer       notify_data,
428                                       GClosureNotify notify_func)
429 {
430   g_return_if_fail (closure != NULL);
431   g_return_if_fail (notify_func != NULL);
432
433   if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while its called */
434       ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
435       closure->data == notify_data)
436     closure->marshal = NULL;
437   else if (!closure_try_remove_inotify (closure, notify_data, notify_func))
438     g_warning (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)",
439                notify_func, notify_data);
440 }
441
442 void
443 g_closure_remove_finalize_notifier (GClosure      *closure,
444                                     gpointer       notify_data,
445                                     GClosureNotify notify_func)
446 {
447   g_return_if_fail (closure != NULL);
448   g_return_if_fail (notify_func != NULL);
449
450   if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while its called */
451       ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
452       closure->data == notify_data)
453     closure->marshal = NULL;
454   else if (!closure_try_remove_fnotify (closure, notify_data, notify_func))
455     g_warning (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)",
456                notify_func, notify_data);
457 }
458
459 void
460 g_closure_invoke (GClosure       *closure,
461                   GValue /*out*/ *return_value,
462                   guint           n_param_values,
463                   const GValue   *param_values,
464                   gpointer        invocation_hint)
465 {
466   g_return_if_fail (closure != NULL);
467
468   g_closure_ref (closure);      /* preserve floating flag */
469   if (!closure->is_invalid)
470     {
471       GClosureMarshal marshal;
472       gpointer marshal_data;
473       gboolean in_marshal = closure->in_marshal;
474
475       g_return_if_fail (closure->marshal || closure->meta_marshal);
476
477       SET (closure, in_marshal, TRUE);
478       if (closure->meta_marshal)
479         {
480           marshal_data = closure->notifiers[0].data;
481           marshal = (GClosureMarshal) closure->notifiers[0].notify;
482         }
483       else
484         {
485           marshal_data = NULL;
486           marshal = closure->marshal;
487         }
488       if (!in_marshal)
489         closure_invoke_notifiers (closure, PRE_NOTIFY);
490       marshal (closure,
491                return_value,
492                n_param_values, param_values,
493                invocation_hint,
494                marshal_data);
495       if (!in_marshal)
496         closure_invoke_notifiers (closure, POST_NOTIFY);
497       SET (closure, in_marshal, in_marshal);
498     }
499   g_closure_unref (closure);
500 }
501
502 void
503 g_closure_set_marshal (GClosure       *closure,
504                        GClosureMarshal marshal)
505 {
506   g_return_if_fail (closure != NULL);
507   g_return_if_fail (marshal != NULL);
508
509   if (closure->marshal && closure->marshal != marshal)
510     g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
511                closure->marshal, marshal);
512   else
513     closure->marshal = marshal;
514 }
515
516 GClosure*
517 g_cclosure_new (GCallback      callback_func,
518                 gpointer       user_data,
519                 GClosureNotify destroy_data)
520 {
521   GClosure *closure;
522   
523   g_return_val_if_fail (callback_func != NULL, NULL);
524   
525   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
526   if (destroy_data)
527     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
528   ((GCClosure*) closure)->callback = (gpointer) callback_func;
529   
530   return closure;
531 }
532
533 GClosure*
534 g_cclosure_new_swap (GCallback      callback_func,
535                      gpointer       user_data,
536                      GClosureNotify destroy_data)
537 {
538   GClosure *closure;
539   
540   g_return_val_if_fail (callback_func != NULL, NULL);
541   
542   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
543   if (destroy_data)
544     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
545   ((GCClosure*) closure)->callback = (gpointer) callback_func;
546   SET (closure, derivative_flag, TRUE);
547   
548   return closure;
549 }
550
551 static void
552 g_type_class_meta_marshal (GClosure       *closure,
553                            GValue /*out*/ *return_value,
554                            guint           n_param_values,
555                            const GValue   *param_values,
556                            gpointer        invocation_hint,
557                            gpointer        marshal_data)
558 {
559   GTypeClass *class;
560   gpointer callback;
561   /* GType itype = (GType) closure->data; */
562   guint offset = GPOINTER_TO_UINT (marshal_data);
563   
564   class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
565   callback = G_STRUCT_MEMBER (gpointer, class, offset);
566   if (callback)
567     closure->marshal (closure,
568                       return_value,
569                       n_param_values, param_values,
570                       invocation_hint,
571                       callback);
572 }
573
574 static void
575 g_type_iface_meta_marshal (GClosure       *closure,
576                            GValue /*out*/ *return_value,
577                            guint           n_param_values,
578                            const GValue   *param_values,
579                            gpointer        invocation_hint,
580                            gpointer        marshal_data)
581 {
582   GTypeClass *class;
583   gpointer callback;
584   GType itype = (GType) closure->data;
585   guint offset = GPOINTER_TO_UINT (marshal_data);
586   
587   class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
588   callback = G_STRUCT_MEMBER (gpointer, class, offset);
589   if (callback)
590     closure->marshal (closure,
591                       return_value,
592                       n_param_values, param_values,
593                       invocation_hint,
594                       callback);
595 }
596
597 GClosure*
598 g_signal_type_cclosure_new (GType    itype,
599                             guint    struct_offset)
600 {
601   GClosure *closure;
602   
603   g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
604   g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
605   
606   closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
607   if (G_TYPE_IS_INTERFACE (itype))
608     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
609   else
610     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
611   
612   return closure;
613 }
614
615 #define __G_CLOSURE_C__
616 #include "gobjectaliasdef.c"