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.
37 * @short_description: Functions as first-class objects
40 * A #GClosure represents a callback supplied by the programmer. It
41 * will generally comprise a function of some kind and a marshaller
42 * used to call it. It is the reponsibility of the marshaller to
43 * convert the arguments for the invocation from #GValue<!-- -->s into
44 * a suitable form, perform the callback on the converted arguments,
45 * and transform the return value back into a #GValue.
47 * In the case of C programs, a closure usually just holds a pointer
48 * to a function and maybe a data argument, and the marshaller
49 * converts between #GValue<!-- --> and native C types. The GObject
50 * library provides the #GCClosure type for this purpose. Bindings for
51 * other languages need marshallers which convert between #GValue<!--
52 * -->s and suitable representations in the runtime of the language in
53 * order to use functions written in that languages as callbacks.
55 * Within GObject, closures play an important role in the
56 * implementation of signals. When a signal is registered, the
57 * @c_marshaller argument to g_signal_new() specifies the default C
58 * marshaller for any closure which is connected to this
59 * signal. GObject provides a number of C marshallers for this
60 * purpose, see the g_cclosure_marshal_*() functions. Additional C
61 * marshallers can be generated with the <link
62 * linkend="glib-genmarshal">glib-genmarshal</link> utility. Closures
63 * can be explicitly connected to signals with
64 * g_signal_connect_closure(), but it usually more convenient to let
65 * GObject create a closure automatically by using one of the
66 * g_signal_connect_*() functions which take a callback function/user
69 * Using closures has a number of important advantages over a simple
70 * callback function/data pointer combination:
73 * Closures allow the callee to get the types of the callback parameters,
74 * which means that language bindings don't have to write individual glue
75 * for each callback type.
78 * The reference counting of #GClosure makes it easy to handle reentrancy
79 * right; if a callback is removed while it is being invoked, the closure
80 * and its parameters won't be freed until the invocation finishes.
83 * g_closure_invalidate() and invalidation notifiers allow callbacks to be
84 * automatically removed when the objects they point to go away.
90 #define CLOSURE_MAX_REF_COUNT ((1 << 15) - 1)
91 #define CLOSURE_MAX_N_GUARDS ((1 << 1) - 1)
92 #define CLOSURE_MAX_N_FNOTIFIERS ((1 << 2) - 1)
93 #define CLOSURE_MAX_N_INOTIFIERS ((1 << 8) - 1)
94 #define CLOSURE_N_MFUNCS(cl) ((cl)->meta_marshal + \
95 ((cl)->n_guards << 1L))
96 /* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */
97 #define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \
98 (cl)->n_fnotifiers + \
106 #define CHANGE_FIELD(_closure, _field, _OP, _value, _must_set, _SET_OLD, _SET_NEW) \
108 ClosureInt *cunion = (ClosureInt*) _closure; \
109 gint new_int, old_int, success; \
113 tmp.vint = old_int = cunion->vint; \
114 _SET_OLD tmp.closure._field; \
115 tmp.closure._field _OP _value; \
116 _SET_NEW tmp.closure._field; \
117 new_int = tmp.vint; \
118 success = g_atomic_int_compare_and_exchange (&cunion->vint, old_int, new_int); \
120 while (!success && _must_set); \
123 #define SWAP(_closure, _field, _value, _oldv) CHANGE_FIELD (_closure, _field, =, _value, TRUE, *(_oldv) =, (void) )
124 #define SET(_closure, _field, _value) CHANGE_FIELD (_closure, _field, =, _value, TRUE, (void), (void) )
125 #define INC(_closure, _field) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), (void) )
126 #define INC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), *(_newv) = )
127 #define DEC(_closure, _field) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), (void) )
128 #define DEC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), *(_newv) = )
130 #if 0 /* for non-thread-safe closures */
131 #define SWAP(cl,f,v,o) (void) (*(o) = cl->f, cl->f = v)
132 #define SET(cl,f,v) (void) (cl->f = v)
133 #define INC(cl,f) (void) (cl->f += 1)
134 #define INC_ASSIGN(cl,f,n) (void) (cl->f += 1, *(n) = cl->f)
135 #define DEC(cl,f) (void) (cl->f -= 1)
136 #define DEC_ASSIGN(cl,f,n) (void) (cl->f -= 1, *(n) = cl->f)
147 /* --- functions --- */
149 * g_closure_new_simple:
150 * @sizeof_closure: the size of the structure to allocate, must be at least
151 * <literal>sizeof (GClosure)</literal>
152 * @data: data to store in the @data field of the newly allocated #GClosure
154 * Allocates a struct of the given size and initializes the initial
155 * part as a #GClosure. This function is mainly useful when
156 * implementing new types of closures.
159 * typedef struct _MyClosure MyClosure;
163 * // extra data goes here
167 * my_closure_finalize (gpointer notify_data,
170 * MyClosure *my_closure = (MyClosure *)closure;
172 * // free extra data here
175 * MyClosure *my_closure_new (gpointer data)
178 * MyClosure *my_closure;
180 * closure = g_closure_new_simple (sizeof (MyClosure), data);
181 * my_closure = (MyClosure *) closure;
183 * // initialize extra data here
185 * g_closure_add_finalize_notifier (closure, notify_data,
186 * my_closure_finalize);
191 * Returns: (transfer full): a newly allocated #GClosure
194 g_closure_new_simple (guint sizeof_closure,
199 g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
201 closure = g_malloc0 (sizeof_closure);
202 SET (closure, ref_count, 1);
203 SET (closure, meta_marshal, 0);
204 SET (closure, n_guards, 0);
205 SET (closure, n_fnotifiers, 0);
206 SET (closure, n_inotifiers, 0);
207 SET (closure, in_inotify, FALSE);
208 SET (closure, floating, TRUE);
209 SET (closure, derivative_flag, 0);
210 SET (closure, in_marshal, FALSE);
211 SET (closure, is_invalid, FALSE);
212 closure->marshal = NULL;
213 closure->data = data;
214 closure->notifiers = NULL;
215 memset (G_STRUCT_MEMBER_P (closure, sizeof (*closure)), 0, sizeof_closure - sizeof (*closure));
221 closure_invoke_notifiers (GClosure *closure,
225 * meta_marshal n_guards n_guards n_fnotif. n_inotifiers
226 * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]]
228 * CLOSURE_N_MFUNCS(cl) = meta_marshal + n_guards + n_guards;
229 * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
231 * constrains/catches:
232 * - closure->notifiers may be reloacted during callback
233 * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
234 * - i.e. callbacks can be removed/added during invocation
235 * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=)
236 * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify)
237 * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY
238 * + closure->meta_marshal is const for all cases
239 * + none of the callbacks can cause recursion
240 * + closure->n_inotifiers is const 0 during FNOTIFY
244 GClosureNotifyData *ndata;
247 while (closure->n_fnotifiers)
250 DEC_ASSIGN (closure, n_fnotifiers, &n);
252 ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
253 closure->marshal = (GClosureMarshal) ndata->notify;
254 closure->data = ndata->data;
255 ndata->notify (ndata->data, closure);
257 closure->marshal = NULL;
258 closure->data = NULL;
261 SET (closure, in_inotify, TRUE);
262 while (closure->n_inotifiers)
265 DEC_ASSIGN (closure, n_inotifiers, &n);
267 ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
268 closure->marshal = (GClosureMarshal) ndata->notify;
269 closure->data = ndata->data;
270 ndata->notify (ndata->data, closure);
272 closure->marshal = NULL;
273 closure->data = NULL;
274 SET (closure, in_inotify, FALSE);
277 i = closure->n_guards;
278 offs = closure->meta_marshal;
281 ndata = closure->notifiers + offs + i;
282 ndata->notify (ndata->data, closure);
286 i = closure->n_guards;
287 offs = closure->meta_marshal + i;
290 ndata = closure->notifiers + offs + i;
291 ndata->notify (ndata->data, closure);
298 * g_closure_set_meta_marshal: (skip)
299 * @closure: a #GClosure
300 * @marshal_data: context-dependent data to pass to @meta_marshal
301 * @meta_marshal: a #GClosureMarshal function
303 * Sets the meta marshaller of @closure. A meta marshaller wraps
304 * @closure->marshal and modifies the way it is called in some
305 * fashion. The most common use of this facility is for C callbacks.
306 * The same marshallers (generated by <link
307 * linkend="glib-genmarshal">glib-genmarshal</link>) are used
308 * everywhere, but the way that we get the callback function
309 * differs. In most cases we want to use @closure->callback, but in
310 * other cases we want to use some different technique to retrieve the
313 * For example, class closures for signals (see
314 * g_signal_type_cclosure_new()) retrieve the callback function from a
315 * fixed offset in the class structure. The meta marshaller retrieves
316 * the right callback and passes it to the marshaller as the
317 * @marshal_data argument.
320 g_closure_set_meta_marshal (GClosure *closure,
321 gpointer marshal_data,
322 GClosureMarshal meta_marshal)
324 GClosureNotifyData *notifiers;
326 g_return_if_fail (closure != NULL);
327 g_return_if_fail (meta_marshal != NULL);
328 g_return_if_fail (closure->is_invalid == FALSE);
329 g_return_if_fail (closure->in_marshal == FALSE);
330 g_return_if_fail (closure->meta_marshal == 0);
332 notifiers = closure->notifiers;
333 closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
336 /* usually the meta marshal will be setup right after creation, so the
337 * g_memmove() should be rare-case scenario
339 g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
342 closure->notifiers[0].data = marshal_data;
343 closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
344 SET (closure, meta_marshal, 1);
348 * g_closure_add_marshal_guards: (skip)
349 * @closure: a #GClosure
350 * @pre_marshal_data: data to pass to @pre_marshal_notify
351 * @pre_marshal_notify: a function to call before the closure callback
352 * @post_marshal_data: data to pass to @post_marshal_notify
353 * @post_marshal_notify: a function to call after the closure callback
355 * Adds a pair of notifiers which get invoked before and after the
356 * closure callback, respectively. This is typically used to protect
357 * the extra arguments for the duration of the callback. See
358 * g_object_watch_closure() for an example of marshal guards.
361 g_closure_add_marshal_guards (GClosure *closure,
362 gpointer pre_marshal_data,
363 GClosureNotify pre_marshal_notify,
364 gpointer post_marshal_data,
365 GClosureNotify post_marshal_notify)
369 g_return_if_fail (closure != NULL);
370 g_return_if_fail (pre_marshal_notify != NULL);
371 g_return_if_fail (post_marshal_notify != NULL);
372 g_return_if_fail (closure->is_invalid == FALSE);
373 g_return_if_fail (closure->in_marshal == FALSE);
374 g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
376 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
377 if (closure->n_inotifiers)
378 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
379 closure->n_fnotifiers +
380 closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
381 closure->n_fnotifiers + 0)];
382 if (closure->n_inotifiers > 1)
383 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
384 closure->n_fnotifiers +
385 closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
386 closure->n_fnotifiers + 1)];
387 if (closure->n_fnotifiers)
388 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
389 closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
390 if (closure->n_fnotifiers > 1)
391 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
392 closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
393 if (closure->n_guards)
394 closure->notifiers[(closure->meta_marshal +
396 closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
397 i = closure->n_guards;
398 closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
399 closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
400 closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
401 closure->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
402 INC (closure, n_guards);
406 * g_closure_add_finalize_notifier: (skip)
407 * @closure: a #GClosure
408 * @notify_data: data to pass to @notify_func
409 * @notify_func: the callback function to register
411 * Registers a finalization notifier which will be called when the
412 * reference count of @closure goes down to 0. Multiple finalization
413 * notifiers on a single closure are invoked in unspecified order. If
414 * a single call to g_closure_unref() results in the closure being
415 * both invalidated and finalized, then the invalidate notifiers will
416 * be run before the finalize notifiers.
419 g_closure_add_finalize_notifier (GClosure *closure,
420 gpointer notify_data,
421 GClosureNotify notify_func)
425 g_return_if_fail (closure != NULL);
426 g_return_if_fail (notify_func != NULL);
427 g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
429 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
430 if (closure->n_inotifiers)
431 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
432 closure->n_fnotifiers +
433 closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
434 closure->n_fnotifiers + 0)];
435 i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers;
436 closure->notifiers[i].data = notify_data;
437 closure->notifiers[i].notify = notify_func;
438 INC (closure, n_fnotifiers);
442 * g_closure_add_invalidate_notifier: (skip)
443 * @closure: a #GClosure
444 * @notify_data: data to pass to @notify_func
445 * @notify_func: the callback function to register
447 * Registers an invalidation notifier which will be called when the
448 * @closure is invalidated with g_closure_invalidate(). Invalidation
449 * notifiers are invoked before finalization notifiers, in an
453 g_closure_add_invalidate_notifier (GClosure *closure,
454 gpointer notify_data,
455 GClosureNotify notify_func)
459 g_return_if_fail (closure != NULL);
460 g_return_if_fail (notify_func != NULL);
461 g_return_if_fail (closure->is_invalid == FALSE);
462 g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
464 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
465 i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers;
466 closure->notifiers[i].data = notify_data;
467 closure->notifiers[i].notify = notify_func;
468 INC (closure, n_inotifiers);
471 static inline gboolean
472 closure_try_remove_inotify (GClosure *closure,
473 gpointer notify_data,
474 GClosureNotify notify_func)
476 GClosureNotifyData *ndata, *nlast;
478 nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
479 for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
480 if (ndata->notify == notify_func && ndata->data == notify_data)
482 DEC (closure, n_inotifiers);
491 static inline gboolean
492 closure_try_remove_fnotify (GClosure *closure,
493 gpointer notify_data,
494 GClosureNotify notify_func)
496 GClosureNotifyData *ndata, *nlast;
498 nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
499 for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
500 if (ndata->notify == notify_func && ndata->data == notify_data)
502 DEC (closure, n_fnotifiers);
505 if (closure->n_inotifiers)
506 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
507 closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
508 closure->n_fnotifiers +
509 closure->n_inotifiers)];
517 * @closure: #GClosure to increment the reference count on
519 * Increments the reference count on a closure to force it staying
520 * alive while the caller holds a pointer to it.
522 * Returns: (transfer none): The @closure passed in, for convenience
525 g_closure_ref (GClosure *closure)
528 g_return_val_if_fail (closure != NULL, NULL);
529 g_return_val_if_fail (closure->ref_count > 0, NULL);
530 g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
532 INC_ASSIGN (closure, ref_count, &new_ref_count);
533 g_return_val_if_fail (new_ref_count > 1, NULL);
539 * g_closure_invalidate:
540 * @closure: GClosure to invalidate
542 * Sets a flag on the closure to indicate that its calling
543 * environment has become invalid, and thus causes any future
544 * invocations of g_closure_invoke() on this @closure to be
545 * ignored. Also, invalidation notifiers installed on the closure will
546 * be called at this point. Note that unless you are holding a
547 * reference to the closure yourself, the invalidation notifiers may
548 * unref the closure and cause it to be destroyed, so if you need to
549 * access the closure after calling g_closure_invalidate(), make sure
550 * that you've previously called g_closure_ref().
552 * Note that g_closure_invalidate() will also be called when the
553 * reference count of a closure drops to zero (unless it has already
554 * been invalidated before).
557 g_closure_invalidate (GClosure *closure)
559 g_return_if_fail (closure != NULL);
561 if (!closure->is_invalid)
563 gboolean was_invalid;
564 g_closure_ref (closure); /* preserve floating flag */
565 SWAP (closure, is_invalid, TRUE, &was_invalid);
566 /* invalidate only once */
568 closure_invoke_notifiers (closure, INOTIFY);
569 g_closure_unref (closure);
575 * @closure: #GClosure to decrement the reference count on
577 * Decrements the reference count of a closure after it was previously
578 * incremented by the same caller. If no other callers are using the
579 * closure, then the closure will be destroyed and freed.
582 g_closure_unref (GClosure *closure)
586 g_return_if_fail (closure != NULL);
587 g_return_if_fail (closure->ref_count > 0);
589 if (closure->ref_count == 1) /* last unref, invalidate first */
590 g_closure_invalidate (closure);
592 DEC_ASSIGN (closure, ref_count, &new_ref_count);
594 if (new_ref_count == 0)
596 closure_invoke_notifiers (closure, FNOTIFY);
597 g_free (closure->notifiers);
604 * @closure: #GClosure to decrement the initial reference count on, if it's
607 * Takes over the initial ownership of a closure. Each closure is
608 * initially created in a <firstterm>floating</firstterm> state, which
609 * means that the initial reference count is not owned by any caller.
610 * g_closure_sink() checks to see if the object is still floating, and
611 * if so, unsets the floating state and decreases the reference
612 * count. If the closure is not floating, g_closure_sink() does
613 * nothing. The reason for the existance of the floating state is to
614 * prevent cumbersome code sequences like:
616 * closure = g_cclosure_new (cb_func, cb_data);
617 * g_source_set_closure (source, closure);
618 * g_closure_unref (closure); // XXX GObject doesn't really need this
620 * Because g_source_set_closure() (and similar functions) take ownership of the
621 * initial reference count, if it is unowned, we instead can write:
623 * g_source_set_closure (source, g_cclosure_new (cb_func, cb_data));
626 * Generally, this function is used together with g_closure_ref(). Ane example
627 * of storing a closure for later notification looks like:
629 * static GClosure *notify_closure = NULL;
631 * foo_notify_set_closure (GClosure *closure)
633 * if (notify_closure)
634 * g_closure_unref (notify_closure);
635 * notify_closure = closure;
636 * if (notify_closure)
638 * g_closure_ref (notify_closure);
639 * g_closure_sink (notify_closure);
644 * Because g_closure_sink() may decrement the reference count of a closure
645 * (if it hasn't been called on @closure yet) just like g_closure_unref(),
646 * g_closure_ref() should be called prior to this function.
649 g_closure_sink (GClosure *closure)
651 g_return_if_fail (closure != NULL);
652 g_return_if_fail (closure->ref_count > 0);
654 /* floating is basically a kludge to avoid creating closures
655 * with a ref_count of 0. so the intial ref_count a closure has
656 * is unowned. with invoking g_closure_sink() code may
657 * indicate that it takes over that intiial ref_count.
659 if (closure->floating)
661 gboolean was_floating;
662 SWAP (closure, floating, FALSE, &was_floating);
663 /* unref floating flag only once */
665 g_closure_unref (closure);
670 * g_closure_remove_invalidate_notifier: (skip)
671 * @closure: a #GClosure
672 * @notify_data: data which was passed to g_closure_add_invalidate_notifier()
673 * when registering @notify_func
674 * @notify_func: the callback function to remove
676 * Removes an invalidation notifier.
678 * Notice that notifiers are automatically removed after they are run.
681 g_closure_remove_invalidate_notifier (GClosure *closure,
682 gpointer notify_data,
683 GClosureNotify notify_func)
685 g_return_if_fail (closure != NULL);
686 g_return_if_fail (notify_func != NULL);
688 if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while it's called */
689 ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
690 closure->data == notify_data)
691 closure->marshal = NULL;
692 else if (!closure_try_remove_inotify (closure, notify_data, notify_func))
693 g_warning (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)",
694 notify_func, notify_data);
698 * g_closure_remove_finalize_notifier: (skip)
699 * @closure: a #GClosure
700 * @notify_data: data which was passed to g_closure_add_finalize_notifier()
701 * when registering @notify_func
702 * @notify_func: the callback function to remove
704 * Removes a finalization notifier.
706 * Notice that notifiers are automatically removed after they are run.
709 g_closure_remove_finalize_notifier (GClosure *closure,
710 gpointer notify_data,
711 GClosureNotify notify_func)
713 g_return_if_fail (closure != NULL);
714 g_return_if_fail (notify_func != NULL);
716 if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while it's called */
717 ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
718 closure->data == notify_data)
719 closure->marshal = NULL;
720 else if (!closure_try_remove_fnotify (closure, notify_data, notify_func))
721 g_warning (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)",
722 notify_func, notify_data);
727 * @closure: a #GClosure
728 * @return_value: a #GValue to store the return value. May be %NULL if the
729 * callback of @closure doesn't return a value.
730 * @n_param_values: the length of the @param_values array
731 * @param_values: (array length=n_param_values): an array of
732 * #GValue<!-- -->s holding the arguments on which to
733 * invoke the callback of @closure
734 * @invocation_hint: a context-dependent invocation hint
736 * Invokes the closure, i.e. executes the callback represented by the @closure.
739 g_closure_invoke (GClosure *closure,
740 GValue /*out*/ *return_value,
741 guint n_param_values,
742 const GValue *param_values,
743 gpointer invocation_hint)
745 g_return_if_fail (closure != NULL);
747 g_closure_ref (closure); /* preserve floating flag */
748 if (!closure->is_invalid)
750 GClosureMarshal marshal;
751 gpointer marshal_data;
752 gboolean in_marshal = closure->in_marshal;
754 g_return_if_fail (closure->marshal || closure->meta_marshal);
756 SET (closure, in_marshal, TRUE);
757 if (closure->meta_marshal)
759 marshal_data = closure->notifiers[0].data;
760 marshal = (GClosureMarshal) closure->notifiers[0].notify;
765 marshal = closure->marshal;
768 closure_invoke_notifiers (closure, PRE_NOTIFY);
771 n_param_values, param_values,
775 closure_invoke_notifiers (closure, POST_NOTIFY);
776 SET (closure, in_marshal, in_marshal);
778 g_closure_unref (closure);
782 * g_closure_set_marshal: (skip)
783 * @closure: a #GClosure
784 * @marshal: a #GClosureMarshal function
786 * Sets the marshaller of @closure. The <literal>marshal_data</literal>
787 * of @marshal provides a way for a meta marshaller to provide additional
788 * information to the marshaller. (See g_closure_set_meta_marshal().) For
789 * GObject's C predefined marshallers (the g_cclosure_marshal_*()
790 * functions), what it provides is a callback function to use instead of
791 * @closure->callback.
794 g_closure_set_marshal (GClosure *closure,
795 GClosureMarshal marshal)
797 g_return_if_fail (closure != NULL);
798 g_return_if_fail (marshal != NULL);
800 if (closure->marshal && closure->marshal != marshal)
801 g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
802 closure->marshal, marshal);
804 closure->marshal = marshal;
808 * g_cclosure_new: (skip)
809 * @callback_func: the function to invoke
810 * @user_data: user data to pass to @callback_func
811 * @destroy_data: destroy notify to be called when @user_data is no longer used
813 * Creates a new closure which invokes @callback_func with @user_data as
814 * the last parameter.
816 * Returns: a new #GCClosure
819 g_cclosure_new (GCallback callback_func,
821 GClosureNotify destroy_data)
825 g_return_val_if_fail (callback_func != NULL, NULL);
827 closure = g_closure_new_simple (sizeof (GCClosure), user_data);
829 g_closure_add_finalize_notifier (closure, user_data, destroy_data);
830 ((GCClosure*) closure)->callback = (gpointer) callback_func;
836 * g_cclosure_new_swap: (skip)
837 * @callback_func: the function to invoke
838 * @user_data: user data to pass to @callback_func
839 * @destroy_data: destroy notify to be called when @user_data is no longer used
841 * Creates a new closure which invokes @callback_func with @user_data as
842 * the first parameter.
844 * Returns: (transfer full): a new #GCClosure
847 g_cclosure_new_swap (GCallback callback_func,
849 GClosureNotify destroy_data)
853 g_return_val_if_fail (callback_func != NULL, NULL);
855 closure = g_closure_new_simple (sizeof (GCClosure), user_data);
857 g_closure_add_finalize_notifier (closure, user_data, destroy_data);
858 ((GCClosure*) closure)->callback = (gpointer) callback_func;
859 SET (closure, derivative_flag, TRUE);
865 g_type_class_meta_marshal (GClosure *closure,
866 GValue /*out*/ *return_value,
867 guint n_param_values,
868 const GValue *param_values,
869 gpointer invocation_hint,
870 gpointer marshal_data)
874 /* GType itype = (GType) closure->data; */
875 guint offset = GPOINTER_TO_UINT (marshal_data);
877 class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
878 callback = G_STRUCT_MEMBER (gpointer, class, offset);
880 closure->marshal (closure,
882 n_param_values, param_values,
888 g_type_iface_meta_marshal (GClosure *closure,
889 GValue /*out*/ *return_value,
890 guint n_param_values,
891 const GValue *param_values,
892 gpointer invocation_hint,
893 gpointer marshal_data)
897 GType itype = (GType) closure->data;
898 guint offset = GPOINTER_TO_UINT (marshal_data);
900 class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
901 callback = G_STRUCT_MEMBER (gpointer, class, offset);
903 closure->marshal (closure,
905 n_param_values, param_values,
911 * g_signal_type_cclosure_new:
912 * @itype: the #GType identifier of an interface or classed type
913 * @struct_offset: the offset of the member function of @itype's class
914 * structure which is to be invoked by the new closure
916 * Creates a new closure which invokes the function found at the offset
917 * @struct_offset in the class structure of the interface or classed type
918 * identified by @itype.
920 * Returns: a new #GCClosure
923 g_signal_type_cclosure_new (GType itype,
928 g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
929 g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
931 closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
932 if (G_TYPE_IS_INTERFACE (itype))
933 g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
935 g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
942 value_to_ffi_type (const GValue *gvalue, gpointer *value)
944 ffi_type *rettype = NULL;
945 GType type = g_type_fundamental (G_VALUE_TYPE (gvalue));
946 g_assert (type != G_TYPE_INVALID);
953 rettype = &ffi_type_sint;
954 *value = (gpointer)&(gvalue->data[0].v_int);
958 rettype = &ffi_type_uint;
959 *value = (gpointer)&(gvalue->data[0].v_uint);
965 case G_TYPE_INTERFACE:
967 rettype = &ffi_type_pointer;
968 *value = (gpointer)&(gvalue->data[0].v_pointer);
971 rettype = &ffi_type_float;
972 *value = (gpointer)&(gvalue->data[0].v_float);
975 rettype = &ffi_type_double;
976 *value = (gpointer)&(gvalue->data[0].v_double);
979 rettype = &ffi_type_slong;
980 *value = (gpointer)&(gvalue->data[0].v_long);
983 rettype = &ffi_type_ulong;
984 *value = (gpointer)&(gvalue->data[0].v_ulong);
987 rettype = &ffi_type_sint64;
988 *value = (gpointer)&(gvalue->data[0].v_int64);
991 rettype = &ffi_type_uint64;
992 *value = (gpointer)&(gvalue->data[0].v_uint64);
995 rettype = &ffi_type_pointer;
997 g_warning ("value_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type));
1004 value_from_ffi_type (GValue *gvalue, gpointer *value)
1006 switch (g_type_fundamental (G_VALUE_TYPE (gvalue)))
1009 g_value_set_int (gvalue, *(gint*)value);
1012 g_value_set_float (gvalue, *(gfloat*)value);
1015 g_value_set_double (gvalue, *(gdouble*)value);
1017 case G_TYPE_BOOLEAN:
1018 g_value_set_boolean (gvalue, *(gboolean*)value);
1021 g_value_set_string (gvalue, *(gchar**)value);
1024 g_value_set_char (gvalue, *(gchar*)value);
1027 g_value_set_uchar (gvalue, *(guchar*)value);
1030 g_value_set_uint (gvalue, *(guint*)value);
1032 case G_TYPE_POINTER:
1033 g_value_set_pointer (gvalue, *(gpointer*)value);
1036 g_value_set_long (gvalue, *(glong*)value);
1039 g_value_set_ulong (gvalue, *(gulong*)value);
1042 g_value_set_int64 (gvalue, *(gint64*)value);
1045 g_value_set_uint64 (gvalue, *(guint64*)value);
1048 g_value_set_boxed (gvalue, *(gpointer*)value);
1051 g_warning ("value_from_ffi_type: Unsupported fundamental type: %s",
1052 g_type_name (g_type_fundamental (G_VALUE_TYPE (gvalue))));
1057 * g_cclosure_marshal_generic:
1058 * @closure: A #GClosure.
1059 * @return_gvalue: A #GValue to store the return value. May be %NULL
1060 * if the callback of closure doesn't return a value.
1061 * @n_param_values: The length of the @param_values array.
1062 * @param_values: An array of #GValue<!-- -->s holding the arguments
1063 * on which to invoke the callback of closure.
1064 * @invocation_hint: The invocation hint given as the last argument to
1065 * g_closure_invoke().
1066 * @marshal_data: Additional data specified when registering the
1067 * marshaller, see g_closure_set_marshal() and
1068 * g_closure_set_meta_marshal()
1070 * A generic marshaller function implemented via <ulink
1071 * url="http://sourceware.org/libffi/">libffi</ulink>.
1076 g_cclosure_marshal_generic (GClosure *closure,
1077 GValue *return_gvalue,
1078 guint n_param_values,
1079 const GValue *param_values,
1080 gpointer invocation_hint,
1081 gpointer marshal_data)
1090 GCClosure *cc = (GCClosure*) closure;
1092 if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1094 rtype = value_to_ffi_type (return_gvalue, &rvalue);
1098 rtype = &ffi_type_void;
1101 rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
1103 n_args = n_param_values + 1;
1104 atypes = g_alloca (sizeof (ffi_type *) * n_args);
1105 args = g_alloca (sizeof (gpointer) * n_args);
1107 if (G_CCLOSURE_SWAP_DATA (closure))
1109 atypes[n_args-1] = value_to_ffi_type (param_values + 0,
1111 atypes[0] = &ffi_type_pointer;
1112 args[0] = &closure->data;
1116 atypes[0] = value_to_ffi_type (param_values + 0, &args[0]);
1117 atypes[n_args-1] = &ffi_type_pointer;
1118 args[n_args-1] = &closure->data;
1121 for (i = 1; i < n_args - 1; i++)
1122 atypes[i] = value_to_ffi_type (param_values + i, &args[i]);
1124 if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK)
1127 ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
1129 if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1130 value_from_ffi_type (return_gvalue, rvalue);
1134 * g_cclosure_marshal_VOID__VOID:
1135 * @closure: the #GClosure to which the marshaller belongs
1136 * @return_value: ignored
1137 * @n_param_values: 1
1138 * @param_values: a #GValue array holding only the instance
1139 * @invocation_hint: the invocation hint given as the last argument
1140 * to g_closure_invoke()
1141 * @marshal_data: additional data specified when registering the marshaller
1143 * A marshaller for a #GCClosure with a callback of type
1144 * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>.
1148 * g_cclosure_marshal_VOID__BOOLEAN:
1149 * @closure: the #GClosure to which the marshaller belongs
1150 * @return_value: ignored
1151 * @n_param_values: 2
1152 * @param_values: a #GValue array holding the instance and the #gboolean parameter
1153 * @invocation_hint: the invocation hint given as the last argument
1154 * to g_closure_invoke()
1155 * @marshal_data: additional data specified when registering the marshaller
1157 * A marshaller for a #GCClosure with a callback of type
1158 * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>.
1162 * g_cclosure_marshal_VOID__CHAR:
1163 * @closure: the #GClosure to which the marshaller belongs
1164 * @return_value: ignored
1165 * @n_param_values: 2
1166 * @param_values: a #GValue array holding the instance and the #gchar parameter
1167 * @invocation_hint: the invocation hint given as the last argument
1168 * to g_closure_invoke()
1169 * @marshal_data: additional data specified when registering the marshaller
1171 * A marshaller for a #GCClosure with a callback of type
1172 * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>.
1176 * g_cclosure_marshal_VOID__UCHAR:
1177 * @closure: the #GClosure to which the marshaller belongs
1178 * @return_value: ignored
1179 * @n_param_values: 2
1180 * @param_values: a #GValue array holding the instance and the #guchar parameter
1181 * @invocation_hint: the invocation hint given as the last argument
1182 * to g_closure_invoke()
1183 * @marshal_data: additional data specified when registering the marshaller
1185 * A marshaller for a #GCClosure with a callback of type
1186 * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>.
1190 * g_cclosure_marshal_VOID__INT:
1191 * @closure: the #GClosure to which the marshaller belongs
1192 * @return_value: ignored
1193 * @n_param_values: 2
1194 * @param_values: a #GValue array holding the instance and the #gint parameter
1195 * @invocation_hint: the invocation hint given as the last argument
1196 * to g_closure_invoke()
1197 * @marshal_data: additional data specified when registering the marshaller
1199 * A marshaller for a #GCClosure with a callback of type
1200 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>.
1204 * g_cclosure_marshal_VOID__UINT:
1205 * @closure: the #GClosure to which the marshaller belongs
1206 * @return_value: ignored
1207 * @n_param_values: 2
1208 * @param_values: a #GValue array holding the instance and the #guint parameter
1209 * @invocation_hint: the invocation hint given as the last argument
1210 * to g_closure_invoke()
1211 * @marshal_data: additional data specified when registering the marshaller
1213 * A marshaller for a #GCClosure with a callback of type
1214 * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>.
1218 * g_cclosure_marshal_VOID__LONG:
1219 * @closure: the #GClosure to which the marshaller belongs
1220 * @return_value: ignored
1221 * @n_param_values: 2
1222 * @param_values: a #GValue array holding the instance and the #glong parameter
1223 * @invocation_hint: the invocation hint given as the last argument
1224 * to g_closure_invoke()
1225 * @marshal_data: additional data specified when registering the marshaller
1227 * A marshaller for a #GCClosure with a callback of type
1228 * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>.
1232 * g_cclosure_marshal_VOID__ULONG:
1233 * @closure: the #GClosure to which the marshaller belongs
1234 * @return_value: ignored
1235 * @n_param_values: 2
1236 * @param_values: a #GValue array holding the instance and the #gulong parameter
1237 * @invocation_hint: the invocation hint given as the last argument
1238 * to g_closure_invoke()
1239 * @marshal_data: additional data specified when registering the marshaller
1241 * A marshaller for a #GCClosure with a callback of type
1242 * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>.
1246 * g_cclosure_marshal_VOID__ENUM:
1247 * @closure: the #GClosure to which the marshaller belongs
1248 * @return_value: ignored
1249 * @n_param_values: 2
1250 * @param_values: a #GValue array holding the instance and the enumeration parameter
1251 * @invocation_hint: the invocation hint given as the last argument
1252 * to g_closure_invoke()
1253 * @marshal_data: additional data specified when registering the marshaller
1255 * A marshaller for a #GCClosure with a callback of type
1256 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type..
1260 * g_cclosure_marshal_VOID__FLAGS:
1261 * @closure: the #GClosure to which the marshaller belongs
1262 * @return_value: ignored
1263 * @n_param_values: 2
1264 * @param_values: a #GValue array holding the instance and the flags parameter
1265 * @invocation_hint: the invocation hint given as the last argument
1266 * to g_closure_invoke()
1267 * @marshal_data: additional data specified when registering the marshaller
1269 * A marshaller for a #GCClosure with a callback of type
1270 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type.
1274 * g_cclosure_marshal_VOID__FLOAT:
1275 * @closure: the #GClosure to which the marshaller belongs
1276 * @return_value: ignored
1277 * @n_param_values: 2
1278 * @param_values: a #GValue array holding the instance and the #gfloat parameter
1279 * @invocation_hint: the invocation hint given as the last argument
1280 * to g_closure_invoke()
1281 * @marshal_data: additional data specified when registering the marshaller
1283 * A marshaller for a #GCClosure with a callback of type
1284 * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>.
1288 * g_cclosure_marshal_VOID__DOUBLE:
1289 * @closure: the #GClosure to which the marshaller belongs
1290 * @return_value: ignored
1291 * @n_param_values: 2
1292 * @param_values: a #GValue array holding the instance and the #gdouble parameter
1293 * @invocation_hint: the invocation hint given as the last argument
1294 * to g_closure_invoke()
1295 * @marshal_data: additional data specified when registering the marshaller
1297 * A marshaller for a #GCClosure with a callback of type
1298 * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>.
1302 * g_cclosure_marshal_VOID__STRING:
1303 * @closure: the #GClosure to which the marshaller belongs
1304 * @return_value: ignored
1305 * @n_param_values: 2
1306 * @param_values: a #GValue array holding the instance and the #gchar* parameter
1307 * @invocation_hint: the invocation hint given as the last argument
1308 * to g_closure_invoke()
1309 * @marshal_data: additional data specified when registering the marshaller
1311 * A marshaller for a #GCClosure with a callback of type
1312 * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>.
1316 * g_cclosure_marshal_VOID__PARAM:
1317 * @closure: the #GClosure to which the marshaller belongs
1318 * @return_value: ignored
1319 * @n_param_values: 2
1320 * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
1321 * @invocation_hint: the invocation hint given as the last argument
1322 * to g_closure_invoke()
1323 * @marshal_data: additional data specified when registering the marshaller
1325 * A marshaller for a #GCClosure with a callback of type
1326 * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>.
1330 * g_cclosure_marshal_VOID__BOXED:
1331 * @closure: the #GClosure to which the marshaller belongs
1332 * @return_value: ignored
1333 * @n_param_values: 2
1334 * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
1335 * @invocation_hint: the invocation hint given as the last argument
1336 * to g_closure_invoke()
1337 * @marshal_data: additional data specified when registering the marshaller
1339 * A marshaller for a #GCClosure with a callback of type
1340 * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>.
1344 * g_cclosure_marshal_VOID__POINTER:
1345 * @closure: the #GClosure to which the marshaller belongs
1346 * @return_value: ignored
1347 * @n_param_values: 2
1348 * @param_values: a #GValue array holding the instance and the #gpointer parameter
1349 * @invocation_hint: the invocation hint given as the last argument
1350 * to g_closure_invoke()
1351 * @marshal_data: additional data specified when registering the marshaller
1353 * A marshaller for a #GCClosure with a callback of type
1354 * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>.
1358 * g_cclosure_marshal_VOID__OBJECT:
1359 * @closure: the #GClosure to which the marshaller belongs
1360 * @return_value: ignored
1361 * @n_param_values: 2
1362 * @param_values: a #GValue array holding the instance and the #GObject* parameter
1363 * @invocation_hint: the invocation hint given as the last argument
1364 * to g_closure_invoke()
1365 * @marshal_data: additional data specified when registering the marshaller
1367 * A marshaller for a #GCClosure with a callback of type
1368 * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>.
1372 * g_cclosure_marshal_VOID__VARIANT:
1373 * @closure: the #GClosure to which the marshaller belongs
1374 * @return_value: ignored
1375 * @n_param_values: 2
1376 * @param_values: a #GValue array holding the instance and the #GVariant* parameter
1377 * @invocation_hint: the invocation hint given as the last argument
1378 * to g_closure_invoke()
1379 * @marshal_data: additional data specified when registering the marshaller
1381 * A marshaller for a #GCClosure with a callback of type
1382 * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>.
1388 * g_cclosure_marshal_VOID__UINT_POINTER:
1389 * @closure: the #GClosure to which the marshaller belongs
1390 * @return_value: ignored
1391 * @n_param_values: 3
1392 * @param_values: a #GValue array holding instance, arg1 and arg2
1393 * @invocation_hint: the invocation hint given as the last argument
1394 * to g_closure_invoke()
1395 * @marshal_data: additional data specified when registering the marshaller
1397 * A marshaller for a #GCClosure with a callback of type
1398 * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>.
1402 * g_cclosure_marshal_BOOLEAN__FLAGS:
1403 * @closure: the #GClosure to which the marshaller belongs
1404 * @return_value: a #GValue which can store the returned #gboolean
1405 * @n_param_values: 2
1406 * @param_values: a #GValue array holding instance and arg1
1407 * @invocation_hint: the invocation hint given as the last argument
1408 * to g_closure_invoke()
1409 * @marshal_data: additional data specified when registering the marshaller
1411 * A marshaller for a #GCClosure with a callback of type
1412 * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter
1413 * denotes a flags type.
1417 * g_cclosure_marshal_BOOL__FLAGS:
1419 * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
1422 * g_cclosure_marshal_STRING__OBJECT_POINTER:
1423 * @closure: the #GClosure to which the marshaller belongs
1424 * @return_value: a #GValue, which can store the returned string
1425 * @n_param_values: 3
1426 * @param_values: a #GValue array holding instance, arg1 and arg2
1427 * @invocation_hint: the invocation hint given as the last argument
1428 * to g_closure_invoke()
1429 * @marshal_data: additional data specified when registering the marshaller
1431 * A marshaller for a #GCClosure with a callback of type
1432 * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
1435 * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
1436 * @closure: the #GClosure to which the marshaller belongs
1437 * @return_value: a #GValue, which can store the returned string
1438 * @n_param_values: 3
1439 * @param_values: a #GValue array holding instance, arg1 and arg2
1440 * @invocation_hint: the invocation hint given as the last argument
1441 * to g_closure_invoke()
1442 * @marshal_data: additional data specified when registering the marshaller
1444 * A marshaller for a #GCClosure with a callback of type
1445 * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.