1 /* GObject - GLib Type, Object, Parameter and Signal Library 2 * Copyright (C) 2000-2001 Red Hat, Inc. 3 * Copyright (C) 2005 Imendio AB 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General 16 * Public License along with this library; if not, write to the 17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 18 * Boston, MA 02111-1307, USA. 19 */ 20 21 /* 22 * MT safe with regards to reference counting. 23 */ 24 25 #include "config.h" 26 27 #include <string.h> 28 29 #include "gclosure.h" 30 #include "gvalue.h" 31 32 33 /** 34 * SECTION:gclosure 35 * @short_description: Functions as first-class objects 36 * @title: Closures 37 * 38 * A #GClosure represents a callback supplied by the programmer. It 39 * will generally comprise a function of some kind and a marshaller 40 * used to call it. It is the reponsibility of the marshaller to 41 * convert the arguments for the invocation from #GValue<!-- -->s into 42 * a suitable form, perform the callback on the converted arguments, 43 * and transform the return value back into a #GValue. 44 * 45 * In the case of C programs, a closure usually just holds a pointer 46 * to a function and maybe a data argument, and the marshaller 47 * converts between #GValue<!-- --> and native C types. The GObject 48 * library provides the #GCClosure type for this purpose. Bindings for 49 * other languages need marshallers which convert between #GValue<!-- 50 * -->s and suitable representations in the runtime of the language in 51 * order to use functions written in that languages as callbacks. 52 * 53 * Within GObject, closures play an important role in the 54 * implementation of signals. When a signal is registered, the 55 * @c_marshaller argument to g_signal_new() specifies the default C 56 * marshaller for any closure which is connected to this 57 * signal. GObject provides a number of C marshallers for this 58 * purpose, see the g_cclosure_marshal_*() functions. Additional C 59 * marshallers can be generated with the <link 60 * linkend="glib-genmarshal">glib-genmarshal</link> utility. Closures 61 * can be explicitly connected to signals with 62 * g_signal_connect_closure(), but it usually more convenient to let 63 * GObject create a closure automatically by using one of the 64 * g_signal_connect_*() functions which take a callback function/user 65 * data pair. 66 * 67 * Using closures has a number of important advantages over a simple 68 * callback function/data pointer combination: 69 * <itemizedlist> 70 * <listitem><para> 71 * Closures allow the callee to get the types of the callback parameters, 72 * which means that language bindings don't have to write individual glue 73 * for each callback type. 74 * </para></listitem> 75 * <listitem><para> 76 * The reference counting of #GClosure makes it easy to handle reentrancy 77 * right; if a callback is removed while it is being invoked, the closure 78 * and its parameters won't be freed until the invocation finishes. 79 * </para></listitem> 80 * <listitem><para> 81 * g_closure_invalidate() and invalidation notifiers allow callbacks to be 82 * automatically removed when the objects they point to go away. 83 * </para></listitem> 84 * </itemizedlist> 85 */ 86 87 88 #define CLOSURE_MAX_REF_COUNT ((1 << 15) - 1) 89 #define CLOSURE_MAX_N_GUARDS ((1 << 1) - 1) 90 #define CLOSURE_MAX_N_FNOTIFIERS ((1 << 2) - 1) 91 #define CLOSURE_MAX_N_INOTIFIERS ((1 << 8) - 1) 92 #define CLOSURE_N_MFUNCS(cl) ((cl)->meta_marshal + \ 93 ((cl)->n_guards << 1L)) 94 /* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */ 95 #define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \ 96 (cl)->n_fnotifiers + \ 97 (cl)->n_inotifiers) 98 99 typedef union { 100 GClosure closure; 101 volatile gint vint; 102 } ClosureInt; 103 104 #define CHANGE_FIELD(_closure, _field, _OP, _value, _must_set, _SET_OLD, _SET_NEW) \ 105 G_STMT_START { \ 106 ClosureInt *cunion = (ClosureInt*) _closure; \ 107 gint new_int, old_int, success; \ 108 do \ 109 { \ 110 ClosureInt tmp; \ 111 tmp.vint = old_int = cunion->vint; \ 112 _SET_OLD tmp.closure._field; \ 113 tmp.closure._field _OP _value; \ 114 _SET_NEW tmp.closure._field; \ 115 new_int = tmp.vint; \ 116 success = g_atomic_int_compare_and_exchange (&cunion->vint, old_int, new_int); \ 117 } \ 118 while (!success && _must_set); \ 119 } G_STMT_END 120 121 #define SWAP(_closure, _field, _value, _oldv) CHANGE_FIELD (_closure, _field, =, _value, TRUE, *(_oldv) =, (void) ) 122 #define SET(_closure, _field, _value) CHANGE_FIELD (_closure, _field, =, _value, TRUE, (void), (void) ) 123 #define INC(_closure, _field) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), (void) ) 124 #define INC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), *(_newv) = ) 125 #define DEC(_closure, _field) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), (void) ) 126 #define DEC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), *(_newv) = ) 127 128 #if 0 /* for non-thread-safe closures */ 129 #define SWAP(cl,f,v,o) (void) (*(o) = cl->f, cl->f = v) 130 #define SET(cl,f,v) (void) (cl->f = v) 131 #define INC(cl,f) (void) (cl->f += 1) 132 #define INC_ASSIGN(cl,f,n) (void) (cl->f += 1, *(n) = cl->f) 133 #define DEC(cl,f) (void) (cl->f -= 1) 134 #define DEC_ASSIGN(cl,f,n) (void) (cl->f -= 1, *(n) = cl->f) 135 #endif 136 137 enum { 138 FNOTIFY, 139 INOTIFY, 140 PRE_NOTIFY, 141 POST_NOTIFY 142 }; 143 144 145 /* --- functions --- */ 146 /** 147 * g_closure_new_simple: 148 * @sizeof_closure: the size of the structure to allocate, must be at least 149 * <literal>sizeof (GClosure)</literal> 150 * @data: data to store in the @data field of the newly allocated #GClosure 151 * 152 * Allocates a struct of the given size and initializes the initial 153 * part as a #GClosure. This function is mainly useful when 154 * implementing new types of closures. 155 * 156 * |[ 157 * typedef struct _MyClosure MyClosure; 158 * struct _MyClosure 159 * { 160 * GClosure closure; 161 * // extra data goes here 162 * }; 163 * 164 * static void 165 * my_closure_finalize (gpointer notify_data, 166 * GClosure *closure) 167 * { 168 * MyClosure *my_closure = (MyClosure *)closure; 169 * 170 * // free extra data here 171 * } 172 * 173 * MyClosure *my_closure_new (gpointer data) 174 * { 175 * GClosure *closure; 176 * MyClosure *my_closure; 177 * 178 * closure = g_closure_new_simple (sizeof (MyClosure), data); 179 * my_closure = (MyClosure *) closure; 180 * 181 * // initialize extra data here 182 * 183 * g_closure_add_finalize_notifier (closure, notify_data, 184 * my_closure_finalize); 185 * return my_closure; 186 * } 187 * ]| 188 * 189 * Returns: (transfer full): a newly allocated #GClosure 190 */ 191 GClosure* 192 g_closure_new_simple (guint sizeof_closure, 193 gpointer data) 194 { 195 GClosure *closure; 196 197 g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL); 198 199 closure = g_malloc0 (sizeof_closure); 200 #ifdef GSTREAMER_LITE 201 if (closure == NULL) 202 return NULL; 203 #endif // GSTREAMER_LITE 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)); 218 219 return closure; 220 } 221 222 static inline void 223 closure_invoke_notifiers (GClosure *closure, 224 guint notify_type) 225 { 226 /* notifier layout: 227 * meta_marshal n_guards n_guards n_fnotif. n_inotifiers 228 * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]] 229 * 230 * CLOSURE_N_MFUNCS(cl) = meta_marshal + n_guards + n_guards; 231 * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers 232 * 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 243 */ 244 switch (notify_type) 245 { 246 GClosureNotifyData *ndata; 247 guint i, offs; 248 case FNOTIFY: 249 while (closure->n_fnotifiers) 250 { 251 guint n; 252 DEC_ASSIGN (closure, n_fnotifiers, &n); 253 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); 258 } 259 closure->marshal = NULL; 260 closure->data = NULL; 261 break; 262 case INOTIFY: 263 SET (closure, in_inotify, TRUE); 264 while (closure->n_inotifiers) 265 { 266 guint n; 267 DEC_ASSIGN (closure, n_inotifiers, &n); 268 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); 273 } 274 closure->marshal = NULL; 275 closure->data = NULL; 276 SET (closure, in_inotify, FALSE); 277 break; 278 case PRE_NOTIFY: 279 i = closure->n_guards; 280 offs = closure->meta_marshal; 281 while (i--) 282 { 283 ndata = closure->notifiers + offs + i; 284 ndata->notify (ndata->data, closure); 285 } 286 break; 287 case POST_NOTIFY: 288 i = closure->n_guards; 289 offs = closure->meta_marshal + i; 290 while (i--) 291 { 292 ndata = closure->notifiers + offs + i; 293 ndata->notify (ndata->data, closure); 294 } 295 break; 296 } 297 } 298 299 /** 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 304 * 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 313 * callback function. 314 * 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. 320 */ 321 void 322 g_closure_set_meta_marshal (GClosure *closure, 323 gpointer marshal_data, 324 GClosureMarshal meta_marshal) 325 { 326 GClosureNotifyData *notifiers; 327 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); 333 334 notifiers = closure->notifiers; 335 closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1); 336 if (notifiers) 337 { 338 /* usually the meta marshal will be setup right after creation, so the 339 * g_memmove() should be rare-case scenario 340 */ 341 g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0])); 342 g_free (notifiers); 343 } 344 closure->notifiers[0].data = marshal_data; 345 closure->notifiers[0].notify = (GClosureNotify) meta_marshal; 346 SET (closure, meta_marshal, 1); 347 } 348 349 /** 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 356 * 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. 361 */ 362 void 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) 368 { 369 guint i; 370 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); 377 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 + 397 closure->n_guards + 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); 405 } 406 407 /** 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 412 * 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. 419 */ 420 void 421 g_closure_add_finalize_notifier (GClosure *closure, 422 gpointer notify_data, 423 GClosureNotify notify_func) 424 { 425 guint i; 426 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); 430 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); 441 } 442 443 /** 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 448 * 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 452 * unspecified order. 453 */ 454 void 455 g_closure_add_invalidate_notifier (GClosure *closure, 456 gpointer notify_data, 457 GClosureNotify notify_func) 458 { 459 guint i; 460 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); 465 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); 471 } 472 473 static inline gboolean 474 closure_try_remove_inotify (GClosure *closure, 475 gpointer notify_data, 476 GClosureNotify notify_func) 477 { 478 GClosureNotifyData *ndata, *nlast; 479 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) 483 { 484 DEC (closure, n_inotifiers); 485 if (ndata < nlast) 486 *ndata = *nlast; 487 488 return TRUE; 489 } 490 return FALSE; 491 } 492 493 static inline gboolean 494 closure_try_remove_fnotify (GClosure *closure, 495 gpointer notify_data, 496 GClosureNotify notify_func) 497 { 498 GClosureNotifyData *ndata, *nlast; 499 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) 503 { 504 DEC (closure, n_fnotifiers); 505 if (ndata < nlast) 506 *ndata = *nlast; 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)]; 512 return TRUE; 513 } 514 return FALSE; 515 } 516 517 /** 518 * g_closure_ref: 519 * @closure: #GClosure to increment the reference count on 520 * 521 * Increments the reference count on a closure to force it staying 522 * alive while the caller holds a pointer to it. 523 * 524 * Returns: (transfer none): The @closure passed in, for convenience 525 */ 526 GClosure* 527 g_closure_ref (GClosure *closure) 528 { 529 guint new_ref_count; 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); 533 534 INC_ASSIGN (closure, ref_count, &new_ref_count); 535 g_return_val_if_fail (new_ref_count > 1, NULL); 536 537 return closure; 538 } 539 540 /** 541 * g_closure_invalidate: 542 * @closure: GClosure to invalidate 543 * 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(). 553 * 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). 557 */ 558 void 559 g_closure_invalidate (GClosure *closure) 560 { 561 g_return_if_fail (closure != NULL); 562 563 if (!closure->is_invalid) 564 { 565 gboolean was_invalid; 566 g_closure_ref (closure); /* preserve floating flag */ 567 SWAP (closure, is_invalid, TRUE, &was_invalid); 568 /* invalidate only once */ 569 if (!was_invalid) 570 closure_invoke_notifiers (closure, INOTIFY); 571 g_closure_unref (closure); 572 } 573 } 574 575 /** 576 * g_closure_unref: 577 * @closure: #GClosure to decrement the reference count on 578 * 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. 582 */ 583 void 584 g_closure_unref (GClosure *closure) 585 { 586 guint new_ref_count; 587 588 g_return_if_fail (closure != NULL); 589 g_return_if_fail (closure->ref_count > 0); 590 591 if (closure->ref_count == 1) /* last unref, invalidate first */ 592 g_closure_invalidate (closure); 593 594 DEC_ASSIGN (closure, ref_count, &new_ref_count); 595 596 if (new_ref_count == 0) 597 { 598 closure_invoke_notifiers (closure, FNOTIFY); 599 g_free (closure->notifiers); 600 g_free (closure); 601 } 602 } 603 604 /** 605 * g_closure_sink: 606 * @closure: #GClosure to decrement the initial reference count on, if it's 607 * still being held 608 * 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: 617 * |[ 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 621 * ]| 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: 624 * |[ 625 * g_source_set_closure (source, g_cclosure_new (cb_func, cb_data)); 626 * ]| 627 * 628 * Generally, this function is used together with g_closure_ref(). Ane example 629 * of storing a closure for later notification looks like: 630 * |[ 631 * static GClosure *notify_closure = NULL; 632 * void 633 * foo_notify_set_closure (GClosure *closure) 634 * { 635 * if (notify_closure) 636 * g_closure_unref (notify_closure); 637 * notify_closure = closure; 638 * if (notify_closure) 639 * { 640 * g_closure_ref (notify_closure); 641 * g_closure_sink (notify_closure); 642 * } 643 * } 644 * ]| 645 * 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. 649 */ 650 void 651 g_closure_sink (GClosure *closure) 652 { 653 g_return_if_fail (closure != NULL); 654 g_return_if_fail (closure->ref_count > 0); 655 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. 660 */ 661 if (closure->floating) 662 { 663 gboolean was_floating; 664 SWAP (closure, floating, FALSE, &was_floating); 665 /* unref floating flag only once */ 666 if (was_floating) 667 g_closure_unref (closure); 668 } 669 } 670 671 /** 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 677 * 678 * Removes an invalidation notifier. 679 * 680 * Notice that notifiers are automatically removed after they are run. 681 */ 682 void 683 g_closure_remove_invalidate_notifier (GClosure *closure, 684 gpointer notify_data, 685 GClosureNotify notify_func) 686 { 687 g_return_if_fail (closure != NULL); 688 g_return_if_fail (notify_func != NULL); 689 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); 697 } 698 699 /** 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 705 * 706 * Removes a finalization notifier. 707 * 708 * Notice that notifiers are automatically removed after they are run. 709 */ 710 void 711 g_closure_remove_finalize_notifier (GClosure *closure, 712 gpointer notify_data, 713 GClosureNotify notify_func) 714 { 715 g_return_if_fail (closure != NULL); 716 g_return_if_fail (notify_func != NULL); 717 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); 725 } 726 727 /** 728 * g_closure_invoke: 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 737 * 738 * Invokes the closure, i.e. executes the callback represented by the @closure. 739 */ 740 void 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) 746 { 747 g_return_if_fail (closure != NULL); 748 749 g_closure_ref (closure); /* preserve floating flag */ 750 if (!closure->is_invalid) 751 { 752 GClosureMarshal marshal; 753 gpointer marshal_data; 754 gboolean in_marshal = closure->in_marshal; 755 756 g_return_if_fail (closure->marshal || closure->meta_marshal); 757 758 SET (closure, in_marshal, TRUE); 759 if (closure->meta_marshal) 760 { 761 marshal_data = closure->notifiers[0].data; 762 marshal = (GClosureMarshal) closure->notifiers[0].notify; 763 } 764 else 765 { 766 marshal_data = NULL; 767 marshal = closure->marshal; 768 } 769 if (!in_marshal) 770 closure_invoke_notifiers (closure, PRE_NOTIFY); 771 marshal (closure, 772 return_value, 773 n_param_values, param_values, 774 invocation_hint, 775 marshal_data); 776 if (!in_marshal) 777 closure_invoke_notifiers (closure, POST_NOTIFY); 778 SET (closure, in_marshal, in_marshal); 779 } 780 g_closure_unref (closure); 781 } 782 783 /** 784 * g_closure_set_marshal: (skip) 785 * @closure: a #GClosure 786 * @marshal: a #GClosureMarshal function 787 * 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. 794 */ 795 void 796 g_closure_set_marshal (GClosure *closure, 797 GClosureMarshal marshal) 798 { 799 g_return_if_fail (closure != NULL); 800 g_return_if_fail (marshal != NULL); 801 802 if (closure->marshal && closure->marshal != marshal) 803 g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)", 804 closure->marshal, marshal); 805 else 806 closure->marshal = marshal; 807 } 808 809 /** 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 814 * 815 * Creates a new closure which invokes @callback_func with @user_data as 816 * the last parameter. 817 * 818 * Returns: a new #GCClosure 819 */ 820 GClosure* 821 g_cclosure_new (GCallback callback_func, 822 gpointer user_data, 823 GClosureNotify destroy_data) 824 { 825 GClosure *closure; 826 827 g_return_val_if_fail (callback_func != NULL, NULL); 828 829 closure = g_closure_new_simple (sizeof (GCClosure), user_data); 830 if (destroy_data) 831 g_closure_add_finalize_notifier (closure, user_data, destroy_data); 832 ((GCClosure*) closure)->callback = (gpointer) callback_func; 833 834 return closure; 835 } 836 837 /** 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 842 * 843 * Creates a new closure which invokes @callback_func with @user_data as 844 * the first parameter. 845 * 846 * Returns: (transfer full): a new #GCClosure 847 */ 848 GClosure* 849 g_cclosure_new_swap (GCallback callback_func, 850 gpointer user_data, 851 GClosureNotify destroy_data) 852 { 853 GClosure *closure; 854 855 g_return_val_if_fail (callback_func != NULL, NULL); 856 857 closure = g_closure_new_simple (sizeof (GCClosure), user_data); 858 if (destroy_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); 862 863 return closure; 864 } 865 866 static void 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) 873 { 874 GTypeClass *class; 875 gpointer callback; 876 /* GType itype = (GType) closure->data; */ 877 guint offset = GPOINTER_TO_UINT (marshal_data); 878 879 class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass); 880 callback = G_STRUCT_MEMBER (gpointer, class, offset); 881 if (callback) 882 closure->marshal (closure, 883 return_value, 884 n_param_values, param_values, 885 invocation_hint, 886 callback); 887 } 888 889 static void 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) 896 { 897 GTypeClass *class; 898 gpointer callback; 899 GType itype = (GType) closure->data; 900 guint offset = GPOINTER_TO_UINT (marshal_data); 901 902 class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass); 903 callback = G_STRUCT_MEMBER (gpointer, class, offset); 904 if (callback) 905 closure->marshal (closure, 906 return_value, 907 n_param_values, param_values, 908 invocation_hint, 909 callback); 910 } 911 912 /** 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 917 * 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. 921 * 922 * Returns: a new #GCClosure 923 */ 924 GClosure* 925 g_signal_type_cclosure_new (GType itype, 926 guint struct_offset) 927 { 928 GClosure *closure; 929 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); 932 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); 936 else 937 g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal); 938 939 return closure; 940 } 941 942 943 /** 944 * g_cclosure_marshal_VOID__VOID: 945 * @closure: the #GClosure to which the marshaller belongs 946 * @return_value: ignored 947 * @n_param_values: 1 948 * @param_values: a #GValue array holding only the instance 949 * @invocation_hint: the invocation hint given as the last argument 950 * to g_closure_invoke() 951 * @marshal_data: additional data specified when registering the marshaller 952 * 953 * A marshaller for a #GCClosure with a callback of type 954 * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>. 955 */ 956 957 /** 958 * g_cclosure_marshal_VOID__BOOLEAN: 959 * @closure: the #GClosure to which the marshaller belongs 960 * @return_value: ignored 961 * @n_param_values: 2 962 * @param_values: a #GValue array holding the instance and the #gboolean parameter 963 * @invocation_hint: the invocation hint given as the last argument 964 * to g_closure_invoke() 965 * @marshal_data: additional data specified when registering the marshaller 966 * 967 * A marshaller for a #GCClosure with a callback of type 968 * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>. 969 */ 970 971 /** 972 * g_cclosure_marshal_VOID__CHAR: 973 * @closure: the #GClosure to which the marshaller belongs 974 * @return_value: ignored 975 * @n_param_values: 2 976 * @param_values: a #GValue array holding the instance and the #gchar parameter 977 * @invocation_hint: the invocation hint given as the last argument 978 * to g_closure_invoke() 979 * @marshal_data: additional data specified when registering the marshaller 980 * 981 * A marshaller for a #GCClosure with a callback of type 982 * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>. 983 */ 984 985 /** 986 * g_cclosure_marshal_VOID__UCHAR: 987 * @closure: the #GClosure to which the marshaller belongs 988 * @return_value: ignored 989 * @n_param_values: 2 990 * @param_values: a #GValue array holding the instance and the #guchar parameter 991 * @invocation_hint: the invocation hint given as the last argument 992 * to g_closure_invoke() 993 * @marshal_data: additional data specified when registering the marshaller 994 * 995 * A marshaller for a #GCClosure with a callback of type 996 * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>. 997 */ 998 999 /** 1000 * g_cclosure_marshal_VOID__INT: 1001 * @closure: the #GClosure to which the marshaller belongs 1002 * @return_value: ignored 1003 * @n_param_values: 2 1004 * @param_values: a #GValue array holding the instance and the #gint parameter 1005 * @invocation_hint: the invocation hint given as the last argument 1006 * to g_closure_invoke() 1007 * @marshal_data: additional data specified when registering the marshaller 1008 * 1009 * A marshaller for a #GCClosure with a callback of type 1010 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>. 1011 */ 1012 1013 /** 1014 * g_cclosure_marshal_VOID__UINT: 1015 * @closure: the #GClosure to which the marshaller belongs 1016 * @return_value: ignored 1017 * @n_param_values: 2 1018 * @param_values: a #GValue array holding the instance and the #guint parameter 1019 * @invocation_hint: the invocation hint given as the last argument 1020 * to g_closure_invoke() 1021 * @marshal_data: additional data specified when registering the marshaller 1022 * 1023 * A marshaller for a #GCClosure with a callback of type 1024 * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>. 1025 */ 1026 1027 /** 1028 * g_cclosure_marshal_VOID__LONG: 1029 * @closure: the #GClosure to which the marshaller belongs 1030 * @return_value: ignored 1031 * @n_param_values: 2 1032 * @param_values: a #GValue array holding the instance and the #glong parameter 1033 * @invocation_hint: the invocation hint given as the last argument 1034 * to g_closure_invoke() 1035 * @marshal_data: additional data specified when registering the marshaller 1036 * 1037 * A marshaller for a #GCClosure with a callback of type 1038 * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>. 1039 */ 1040 1041 /** 1042 * g_cclosure_marshal_VOID__ULONG: 1043 * @closure: the #GClosure to which the marshaller belongs 1044 * @return_value: ignored 1045 * @n_param_values: 2 1046 * @param_values: a #GValue array holding the instance and the #gulong parameter 1047 * @invocation_hint: the invocation hint given as the last argument 1048 * to g_closure_invoke() 1049 * @marshal_data: additional data specified when registering the marshaller 1050 * 1051 * A marshaller for a #GCClosure with a callback of type 1052 * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>. 1053 */ 1054 1055 /** 1056 * g_cclosure_marshal_VOID__ENUM: 1057 * @closure: the #GClosure to which the marshaller belongs 1058 * @return_value: ignored 1059 * @n_param_values: 2 1060 * @param_values: a #GValue array holding the instance and the enumeration parameter 1061 * @invocation_hint: the invocation hint given as the last argument 1062 * to g_closure_invoke() 1063 * @marshal_data: additional data specified when registering the marshaller 1064 * 1065 * A marshaller for a #GCClosure with a callback of type 1066 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type.. 1067 */ 1068 1069 /** 1070 * g_cclosure_marshal_VOID__FLAGS: 1071 * @closure: the #GClosure to which the marshaller belongs 1072 * @return_value: ignored 1073 * @n_param_values: 2 1074 * @param_values: a #GValue array holding the instance and the flags parameter 1075 * @invocation_hint: the invocation hint given as the last argument 1076 * to g_closure_invoke() 1077 * @marshal_data: additional data specified when registering the marshaller 1078 * 1079 * A marshaller for a #GCClosure with a callback of type 1080 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type. 1081 */ 1082 1083 /** 1084 * g_cclosure_marshal_VOID__FLOAT: 1085 * @closure: the #GClosure to which the marshaller belongs 1086 * @return_value: ignored 1087 * @n_param_values: 2 1088 * @param_values: a #GValue array holding the instance and the #gfloat parameter 1089 * @invocation_hint: the invocation hint given as the last argument 1090 * to g_closure_invoke() 1091 * @marshal_data: additional data specified when registering the marshaller 1092 * 1093 * A marshaller for a #GCClosure with a callback of type 1094 * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>. 1095 */ 1096 1097 /** 1098 * g_cclosure_marshal_VOID__DOUBLE: 1099 * @closure: the #GClosure to which the marshaller belongs 1100 * @return_value: ignored 1101 * @n_param_values: 2 1102 * @param_values: a #GValue array holding the instance and the #gdouble parameter 1103 * @invocation_hint: the invocation hint given as the last argument 1104 * to g_closure_invoke() 1105 * @marshal_data: additional data specified when registering the marshaller 1106 * 1107 * A marshaller for a #GCClosure with a callback of type 1108 * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>. 1109 */ 1110 1111 /** 1112 * g_cclosure_marshal_VOID__STRING: 1113 * @closure: the #GClosure to which the marshaller belongs 1114 * @return_value: ignored 1115 * @n_param_values: 2 1116 * @param_values: a #GValue array holding the instance and the #gchar* parameter 1117 * @invocation_hint: the invocation hint given as the last argument 1118 * to g_closure_invoke() 1119 * @marshal_data: additional data specified when registering the marshaller 1120 * 1121 * A marshaller for a #GCClosure with a callback of type 1122 * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>. 1123 */ 1124 1125 /** 1126 * g_cclosure_marshal_VOID__PARAM: 1127 * @closure: the #GClosure to which the marshaller belongs 1128 * @return_value: ignored 1129 * @n_param_values: 2 1130 * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter 1131 * @invocation_hint: the invocation hint given as the last argument 1132 * to g_closure_invoke() 1133 * @marshal_data: additional data specified when registering the marshaller 1134 * 1135 * A marshaller for a #GCClosure with a callback of type 1136 * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>. 1137 */ 1138 1139 /** 1140 * g_cclosure_marshal_VOID__BOXED: 1141 * @closure: the #GClosure to which the marshaller belongs 1142 * @return_value: ignored 1143 * @n_param_values: 2 1144 * @param_values: a #GValue array holding the instance and the #GBoxed* parameter 1145 * @invocation_hint: the invocation hint given as the last argument 1146 * to g_closure_invoke() 1147 * @marshal_data: additional data specified when registering the marshaller 1148 * 1149 * A marshaller for a #GCClosure with a callback of type 1150 * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>. 1151 */ 1152 1153 /** 1154 * g_cclosure_marshal_VOID__POINTER: 1155 * @closure: the #GClosure to which the marshaller belongs 1156 * @return_value: ignored 1157 * @n_param_values: 2 1158 * @param_values: a #GValue array holding the instance and the #gpointer parameter 1159 * @invocation_hint: the invocation hint given as the last argument 1160 * to g_closure_invoke() 1161 * @marshal_data: additional data specified when registering the marshaller 1162 * 1163 * A marshaller for a #GCClosure with a callback of type 1164 * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>. 1165 */ 1166 1167 /** 1168 * g_cclosure_marshal_VOID__OBJECT: 1169 * @closure: the #GClosure to which the marshaller belongs 1170 * @return_value: ignored 1171 * @n_param_values: 2 1172 * @param_values: a #GValue array holding the instance and the #GObject* parameter 1173 * @invocation_hint: the invocation hint given as the last argument 1174 * to g_closure_invoke() 1175 * @marshal_data: additional data specified when registering the marshaller 1176 * 1177 * A marshaller for a #GCClosure with a callback of type 1178 * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>. 1179 */ 1180 1181 /** 1182 * g_cclosure_marshal_VOID__VARIANT: 1183 * @closure: the #GClosure to which the marshaller belongs 1184 * @return_value: ignored 1185 * @n_param_values: 2 1186 * @param_values: a #GValue array holding the instance and the #GVariant* parameter 1187 * @invocation_hint: the invocation hint given as the last argument 1188 * to g_closure_invoke() 1189 * @marshal_data: additional data specified when registering the marshaller 1190 * 1191 * A marshaller for a #GCClosure with a callback of type 1192 * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>. 1193 * 1194 * Since: 2.26 1195 */ 1196 1197 /** 1198 * g_cclosure_marshal_VOID__UINT_POINTER: 1199 * @closure: the #GClosure to which the marshaller belongs 1200 * @return_value: ignored 1201 * @n_param_values: 3 1202 * @param_values: a #GValue array holding instance, arg1 and arg2 1203 * @invocation_hint: the invocation hint given as the last argument 1204 * to g_closure_invoke() 1205 * @marshal_data: additional data specified when registering the marshaller 1206 * 1207 * A marshaller for a #GCClosure with a callback of type 1208 * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>. 1209 */ 1210 1211 /** 1212 * g_cclosure_marshal_BOOLEAN__FLAGS: 1213 * @closure: the #GClosure to which the marshaller belongs 1214 * @return_value: a #GValue which can store the returned #gboolean 1215 * @n_param_values: 2 1216 * @param_values: a #GValue array holding instance and arg1 1217 * @invocation_hint: the invocation hint given as the last argument 1218 * to g_closure_invoke() 1219 * @marshal_data: additional data specified when registering the marshaller 1220 * 1221 * A marshaller for a #GCClosure with a callback of type 1222 * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter 1223 * denotes a flags type. 1224 */ 1225 1226 /** 1227 * g_cclosure_marshal_BOOL__FLAGS: 1228 * 1229 * Another name for g_cclosure_marshal_BOOLEAN__FLAGS(). 1230 */ 1231 /** 1232 * g_cclosure_marshal_STRING__OBJECT_POINTER: 1233 * @closure: the #GClosure to which the marshaller belongs 1234 * @return_value: a #GValue, which can store the returned string 1235 * @n_param_values: 3 1236 * @param_values: a #GValue array holding instance, arg1 and arg2 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 1240 * 1241 * A marshaller for a #GCClosure with a callback of type 1242 * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>. 1243 */ 1244 /** 1245 * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED: 1246 * @closure: the #GClosure to which the marshaller belongs 1247 * @return_value: a #GValue, which can store the returned string 1248 * @n_param_values: 3 1249 * @param_values: a #GValue array holding instance, arg1 and arg2 1250 * @invocation_hint: the invocation hint given as the last argument 1251 * to g_closure_invoke() 1252 * @marshal_data: additional data specified when registering the marshaller 1253 * 1254 * A marshaller for a #GCClosure with a callback of type 1255 * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>. 1256 * 1257 * Since: 2.26 1258 */