1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
3 * Copyright (C) 2005 Imendio AB
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.
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.
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.
22 * MT safe with regards to reference counting.
34 #include "gvaluetypes.h"
39 * @short_description: Functions as first-class objects
42 * A #GClosure represents a callback supplied by the programmer. It
43 * will generally comprise a function of some kind and a marshaller
44 * used to call it. It is the reponsibility of the marshaller to
45 * convert the arguments for the invocation from #GValue<!-- -->s into
46 * a suitable form, perform the callback on the converted arguments,
47 * and transform the return value back into a #GValue.
49 * In the case of C programs, a closure usually just holds a pointer
50 * to a function and maybe a data argument, and the marshaller
51 * converts between #GValue<!-- --> and native C types. The GObject
52 * library provides the #GCClosure type for this purpose. Bindings for
53 * other languages need marshallers which convert between #GValue<!--
54 * -->s and suitable representations in the runtime of the language in
55 * order to use functions written in that languages as callbacks.
57 * Within GObject, closures play an important role in the
58 * implementation of signals. When a signal is registered, the
59 * @c_marshaller argument to g_signal_new() specifies the default C
60 * marshaller for any closure which is connected to this
61 * signal. GObject provides a number of C marshallers for this
62 * purpose, see the g_cclosure_marshal_*() functions. Additional C
63 * marshallers can be generated with the <link
64 * linkend="glib-genmarshal">glib-genmarshal</link> utility. Closures
65 * can be explicitly connected to signals with
66 * g_signal_connect_closure(), but it usually more convenient to let
67 * GObject create a closure automatically by using one of the
68 * g_signal_connect_*() functions which take a callback function/user
71 * Using closures has a number of important advantages over a simple
72 * callback function/data pointer combination:
75 * Closures allow the callee to get the types of the callback parameters,
76 * which means that language bindings don't have to write individual glue
77 * for each callback type.
80 * The reference counting of #GClosure makes it easy to handle reentrancy
81 * right; if a callback is removed while it is being invoked, the closure
82 * and its parameters won't be freed until the invocation finishes.
85 * g_closure_invalidate() and invalidation notifiers allow callbacks to be
86 * automatically removed when the objects they point to go away.
92 #define CLOSURE_MAX_REF_COUNT ((1 << 15) - 1)
93 #define CLOSURE_MAX_N_GUARDS ((1 << 1) - 1)
94 #define CLOSURE_MAX_N_FNOTIFIERS ((1 << 2) - 1)
95 #define CLOSURE_MAX_N_INOTIFIERS ((1 << 8) - 1)
96 #define CLOSURE_N_MFUNCS(cl) ((cl)->meta_marshal + \
97 ((cl)->n_guards << 1L))
98 /* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */
99 #define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \
100 (cl)->n_fnotifiers + \
108 #define CHANGE_FIELD(_closure, _field, _OP, _value, _must_set, _SET_OLD, _SET_NEW) \
110 ClosureInt *cunion = (ClosureInt*) _closure; \
111 gint new_int, old_int, success; \
115 tmp.vint = old_int = cunion->vint; \
116 _SET_OLD tmp.closure._field; \
117 tmp.closure._field _OP _value; \
118 _SET_NEW tmp.closure._field; \
119 new_int = tmp.vint; \
120 success = g_atomic_int_compare_and_exchange (&cunion->vint, old_int, new_int); \
122 while (!success && _must_set); \
125 #define SWAP(_closure, _field, _value, _oldv) CHANGE_FIELD (_closure, _field, =, _value, TRUE, *(_oldv) =, (void) )
126 #define SET(_closure, _field, _value) CHANGE_FIELD (_closure, _field, =, _value, TRUE, (void), (void) )
127 #define INC(_closure, _field) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), (void) )
128 #define INC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), *(_newv) = )
129 #define DEC(_closure, _field) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), (void) )
130 #define DEC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), *(_newv) = )
132 #if 0 /* for non-thread-safe closures */
133 #define SWAP(cl,f,v,o) (void) (*(o) = cl->f, cl->f = v)
134 #define SET(cl,f,v) (void) (cl->f = v)
135 #define INC(cl,f) (void) (cl->f += 1)
136 #define INC_ASSIGN(cl,f,n) (void) (cl->f += 1, *(n) = cl->f)
137 #define DEC(cl,f) (void) (cl->f -= 1)
138 #define DEC_ASSIGN(cl,f,n) (void) (cl->f -= 1, *(n) = cl->f)
149 /* --- functions --- */
151 * g_closure_new_simple:
152 * @sizeof_closure: the size of the structure to allocate, must be at least
153 * <literal>sizeof (GClosure)</literal>
154 * @data: data to store in the @data field of the newly allocated #GClosure
156 * Allocates a struct of the given size and initializes the initial
157 * part as a #GClosure. This function is mainly useful when
158 * implementing new types of closures.
161 * typedef struct _MyClosure MyClosure;
165 * // extra data goes here
169 * my_closure_finalize (gpointer notify_data,
172 * MyClosure *my_closure = (MyClosure *)closure;
174 * // free extra data here
177 * MyClosure *my_closure_new (gpointer data)
180 * MyClosure *my_closure;
182 * closure = g_closure_new_simple (sizeof (MyClosure), data);
183 * my_closure = (MyClosure *) closure;
185 * // initialize extra data here
187 * g_closure_add_finalize_notifier (closure, notify_data,
188 * my_closure_finalize);
193 * Returns: (transfer full): a newly allocated #GClosure
196 g_closure_new_simple (guint sizeof_closure,
201 g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
203 closure = g_malloc0 (sizeof_closure);
204 SET (closure, ref_count, 1);
205 SET (closure, meta_marshal, 0);
206 SET (closure, n_guards, 0);
207 SET (closure, n_fnotifiers, 0);
208 SET (closure, n_inotifiers, 0);
209 SET (closure, in_inotify, FALSE);
210 SET (closure, floating, TRUE);
211 SET (closure, derivative_flag, 0);
212 SET (closure, in_marshal, FALSE);
213 SET (closure, is_invalid, FALSE);
214 closure->marshal = NULL;
215 closure->data = data;
216 closure->notifiers = NULL;
217 memset (G_STRUCT_MEMBER_P (closure, sizeof (*closure)), 0, sizeof_closure - sizeof (*closure));
223 closure_invoke_notifiers (GClosure *closure,
227 * meta_marshal n_guards n_guards n_fnotif. n_inotifiers
228 * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]]
230 * CLOSURE_N_MFUNCS(cl) = meta_marshal + n_guards + n_guards;
231 * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
233 * constrains/catches:
234 * - closure->notifiers may be reloacted during callback
235 * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
236 * - i.e. callbacks can be removed/added during invocation
237 * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=)
238 * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify)
239 * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY
240 * + closure->meta_marshal is const for all cases
241 * + none of the callbacks can cause recursion
242 * + closure->n_inotifiers is const 0 during FNOTIFY
246 GClosureNotifyData *ndata;
249 while (closure->n_fnotifiers)
252 DEC_ASSIGN (closure, n_fnotifiers, &n);
254 ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
255 closure->marshal = (GClosureMarshal) ndata->notify;
256 closure->data = ndata->data;
257 ndata->notify (ndata->data, closure);
259 closure->marshal = NULL;
260 closure->data = NULL;
263 SET (closure, in_inotify, TRUE);
264 while (closure->n_inotifiers)
267 DEC_ASSIGN (closure, n_inotifiers, &n);
269 ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
270 closure->marshal = (GClosureMarshal) ndata->notify;
271 closure->data = ndata->data;
272 ndata->notify (ndata->data, closure);
274 closure->marshal = NULL;
275 closure->data = NULL;
276 SET (closure, in_inotify, FALSE);
279 i = closure->n_guards;
280 offs = closure->meta_marshal;
283 ndata = closure->notifiers + offs + i;
284 ndata->notify (ndata->data, closure);
288 i = closure->n_guards;
289 offs = closure->meta_marshal + i;
292 ndata = closure->notifiers + offs + i;
293 ndata->notify (ndata->data, closure);
300 * g_closure_set_meta_marshal: (skip)
301 * @closure: a #GClosure
302 * @marshal_data: context-dependent data to pass to @meta_marshal
303 * @meta_marshal: a #GClosureMarshal function
305 * Sets the meta marshaller of @closure. A meta marshaller wraps
306 * @closure->marshal and modifies the way it is called in some
307 * fashion. The most common use of this facility is for C callbacks.
308 * The same marshallers (generated by <link
309 * linkend="glib-genmarshal">glib-genmarshal</link>) are used
310 * everywhere, but the way that we get the callback function
311 * differs. In most cases we want to use @closure->callback, but in
312 * other cases we want to use some different technique to retrieve the
315 * For example, class closures for signals (see
316 * g_signal_type_cclosure_new()) retrieve the callback function from a
317 * fixed offset in the class structure. The meta marshaller retrieves
318 * the right callback and passes it to the marshaller as the
319 * @marshal_data argument.
322 g_closure_set_meta_marshal (GClosure *closure,
323 gpointer marshal_data,
324 GClosureMarshal meta_marshal)
326 GClosureNotifyData *notifiers;
328 g_return_if_fail (closure != NULL);
329 g_return_if_fail (meta_marshal != NULL);
330 g_return_if_fail (closure->is_invalid == FALSE);
331 g_return_if_fail (closure->in_marshal == FALSE);
332 g_return_if_fail (closure->meta_marshal == 0);
334 notifiers = closure->notifiers;
335 closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
338 /* usually the meta marshal will be setup right after creation, so the
339 * g_memmove() should be rare-case scenario
341 g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
344 closure->notifiers[0].data = marshal_data;
345 closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
346 SET (closure, meta_marshal, 1);
350 * g_closure_add_marshal_guards: (skip)
351 * @closure: a #GClosure
352 * @pre_marshal_data: data to pass to @pre_marshal_notify
353 * @pre_marshal_notify: a function to call before the closure callback
354 * @post_marshal_data: data to pass to @post_marshal_notify
355 * @post_marshal_notify: a function to call after the closure callback
357 * Adds a pair of notifiers which get invoked before and after the
358 * closure callback, respectively. This is typically used to protect
359 * the extra arguments for the duration of the callback. See
360 * g_object_watch_closure() for an example of marshal guards.
363 g_closure_add_marshal_guards (GClosure *closure,
364 gpointer pre_marshal_data,
365 GClosureNotify pre_marshal_notify,
366 gpointer post_marshal_data,
367 GClosureNotify post_marshal_notify)
371 g_return_if_fail (closure != NULL);
372 g_return_if_fail (pre_marshal_notify != NULL);
373 g_return_if_fail (post_marshal_notify != NULL);
374 g_return_if_fail (closure->is_invalid == FALSE);
375 g_return_if_fail (closure->in_marshal == FALSE);
376 g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
378 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
379 if (closure->n_inotifiers)
380 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
381 closure->n_fnotifiers +
382 closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
383 closure->n_fnotifiers + 0)];
384 if (closure->n_inotifiers > 1)
385 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
386 closure->n_fnotifiers +
387 closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
388 closure->n_fnotifiers + 1)];
389 if (closure->n_fnotifiers)
390 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
391 closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
392 if (closure->n_fnotifiers > 1)
393 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
394 closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
395 if (closure->n_guards)
396 closure->notifiers[(closure->meta_marshal +
398 closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
399 i = closure->n_guards;
400 closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
401 closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
402 closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
403 closure->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
404 INC (closure, n_guards);
408 * g_closure_add_finalize_notifier: (skip)
409 * @closure: a #GClosure
410 * @notify_data: data to pass to @notify_func
411 * @notify_func: the callback function to register
413 * Registers a finalization notifier which will be called when the
414 * reference count of @closure goes down to 0. Multiple finalization
415 * notifiers on a single closure are invoked in unspecified order. If
416 * a single call to g_closure_unref() results in the closure being
417 * both invalidated and finalized, then the invalidate notifiers will
418 * be run before the finalize notifiers.
421 g_closure_add_finalize_notifier (GClosure *closure,
422 gpointer notify_data,
423 GClosureNotify notify_func)
427 g_return_if_fail (closure != NULL);
428 g_return_if_fail (notify_func != NULL);
429 g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
431 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
432 if (closure->n_inotifiers)
433 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
434 closure->n_fnotifiers +
435 closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
436 closure->n_fnotifiers + 0)];
437 i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers;
438 closure->notifiers[i].data = notify_data;
439 closure->notifiers[i].notify = notify_func;
440 INC (closure, n_fnotifiers);
444 * g_closure_add_invalidate_notifier: (skip)
445 * @closure: a #GClosure
446 * @notify_data: data to pass to @notify_func
447 * @notify_func: the callback function to register
449 * Registers an invalidation notifier which will be called when the
450 * @closure is invalidated with g_closure_invalidate(). Invalidation
451 * notifiers are invoked before finalization notifiers, in an
455 g_closure_add_invalidate_notifier (GClosure *closure,
456 gpointer notify_data,
457 GClosureNotify notify_func)
461 g_return_if_fail (closure != NULL);
462 g_return_if_fail (notify_func != NULL);
463 g_return_if_fail (closure->is_invalid == FALSE);
464 g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
466 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
467 i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers;
468 closure->notifiers[i].data = notify_data;
469 closure->notifiers[i].notify = notify_func;
470 INC (closure, n_inotifiers);
473 static inline gboolean
474 closure_try_remove_inotify (GClosure *closure,
475 gpointer notify_data,
476 GClosureNotify notify_func)
478 GClosureNotifyData *ndata, *nlast;
480 nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
481 for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
482 if (ndata->notify == notify_func && ndata->data == notify_data)
484 DEC (closure, n_inotifiers);
493 static inline gboolean
494 closure_try_remove_fnotify (GClosure *closure,
495 gpointer notify_data,
496 GClosureNotify notify_func)
498 GClosureNotifyData *ndata, *nlast;
500 nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
501 for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
502 if (ndata->notify == notify_func && ndata->data == notify_data)
504 DEC (closure, n_fnotifiers);
507 if (closure->n_inotifiers)
508 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
509 closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
510 closure->n_fnotifiers +
511 closure->n_inotifiers)];
519 * @closure: #GClosure to increment the reference count on
521 * Increments the reference count on a closure to force it staying
522 * alive while the caller holds a pointer to it.
524 * Returns: (transfer none): The @closure passed in, for convenience
527 g_closure_ref (GClosure *closure)
530 g_return_val_if_fail (closure != NULL, NULL);
531 g_return_val_if_fail (closure->ref_count > 0, NULL);
532 g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
534 INC_ASSIGN (closure, ref_count, &new_ref_count);
535 g_return_val_if_fail (new_ref_count > 1, NULL);
541 * g_closure_invalidate:
542 * @closure: GClosure to invalidate
544 * Sets a flag on the closure to indicate that its calling
545 * environment has become invalid, and thus causes any future
546 * invocations of g_closure_invoke() on this @closure to be
547 * ignored. Also, invalidation notifiers installed on the closure will
548 * be called at this point. Note that unless you are holding a
549 * reference to the closure yourself, the invalidation notifiers may
550 * unref the closure and cause it to be destroyed, so if you need to
551 * access the closure after calling g_closure_invalidate(), make sure
552 * that you've previously called g_closure_ref().
554 * Note that g_closure_invalidate() will also be called when the
555 * reference count of a closure drops to zero (unless it has already
556 * been invalidated before).
559 g_closure_invalidate (GClosure *closure)
561 g_return_if_fail (closure != NULL);
563 if (!closure->is_invalid)
565 gboolean was_invalid;
566 g_closure_ref (closure); /* preserve floating flag */
567 SWAP (closure, is_invalid, TRUE, &was_invalid);
568 /* invalidate only once */
570 closure_invoke_notifiers (closure, INOTIFY);
571 g_closure_unref (closure);
577 * @closure: #GClosure to decrement the reference count on
579 * Decrements the reference count of a closure after it was previously
580 * incremented by the same caller. If no other callers are using the
581 * closure, then the closure will be destroyed and freed.
584 g_closure_unref (GClosure *closure)
588 g_return_if_fail (closure != NULL);
589 g_return_if_fail (closure->ref_count > 0);
591 if (closure->ref_count == 1) /* last unref, invalidate first */
592 g_closure_invalidate (closure);
594 DEC_ASSIGN (closure, ref_count, &new_ref_count);
596 if (new_ref_count == 0)
598 closure_invoke_notifiers (closure, FNOTIFY);
599 g_free (closure->notifiers);
606 * @closure: #GClosure to decrement the initial reference count on, if it's
609 * Takes over the initial ownership of a closure. Each closure is
610 * initially created in a <firstterm>floating</firstterm> state, which
611 * means that the initial reference count is not owned by any caller.
612 * g_closure_sink() checks to see if the object is still floating, and
613 * if so, unsets the floating state and decreases the reference
614 * count. If the closure is not floating, g_closure_sink() does
615 * nothing. The reason for the existance of the floating state is to
616 * prevent cumbersome code sequences like:
618 * closure = g_cclosure_new (cb_func, cb_data);
619 * g_source_set_closure (source, closure);
620 * g_closure_unref (closure); // XXX GObject doesn't really need this
622 * Because g_source_set_closure() (and similar functions) take ownership of the
623 * initial reference count, if it is unowned, we instead can write:
625 * g_source_set_closure (source, g_cclosure_new (cb_func, cb_data));
628 * Generally, this function is used together with g_closure_ref(). Ane example
629 * of storing a closure for later notification looks like:
631 * static GClosure *notify_closure = NULL;
633 * foo_notify_set_closure (GClosure *closure)
635 * if (notify_closure)
636 * g_closure_unref (notify_closure);
637 * notify_closure = closure;
638 * if (notify_closure)
640 * g_closure_ref (notify_closure);
641 * g_closure_sink (notify_closure);
646 * Because g_closure_sink() may decrement the reference count of a closure
647 * (if it hasn't been called on @closure yet) just like g_closure_unref(),
648 * g_closure_ref() should be called prior to this function.
651 g_closure_sink (GClosure *closure)
653 g_return_if_fail (closure != NULL);
654 g_return_if_fail (closure->ref_count > 0);
656 /* floating is basically a kludge to avoid creating closures
657 * with a ref_count of 0. so the intial ref_count a closure has
658 * is unowned. with invoking g_closure_sink() code may
659 * indicate that it takes over that intiial ref_count.
661 if (closure->floating)
663 gboolean was_floating;
664 SWAP (closure, floating, FALSE, &was_floating);
665 /* unref floating flag only once */
667 g_closure_unref (closure);
672 * g_closure_remove_invalidate_notifier: (skip)
673 * @closure: a #GClosure
674 * @notify_data: data which was passed to g_closure_add_invalidate_notifier()
675 * when registering @notify_func
676 * @notify_func: the callback function to remove
678 * Removes an invalidation notifier.
680 * Notice that notifiers are automatically removed after they are run.
683 g_closure_remove_invalidate_notifier (GClosure *closure,
684 gpointer notify_data,
685 GClosureNotify notify_func)
687 g_return_if_fail (closure != NULL);
688 g_return_if_fail (notify_func != NULL);
690 if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while it's called */
691 ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
692 closure->data == notify_data)
693 closure->marshal = NULL;
694 else if (!closure_try_remove_inotify (closure, notify_data, notify_func))
695 g_warning (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)",
696 notify_func, notify_data);
700 * g_closure_remove_finalize_notifier: (skip)
701 * @closure: a #GClosure
702 * @notify_data: data which was passed to g_closure_add_finalize_notifier()
703 * when registering @notify_func
704 * @notify_func: the callback function to remove
706 * Removes a finalization notifier.
708 * Notice that notifiers are automatically removed after they are run.
711 g_closure_remove_finalize_notifier (GClosure *closure,
712 gpointer notify_data,
713 GClosureNotify notify_func)
715 g_return_if_fail (closure != NULL);
716 g_return_if_fail (notify_func != NULL);
718 if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while it's called */
719 ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
720 closure->data == notify_data)
721 closure->marshal = NULL;
722 else if (!closure_try_remove_fnotify (closure, notify_data, notify_func))
723 g_warning (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)",
724 notify_func, notify_data);
729 * @closure: a #GClosure
730 * @return_value: a #GValue to store the return value. May be %NULL if the
731 * callback of @closure doesn't return a value.
732 * @n_param_values: the length of the @param_values array
733 * @param_values: (array length=n_param_values): an array of
734 * #GValue<!-- -->s holding the arguments on which to
735 * invoke the callback of @closure
736 * @invocation_hint: a context-dependent invocation hint
738 * Invokes the closure, i.e. executes the callback represented by the @closure.
741 g_closure_invoke (GClosure *closure,
742 GValue /*out*/ *return_value,
743 guint n_param_values,
744 const GValue *param_values,
745 gpointer invocation_hint)
747 g_return_if_fail (closure != NULL);
749 g_closure_ref (closure); /* preserve floating flag */
750 if (!closure->is_invalid)
752 GClosureMarshal marshal;
753 gpointer marshal_data;
754 gboolean in_marshal = closure->in_marshal;
756 g_return_if_fail (closure->marshal || closure->meta_marshal);
758 SET (closure, in_marshal, TRUE);
759 if (closure->meta_marshal)
761 marshal_data = closure->notifiers[0].data;
762 marshal = (GClosureMarshal) closure->notifiers[0].notify;
767 marshal = closure->marshal;
770 closure_invoke_notifiers (closure, PRE_NOTIFY);
773 n_param_values, param_values,
777 closure_invoke_notifiers (closure, POST_NOTIFY);
778 SET (closure, in_marshal, in_marshal);
780 g_closure_unref (closure);
784 * g_closure_set_marshal: (skip)
785 * @closure: a #GClosure
786 * @marshal: a #GClosureMarshal function
788 * Sets the marshaller of @closure. The <literal>marshal_data</literal>
789 * of @marshal provides a way for a meta marshaller to provide additional
790 * information to the marshaller. (See g_closure_set_meta_marshal().) For
791 * GObject's C predefined marshallers (the g_cclosure_marshal_*()
792 * functions), what it provides is a callback function to use instead of
793 * @closure->callback.
796 g_closure_set_marshal (GClosure *closure,
797 GClosureMarshal marshal)
799 g_return_if_fail (closure != NULL);
800 g_return_if_fail (marshal != NULL);
802 if (closure->marshal && closure->marshal != marshal)
803 g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
804 closure->marshal, marshal);
806 closure->marshal = marshal;
810 * g_cclosure_new: (skip)
811 * @callback_func: the function to invoke
812 * @user_data: user data to pass to @callback_func
813 * @destroy_data: destroy notify to be called when @user_data is no longer used
815 * Creates a new closure which invokes @callback_func with @user_data as
816 * the last parameter.
818 * Returns: a new #GCClosure
821 g_cclosure_new (GCallback callback_func,
823 GClosureNotify destroy_data)
827 g_return_val_if_fail (callback_func != NULL, NULL);
829 closure = g_closure_new_simple (sizeof (GCClosure), user_data);
831 g_closure_add_finalize_notifier (closure, user_data, destroy_data);
832 ((GCClosure*) closure)->callback = (gpointer) callback_func;
838 * g_cclosure_new_swap: (skip)
839 * @callback_func: the function to invoke
840 * @user_data: user data to pass to @callback_func
841 * @destroy_data: destroy notify to be called when @user_data is no longer used
843 * Creates a new closure which invokes @callback_func with @user_data as
844 * the first parameter.
846 * Returns: (transfer full): a new #GCClosure
849 g_cclosure_new_swap (GCallback callback_func,
851 GClosureNotify destroy_data)
855 g_return_val_if_fail (callback_func != NULL, NULL);
857 closure = g_closure_new_simple (sizeof (GCClosure), user_data);
859 g_closure_add_finalize_notifier (closure, user_data, destroy_data);
860 ((GCClosure*) closure)->callback = (gpointer) callback_func;
861 SET (closure, derivative_flag, TRUE);
867 g_type_class_meta_marshal (GClosure *closure,
868 GValue /*out*/ *return_value,
869 guint n_param_values,
870 const GValue *param_values,
871 gpointer invocation_hint,
872 gpointer marshal_data)
876 /* GType itype = (GType) closure->data; */
877 guint offset = GPOINTER_TO_UINT (marshal_data);
879 class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
880 callback = G_STRUCT_MEMBER (gpointer, class, offset);
882 closure->marshal (closure,
884 n_param_values, param_values,
890 g_type_iface_meta_marshal (GClosure *closure,
891 GValue /*out*/ *return_value,
892 guint n_param_values,
893 const GValue *param_values,
894 gpointer invocation_hint,
895 gpointer marshal_data)
899 GType itype = (GType) closure->data;
900 guint offset = GPOINTER_TO_UINT (marshal_data);
902 class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
903 callback = G_STRUCT_MEMBER (gpointer, class, offset);
905 closure->marshal (closure,
907 n_param_values, param_values,
913 * g_signal_type_cclosure_new:
914 * @itype: the #GType identifier of an interface or classed type
915 * @struct_offset: the offset of the member function of @itype's class
916 * structure which is to be invoked by the new closure
918 * Creates a new closure which invokes the function found at the offset
919 * @struct_offset in the class structure of the interface or classed type
920 * identified by @itype.
922 * Returns: a new #GCClosure
925 g_signal_type_cclosure_new (GType itype,
930 g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
931 g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
933 closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
934 if (G_TYPE_IS_INTERFACE (itype))
935 g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
937 g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
944 value_to_ffi_type (const GValue *gvalue, gpointer *value)
946 ffi_type *rettype = NULL;
947 GType type = g_type_fundamental (G_VALUE_TYPE (gvalue));
948 g_assert (type != G_TYPE_INVALID);
955 rettype = &ffi_type_sint;
956 *value = (gpointer)&(gvalue->data[0].v_int);
960 rettype = &ffi_type_uint;
961 *value = (gpointer)&(gvalue->data[0].v_uint);
967 case G_TYPE_INTERFACE:
969 rettype = &ffi_type_pointer;
970 *value = (gpointer)&(gvalue->data[0].v_pointer);
973 rettype = &ffi_type_float;
974 *value = (gpointer)&(gvalue->data[0].v_float);
977 rettype = &ffi_type_double;
978 *value = (gpointer)&(gvalue->data[0].v_double);
981 rettype = &ffi_type_slong;
982 *value = (gpointer)&(gvalue->data[0].v_long);
985 rettype = &ffi_type_ulong;
986 *value = (gpointer)&(gvalue->data[0].v_ulong);
989 rettype = &ffi_type_sint64;
990 *value = (gpointer)&(gvalue->data[0].v_int64);
993 rettype = &ffi_type_uint64;
994 *value = (gpointer)&(gvalue->data[0].v_uint64);
997 rettype = &ffi_type_pointer;
999 g_warning ("value_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type));
1006 value_from_ffi_type (GValue *gvalue, gpointer *value)
1008 switch (g_type_fundamental (G_VALUE_TYPE (gvalue)))
1011 g_value_set_int (gvalue, *(gint*)value);
1014 g_value_set_float (gvalue, *(gfloat*)value);
1017 g_value_set_double (gvalue, *(gdouble*)value);
1019 case G_TYPE_BOOLEAN:
1020 g_value_set_boolean (gvalue, *(gboolean*)value);
1023 g_value_set_string (gvalue, *(gchar**)value);
1026 g_value_set_char (gvalue, *(gchar*)value);
1029 g_value_set_uchar (gvalue, *(guchar*)value);
1032 g_value_set_uint (gvalue, *(guint*)value);
1034 case G_TYPE_POINTER:
1035 g_value_set_pointer (gvalue, *(gpointer*)value);
1038 g_value_set_long (gvalue, *(glong*)value);
1041 g_value_set_ulong (gvalue, *(gulong*)value);
1044 g_value_set_int64 (gvalue, *(gint64*)value);
1047 g_value_set_uint64 (gvalue, *(guint64*)value);
1050 g_value_set_boxed (gvalue, *(gpointer*)value);
1053 g_warning ("value_from_ffi_type: Unsupported fundamental type: %s",
1054 g_type_name (g_type_fundamental (G_VALUE_TYPE (gvalue))));
1059 * g_cclosure_marshal_generic:
1060 * @closure: A #GClosure.
1061 * @return_gvalue: A #GValue to store the return value. May be %NULL
1062 * if the callback of closure doesn't return a value.
1063 * @n_param_values: The length of the @param_values array.
1064 * @param_values: An array of #GValue<!-- -->s holding the arguments
1065 * on which to invoke the callback of closure.
1066 * @invocation_hint: The invocation hint given as the last argument to
1067 * g_closure_invoke().
1068 * @marshal_data: Additional data specified when registering the
1069 * marshaller, see g_closure_set_marshal() and
1070 * g_closure_set_meta_marshal()
1072 * A generic marshaller function implemented via <ulink
1073 * url="http://sourceware.org/libffi/">libffi</ulink>.
1078 g_cclosure_marshal_generic (GClosure *closure,
1079 GValue *return_gvalue,
1080 guint n_param_values,
1081 const GValue *param_values,
1082 gpointer invocation_hint,
1083 gpointer marshal_data)
1092 GCClosure *cc = (GCClosure*) closure;
1094 if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1096 rtype = value_to_ffi_type (return_gvalue, &rvalue);
1100 rtype = &ffi_type_void;
1103 rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
1105 n_args = n_param_values + 1;
1106 atypes = g_alloca (sizeof (ffi_type *) * n_args);
1107 args = g_alloca (sizeof (gpointer) * n_args);
1109 if (G_CCLOSURE_SWAP_DATA (closure))
1111 atypes[n_args-1] = value_to_ffi_type (param_values + 0,
1113 atypes[0] = &ffi_type_pointer;
1114 args[0] = &closure->data;
1118 atypes[0] = value_to_ffi_type (param_values + 0, &args[0]);
1119 atypes[n_args-1] = &ffi_type_pointer;
1120 args[n_args-1] = &closure->data;
1123 for (i = 1; i < n_args - 1; i++)
1124 atypes[i] = value_to_ffi_type (param_values + i, &args[i]);
1126 if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK)
1129 ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
1131 if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1132 value_from_ffi_type (return_gvalue, rvalue);
1136 * g_cclosure_marshal_VOID__VOID:
1137 * @closure: the #GClosure to which the marshaller belongs
1138 * @return_value: ignored
1139 * @n_param_values: 1
1140 * @param_values: a #GValue array holding only the instance
1141 * @invocation_hint: the invocation hint given as the last argument
1142 * to g_closure_invoke()
1143 * @marshal_data: additional data specified when registering the marshaller
1145 * A marshaller for a #GCClosure with a callback of type
1146 * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>.
1150 * g_cclosure_marshal_VOID__BOOLEAN:
1151 * @closure: the #GClosure to which the marshaller belongs
1152 * @return_value: ignored
1153 * @n_param_values: 2
1154 * @param_values: a #GValue array holding the instance and the #gboolean parameter
1155 * @invocation_hint: the invocation hint given as the last argument
1156 * to g_closure_invoke()
1157 * @marshal_data: additional data specified when registering the marshaller
1159 * A marshaller for a #GCClosure with a callback of type
1160 * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>.
1164 * g_cclosure_marshal_VOID__CHAR:
1165 * @closure: the #GClosure to which the marshaller belongs
1166 * @return_value: ignored
1167 * @n_param_values: 2
1168 * @param_values: a #GValue array holding the instance and the #gchar parameter
1169 * @invocation_hint: the invocation hint given as the last argument
1170 * to g_closure_invoke()
1171 * @marshal_data: additional data specified when registering the marshaller
1173 * A marshaller for a #GCClosure with a callback of type
1174 * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>.
1178 * g_cclosure_marshal_VOID__UCHAR:
1179 * @closure: the #GClosure to which the marshaller belongs
1180 * @return_value: ignored
1181 * @n_param_values: 2
1182 * @param_values: a #GValue array holding the instance and the #guchar parameter
1183 * @invocation_hint: the invocation hint given as the last argument
1184 * to g_closure_invoke()
1185 * @marshal_data: additional data specified when registering the marshaller
1187 * A marshaller for a #GCClosure with a callback of type
1188 * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>.
1192 * g_cclosure_marshal_VOID__INT:
1193 * @closure: the #GClosure to which the marshaller belongs
1194 * @return_value: ignored
1195 * @n_param_values: 2
1196 * @param_values: a #GValue array holding the instance and the #gint parameter
1197 * @invocation_hint: the invocation hint given as the last argument
1198 * to g_closure_invoke()
1199 * @marshal_data: additional data specified when registering the marshaller
1201 * A marshaller for a #GCClosure with a callback of type
1202 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>.
1206 * g_cclosure_marshal_VOID__UINT:
1207 * @closure: the #GClosure to which the marshaller belongs
1208 * @return_value: ignored
1209 * @n_param_values: 2
1210 * @param_values: a #GValue array holding the instance and the #guint parameter
1211 * @invocation_hint: the invocation hint given as the last argument
1212 * to g_closure_invoke()
1213 * @marshal_data: additional data specified when registering the marshaller
1215 * A marshaller for a #GCClosure with a callback of type
1216 * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>.
1220 * g_cclosure_marshal_VOID__LONG:
1221 * @closure: the #GClosure to which the marshaller belongs
1222 * @return_value: ignored
1223 * @n_param_values: 2
1224 * @param_values: a #GValue array holding the instance and the #glong parameter
1225 * @invocation_hint: the invocation hint given as the last argument
1226 * to g_closure_invoke()
1227 * @marshal_data: additional data specified when registering the marshaller
1229 * A marshaller for a #GCClosure with a callback of type
1230 * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>.
1234 * g_cclosure_marshal_VOID__ULONG:
1235 * @closure: the #GClosure to which the marshaller belongs
1236 * @return_value: ignored
1237 * @n_param_values: 2
1238 * @param_values: a #GValue array holding the instance and the #gulong parameter
1239 * @invocation_hint: the invocation hint given as the last argument
1240 * to g_closure_invoke()
1241 * @marshal_data: additional data specified when registering the marshaller
1243 * A marshaller for a #GCClosure with a callback of type
1244 * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>.
1248 * g_cclosure_marshal_VOID__ENUM:
1249 * @closure: the #GClosure to which the marshaller belongs
1250 * @return_value: ignored
1251 * @n_param_values: 2
1252 * @param_values: a #GValue array holding the instance and the enumeration parameter
1253 * @invocation_hint: the invocation hint given as the last argument
1254 * to g_closure_invoke()
1255 * @marshal_data: additional data specified when registering the marshaller
1257 * A marshaller for a #GCClosure with a callback of type
1258 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type..
1262 * g_cclosure_marshal_VOID__FLAGS:
1263 * @closure: the #GClosure to which the marshaller belongs
1264 * @return_value: ignored
1265 * @n_param_values: 2
1266 * @param_values: a #GValue array holding the instance and the flags parameter
1267 * @invocation_hint: the invocation hint given as the last argument
1268 * to g_closure_invoke()
1269 * @marshal_data: additional data specified when registering the marshaller
1271 * A marshaller for a #GCClosure with a callback of type
1272 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type.
1276 * g_cclosure_marshal_VOID__FLOAT:
1277 * @closure: the #GClosure to which the marshaller belongs
1278 * @return_value: ignored
1279 * @n_param_values: 2
1280 * @param_values: a #GValue array holding the instance and the #gfloat parameter
1281 * @invocation_hint: the invocation hint given as the last argument
1282 * to g_closure_invoke()
1283 * @marshal_data: additional data specified when registering the marshaller
1285 * A marshaller for a #GCClosure with a callback of type
1286 * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>.
1290 * g_cclosure_marshal_VOID__DOUBLE:
1291 * @closure: the #GClosure to which the marshaller belongs
1292 * @return_value: ignored
1293 * @n_param_values: 2
1294 * @param_values: a #GValue array holding the instance and the #gdouble parameter
1295 * @invocation_hint: the invocation hint given as the last argument
1296 * to g_closure_invoke()
1297 * @marshal_data: additional data specified when registering the marshaller
1299 * A marshaller for a #GCClosure with a callback of type
1300 * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>.
1304 * g_cclosure_marshal_VOID__STRING:
1305 * @closure: the #GClosure to which the marshaller belongs
1306 * @return_value: ignored
1307 * @n_param_values: 2
1308 * @param_values: a #GValue array holding the instance and the #gchar* parameter
1309 * @invocation_hint: the invocation hint given as the last argument
1310 * to g_closure_invoke()
1311 * @marshal_data: additional data specified when registering the marshaller
1313 * A marshaller for a #GCClosure with a callback of type
1314 * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>.
1318 * g_cclosure_marshal_VOID__PARAM:
1319 * @closure: the #GClosure to which the marshaller belongs
1320 * @return_value: ignored
1321 * @n_param_values: 2
1322 * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
1323 * @invocation_hint: the invocation hint given as the last argument
1324 * to g_closure_invoke()
1325 * @marshal_data: additional data specified when registering the marshaller
1327 * A marshaller for a #GCClosure with a callback of type
1328 * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>.
1332 * g_cclosure_marshal_VOID__BOXED:
1333 * @closure: the #GClosure to which the marshaller belongs
1334 * @return_value: ignored
1335 * @n_param_values: 2
1336 * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
1337 * @invocation_hint: the invocation hint given as the last argument
1338 * to g_closure_invoke()
1339 * @marshal_data: additional data specified when registering the marshaller
1341 * A marshaller for a #GCClosure with a callback of type
1342 * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>.
1346 * g_cclosure_marshal_VOID__POINTER:
1347 * @closure: the #GClosure to which the marshaller belongs
1348 * @return_value: ignored
1349 * @n_param_values: 2
1350 * @param_values: a #GValue array holding the instance and the #gpointer parameter
1351 * @invocation_hint: the invocation hint given as the last argument
1352 * to g_closure_invoke()
1353 * @marshal_data: additional data specified when registering the marshaller
1355 * A marshaller for a #GCClosure with a callback of type
1356 * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>.
1360 * g_cclosure_marshal_VOID__OBJECT:
1361 * @closure: the #GClosure to which the marshaller belongs
1362 * @return_value: ignored
1363 * @n_param_values: 2
1364 * @param_values: a #GValue array holding the instance and the #GObject* parameter
1365 * @invocation_hint: the invocation hint given as the last argument
1366 * to g_closure_invoke()
1367 * @marshal_data: additional data specified when registering the marshaller
1369 * A marshaller for a #GCClosure with a callback of type
1370 * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>.
1374 * g_cclosure_marshal_VOID__VARIANT:
1375 * @closure: the #GClosure to which the marshaller belongs
1376 * @return_value: ignored
1377 * @n_param_values: 2
1378 * @param_values: a #GValue array holding the instance and the #GVariant* parameter
1379 * @invocation_hint: the invocation hint given as the last argument
1380 * to g_closure_invoke()
1381 * @marshal_data: additional data specified when registering the marshaller
1383 * A marshaller for a #GCClosure with a callback of type
1384 * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>.
1390 * g_cclosure_marshal_VOID__UINT_POINTER:
1391 * @closure: the #GClosure to which the marshaller belongs
1392 * @return_value: ignored
1393 * @n_param_values: 3
1394 * @param_values: a #GValue array holding instance, arg1 and arg2
1395 * @invocation_hint: the invocation hint given as the last argument
1396 * to g_closure_invoke()
1397 * @marshal_data: additional data specified when registering the marshaller
1399 * A marshaller for a #GCClosure with a callback of type
1400 * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>.
1404 * g_cclosure_marshal_BOOLEAN__FLAGS:
1405 * @closure: the #GClosure to which the marshaller belongs
1406 * @return_value: a #GValue which can store the returned #gboolean
1407 * @n_param_values: 2
1408 * @param_values: a #GValue array holding instance and arg1
1409 * @invocation_hint: the invocation hint given as the last argument
1410 * to g_closure_invoke()
1411 * @marshal_data: additional data specified when registering the marshaller
1413 * A marshaller for a #GCClosure with a callback of type
1414 * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter
1415 * denotes a flags type.
1419 * g_cclosure_marshal_BOOL__FLAGS:
1421 * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
1424 * g_cclosure_marshal_STRING__OBJECT_POINTER:
1425 * @closure: the #GClosure to which the marshaller belongs
1426 * @return_value: a #GValue, which can store the returned string
1427 * @n_param_values: 3
1428 * @param_values: a #GValue array holding instance, arg1 and arg2
1429 * @invocation_hint: the invocation hint given as the last argument
1430 * to g_closure_invoke()
1431 * @marshal_data: additional data specified when registering the marshaller
1433 * A marshaller for a #GCClosure with a callback of type
1434 * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
1437 * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
1438 * @closure: the #GClosure to which the marshaller belongs
1439 * @return_value: a #GValue, which can store the returned string
1440 * @n_param_values: 3
1441 * @param_values: a #GValue array holding instance, arg1 and arg2
1442 * @invocation_hint: the invocation hint given as the last argument
1443 * to g_closure_invoke()
1444 * @marshal_data: additional data specified when registering the marshaller
1446 * A marshaller for a #GCClosure with a callback of type
1447 * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.