1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * this code is based on the original GtkSignal implementation
20 * for the Gtk+ library by Peter Mattis <petm@xcf.berkeley.edu>
28 #include "gbsearcharray.h"
29 #include "gvaluecollector.h"
33 /* pre allocation configurations
35 #define MAX_STACK_VALUES (16)
36 #define BSA_PRE_ALLOC (20)
37 #define HANDLER_PRE_ALLOC (48)
38 #define EMISSION_PRE_ALLOC (16)
40 #define REPORT_BUG "please report occourance circumstances to gtk-devel-list@gnome.org"
42 #define IF_DEBUG(debug_type, cond) if ((_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type) || cond)
43 static volatile gpointer *g_trace_instance_signals = NULL;
44 static volatile gpointer *g_trap_instance_signals = NULL;
45 #endif /* G_ENABLE_DEBUG */
48 /* --- generic allocation --- */
49 /* we special case allocations generically by replacing
50 * these functions with more speed/memory aware variants
52 #ifndef DISABLE_MEM_POOLS
53 static inline gpointer
54 g_generic_node_alloc (GTrashStack **trash_stack_p,
56 guint nodes_pre_alloc)
58 gpointer node = g_trash_stack_pop (trash_stack_p);
64 nodes_pre_alloc = MAX (nodes_pre_alloc, 1);
65 block = g_malloc (sizeof_node * nodes_pre_alloc);
66 while (--nodes_pre_alloc)
68 g_trash_stack_push (trash_stack_p, block);
76 #define g_generic_node_free(trash_stack_p, node) g_trash_stack_push (trash_stack_p, node)
77 #else /* !DISABLE_MEM_POOLS */
78 #define g_generic_node_alloc(t,sizeof_node,p) g_malloc (sizeof_node)
79 #define g_generic_node_free(t,node) g_free (node)
80 #endif /* !DISABLE_MEM_POOLS */
83 /* --- typedefs --- */
84 typedef struct _SignalNode SignalNode;
85 typedef struct _SignalKey SignalKey;
86 typedef struct _Emission Emission;
87 typedef struct _Handler Handler;
88 typedef struct _HandlerList HandlerList;
89 typedef struct _HandlerMatch HandlerMatch;
99 /* --- prototypes --- */
100 static inline guint signal_id_lookup (GQuark quark,
102 static void signal_destroy_R (SignalNode *signal_node);
103 static inline HandlerList* handler_list_ensure (guint signal_id,
105 static inline HandlerList* handler_list_lookup (guint signal_id,
107 static inline Handler* handler_new (gboolean after);
108 static void handler_insert (guint signal_id,
111 static Handler* handler_lookup (gpointer instance,
114 static inline HandlerMatch* handler_match_prepend (HandlerMatch *list,
117 static inline HandlerMatch* handler_match_free1_R (HandlerMatch *node,
119 static HandlerMatch* handlers_find (gpointer instance,
120 GSignalMatchType mask,
126 gboolean one_and_only);
127 static inline void handler_ref (Handler *handler);
128 static inline void handler_unref_R (guint signal_id,
131 static inline void emission_push (Emission **emission_list_p,
135 EmissionState *state_p);
136 static inline void emission_pop (Emission **emission_list_p,
137 EmissionState *state_p);
138 static inline Emission* emission_find (Emission *emission_list,
142 static gboolean signal_emit_R (SignalNode *node,
145 GValue *return_value,
146 const GValue *instance_and_params);
149 /* --- structures --- */
152 /* permanent portion */
158 /* reinitializable portion */
161 GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
162 GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
163 GClosure *class_closure;
164 GSignalAccumulator accumulator;
165 GSignalCMarshaller c_marshaller;
166 GHookList *emission_hooks;
182 EmissionState *state_p;
196 guint ref_count : 16;
197 #define HANDLER_MAX_REF_COUNT (1 << 16)
198 guint block_count : 12;
199 #define HANDLER_MAX_BLOCK_COUNT (1 << 12)
214 /* --- variables --- */
215 static GBSearchArray g_signal_key_bsa = { NULL, 0, 0, 0, NULL };
216 static GHashTable *g_handler_list_bsa_ht = NULL;
217 static Emission *g_recursive_emissions = NULL;
218 static Emission *g_restart_emissions = NULL;
219 static GTrashStack *g_bsa_ts = NULL;
220 static GTrashStack *g_handler_ts = NULL;
221 static GTrashStack *g_emission_ts = NULL;
222 G_LOCK_DEFINE_STATIC (g_signal_mutex);
225 /* --- signal nodes --- */
226 static guint g_n_signal_nodes = 0;
227 static SignalNode **g_signal_nodes = NULL;
229 static inline SignalNode*
230 LOOKUP_SIGNAL_NODE (register guint signal_id)
232 if (signal_id < g_n_signal_nodes)
233 return g_signal_nodes[signal_id];
239 /* --- functions --- */
241 signal_id_lookup (GQuark quark,
244 GType *ifaces, type = itype;
250 /* try looking up signals for this type and its anchestors */
253 SignalKey *signal_key;
256 signal_key = g_bsearch_array_lookup (&g_signal_key_bsa, &key);
259 return signal_key->signal_id;
261 type = g_type_parent (type);
265 /* no luck, try interfaces it exports */
266 ifaces = g_type_interfaces (itype, &n_ifaces);
269 SignalKey *signal_key;
271 key.itype = ifaces[n_ifaces];
272 signal_key = g_bsearch_array_lookup (&g_signal_key_bsa, &key);
277 return signal_key->signal_id;
286 handler_lists_cmp (gconstpointer node1,
289 const HandlerList *hlist1 = node1, *hlist2 = node2;
291 return G_BSEARCH_ARRAY_CMP (hlist1->signal_id, hlist2->signal_id);
294 static inline HandlerList*
295 handler_list_ensure (guint signal_id,
298 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
303 hlbsa = g_generic_node_alloc (&g_bsa_ts,
304 sizeof (GBSearchArray),
306 hlbsa->cmp_func = handler_lists_cmp;
307 hlbsa->sizeof_node = sizeof (HandlerList);
308 hlbsa->flags = G_BSEARCH_DEFER_SHRINK;
311 g_hash_table_insert (g_handler_list_bsa_ht, instance, hlbsa);
313 key.signal_id = signal_id;
316 return g_bsearch_array_insert (hlbsa, &key, FALSE);
319 static inline HandlerList*
320 handler_list_lookup (guint signal_id,
323 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
326 key.signal_id = signal_id;
328 return hlbsa ? g_bsearch_array_lookup (hlbsa, &key) : NULL;
332 handler_lookup (gpointer instance,
336 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
342 for (i = 0; i < hlbsa->n_nodes; i++)
344 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, i);
347 for (handler = hlist->handlers; handler; handler = handler->next)
348 if (handler->id == handler_id)
351 *signal_id_p = hlist->signal_id;
361 static inline HandlerMatch*
362 handler_match_prepend (HandlerMatch *list,
368 /* yeah, we could use our own memchunk here, introducing yet more
369 * rarely used cached nodes and extra allocation overhead.
370 * instead, we use GList* nodes, since they are exactly the size
371 * we need and are already cached. g_signal_init() asserts this.
373 node = (HandlerMatch*) g_list_alloc ();
374 node->handler = handler;
376 node->d.signal_id = signal_id;
377 handler_ref (handler);
381 static inline HandlerMatch*
382 handler_match_free1_R (HandlerMatch *node,
385 HandlerMatch *next = node->next;
387 handler_unref_R (node->d.signal_id, instance, node->handler);
388 g_list_free_1 ((GList*) node);
394 handlers_find (gpointer instance,
395 GSignalMatchType mask,
401 gboolean one_and_only)
403 HandlerMatch *mlist = NULL;
405 if (mask & G_SIGNAL_MATCH_ID)
407 HandlerList *hlist = handler_list_lookup (signal_id, instance);
409 SignalNode *node = NULL;
411 if (mask & G_SIGNAL_MATCH_FUNC)
413 node = LOOKUP_SIGNAL_NODE (signal_id);
414 if (!node || !node->c_marshaller)
419 for (handler = hlist ? hlist->handlers : NULL; handler; handler = handler->next)
421 ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
422 ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
423 ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
424 ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
425 ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
426 handler->closure->meta_marshal == 0 &&
427 ((GCClosure*) handler->closure)->callback == func)))
429 mlist = handler_match_prepend (mlist, handler, signal_id);
436 GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
443 for (i = 0; i < hlbsa->n_nodes; i++)
445 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, i);
446 SignalNode *node = NULL;
449 if (!(mask & G_SIGNAL_MATCH_FUNC))
451 node = LOOKUP_SIGNAL_NODE (hlist->signal_id);
452 if (!node->c_marshaller)
456 for (handler = hlist->handlers; handler; handler = handler->next)
458 ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
459 ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
460 ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
461 ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
462 ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
463 handler->closure->meta_marshal == 0 &&
464 ((GCClosure*) handler->closure)->callback == func)))
466 mlist = handler_match_prepend (mlist, handler, hlist->signal_id);
477 static inline Handler*
478 handler_new (gboolean after)
480 static guint handler_id = 1;
481 Handler *handler = g_generic_node_alloc (&g_handler_ts,
484 #ifndef G_DISABLE_CHECKS
486 g_error (G_STRLOC ": handler id overflow, %s", REPORT_BUG);
489 handler->id = handler_id++;
490 handler->prev = NULL;
491 handler->next = NULL;
493 handler->ref_count = 1;
494 handler->block_count = 0;
495 handler->after = after != FALSE;
496 handler->closure = NULL;
502 handler_ref (Handler *handler)
504 g_return_if_fail (handler->ref_count > 0);
506 #ifndef G_DISABLE_CHECKS
507 if (handler->ref_count >= HANDLER_MAX_REF_COUNT - 1)
508 g_error (G_STRLOC ": handler ref_count overflow, %s", REPORT_BUG);
511 handler->ref_count += 1;
515 handler_unref_R (guint signal_id,
519 g_return_if_fail (handler->ref_count > 0);
521 handler->ref_count -= 1;
522 if (!handler->ref_count)
525 handler->next->prev = handler->prev;
526 if (handler->prev) /* watch out for g_signal_handlers_destroy()! */
527 handler->prev->next = handler->next;
530 HandlerList *hlist = handler_list_lookup (signal_id, instance);
532 hlist->handlers = handler->next;
534 G_UNLOCK (g_signal_mutex);
535 g_closure_unref (handler->closure);
536 G_LOCK (g_signal_mutex);
537 g_generic_node_free (&g_handler_ts, handler);
542 handler_insert (guint signal_id,
548 g_assert (handler->prev == NULL && handler->next == NULL); /* paranoid */
550 hlist = handler_list_ensure (signal_id, instance);
551 if (!hlist->handlers)
552 hlist->handlers = handler;
553 else if (hlist->handlers->after && !handler->after)
555 handler->next = hlist->handlers;
556 hlist->handlers->prev = handler;
557 hlist->handlers = handler;
561 Handler *tmp = hlist->handlers;
567 while (tmp->next && !tmp->next->after)
570 tmp->next->prev = handler;
571 handler->next = tmp->next;
578 emission_push (Emission **emission_list_p,
582 EmissionState *state_p)
584 Emission *emission = g_generic_node_alloc (&g_emission_ts,
587 emission->next = *emission_list_p;
588 emission->signal_id = signal_id;
589 emission->detail = detail;
590 emission->instance = instance;
591 emission->state_p = state_p;
592 *emission_list_p = emission;
596 emission_pop (Emission **emission_list_p,
597 EmissionState *state_p)
599 Emission **loc = emission_list_p, *emission = *loc;
601 while (emission->state_p != state_p)
603 loc = &emission->next;
606 *loc = emission->next;
607 g_generic_node_free (&g_emission_ts, emission);
610 static inline Emission*
611 emission_find (Emission *emission_list,
618 for (emission = emission_list; emission; emission = emission->next)
619 if (emission->instance == instance &&
620 emission->signal_id == signal_id &&
621 emission->detail == detail)
627 signal_key_cmp (gconstpointer node1,
630 const SignalKey *key1 = node1, *key2 = node2;
632 if (key1->itype == key2->itype)
633 return G_BSEARCH_ARRAY_CMP (key1->quark, key2->quark);
635 return G_BSEARCH_ARRAY_CMP (key1->itype, key2->itype);
639 g_signal_init (void) /* sync with gtype.c */
641 G_LOCK (g_signal_mutex);
642 if (!g_n_signal_nodes)
644 /* handler_id_node_prepend() requires this */
645 g_assert (sizeof (GList) == sizeof (HandlerMatch));
647 /* setup signal key array */
648 g_signal_key_bsa.cmp_func = signal_key_cmp;
649 g_signal_key_bsa.sizeof_node = sizeof (SignalKey);
650 g_signal_key_bsa.flags = G_BSEARCH_ALIGN_POWER2; /* alloc-only */
652 /* setup handler list binary searchable array hash table (in german, that'd be one word ;) */
653 g_handler_list_bsa_ht = g_hash_table_new (g_direct_hash, NULL);
655 /* invalid (0) signal_id */
656 g_n_signal_nodes = 1;
657 g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
658 g_signal_nodes[0] = NULL;
660 G_UNLOCK (g_signal_mutex);
664 _g_signals_destroy (GType itype)
668 G_LOCK (g_signal_mutex);
669 for (i = 1; i < g_n_signal_nodes; i++)
671 SignalNode *node = g_signal_nodes[i];
673 if (node->itype == itype)
676 g_warning (G_STRLOC ": signal \"%s\" of type `%s' already destroyed",
678 g_type_name (node->itype));
680 signal_destroy_R (node);
683 G_UNLOCK (g_signal_mutex);
687 g_signal_stop_emission (gpointer instance,
693 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
694 g_return_if_fail (signal_id > 0);
696 G_LOCK (g_signal_mutex);
697 node = LOOKUP_SIGNAL_NODE (signal_id);
698 if (node && detail && !(node->flags & G_SIGNAL_DETAILED))
700 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
701 G_UNLOCK (g_signal_mutex);
704 if (node && g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
706 Emission *emission_list = node->flags & G_SIGNAL_NO_RECURSE ? g_restart_emissions : g_recursive_emissions;
707 Emission *emission = emission_find (emission_list, signal_id, detail, instance);
711 if (*emission->state_p == EMISSION_HOOK)
712 g_warning (G_STRLOC ": emission of signal \"%s\" for instance `%p' cannot be stopped from emission hook",
713 node->name, instance);
714 else if (*emission->state_p == EMISSION_RUN)
715 *emission->state_p = EMISSION_STOP;
718 g_warning (G_STRLOC ": no emission of signal \"%s\" to stop for instance `%p'",
719 node->name, instance);
722 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
723 G_UNLOCK (g_signal_mutex);
727 signal_parse_name (const gchar *name,
730 gboolean force_quark)
732 const gchar *colon = strchr (name, ':');
737 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
738 if (signal_id && detail_p)
741 else if (colon[1] == ':')
744 guint l = colon - name;
748 memcpy (buffer, name, l);
750 signal_id = signal_id_lookup (g_quark_try_string (buffer), itype);
754 gchar *signal = g_new (gchar, l + 1);
756 memcpy (signal, name, l);
758 signal_id = signal_id_lookup (g_quark_try_string (signal), itype);
762 if (signal_id && detail_p)
763 *detail_p = colon[2] ? (force_quark ? g_quark_from_string : g_quark_try_string) (colon + 2) : 0;
771 g_signal_parse_name (const gchar *detailed_signal,
775 gboolean force_detail_quark)
781 g_return_val_if_fail (detailed_signal != NULL, FALSE);
782 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), FALSE);
784 G_LOCK (g_signal_mutex);
785 signal_id = signal_parse_name (detailed_signal, itype, &detail, force_detail_quark);
786 G_UNLOCK (g_signal_mutex);
788 node = signal_id ? LOOKUP_SIGNAL_NODE (signal_id) : NULL;
789 if (!node || node->destroyed ||
790 (detail && !(node->flags & G_SIGNAL_DETAILED)))
794 *signal_id_p = signal_id;
802 g_signal_lookup (const gchar *name,
807 g_return_val_if_fail (name != NULL, 0);
808 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
810 G_LOCK (g_signal_mutex);
811 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
812 G_UNLOCK (g_signal_mutex);
817 G_CONST_RETURN gchar*
818 g_signal_name (guint signal_id)
823 G_LOCK (g_signal_mutex);
824 node = LOOKUP_SIGNAL_NODE (signal_id);
825 name = node ? node->name : NULL;
826 G_UNLOCK (g_signal_mutex);
832 g_signal_query (guint signal_id,
837 g_return_if_fail (query != NULL);
839 G_LOCK (g_signal_mutex);
840 node = LOOKUP_SIGNAL_NODE (signal_id);
841 if (!node || node->destroyed)
842 query->signal_id = 0;
845 query->signal_id = node->signal_id;
846 query->signal_name = node->name;
847 query->itype = node->itype;
848 query->signal_flags = node->flags;
849 query->return_type = node->return_type;
850 query->n_params = node->n_params;
851 query->param_types = node->param_types;
853 G_UNLOCK (g_signal_mutex);
857 g_signal_list_ids (GType itype,
865 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
866 g_return_val_if_fail (n_ids != NULL, NULL);
868 G_LOCK (g_signal_mutex);
870 keys = g_signal_key_bsa.nodes;
871 n_nodes = g_signal_key_bsa.n_nodes;
872 result = g_array_new (FALSE, FALSE, sizeof (guint));
874 for (i = 0; i < n_nodes; i++)
875 if (keys[i].itype == itype)
877 const gchar *name = g_quark_to_string (keys[i].quark);
879 /* Signal names with "_" in them are aliases to the same
880 * name with "-" instead of "_".
882 if (!strchr (name, '_'))
883 g_array_append_val (result, keys[i].signal_id);
886 *n_ids = result->len;
888 G_UNLOCK (g_signal_mutex);
890 return (guint *) g_array_free (result, FALSE);
894 g_signal_new_valist (const gchar *signal_name,
896 GSignalFlags signal_flags,
897 GClosure *class_closure,
898 GSignalAccumulator accumulator,
899 GSignalCMarshaller c_marshaller,
910 param_types = g_new (GType, n_params);
912 for (i = 0; i < n_params; i++)
913 param_types[i] = va_arg (args, GType);
918 signal_id = g_signal_newv (signal_name, itype, signal_flags,
919 class_closure, accumulator, c_marshaller,
920 return_type, n_params, param_types);
921 g_free (param_types);
927 g_signal_newc (const gchar *signal_name,
929 GSignalFlags signal_flags,
931 GSignalAccumulator accumulator,
932 GSignalCMarshaller c_marshaller,
940 g_return_val_if_fail (signal_name != NULL, 0);
942 va_start (args, n_params);
944 signal_id = g_signal_new_valist (signal_name, itype, signal_flags,
945 g_signal_type_cclosure_new (itype, class_offset),
946 accumulator, c_marshaller,
947 return_type, n_params, args);
955 g_signal_newv (const gchar *signal_name,
957 GSignalFlags signal_flags,
958 GClosure *class_closure,
959 GSignalAccumulator accumulator,
960 GSignalCMarshaller c_marshaller,
969 g_return_val_if_fail (signal_name != NULL, 0);
970 g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
972 g_return_val_if_fail (param_types != NULL, 0);
973 if (return_type != G_TYPE_NONE)
974 g_return_val_if_fail (accumulator == NULL, 0);
976 name = g_strdup (signal_name);
977 g_strdelimit (name, G_STR_DELIMITERS ":^", '_'); // FIXME do character checks like for types
979 G_LOCK (g_signal_mutex);
981 signal_id = signal_id_lookup (g_quark_try_string (name), itype);
982 node = LOOKUP_SIGNAL_NODE (signal_id);
983 if (node && !node->destroyed)
985 g_warning (G_STRLOC ": signal \"%s\" already exists in the `%s' %s",
987 g_type_name (node->itype),
988 G_TYPE_IS_INTERFACE (node->itype) ? "interface" : "class ancestry");
990 G_UNLOCK (g_signal_mutex);
993 if (node && node->itype != itype)
995 g_warning (G_STRLOC ": signal \"%s\" for type `%s' was previously created for type `%s'",
998 g_type_name (node->itype));
1000 G_UNLOCK (g_signal_mutex);
1003 for (i = 0; i < n_params; i++)
1004 if (!G_TYPE_IS_VALUE (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1006 g_warning (G_STRLOC ": parameter %d of type `%s' for signal \"%s::%s\" is not a value type",
1007 i + 1, g_type_name (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE), g_type_name (itype), name);
1009 G_UNLOCK (g_signal_mutex);
1012 if (return_type != G_TYPE_NONE && !G_TYPE_IS_VALUE (return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1014 g_warning (G_STRLOC ": return value of type `%s' for signal \"%s::%s\" is not a value type",
1015 g_type_name (return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE), g_type_name (itype), name);
1017 G_UNLOCK (g_signal_mutex);
1021 /* setup permanent portion of signal node */
1026 signal_id = g_n_signal_nodes++;
1027 node = g_new (SignalNode, 1);
1028 node->signal_id = signal_id;
1029 g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes);
1030 g_signal_nodes[signal_id] = node;
1031 node->itype = itype;
1034 key.quark = g_quark_from_string (node->name);
1035 key.signal_id = signal_id;
1036 g_bsearch_array_insert (&g_signal_key_bsa, &key, FALSE);
1037 g_strdelimit (node->name, "_", '-');
1038 key.quark = g_quark_from_static_string (node->name);
1039 g_bsearch_array_insert (&g_signal_key_bsa, &key, FALSE);
1041 node->destroyed = FALSE;
1043 /* setup reinitializable portion */
1044 node->flags = signal_flags & G_SIGNAL_FLAGS_MASK;
1045 node->n_params = n_params;
1046 node->param_types = g_memdup (param_types, sizeof (GType) * n_params);
1047 node->return_type = return_type;
1048 node->class_closure = class_closure ? g_closure_ref (class_closure) : NULL;
1050 g_closure_sink (class_closure);
1051 node->accumulator = accumulator;
1052 node->c_marshaller = c_marshaller;
1053 node->emission_hooks = NULL;
1054 if (node->c_marshaller && class_closure && G_CLOSURE_NEEDS_MARSHAL (class_closure))
1055 g_closure_set_marshal (class_closure, node->c_marshaller);
1057 G_UNLOCK (g_signal_mutex);
1062 signal_destroy_R (SignalNode *signal_node)
1064 SignalNode node = *signal_node;
1066 signal_node->destroyed = TRUE;
1068 /* reentrancy caution, zero out real contents first */
1069 signal_node->n_params = 0;
1070 signal_node->param_types = NULL;
1071 signal_node->return_type = 0;
1072 signal_node->class_closure = NULL;
1073 signal_node->accumulator = NULL;
1074 signal_node->c_marshaller = NULL;
1075 signal_node->emission_hooks = NULL;
1077 #ifdef G_ENABLE_DEBUG
1078 /* check current emissions */
1082 for (emission = (node.flags & G_SIGNAL_NO_RECURSE) ? g_restart_emissions : g_recursive_emissions;
1083 emission; emission = emission->next)
1084 if (emission->signal_id == node.signal_id)
1085 g_critical (G_STRLOC ": signal \"%s\" being destroyed is currently in emission (instance `%p')",
1086 node.name, emission->instance);
1090 /* free contents that need to
1092 G_UNLOCK (g_signal_mutex);
1093 g_free (node.param_types);
1094 g_closure_unref (node.class_closure);
1095 if (node.emission_hooks)
1097 g_hook_list_clear (node.emission_hooks);
1098 g_free (node.emission_hooks);
1100 G_LOCK (g_signal_mutex);
1104 g_signal_connect_closure_by_id (gpointer instance,
1111 guint handler_id = 0;
1113 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
1114 g_return_val_if_fail (signal_id > 0, 0);
1115 g_return_val_if_fail (closure != NULL, 0);
1117 G_LOCK (g_signal_mutex);
1118 node = LOOKUP_SIGNAL_NODE (signal_id);
1121 if (detail && !(node->flags & G_SIGNAL_DETAILED))
1122 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
1123 else if (!g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
1124 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
1127 Handler *handler = handler_new (after);
1129 handler_id = handler->id;
1130 handler->detail = detail;
1131 handler->closure = g_closure_ref (closure);
1132 g_closure_sink (closure);
1133 handler_insert (signal_id, instance, handler);
1134 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (closure))
1135 g_closure_set_marshal (closure, node->c_marshaller);
1139 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
1140 G_UNLOCK (g_signal_mutex);
1146 g_signal_connect_closure (gpointer instance,
1147 const gchar *detailed_signal,
1151 guint signal_id, handler_id = 0;
1155 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
1156 g_return_val_if_fail (detailed_signal != NULL, 0);
1157 g_return_val_if_fail (closure != NULL, 0);
1159 G_LOCK (g_signal_mutex);
1160 itype = G_TYPE_FROM_INSTANCE (instance);
1161 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
1164 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
1166 if (detail && !(node->flags & G_SIGNAL_DETAILED))
1167 g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
1168 else if (!g_type_is_a (itype, node->itype))
1169 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1172 Handler *handler = handler_new (after);
1174 handler_id = handler->id;
1175 handler->detail = detail;
1176 handler->closure = g_closure_ref (closure);
1177 g_closure_sink (closure);
1178 handler_insert (signal_id, instance, handler);
1179 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
1180 g_closure_set_marshal (handler->closure, node->c_marshaller);
1184 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1185 G_UNLOCK (g_signal_mutex);
1191 g_signal_connect_data (gpointer instance,
1192 const gchar *detailed_signal,
1193 GCallback c_handler,
1195 GClosureNotify destroy_data,
1199 guint signal_id, handler_id = 0;
1203 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
1204 g_return_val_if_fail (detailed_signal != NULL, 0);
1205 g_return_val_if_fail (c_handler != NULL, 0);
1207 G_LOCK (g_signal_mutex);
1208 itype = G_TYPE_FROM_INSTANCE (instance);
1209 signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE);
1212 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
1214 if (detail && !(node->flags & G_SIGNAL_DETAILED))
1215 g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
1216 else if (!g_type_is_a (itype, node->itype))
1217 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1220 Handler *handler = handler_new (after);
1222 handler_id = handler->id;
1223 handler->detail = detail;
1224 handler->closure = g_closure_ref ((swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data));
1225 g_closure_sink (handler->closure);
1226 handler_insert (signal_id, instance, handler);
1227 if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure))
1228 g_closure_set_marshal (handler->closure, node->c_marshaller);
1232 g_warning ("%s: signal `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1233 G_UNLOCK (g_signal_mutex);
1239 g_signal_handler_block (gpointer instance,
1244 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1245 g_return_if_fail (handler_id > 0);
1247 G_LOCK (g_signal_mutex);
1248 handler = handler_lookup (instance, handler_id, NULL);
1251 #ifndef G_DISABLE_CHECKS
1252 if (handler->block_count >= HANDLER_MAX_BLOCK_COUNT - 1)
1253 g_error (G_STRLOC ": handler block_count overflow, %s", REPORT_BUG);
1256 handler->block_count += 1;
1259 g_warning ("%s: instance `%p' has no handler with id `%u'", G_STRLOC, instance, handler_id);
1260 G_UNLOCK (g_signal_mutex);
1264 g_signal_handler_unblock (gpointer instance,
1269 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1270 g_return_if_fail (handler_id > 0);
1272 G_LOCK (g_signal_mutex);
1273 handler = handler_lookup (instance, handler_id, NULL);
1276 if (handler->block_count)
1277 handler->block_count -= 1;
1279 g_warning (G_STRLOC ": handler `%u' of instance `%p' is not blocked", handler_id, instance);
1282 g_warning ("%s: instance `%p' has no handler with id `%u'", G_STRLOC, instance, handler_id);
1283 G_UNLOCK (g_signal_mutex);
1287 g_signal_handler_disconnect (gpointer instance,
1293 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1294 g_return_if_fail (handler_id > 0);
1296 G_LOCK (g_signal_mutex);
1297 handler = handler_lookup (instance, handler_id, &signal_id);
1301 handler->block_count = 1;
1302 handler_unref_R (signal_id, instance, handler);
1305 g_warning ("%s: instance `%p' has no handler with id `%u'", G_STRLOC, instance, handler_id);
1306 G_UNLOCK (g_signal_mutex);
1310 g_signal_handlers_destroy (gpointer instance)
1312 GBSearchArray *hlbsa;
1314 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1316 G_LOCK (g_signal_mutex);
1317 hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance);
1322 /* reentrancy caution, delete instance trace first */
1323 g_hash_table_remove (g_handler_list_bsa_ht, instance);
1325 for (i = 0; i < hlbsa->n_nodes; i++)
1327 HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, i);
1328 Handler *handler = hlist->handlers;
1332 Handler *tmp = handler;
1334 handler = tmp->next;
1335 tmp->block_count = 1;
1336 /* cruel unlink, this works because _all_ handlers vanish */
1342 handler_unref_R (0, NULL, tmp);
1346 g_free (hlbsa->nodes);
1347 g_generic_node_free (&g_bsa_ts, hlbsa);
1349 G_UNLOCK (g_signal_mutex);
1353 g_signal_handler_find (gpointer instance,
1354 GSignalMatchType mask,
1361 guint handler_id = 0;
1363 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
1364 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0);
1366 if (mask & G_SIGNAL_MATCH_MASK)
1368 HandlerMatch *mlist;
1370 G_LOCK (g_signal_mutex);
1371 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, TRUE);
1374 handler_id = mlist->handler->id;
1375 handler_match_free1_R (mlist, instance);
1377 G_UNLOCK (g_signal_mutex);
1384 signal_handlers_foreach_matched_R (gpointer instance,
1385 GSignalMatchType mask,
1391 void (*callback) (gpointer instance,
1394 HandlerMatch *mlist;
1395 guint n_handlers = 0;
1397 mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, FALSE);
1401 G_UNLOCK (g_signal_mutex);
1402 callback (instance, mlist->handler->id);
1403 G_LOCK (g_signal_mutex);
1404 mlist = handler_match_free1_R (mlist, instance);
1411 g_signal_handlers_block_matched (gpointer instance,
1412 GSignalMatchType mask,
1419 guint n_handlers = 0;
1421 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
1422 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, FALSE);
1424 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
1426 G_LOCK (g_signal_mutex);
1427 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
1428 closure, func, data,
1429 g_signal_handler_block);
1430 G_UNLOCK (g_signal_mutex);
1437 g_signal_handlers_unblock_matched (gpointer instance,
1438 GSignalMatchType mask,
1445 guint n_handlers = 0;
1447 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
1448 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, FALSE);
1450 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
1452 G_LOCK (g_signal_mutex);
1453 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
1454 closure, func, data,
1455 g_signal_handler_unblock);
1456 G_UNLOCK (g_signal_mutex);
1463 g_signal_handlers_disconnect_matched (gpointer instance,
1464 GSignalMatchType mask,
1471 guint n_handlers = 0;
1473 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
1474 g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, FALSE);
1476 if (mask & (G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA))
1478 G_LOCK (g_signal_mutex);
1479 n_handlers = signal_handlers_foreach_matched_R (instance, mask, signal_id, detail,
1480 closure, func, data,
1481 g_signal_handler_disconnect);
1482 G_UNLOCK (g_signal_mutex);
1489 g_signal_has_handler_pending (gpointer instance,
1492 gboolean may_be_blocked)
1494 HandlerMatch *mlist;
1495 gboolean has_pending;
1497 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE);
1498 g_return_val_if_fail (signal_id > 0, FALSE);
1500 G_LOCK (g_signal_mutex);
1503 SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
1505 if (!(node->flags & G_SIGNAL_DETAILED))
1507 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
1508 G_UNLOCK (g_signal_mutex);
1512 mlist = handlers_find (instance,
1513 (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | (may_be_blocked ? 0 : G_SIGNAL_MATCH_UNBLOCKED)),
1514 signal_id, detail, NULL, NULL, NULL, TRUE);
1518 handler_match_free1_R (mlist, instance);
1521 has_pending = FALSE;
1522 G_UNLOCK (g_signal_mutex);
1528 g_signal_emitv (const GValue *instance_and_params,
1531 GValue *return_value)
1533 const GValue *param_values;
1538 g_return_if_fail (instance_and_params != NULL);
1539 instance = g_value_peek_pointer (instance_and_params);
1540 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1541 g_return_if_fail (signal_id > 0);
1543 param_values = instance_and_params + 1;
1545 G_LOCK (g_signal_mutex);
1546 node = LOOKUP_SIGNAL_NODE (signal_id);
1547 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
1549 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
1550 G_UNLOCK (g_signal_mutex);
1553 #ifdef G_ENABLE_DEBUG
1554 if (detail && !(node->flags & G_SIGNAL_DETAILED))
1556 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
1557 G_UNLOCK (g_signal_mutex);
1560 for (i = 0; i < node->n_params; i++)
1561 if (!G_TYPE_CHECK_VALUE_TYPE (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1563 g_critical ("%s: value for `%s' parameter %u for signal \"%s\" is of type `%s'",
1565 g_type_name (node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE),
1568 G_VALUE_TYPE_NAME (param_values + i));
1569 G_UNLOCK (g_signal_mutex);
1572 if (node->return_type != G_TYPE_NONE)
1576 g_critical ("%s: return value `%s' for signal \"%s\" is (NULL)",
1578 g_type_name (node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE),
1580 G_UNLOCK (g_signal_mutex);
1583 else if (!node->accumulator && !G_TYPE_CHECK_VALUE_TYPE (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE))
1585 g_critical ("%s: return value `%s' for signal \"%s\" is of type `%s'",
1587 g_type_name (node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE),
1589 G_VALUE_TYPE_NAME (return_value));
1590 G_UNLOCK (g_signal_mutex);
1595 return_value = NULL;
1596 #endif /* G_ENABLE_DEBUG */
1598 signal_emit_R (node, detail, instance, return_value, instance_and_params);
1599 G_UNLOCK (g_signal_mutex);
1603 g_signal_emit_valist (gpointer instance,
1608 GValue *instance_and_params, stack_values[MAX_STACK_VALUES], *free_me = NULL;
1609 GValue *param_values;
1613 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1614 g_return_if_fail (signal_id > 0);
1616 G_LOCK (g_signal_mutex);
1617 node = LOOKUP_SIGNAL_NODE (signal_id);
1618 if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype))
1620 g_warning ("%s: signal id `%u' is invalid for instance `%p'", G_STRLOC, signal_id, instance);
1621 G_UNLOCK (g_signal_mutex);
1624 #ifndef G_DISABLE_CHECKS
1625 if (detail && !(node->flags & G_SIGNAL_DETAILED))
1627 g_warning ("%s: signal id `%u' does not support detail (%u)", G_STRLOC, signal_id, detail);
1628 G_UNLOCK (g_signal_mutex);
1631 #endif /* !G_DISABLE_CHECKS */
1633 if (node->n_params < MAX_STACK_VALUES)
1634 instance_and_params = stack_values;
1637 free_me = g_new (GValue, node->n_params + 1);
1638 instance_and_params = free_me;
1640 param_values = instance_and_params + 1;
1641 for (i = 0; i < node->n_params; i++)
1645 param_values[i].g_type = 0;
1646 g_value_init (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE);
1647 G_VALUE_COLLECT (param_values + i,
1649 node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE ? G_VALUE_NOCOPY_CONTENTS : 0,
1653 g_warning ("%s: %s", G_STRLOC, error);
1656 /* we purposely leak the value here, it might not be
1657 * in a sane state if an error condition occoured
1660 g_value_unset (param_values + i);
1662 G_UNLOCK (g_signal_mutex);
1667 instance_and_params->g_type = 0;
1668 g_value_init (instance_and_params, G_TYPE_FROM_INSTANCE (instance));
1669 g_value_set_instance (instance_and_params, instance);
1670 if (node->return_type == G_TYPE_NONE)
1671 signal_emit_R (node, detail, instance, NULL, instance_and_params);
1674 GValue return_value = { 0, };
1675 gchar *error = NULL;
1677 g_value_init (&return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
1678 if (signal_emit_R (node, detail, instance, &return_value, instance_and_params))
1679 G_VALUE_LCOPY (&return_value,
1681 node->return_type & G_SIGNAL_TYPE_STATIC_SCOPE ? G_VALUE_NOCOPY_CONTENTS : 0,
1684 g_value_unset (&return_value);
1687 g_warning ("%s: %s", G_STRLOC, error);
1690 /* we purposely leak the value here, it might not be
1691 * in a sane state if an error condition occoured
1695 for (i = 0; i < node->n_params; i++)
1696 g_value_unset (param_values + i);
1697 g_value_unset (instance_and_params);
1700 G_UNLOCK (g_signal_mutex);
1704 g_signal_emit (gpointer instance,
1711 va_start (var_args, detail);
1712 g_signal_emit_valist (instance, signal_id, detail, var_args);
1717 g_signal_emit_by_name (gpointer instance,
1718 const gchar *detailed_signal,
1724 g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
1725 g_return_if_fail (detailed_signal != NULL);
1727 G_LOCK (g_signal_mutex);
1728 signal_id = signal_parse_name (detailed_signal, G_TYPE_FROM_INSTANCE (instance), &detail, TRUE);
1729 G_UNLOCK (g_signal_mutex);
1735 va_start (var_args, detailed_signal);
1736 g_signal_emit_valist (instance, signal_id, detail, var_args);
1740 g_warning ("%s: signal name `%s' is invalid for instance `%p'", G_STRLOC, detailed_signal, instance);
1744 signal_emit_R (SignalNode *node,
1747 GValue *return_value,
1748 const GValue *instance_and_params)
1750 EmissionState emission_state = 0;
1751 GSignalAccumulator accumulator;
1752 GSignalInvocationHint ihint;
1753 GClosure *class_closure;
1755 Handler *handler_list = NULL;
1756 GValue accu = { 0, };
1757 gboolean accu_used = FALSE;
1758 guint signal_id = node->signal_id;
1759 gboolean return_value_altered = FALSE;
1761 #ifdef G_ENABLE_DEBUG
1762 IF_DEBUG (SIGNALS, g_trace_instance_signals == instance || g_trap_instance_signals == instance)
1764 g_message ("%s::%s(%u) emitted (instance=%p signal-node=%p)\n",
1765 g_type_name (G_TYPE_FROM_INSTANCE (instance)),
1768 if (g_trap_instance_signals == instance)
1771 #endif /* G_ENABLE_DEBUG */
1773 if (node->flags & G_SIGNAL_NO_RECURSE)
1775 Emission *emission = emission_find (g_restart_emissions, signal_id, detail, instance);
1779 *emission->state_p = EMISSION_RESTART;
1780 return return_value_altered;
1783 ihint.signal_id = node->signal_id;
1784 ihint.detail = detail;
1785 accumulator = node->accumulator;
1787 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
1788 emission_push ((node->flags & G_SIGNAL_NO_RECURSE) ? &g_restart_emissions : &g_recursive_emissions,
1789 signal_id, detail, instance, &emission_state);
1790 class_closure = node->class_closure;
1795 handler_unref_R (signal_id, instance, handler_list);
1796 hlist = handler_list_lookup (signal_id, instance);
1797 handler_list = hlist ? hlist->handlers : NULL;
1799 handler_ref (handler_list);
1801 ihint.run_type = G_SIGNAL_RUN_FIRST;
1803 if ((node->flags & G_SIGNAL_RUN_FIRST) && class_closure)
1805 emission_state = EMISSION_RUN;
1807 G_UNLOCK (g_signal_mutex);
1811 g_value_reset (&accu);
1812 g_closure_invoke (class_closure,
1815 instance_and_params,
1817 if (!accumulator (&ihint, return_value, &accu) &&
1818 emission_state == EMISSION_RUN)
1819 emission_state = EMISSION_STOP;
1823 g_closure_invoke (class_closure,
1826 instance_and_params,
1828 G_LOCK (g_signal_mutex);
1829 return_value_altered = TRUE;
1831 if (emission_state == EMISSION_STOP)
1833 else if (emission_state == EMISSION_RESTART)
1837 if (node->emission_hooks)
1839 emission_state = EMISSION_HOOK;
1841 G_UNLOCK (g_signal_mutex);
1842 g_print ("emission_hooks()\n");
1843 G_LOCK (g_signal_mutex);
1845 if (emission_state == EMISSION_RESTART)
1851 Handler *handler = handler_list;
1853 emission_state = EMISSION_RUN;
1854 handler_ref (handler);
1861 handler_unref_R (signal_id, instance, handler_list);
1862 handler_list = handler;
1865 else if (!handler->block_count && (!handler->detail || handler->detail == detail))
1867 G_UNLOCK (g_signal_mutex);
1871 g_value_reset (&accu);
1872 g_closure_invoke (handler->closure,
1875 instance_and_params,
1877 if (!accumulator (&ihint, return_value, &accu) &&
1878 emission_state == EMISSION_RUN)
1879 emission_state = EMISSION_STOP;
1883 g_closure_invoke (handler->closure,
1886 instance_and_params,
1888 G_LOCK (g_signal_mutex);
1889 return_value_altered = TRUE;
1891 tmp = emission_state == EMISSION_RUN ? handler->next : NULL;
1894 tmp = handler->next;
1898 handler_unref_R (signal_id, instance, handler_list);
1899 handler_list = handler;
1904 if (emission_state == EMISSION_STOP)
1906 else if (emission_state == EMISSION_RESTART)
1910 ihint.run_type = G_SIGNAL_RUN_LAST;
1912 if ((node->flags & G_SIGNAL_RUN_LAST) && class_closure)
1914 emission_state = EMISSION_RUN;
1916 G_UNLOCK (g_signal_mutex);
1920 g_value_reset (&accu);
1921 g_closure_invoke (class_closure,
1924 instance_and_params,
1926 if (!accumulator (&ihint, return_value, &accu) &&
1927 emission_state == EMISSION_RUN)
1928 emission_state = EMISSION_STOP;
1932 g_closure_invoke (class_closure,
1935 instance_and_params,
1937 G_LOCK (g_signal_mutex);
1938 return_value_altered = TRUE;
1940 if (emission_state == EMISSION_STOP)
1942 else if (emission_state == EMISSION_RESTART)
1948 Handler *handler = handler_list;
1950 emission_state = EMISSION_RUN;
1951 handler_ref (handler);
1956 if (handler->after && !handler->block_count && (!handler->detail || handler->detail == detail))
1958 G_UNLOCK (g_signal_mutex);
1962 g_value_reset (&accu);
1963 g_closure_invoke (handler->closure,
1966 instance_and_params,
1968 if (!accumulator (&ihint, return_value, &accu) &&
1969 emission_state == EMISSION_RUN)
1970 emission_state = EMISSION_STOP;
1974 g_closure_invoke (handler->closure,
1977 instance_and_params,
1979 G_LOCK (g_signal_mutex);
1980 return_value_altered = TRUE;
1982 tmp = emission_state == EMISSION_RUN ? handler->next : NULL;
1985 tmp = handler->next;
1989 handler_unref_R (signal_id, instance, handler);
1994 if (emission_state == EMISSION_STOP)
1996 else if (emission_state == EMISSION_RESTART)
2002 ihint.run_type = G_SIGNAL_RUN_CLEANUP;
2004 if ((node->flags & G_SIGNAL_RUN_CLEANUP) && class_closure)
2006 gboolean need_unset = FALSE;
2008 emission_state = EMISSION_STOP;
2010 G_UNLOCK (g_signal_mutex);
2011 if (node->return_type != G_TYPE_NONE)
2015 g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE);
2019 g_value_reset (&accu);
2021 g_closure_invoke (class_closure,
2022 node->return_type != G_TYPE_NONE ? &accu : NULL,
2024 instance_and_params,
2027 g_value_unset (&accu);
2028 G_LOCK (g_signal_mutex);
2030 if (emission_state == EMISSION_RESTART)
2035 handler_unref_R (signal_id, instance, handler_list);
2037 emission_pop ((node->flags & G_SIGNAL_NO_RECURSE) ? &g_restart_emissions : &g_recursive_emissions, &emission_state);
2039 g_value_unset (&accu);
2041 return return_value_altered;
2045 /* --- compile standard marshallers --- */
2046 #include "gvaluetypes.h"
2047 #include "gobject.h"
2050 #include "gmarshal.c"