/src/pango/subprojects/glib/gobject/gsignal.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GObject - GLib Type, Object, Parameter and Signal Library |
2 | | * Copyright (C) 2000-2001 Red Hat, Inc. |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | * |
6 | | * This library is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU Lesser General Public |
8 | | * License as published by the Free Software Foundation; either |
9 | | * version 2.1 of the License, or (at your option) any later version. |
10 | | * |
11 | | * This library is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | | * Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General |
17 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
18 | | * |
19 | | * this code is based on the original GtkSignal implementation |
20 | | * for the Gtk+ library by Peter Mattis <petm@xcf.berkeley.edu> |
21 | | */ |
22 | | |
23 | | /* |
24 | | * MT safe |
25 | | */ |
26 | | |
27 | | #include "config.h" |
28 | | |
29 | | #include <string.h> |
30 | | #include <signal.h> |
31 | | |
32 | | #include "gsignal.h" |
33 | | #include "gtype-private.h" |
34 | | #include "gbsearcharray.h" |
35 | | #include "gvaluecollector.h" |
36 | | #include "gvaluetypes.h" |
37 | | #include "gobject.h" |
38 | | #include "genums.h" |
39 | | #include "gobject_trace.h" |
40 | | |
41 | | |
42 | | #define REPORT_BUG "please report occurrence circumstances to https://gitlab.gnome.org/GNOME/glib/issues/new" |
43 | | |
44 | | /* --- typedefs --- */ |
45 | | typedef struct _SignalNode SignalNode; |
46 | | typedef struct _SignalKey SignalKey; |
47 | | typedef struct _Emission Emission; |
48 | | typedef struct _Handler Handler; |
49 | | typedef struct _HandlerList HandlerList; |
50 | | typedef struct _HandlerMatch HandlerMatch; |
51 | | typedef enum |
52 | | { |
53 | | EMISSION_STOP, |
54 | | EMISSION_RUN, |
55 | | EMISSION_HOOK, |
56 | | EMISSION_RESTART |
57 | | } EmissionState; |
58 | | |
59 | | |
60 | | /* --- prototypes --- */ |
61 | | static inline guint signal_id_lookup (const gchar *name, |
62 | | GType itype); |
63 | | static void signal_destroy_R (SignalNode *signal_node); |
64 | | static inline HandlerList* handler_list_ensure (guint signal_id, |
65 | | gpointer instance); |
66 | | static inline HandlerList* handler_list_lookup (guint signal_id, |
67 | | gpointer instance); |
68 | | static inline Handler* handler_new (guint signal_id, |
69 | | gpointer instance, |
70 | | gboolean after); |
71 | | static void handler_insert (guint signal_id, |
72 | | gpointer instance, |
73 | | Handler *handler); |
74 | | static Handler* handler_lookup (gpointer instance, |
75 | | gulong handler_id, |
76 | | GClosure *closure, |
77 | | guint *signal_id_p); |
78 | | static inline HandlerMatch* handler_match_prepend (HandlerMatch *list, |
79 | | Handler *handler, |
80 | | guint signal_id); |
81 | | static inline HandlerMatch* handler_match_free1_R (HandlerMatch *node, |
82 | | gpointer instance); |
83 | | static HandlerMatch* handlers_find (gpointer instance, |
84 | | GSignalMatchType mask, |
85 | | guint signal_id, |
86 | | GQuark detail, |
87 | | GClosure *closure, |
88 | | gpointer func, |
89 | | gpointer data, |
90 | | gboolean one_and_only); |
91 | | static inline void handler_ref (Handler *handler); |
92 | | static inline void handler_unref_R (guint signal_id, |
93 | | gpointer instance, |
94 | | Handler *handler); |
95 | | static gint handler_lists_cmp (gconstpointer node1, |
96 | | gconstpointer node2); |
97 | | static inline void emission_push (Emission *emission); |
98 | | static inline void emission_pop (Emission *emission); |
99 | | static inline Emission* emission_find (guint signal_id, |
100 | | GQuark detail, |
101 | | gpointer instance); |
102 | | static gint class_closures_cmp (gconstpointer node1, |
103 | | gconstpointer node2); |
104 | | static gint signal_key_cmp (gconstpointer node1, |
105 | | gconstpointer node2); |
106 | | static gboolean signal_emit_unlocked_R (SignalNode *node, |
107 | | GQuark detail, |
108 | | gpointer instance, |
109 | | GValue *return_value, |
110 | | const GValue *instance_and_params); |
111 | | static void add_invalid_closure_notify (Handler *handler, |
112 | | gpointer instance); |
113 | | static void remove_invalid_closure_notify (Handler *handler, |
114 | | gpointer instance); |
115 | | static void invalid_closure_notify (gpointer data, |
116 | | GClosure *closure); |
117 | | static const gchar * type_debug_name (GType type); |
118 | | static void node_check_deprecated (const SignalNode *node); |
119 | | static void node_update_single_va_closure (SignalNode *node); |
120 | | |
121 | | |
122 | | /* --- structures --- */ |
123 | | typedef struct |
124 | | { |
125 | | GSignalAccumulator func; |
126 | | gpointer data; |
127 | | } SignalAccumulator; |
128 | | typedef struct |
129 | | { |
130 | | GHook hook; |
131 | | GQuark detail; |
132 | | } SignalHook; |
133 | 0 | #define SIGNAL_HOOK(hook) ((SignalHook*) (hook)) |
134 | | |
135 | | struct _SignalNode |
136 | | { |
137 | | /* permanent portion */ |
138 | | guint signal_id; |
139 | | GType itype; |
140 | | const gchar *name; |
141 | | guint destroyed : 1; |
142 | | |
143 | | /* reinitializable portion */ |
144 | | guint flags : 9; |
145 | | guint n_params : 8; |
146 | | guint single_va_closure_is_valid : 1; |
147 | | guint single_va_closure_is_after : 1; |
148 | | GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */ |
149 | | GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */ |
150 | | GBSearchArray *class_closure_bsa; |
151 | | SignalAccumulator *accumulator; |
152 | | GSignalCMarshaller c_marshaller; |
153 | | GSignalCVaMarshaller va_marshaller; |
154 | | GHookList *emission_hooks; |
155 | | |
156 | | GClosure *single_va_closure; |
157 | | }; |
158 | | |
159 | 0 | #define SINGLE_VA_CLOSURE_EMPTY_MAGIC GINT_TO_POINTER(1) /* indicates single_va_closure is valid but empty */ |
160 | | |
161 | | struct _SignalKey |
162 | | { |
163 | | GType itype; |
164 | | GQuark quark; |
165 | | guint signal_id; |
166 | | }; |
167 | | |
168 | | struct _Emission |
169 | | { |
170 | | Emission *next; |
171 | | gpointer instance; |
172 | | GSignalInvocationHint ihint; |
173 | | EmissionState state; |
174 | | GType chain_type; |
175 | | }; |
176 | | |
177 | | struct _HandlerList |
178 | | { |
179 | | guint signal_id; |
180 | | Handler *handlers; |
181 | | Handler *tail_before; /* normal signal handlers are appended here */ |
182 | | Handler *tail_after; /* CONNECT_AFTER handlers are appended here */ |
183 | | }; |
184 | | |
185 | | struct _Handler |
186 | | { |
187 | | gulong sequential_number; |
188 | | Handler *next; |
189 | | Handler *prev; |
190 | | GQuark detail; |
191 | | guint signal_id; |
192 | | guint ref_count; |
193 | | guint block_count : 16; |
194 | 0 | #define HANDLER_MAX_BLOCK_COUNT (1 << 16) |
195 | | guint after : 1; |
196 | | guint has_invalid_closure_notify : 1; |
197 | | GClosure *closure; |
198 | | gpointer instance; |
199 | | }; |
200 | | struct _HandlerMatch |
201 | | { |
202 | | Handler *handler; |
203 | | HandlerMatch *next; |
204 | | guint signal_id; |
205 | | }; |
206 | | |
207 | | typedef struct |
208 | | { |
209 | | GType instance_type; /* 0 for default closure */ |
210 | | GClosure *closure; |
211 | | } ClassClosure; |
212 | | |
213 | | |
214 | | /* --- variables --- */ |
215 | | static GBSearchArray *g_signal_key_bsa = NULL; |
216 | | static const GBSearchConfig g_signal_key_bconfig = { |
217 | | sizeof (SignalKey), |
218 | | signal_key_cmp, |
219 | | G_BSEARCH_ARRAY_ALIGN_POWER2, |
220 | | }; |
221 | | static GBSearchConfig g_signal_hlbsa_bconfig = { |
222 | | sizeof (HandlerList), |
223 | | handler_lists_cmp, |
224 | | 0, |
225 | | }; |
226 | | static GBSearchConfig g_class_closure_bconfig = { |
227 | | sizeof (ClassClosure), |
228 | | class_closures_cmp, |
229 | | 0, |
230 | | }; |
231 | | static GHashTable *g_handler_list_bsa_ht = NULL; |
232 | | static Emission *g_emissions = NULL; |
233 | | static gulong g_handler_sequential_number = 1; |
234 | | static GHashTable *g_handlers = NULL; |
235 | | |
236 | | G_LOCK_DEFINE_STATIC (g_signal_mutex); |
237 | 75.3k | #define SIGNAL_LOCK() G_LOCK (g_signal_mutex) |
238 | 75.3k | #define SIGNAL_UNLOCK() G_UNLOCK (g_signal_mutex) |
239 | | |
240 | | |
241 | | /* --- signal nodes --- */ |
242 | | static guint g_n_signal_nodes = 0; |
243 | | static SignalNode **g_signal_nodes = NULL; |
244 | | |
245 | | static inline SignalNode* |
246 | | LOOKUP_SIGNAL_NODE (guint signal_id) |
247 | 5 | { |
248 | 5 | if (signal_id < g_n_signal_nodes) |
249 | 5 | return g_signal_nodes[signal_id]; |
250 | 0 | else |
251 | 0 | return NULL; |
252 | 5 | } |
253 | | |
254 | | |
255 | | /* --- functions --- */ |
256 | | /* @key must have already been validated with is_valid() |
257 | | * Modifies @key in place. */ |
258 | | static void |
259 | | canonicalize_key (gchar *key) |
260 | 0 | { |
261 | 0 | gchar *p; |
262 | |
|
263 | 0 | for (p = key; *p != 0; p++) |
264 | 0 | { |
265 | 0 | gchar c = *p; |
266 | |
|
267 | 0 | if (c == '_') |
268 | 0 | *p = '-'; |
269 | 0 | } |
270 | 0 | } |
271 | | |
272 | | /* @key must have already been validated with is_valid() */ |
273 | | static gboolean |
274 | | is_canonical (const gchar *key) |
275 | 10 | { |
276 | 10 | return (strchr (key, '_') == NULL); |
277 | 10 | } |
278 | | |
279 | | /** |
280 | | * g_signal_is_valid_name: |
281 | | * @name: the canonical name of the signal |
282 | | * |
283 | | * Validate a signal name. This can be useful for dynamically-generated signals |
284 | | * which need to be validated at run-time before actually trying to create them. |
285 | | * |
286 | | * See [func@GObject.signal_new] for details of the rules for valid names. |
287 | | * The rules for signal names are the same as those for property names. |
288 | | * |
289 | | * Returns: %TRUE if @name is a valid signal name, %FALSE otherwise. |
290 | | * Since: 2.66 |
291 | | */ |
292 | | gboolean |
293 | | g_signal_is_valid_name (const gchar *name) |
294 | 5 | { |
295 | | /* FIXME: We allow this, against our own documentation (the leading `-` is |
296 | | * invalid), because GTK has historically used this. */ |
297 | 5 | if (g_str_equal (name, "-gtk-private-changed")) |
298 | 0 | return TRUE; |
299 | | |
300 | 5 | return g_param_spec_is_valid_name (name); |
301 | 5 | } |
302 | | |
303 | | static inline guint |
304 | | signal_id_lookup (const gchar *name, |
305 | | GType itype) |
306 | 5 | { |
307 | 5 | GQuark quark; |
308 | 5 | GType *ifaces, type = itype; |
309 | 5 | SignalKey key; |
310 | 5 | guint n_ifaces; |
311 | | |
312 | 5 | quark = g_quark_try_string (name); |
313 | 5 | key.quark = quark; |
314 | | |
315 | | /* try looking up signals for this type and its ancestors */ |
316 | 5 | do |
317 | 5 | { |
318 | 5 | SignalKey *signal_key; |
319 | | |
320 | 5 | key.itype = type; |
321 | 5 | signal_key = g_bsearch_array_lookup (g_signal_key_bsa, &g_signal_key_bconfig, &key); |
322 | | |
323 | 5 | if (signal_key) |
324 | 0 | return signal_key->signal_id; |
325 | | |
326 | 5 | type = g_type_parent (type); |
327 | 5 | } |
328 | 5 | while (type); |
329 | | |
330 | | /* no luck, try interfaces it exports */ |
331 | 5 | ifaces = g_type_interfaces (itype, &n_ifaces); |
332 | 5 | while (n_ifaces--) |
333 | 0 | { |
334 | 0 | SignalKey *signal_key; |
335 | |
|
336 | 0 | key.itype = ifaces[n_ifaces]; |
337 | 0 | signal_key = g_bsearch_array_lookup (g_signal_key_bsa, &g_signal_key_bconfig, &key); |
338 | |
|
339 | 0 | if (signal_key) |
340 | 0 | { |
341 | 0 | g_free (ifaces); |
342 | 0 | return signal_key->signal_id; |
343 | 0 | } |
344 | 0 | } |
345 | 5 | g_free (ifaces); |
346 | | |
347 | | /* If the @name is non-canonical, try again. This is the slow path — people |
348 | | * should use canonical names in their queries if they want performance. */ |
349 | 5 | if (!is_canonical (name)) |
350 | 0 | { |
351 | 0 | guint signal_id; |
352 | 0 | gchar *name_copy = g_strdup (name); |
353 | 0 | canonicalize_key (name_copy); |
354 | |
|
355 | 0 | signal_id = signal_id_lookup (name_copy, itype); |
356 | |
|
357 | 0 | g_free (name_copy); |
358 | |
|
359 | 0 | return signal_id; |
360 | 0 | } |
361 | | |
362 | 5 | return 0; |
363 | 5 | } |
364 | | |
365 | | static gint |
366 | | class_closures_cmp (gconstpointer node1, |
367 | | gconstpointer node2) |
368 | 0 | { |
369 | 0 | const ClassClosure *c1 = node1, *c2 = node2; |
370 | | |
371 | 0 | return G_BSEARCH_ARRAY_CMP (c1->instance_type, c2->instance_type); |
372 | 0 | } |
373 | | |
374 | | static gint |
375 | | handler_lists_cmp (gconstpointer node1, |
376 | | gconstpointer node2) |
377 | 0 | { |
378 | 0 | const HandlerList *hlist1 = node1, *hlist2 = node2; |
379 | | |
380 | 0 | return G_BSEARCH_ARRAY_CMP (hlist1->signal_id, hlist2->signal_id); |
381 | 0 | } |
382 | | |
383 | | static inline HandlerList* |
384 | | handler_list_ensure (guint signal_id, |
385 | | gpointer instance) |
386 | 0 | { |
387 | 0 | GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance); |
388 | 0 | HandlerList key; |
389 | | |
390 | 0 | key.signal_id = signal_id; |
391 | 0 | key.handlers = NULL; |
392 | 0 | key.tail_before = NULL; |
393 | 0 | key.tail_after = NULL; |
394 | 0 | if (!hlbsa) |
395 | 0 | { |
396 | 0 | hlbsa = g_bsearch_array_create (&g_signal_hlbsa_bconfig); |
397 | 0 | } |
398 | 0 | hlbsa = g_bsearch_array_insert (hlbsa, &g_signal_hlbsa_bconfig, &key); |
399 | 0 | g_hash_table_insert (g_handler_list_bsa_ht, instance, hlbsa); |
400 | 0 | return g_bsearch_array_lookup (hlbsa, &g_signal_hlbsa_bconfig, &key); |
401 | 0 | } |
402 | | |
403 | | static inline HandlerList* |
404 | | handler_list_lookup (guint signal_id, |
405 | | gpointer instance) |
406 | 0 | { |
407 | 0 | GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance); |
408 | 0 | HandlerList key; |
409 | | |
410 | 0 | key.signal_id = signal_id; |
411 | | |
412 | 0 | return hlbsa ? g_bsearch_array_lookup (hlbsa, &g_signal_hlbsa_bconfig, &key) : NULL; |
413 | 0 | } |
414 | | |
415 | | static guint |
416 | | handler_hash (gconstpointer key) |
417 | 0 | { |
418 | 0 | return (guint)((Handler*)key)->sequential_number; |
419 | 0 | } |
420 | | |
421 | | static gboolean |
422 | | handler_equal (gconstpointer a, gconstpointer b) |
423 | 0 | { |
424 | 0 | Handler *ha = (Handler *)a; |
425 | 0 | Handler *hb = (Handler *)b; |
426 | 0 | return (ha->sequential_number == hb->sequential_number) && |
427 | 0 | (ha->instance == hb->instance); |
428 | 0 | } |
429 | | |
430 | | static Handler* |
431 | | handler_lookup (gpointer instance, |
432 | | gulong handler_id, |
433 | | GClosure *closure, |
434 | | guint *signal_id_p) |
435 | 0 | { |
436 | 0 | GBSearchArray *hlbsa; |
437 | |
|
438 | 0 | if (handler_id) |
439 | 0 | { |
440 | 0 | Handler key; |
441 | 0 | key.sequential_number = handler_id; |
442 | 0 | key.instance = instance; |
443 | 0 | return g_hash_table_lookup (g_handlers, &key); |
444 | |
|
445 | 0 | } |
446 | | |
447 | 0 | hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance); |
448 | | |
449 | 0 | if (hlbsa) |
450 | 0 | { |
451 | 0 | guint i; |
452 | | |
453 | 0 | for (i = 0; i < hlbsa->n_nodes; i++) |
454 | 0 | { |
455 | 0 | HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i); |
456 | 0 | Handler *handler; |
457 | | |
458 | 0 | for (handler = hlist->handlers; handler; handler = handler->next) |
459 | 0 | if (closure ? (handler->closure == closure) : (handler->sequential_number == handler_id)) |
460 | 0 | { |
461 | 0 | if (signal_id_p) |
462 | 0 | *signal_id_p = hlist->signal_id; |
463 | |
|
464 | 0 | return handler; |
465 | 0 | } |
466 | 0 | } |
467 | 0 | } |
468 | | |
469 | 0 | return NULL; |
470 | 0 | } |
471 | | |
472 | | static inline HandlerMatch* |
473 | | handler_match_prepend (HandlerMatch *list, |
474 | | Handler *handler, |
475 | | guint signal_id) |
476 | 0 | { |
477 | 0 | HandlerMatch *node; |
478 | | |
479 | 0 | node = g_slice_new (HandlerMatch); |
480 | 0 | node->handler = handler; |
481 | 0 | node->next = list; |
482 | 0 | node->signal_id = signal_id; |
483 | 0 | handler_ref (handler); |
484 | | |
485 | 0 | return node; |
486 | 0 | } |
487 | | static inline HandlerMatch* |
488 | | handler_match_free1_R (HandlerMatch *node, |
489 | | gpointer instance) |
490 | 0 | { |
491 | 0 | HandlerMatch *next = node->next; |
492 | | |
493 | 0 | handler_unref_R (node->signal_id, instance, node->handler); |
494 | 0 | g_slice_free (HandlerMatch, node); |
495 | | |
496 | 0 | return next; |
497 | 0 | } |
498 | | |
499 | | static HandlerMatch* |
500 | | handlers_find (gpointer instance, |
501 | | GSignalMatchType mask, |
502 | | guint signal_id, |
503 | | GQuark detail, |
504 | | GClosure *closure, |
505 | | gpointer func, |
506 | | gpointer data, |
507 | | gboolean one_and_only) |
508 | 0 | { |
509 | 0 | HandlerMatch *mlist = NULL; |
510 | | |
511 | 0 | if (mask & G_SIGNAL_MATCH_ID) |
512 | 0 | { |
513 | 0 | HandlerList *hlist = handler_list_lookup (signal_id, instance); |
514 | 0 | Handler *handler; |
515 | 0 | SignalNode *node = NULL; |
516 | | |
517 | 0 | if (mask & G_SIGNAL_MATCH_FUNC) |
518 | 0 | { |
519 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
520 | 0 | if (!node || !node->c_marshaller) |
521 | 0 | return NULL; |
522 | 0 | } |
523 | | |
524 | 0 | mask = ~mask; |
525 | 0 | for (handler = hlist ? hlist->handlers : NULL; handler; handler = handler->next) |
526 | 0 | if (handler->sequential_number && |
527 | 0 | ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) && |
528 | 0 | ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) && |
529 | 0 | ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) && |
530 | 0 | ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) && |
531 | 0 | ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller && |
532 | 0 | G_REAL_CLOSURE (handler->closure)->meta_marshal == NULL && |
533 | 0 | ((GCClosure*) handler->closure)->callback == func))) |
534 | 0 | { |
535 | 0 | mlist = handler_match_prepend (mlist, handler, signal_id); |
536 | 0 | if (one_and_only) |
537 | 0 | return mlist; |
538 | 0 | } |
539 | 0 | } |
540 | 0 | else |
541 | 0 | { |
542 | 0 | GBSearchArray *hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance); |
543 | | |
544 | 0 | mask = ~mask; |
545 | 0 | if (hlbsa) |
546 | 0 | { |
547 | 0 | guint i; |
548 | | |
549 | 0 | for (i = 0; i < hlbsa->n_nodes; i++) |
550 | 0 | { |
551 | 0 | HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i); |
552 | 0 | SignalNode *node = NULL; |
553 | 0 | Handler *handler; |
554 | | |
555 | 0 | if (!(mask & G_SIGNAL_MATCH_FUNC)) |
556 | 0 | { |
557 | 0 | node = LOOKUP_SIGNAL_NODE (hlist->signal_id); |
558 | 0 | if (!node->c_marshaller) |
559 | 0 | continue; |
560 | 0 | } |
561 | | |
562 | 0 | for (handler = hlist->handlers; handler; handler = handler->next) |
563 | 0 | if (handler->sequential_number && |
564 | 0 | ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) && |
565 | 0 | ((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) && |
566 | 0 | ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) && |
567 | 0 | ((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) && |
568 | 0 | ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller && |
569 | 0 | G_REAL_CLOSURE (handler->closure)->meta_marshal == NULL && |
570 | 0 | ((GCClosure*) handler->closure)->callback == func))) |
571 | 0 | { |
572 | 0 | mlist = handler_match_prepend (mlist, handler, hlist->signal_id); |
573 | 0 | if (one_and_only) |
574 | 0 | return mlist; |
575 | 0 | } |
576 | 0 | } |
577 | 0 | } |
578 | 0 | } |
579 | | |
580 | 0 | return mlist; |
581 | 0 | } |
582 | | |
583 | | static inline Handler* |
584 | | handler_new (guint signal_id, gpointer instance, gboolean after) |
585 | 0 | { |
586 | 0 | Handler *handler = g_slice_new (Handler); |
587 | 0 | #ifndef G_DISABLE_CHECKS |
588 | 0 | if (g_handler_sequential_number < 1) |
589 | 0 | g_error (G_STRLOC ": handler id overflow, %s", REPORT_BUG); |
590 | 0 | #endif |
591 | | |
592 | 0 | handler->sequential_number = g_handler_sequential_number++; |
593 | 0 | handler->prev = NULL; |
594 | 0 | handler->next = NULL; |
595 | 0 | handler->detail = 0; |
596 | 0 | handler->signal_id = signal_id; |
597 | 0 | handler->instance = instance; |
598 | 0 | handler->ref_count = 1; |
599 | 0 | handler->block_count = 0; |
600 | 0 | handler->after = after != FALSE; |
601 | 0 | handler->closure = NULL; |
602 | 0 | handler->has_invalid_closure_notify = 0; |
603 | |
|
604 | 0 | g_hash_table_add (g_handlers, handler); |
605 | | |
606 | 0 | return handler; |
607 | 0 | } |
608 | | |
609 | | static inline void |
610 | | handler_ref (Handler *handler) |
611 | 0 | { |
612 | 0 | g_return_if_fail (handler->ref_count > 0); |
613 | | |
614 | 0 | handler->ref_count++; |
615 | 0 | } |
616 | | |
617 | | static inline void |
618 | | handler_unref_R (guint signal_id, |
619 | | gpointer instance, |
620 | | Handler *handler) |
621 | 0 | { |
622 | 0 | g_return_if_fail (handler->ref_count > 0); |
623 | | |
624 | 0 | handler->ref_count--; |
625 | |
|
626 | 0 | if (G_UNLIKELY (handler->ref_count == 0)) |
627 | 0 | { |
628 | 0 | HandlerList *hlist = NULL; |
629 | |
|
630 | 0 | if (handler->next) |
631 | 0 | handler->next->prev = handler->prev; |
632 | 0 | if (handler->prev) /* watch out for g_signal_handlers_destroy()! */ |
633 | 0 | handler->prev->next = handler->next; |
634 | 0 | else |
635 | 0 | { |
636 | 0 | hlist = handler_list_lookup (signal_id, instance); |
637 | 0 | g_assert (hlist != NULL); |
638 | 0 | hlist->handlers = handler->next; |
639 | 0 | } |
640 | | |
641 | 0 | if (instance) |
642 | 0 | { |
643 | | /* check if we are removing the handler pointed to by tail_before */ |
644 | 0 | if (!handler->after && (!handler->next || handler->next->after)) |
645 | 0 | { |
646 | 0 | if (!hlist) |
647 | 0 | hlist = handler_list_lookup (signal_id, instance); |
648 | 0 | if (hlist) |
649 | 0 | { |
650 | 0 | g_assert (hlist->tail_before == handler); /* paranoid */ |
651 | 0 | hlist->tail_before = handler->prev; |
652 | 0 | } |
653 | 0 | } |
654 | | |
655 | | /* check if we are removing the handler pointed to by tail_after */ |
656 | 0 | if (!handler->next) |
657 | 0 | { |
658 | 0 | if (!hlist) |
659 | 0 | hlist = handler_list_lookup (signal_id, instance); |
660 | 0 | if (hlist) |
661 | 0 | { |
662 | 0 | g_assert (hlist->tail_after == handler); /* paranoid */ |
663 | 0 | hlist->tail_after = handler->prev; |
664 | 0 | } |
665 | 0 | } |
666 | 0 | } |
667 | | |
668 | 0 | SIGNAL_UNLOCK (); |
669 | 0 | g_closure_unref (handler->closure); |
670 | 0 | SIGNAL_LOCK (); |
671 | 0 | g_slice_free (Handler, handler); |
672 | 0 | } |
673 | 0 | } |
674 | | |
675 | | static void |
676 | | handler_insert (guint signal_id, |
677 | | gpointer instance, |
678 | | Handler *handler) |
679 | 0 | { |
680 | 0 | HandlerList *hlist; |
681 | | |
682 | 0 | g_assert (handler->prev == NULL && handler->next == NULL); /* paranoid */ |
683 | | |
684 | 0 | hlist = handler_list_ensure (signal_id, instance); |
685 | 0 | if (!hlist->handlers) |
686 | 0 | { |
687 | 0 | hlist->handlers = handler; |
688 | 0 | if (!handler->after) |
689 | 0 | hlist->tail_before = handler; |
690 | 0 | } |
691 | 0 | else if (handler->after) |
692 | 0 | { |
693 | 0 | handler->prev = hlist->tail_after; |
694 | 0 | hlist->tail_after->next = handler; |
695 | 0 | } |
696 | 0 | else |
697 | 0 | { |
698 | 0 | if (hlist->tail_before) |
699 | 0 | { |
700 | 0 | handler->next = hlist->tail_before->next; |
701 | 0 | if (handler->next) |
702 | 0 | handler->next->prev = handler; |
703 | 0 | handler->prev = hlist->tail_before; |
704 | 0 | hlist->tail_before->next = handler; |
705 | 0 | } |
706 | 0 | else /* insert !after handler into a list of only after handlers */ |
707 | 0 | { |
708 | 0 | handler->next = hlist->handlers; |
709 | 0 | if (handler->next) |
710 | 0 | handler->next->prev = handler; |
711 | 0 | hlist->handlers = handler; |
712 | 0 | } |
713 | 0 | hlist->tail_before = handler; |
714 | 0 | } |
715 | |
|
716 | 0 | if (!handler->next) |
717 | 0 | hlist->tail_after = handler; |
718 | 0 | } |
719 | | |
720 | | static void |
721 | | node_update_single_va_closure (SignalNode *node) |
722 | 0 | { |
723 | 0 | GClosure *closure = NULL; |
724 | 0 | gboolean is_after = FALSE; |
725 | | |
726 | | /* Fast path single-handler without boxing the arguments in GValues */ |
727 | 0 | if (G_TYPE_IS_OBJECT (node->itype) && |
728 | 0 | (node->flags & (G_SIGNAL_MUST_COLLECT)) == 0 && |
729 | 0 | (node->emission_hooks == NULL || node->emission_hooks->hooks == NULL)) |
730 | 0 | { |
731 | 0 | GSignalFlags run_type; |
732 | 0 | ClassClosure * cc; |
733 | 0 | GBSearchArray *bsa = node->class_closure_bsa; |
734 | |
|
735 | 0 | if (bsa == NULL || bsa->n_nodes == 0) |
736 | 0 | closure = SINGLE_VA_CLOSURE_EMPTY_MAGIC; |
737 | 0 | else if (bsa->n_nodes == 1) |
738 | 0 | { |
739 | | /* Look for default class closure (can't support non-default as it |
740 | | chains up using GValues */ |
741 | 0 | cc = g_bsearch_array_get_nth (bsa, &g_class_closure_bconfig, 0); |
742 | 0 | if (cc->instance_type == 0) |
743 | 0 | { |
744 | 0 | run_type = node->flags & (G_SIGNAL_RUN_FIRST|G_SIGNAL_RUN_LAST|G_SIGNAL_RUN_CLEANUP); |
745 | | /* Only support *one* of run-first or run-last, not multiple or cleanup */ |
746 | 0 | if (run_type == G_SIGNAL_RUN_FIRST || |
747 | 0 | run_type == G_SIGNAL_RUN_LAST) |
748 | 0 | { |
749 | 0 | closure = cc->closure; |
750 | 0 | is_after = (run_type == G_SIGNAL_RUN_LAST); |
751 | 0 | } |
752 | 0 | } |
753 | 0 | } |
754 | 0 | } |
755 | |
|
756 | 0 | node->single_va_closure_is_valid = TRUE; |
757 | 0 | node->single_va_closure = closure; |
758 | 0 | node->single_va_closure_is_after = (guint) is_after; |
759 | 0 | } |
760 | | |
761 | | static inline void |
762 | | emission_push (Emission *emission) |
763 | 0 | { |
764 | 0 | emission->next = g_emissions; |
765 | 0 | g_emissions = emission; |
766 | 0 | } |
767 | | |
768 | | static inline void |
769 | | emission_pop (Emission *emission) |
770 | 0 | { |
771 | 0 | Emission *node, *last = NULL; |
772 | |
|
773 | 0 | for (node = g_emissions; node; last = node, node = last->next) |
774 | 0 | if (node == emission) |
775 | 0 | { |
776 | 0 | if (last) |
777 | 0 | last->next = node->next; |
778 | 0 | else |
779 | 0 | g_emissions = node->next; |
780 | 0 | return; |
781 | 0 | } |
782 | 0 | g_assert_not_reached (); |
783 | 0 | } |
784 | | |
785 | | static inline Emission* |
786 | | emission_find (guint signal_id, |
787 | | GQuark detail, |
788 | | gpointer instance) |
789 | 0 | { |
790 | 0 | Emission *emission; |
791 | | |
792 | 0 | for (emission = g_emissions; emission; emission = emission->next) |
793 | 0 | if (emission->instance == instance && |
794 | 0 | emission->ihint.signal_id == signal_id && |
795 | 0 | emission->ihint.detail == detail) |
796 | 0 | return emission; |
797 | 0 | return NULL; |
798 | 0 | } |
799 | | |
800 | | static inline Emission* |
801 | | emission_find_innermost (gpointer instance) |
802 | 0 | { |
803 | 0 | Emission *emission; |
804 | | |
805 | 0 | for (emission = g_emissions; emission; emission = emission->next) |
806 | 0 | if (emission->instance == instance) |
807 | 0 | return emission; |
808 | | |
809 | 0 | return NULL; |
810 | 0 | } |
811 | | |
812 | | static gint |
813 | | signal_key_cmp (gconstpointer node1, |
814 | | gconstpointer node2) |
815 | 0 | { |
816 | 0 | const SignalKey *key1 = node1, *key2 = node2; |
817 | | |
818 | 0 | if (key1->itype == key2->itype) |
819 | 0 | return G_BSEARCH_ARRAY_CMP (key1->quark, key2->quark); |
820 | 0 | else |
821 | 0 | return G_BSEARCH_ARRAY_CMP (key1->itype, key2->itype); |
822 | 0 | } |
823 | | |
824 | | void |
825 | | _g_signal_init (void) |
826 | 12 | { |
827 | 12 | SIGNAL_LOCK (); |
828 | 12 | if (!g_n_signal_nodes) |
829 | 12 | { |
830 | | /* setup handler list binary searchable array hash table (in german, that'd be one word ;) */ |
831 | 12 | g_handler_list_bsa_ht = g_hash_table_new (g_direct_hash, NULL); |
832 | 12 | g_signal_key_bsa = g_bsearch_array_create (&g_signal_key_bconfig); |
833 | | |
834 | | /* invalid (0) signal_id */ |
835 | 12 | g_n_signal_nodes = 1; |
836 | 12 | g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes); |
837 | 12 | g_signal_nodes[0] = NULL; |
838 | 12 | g_handlers = g_hash_table_new (handler_hash, handler_equal); |
839 | 12 | } |
840 | 12 | SIGNAL_UNLOCK (); |
841 | 12 | } |
842 | | |
843 | | void |
844 | | _g_signals_destroy (GType itype) |
845 | 0 | { |
846 | 0 | guint i; |
847 | | |
848 | 0 | SIGNAL_LOCK (); |
849 | 0 | for (i = 1; i < g_n_signal_nodes; i++) |
850 | 0 | { |
851 | 0 | SignalNode *node = g_signal_nodes[i]; |
852 | | |
853 | 0 | if (node->itype == itype) |
854 | 0 | { |
855 | 0 | if (node->destroyed) |
856 | 0 | g_critical (G_STRLOC ": signal \"%s\" of type '%s' already destroyed", |
857 | 0 | node->name, |
858 | 0 | type_debug_name (node->itype)); |
859 | 0 | else |
860 | 0 | signal_destroy_R (node); |
861 | 0 | } |
862 | 0 | } |
863 | 0 | SIGNAL_UNLOCK (); |
864 | 0 | } |
865 | | |
866 | | /** |
867 | | * g_signal_stop_emission: |
868 | | * @instance: (type GObject.Object): the object whose signal handlers you wish to stop. |
869 | | * @signal_id: the signal identifier, as returned by g_signal_lookup(). |
870 | | * @detail: the detail which the signal was emitted with. |
871 | | * |
872 | | * Stops a signal's current emission. |
873 | | * |
874 | | * This will prevent the default method from running, if the signal was |
875 | | * %G_SIGNAL_RUN_LAST and you connected normally (i.e. without the "after" |
876 | | * flag). |
877 | | * |
878 | | * Prints a warning if used on a signal which isn't being emitted. |
879 | | */ |
880 | | void |
881 | | g_signal_stop_emission (gpointer instance, |
882 | | guint signal_id, |
883 | | GQuark detail) |
884 | 0 | { |
885 | 0 | SignalNode *node; |
886 | | |
887 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
888 | 0 | g_return_if_fail (signal_id > 0); |
889 | | |
890 | 0 | SIGNAL_LOCK (); |
891 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
892 | 0 | if (node && detail && !(node->flags & G_SIGNAL_DETAILED)) |
893 | 0 | { |
894 | 0 | g_critical ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail); |
895 | 0 | SIGNAL_UNLOCK (); |
896 | 0 | return; |
897 | 0 | } |
898 | 0 | if (node && g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype)) |
899 | 0 | { |
900 | 0 | Emission *emission = emission_find (signal_id, detail, instance); |
901 | | |
902 | 0 | if (emission) |
903 | 0 | { |
904 | 0 | if (emission->state == EMISSION_HOOK) |
905 | 0 | g_critical (G_STRLOC ": emission of signal \"%s\" for instance '%p' cannot be stopped from emission hook", |
906 | 0 | node->name, instance); |
907 | 0 | else if (emission->state == EMISSION_RUN) |
908 | 0 | emission->state = EMISSION_STOP; |
909 | 0 | } |
910 | 0 | else |
911 | 0 | g_critical (G_STRLOC ": no emission of signal \"%s\" to stop for instance '%p'", |
912 | 0 | node->name, instance); |
913 | 0 | } |
914 | 0 | else |
915 | 0 | g_critical ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance); |
916 | 0 | SIGNAL_UNLOCK (); |
917 | 0 | } |
918 | | |
919 | | static void |
920 | | signal_finalize_hook (GHookList *hook_list, |
921 | | GHook *hook) |
922 | 0 | { |
923 | 0 | GDestroyNotify destroy = hook->destroy; |
924 | |
|
925 | 0 | if (destroy) |
926 | 0 | { |
927 | 0 | hook->destroy = NULL; |
928 | 0 | SIGNAL_UNLOCK (); |
929 | 0 | destroy (hook->data); |
930 | 0 | SIGNAL_LOCK (); |
931 | 0 | } |
932 | 0 | } |
933 | | |
934 | | /** |
935 | | * g_signal_add_emission_hook: |
936 | | * @signal_id: the signal identifier, as returned by g_signal_lookup(). |
937 | | * @detail: the detail on which to call the hook. |
938 | | * @hook_func: (not nullable): a #GSignalEmissionHook function. |
939 | | * @hook_data: (nullable) (closure hook_func): user data for @hook_func. |
940 | | * @data_destroy: (nullable) (destroy hook_data): a #GDestroyNotify for @hook_data. |
941 | | * |
942 | | * Adds an emission hook for a signal, which will get called for any emission |
943 | | * of that signal, independent of the instance. This is possible only |
944 | | * for signals which don't have %G_SIGNAL_NO_HOOKS flag set. |
945 | | * |
946 | | * Returns: the hook id, for later use with g_signal_remove_emission_hook(). |
947 | | */ |
948 | | gulong |
949 | | g_signal_add_emission_hook (guint signal_id, |
950 | | GQuark detail, |
951 | | GSignalEmissionHook hook_func, |
952 | | gpointer hook_data, |
953 | | GDestroyNotify data_destroy) |
954 | 0 | { |
955 | 0 | static gulong seq_hook_id = 1; |
956 | 0 | SignalNode *node; |
957 | 0 | GHook *hook; |
958 | 0 | SignalHook *signal_hook; |
959 | |
|
960 | 0 | g_return_val_if_fail (signal_id > 0, 0); |
961 | 0 | g_return_val_if_fail (hook_func != NULL, 0); |
962 | | |
963 | 0 | SIGNAL_LOCK (); |
964 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
965 | 0 | if (!node || node->destroyed) |
966 | 0 | { |
967 | 0 | g_critical ("%s: invalid signal id '%u'", G_STRLOC, signal_id); |
968 | 0 | SIGNAL_UNLOCK (); |
969 | 0 | return 0; |
970 | 0 | } |
971 | 0 | if (node->flags & G_SIGNAL_NO_HOOKS) |
972 | 0 | { |
973 | 0 | g_critical ("%s: signal id '%u' does not support emission hooks (G_SIGNAL_NO_HOOKS flag set)", G_STRLOC, signal_id); |
974 | 0 | SIGNAL_UNLOCK (); |
975 | 0 | return 0; |
976 | 0 | } |
977 | 0 | if (detail && !(node->flags & G_SIGNAL_DETAILED)) |
978 | 0 | { |
979 | 0 | g_critical ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail); |
980 | 0 | SIGNAL_UNLOCK (); |
981 | 0 | return 0; |
982 | 0 | } |
983 | 0 | node->single_va_closure_is_valid = FALSE; |
984 | 0 | if (!node->emission_hooks) |
985 | 0 | { |
986 | 0 | node->emission_hooks = g_new (GHookList, 1); |
987 | 0 | g_hook_list_init (node->emission_hooks, sizeof (SignalHook)); |
988 | 0 | node->emission_hooks->finalize_hook = signal_finalize_hook; |
989 | 0 | } |
990 | |
|
991 | 0 | node_check_deprecated (node); |
992 | |
|
993 | 0 | hook = g_hook_alloc (node->emission_hooks); |
994 | 0 | hook->data = hook_data; |
995 | 0 | hook->func = (gpointer) hook_func; |
996 | 0 | hook->destroy = data_destroy; |
997 | 0 | signal_hook = SIGNAL_HOOK (hook); |
998 | 0 | signal_hook->detail = detail; |
999 | 0 | node->emission_hooks->seq_id = seq_hook_id; |
1000 | 0 | g_hook_append (node->emission_hooks, hook); |
1001 | 0 | seq_hook_id = node->emission_hooks->seq_id; |
1002 | |
|
1003 | 0 | SIGNAL_UNLOCK (); |
1004 | |
|
1005 | 0 | return hook->hook_id; |
1006 | 0 | } |
1007 | | |
1008 | | /** |
1009 | | * g_signal_remove_emission_hook: |
1010 | | * @signal_id: the id of the signal |
1011 | | * @hook_id: the id of the emission hook, as returned by |
1012 | | * g_signal_add_emission_hook() |
1013 | | * |
1014 | | * Deletes an emission hook. |
1015 | | */ |
1016 | | void |
1017 | | g_signal_remove_emission_hook (guint signal_id, |
1018 | | gulong hook_id) |
1019 | 0 | { |
1020 | 0 | SignalNode *node; |
1021 | |
|
1022 | 0 | g_return_if_fail (signal_id > 0); |
1023 | 0 | g_return_if_fail (hook_id > 0); |
1024 | | |
1025 | 0 | SIGNAL_LOCK (); |
1026 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
1027 | 0 | if (!node || node->destroyed) |
1028 | 0 | { |
1029 | 0 | g_critical ("%s: invalid signal id '%u'", G_STRLOC, signal_id); |
1030 | 0 | goto out; |
1031 | 0 | } |
1032 | 0 | else if (!node->emission_hooks || !g_hook_destroy (node->emission_hooks, hook_id)) |
1033 | 0 | g_critical ("%s: signal \"%s\" had no hook (%lu) to remove", G_STRLOC, node->name, hook_id); |
1034 | | |
1035 | 0 | node->single_va_closure_is_valid = FALSE; |
1036 | |
|
1037 | 0 | out: |
1038 | 0 | SIGNAL_UNLOCK (); |
1039 | 0 | } |
1040 | | |
1041 | | static inline guint |
1042 | | signal_parse_name (const gchar *name, |
1043 | | GType itype, |
1044 | | GQuark *detail_p, |
1045 | | gboolean force_quark) |
1046 | 0 | { |
1047 | 0 | const gchar *colon = strchr (name, ':'); |
1048 | 0 | guint signal_id; |
1049 | | |
1050 | 0 | if (!colon) |
1051 | 0 | { |
1052 | 0 | signal_id = signal_id_lookup (name, itype); |
1053 | 0 | if (signal_id && detail_p) |
1054 | 0 | *detail_p = 0; |
1055 | 0 | } |
1056 | 0 | else if (colon[1] == ':') |
1057 | 0 | { |
1058 | 0 | gchar buffer[32]; |
1059 | 0 | size_t l = (size_t) (colon - name); |
1060 | | |
1061 | 0 | if (colon[2] == '\0') |
1062 | 0 | return 0; |
1063 | | |
1064 | 0 | if (l < 32) |
1065 | 0 | { |
1066 | 0 | memcpy (buffer, name, l); |
1067 | 0 | buffer[l] = 0; |
1068 | 0 | signal_id = signal_id_lookup (buffer, itype); |
1069 | 0 | } |
1070 | 0 | else |
1071 | 0 | { |
1072 | 0 | gchar *signal = g_new (gchar, l + 1); |
1073 | | |
1074 | 0 | memcpy (signal, name, l); |
1075 | 0 | signal[l] = 0; |
1076 | 0 | signal_id = signal_id_lookup (signal, itype); |
1077 | 0 | g_free (signal); |
1078 | 0 | } |
1079 | | |
1080 | 0 | if (signal_id && detail_p) |
1081 | 0 | *detail_p = (force_quark ? g_quark_from_string : g_quark_try_string) (colon + 2); |
1082 | 0 | } |
1083 | 0 | else |
1084 | 0 | signal_id = 0; |
1085 | 0 | return signal_id; |
1086 | 0 | } |
1087 | | |
1088 | | /** |
1089 | | * g_signal_parse_name: |
1090 | | * @detailed_signal: a string of the form "signal-name::detail". |
1091 | | * @itype: The interface/instance type that introduced "signal-name". |
1092 | | * @signal_id_p: (out): Location to store the signal id. |
1093 | | * @detail_p: (out): Location to store the detail quark. |
1094 | | * @force_detail_quark: %TRUE forces creation of a #GQuark for the detail. |
1095 | | * |
1096 | | * Internal function to parse a signal name into its @signal_id |
1097 | | * and @detail quark. |
1098 | | * |
1099 | | * Returns: Whether the signal name could successfully be parsed and @signal_id_p and @detail_p contain valid return values. |
1100 | | */ |
1101 | | gboolean |
1102 | | g_signal_parse_name (const gchar *detailed_signal, |
1103 | | GType itype, |
1104 | | guint *signal_id_p, |
1105 | | GQuark *detail_p, |
1106 | | gboolean force_detail_quark) |
1107 | 0 | { |
1108 | 0 | SignalNode *node; |
1109 | 0 | GQuark detail = 0; |
1110 | 0 | guint signal_id; |
1111 | | |
1112 | 0 | g_return_val_if_fail (detailed_signal != NULL, FALSE); |
1113 | 0 | g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), FALSE); |
1114 | | |
1115 | 0 | SIGNAL_LOCK (); |
1116 | 0 | signal_id = signal_parse_name (detailed_signal, itype, &detail, force_detail_quark); |
1117 | |
|
1118 | 0 | node = signal_id ? LOOKUP_SIGNAL_NODE (signal_id) : NULL; |
1119 | |
|
1120 | 0 | if (!node || node->destroyed || |
1121 | 0 | (detail && !(node->flags & G_SIGNAL_DETAILED))) |
1122 | 0 | { |
1123 | 0 | SIGNAL_UNLOCK (); |
1124 | 0 | return FALSE; |
1125 | 0 | } |
1126 | | |
1127 | 0 | SIGNAL_UNLOCK (); |
1128 | |
|
1129 | 0 | if (signal_id_p) |
1130 | 0 | *signal_id_p = signal_id; |
1131 | 0 | if (detail_p) |
1132 | 0 | *detail_p = detail; |
1133 | | |
1134 | 0 | return TRUE; |
1135 | 0 | } |
1136 | | |
1137 | | /** |
1138 | | * g_signal_stop_emission_by_name: |
1139 | | * @instance: (type GObject.Object): the object whose signal handlers you wish to stop. |
1140 | | * @detailed_signal: a string of the form "signal-name::detail". |
1141 | | * |
1142 | | * Stops a signal's current emission. |
1143 | | * |
1144 | | * This is just like g_signal_stop_emission() except it will look up the |
1145 | | * signal id for you. |
1146 | | */ |
1147 | | void |
1148 | | g_signal_stop_emission_by_name (gpointer instance, |
1149 | | const gchar *detailed_signal) |
1150 | 0 | { |
1151 | 0 | guint signal_id; |
1152 | 0 | GQuark detail = 0; |
1153 | 0 | GType itype; |
1154 | | |
1155 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
1156 | 0 | g_return_if_fail (detailed_signal != NULL); |
1157 | | |
1158 | 0 | SIGNAL_LOCK (); |
1159 | 0 | itype = G_TYPE_FROM_INSTANCE (instance); |
1160 | 0 | signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE); |
1161 | 0 | if (signal_id) |
1162 | 0 | { |
1163 | 0 | SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id); |
1164 | | |
1165 | 0 | if (detail && !(node->flags & G_SIGNAL_DETAILED)) |
1166 | 0 | g_critical ("%s: signal '%s' does not support details", G_STRLOC, detailed_signal); |
1167 | 0 | else if (!g_type_is_a (itype, node->itype)) |
1168 | 0 | g_critical ("%s: signal '%s' is invalid for instance '%p' of type '%s'", |
1169 | 0 | G_STRLOC, detailed_signal, instance, g_type_name (itype)); |
1170 | 0 | else |
1171 | 0 | { |
1172 | 0 | Emission *emission = emission_find (signal_id, detail, instance); |
1173 | | |
1174 | 0 | if (emission) |
1175 | 0 | { |
1176 | 0 | if (emission->state == EMISSION_HOOK) |
1177 | 0 | g_critical (G_STRLOC ": emission of signal \"%s\" for instance '%p' cannot be stopped from emission hook", |
1178 | 0 | node->name, instance); |
1179 | 0 | else if (emission->state == EMISSION_RUN) |
1180 | 0 | emission->state = EMISSION_STOP; |
1181 | 0 | } |
1182 | 0 | else |
1183 | 0 | g_critical (G_STRLOC ": no emission of signal \"%s\" to stop for instance '%p'", |
1184 | 0 | node->name, instance); |
1185 | 0 | } |
1186 | 0 | } |
1187 | 0 | else |
1188 | 0 | g_critical ("%s: signal '%s' is invalid for instance '%p' of type '%s'", |
1189 | 0 | G_STRLOC, detailed_signal, instance, g_type_name (itype)); |
1190 | 0 | SIGNAL_UNLOCK (); |
1191 | 0 | } |
1192 | | |
1193 | | /** |
1194 | | * g_signal_lookup: |
1195 | | * @name: the signal's name. |
1196 | | * @itype: the type that the signal operates on. |
1197 | | * |
1198 | | * Given the name of the signal and the type of object it connects to, gets |
1199 | | * the signal's identifying integer. Emitting the signal by number is |
1200 | | * somewhat faster than using the name each time. |
1201 | | * |
1202 | | * Also tries the ancestors of the given type. |
1203 | | * |
1204 | | * The type class passed as @itype must already have been instantiated (for |
1205 | | * example, using g_type_class_ref()) for this function to work, as signals are |
1206 | | * always installed during class initialization. |
1207 | | * |
1208 | | * See g_signal_new() for details on allowed signal names. |
1209 | | * |
1210 | | * Returns: the signal's identifying number, or 0 if no signal was found. |
1211 | | */ |
1212 | | guint |
1213 | | g_signal_lookup (const gchar *name, |
1214 | | GType itype) |
1215 | 0 | { |
1216 | 0 | guint signal_id; |
1217 | 0 | g_return_val_if_fail (name != NULL, 0); |
1218 | 0 | g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0); |
1219 | | |
1220 | 0 | SIGNAL_LOCK (); |
1221 | 0 | signal_id = signal_id_lookup (name, itype); |
1222 | 0 | SIGNAL_UNLOCK (); |
1223 | 0 | if (!signal_id) |
1224 | 0 | { |
1225 | | /* give elaborate warnings */ |
1226 | 0 | if (!g_type_name (itype)) |
1227 | 0 | g_critical (G_STRLOC ": unable to look up signal \"%s\" for invalid type id '%"G_GUINTPTR_FORMAT"'", |
1228 | 0 | name, (guintptr) itype); |
1229 | 0 | else if (!g_signal_is_valid_name (name)) |
1230 | 0 | g_critical (G_STRLOC ": unable to look up invalid signal name \"%s\" on type '%s'", |
1231 | 0 | name, g_type_name (itype)); |
1232 | 0 | } |
1233 | | |
1234 | 0 | return signal_id; |
1235 | 0 | } |
1236 | | |
1237 | | /** |
1238 | | * g_signal_list_ids: |
1239 | | * @itype: Instance or interface type. |
1240 | | * @n_ids: Location to store the number of signal ids for @itype. |
1241 | | * |
1242 | | * Lists the signals by id that a certain instance or interface type |
1243 | | * created. Further information about the signals can be acquired through |
1244 | | * g_signal_query(). |
1245 | | * |
1246 | | * Returns: (array length=n_ids) (transfer full): Newly allocated array of signal IDs. |
1247 | | */ |
1248 | | guint* |
1249 | | g_signal_list_ids (GType itype, |
1250 | | guint *n_ids) |
1251 | 0 | { |
1252 | 0 | SignalKey *keys; |
1253 | 0 | GArray *result; |
1254 | 0 | guint n_nodes; |
1255 | 0 | guint i; |
1256 | | |
1257 | 0 | g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), NULL); |
1258 | 0 | g_return_val_if_fail (n_ids != NULL, NULL); |
1259 | | |
1260 | 0 | SIGNAL_LOCK (); |
1261 | 0 | keys = g_bsearch_array_get_nth (g_signal_key_bsa, &g_signal_key_bconfig, 0); |
1262 | 0 | n_nodes = g_bsearch_array_get_n_nodes (g_signal_key_bsa); |
1263 | 0 | result = g_array_new (FALSE, FALSE, sizeof (guint)); |
1264 | | |
1265 | 0 | for (i = 0; i < n_nodes; i++) |
1266 | 0 | if (keys[i].itype == itype) |
1267 | 0 | { |
1268 | 0 | g_array_append_val (result, keys[i].signal_id); |
1269 | 0 | } |
1270 | 0 | *n_ids = result->len; |
1271 | 0 | SIGNAL_UNLOCK (); |
1272 | 0 | if (!n_nodes) |
1273 | 0 | { |
1274 | | /* give elaborate warnings */ |
1275 | 0 | if (!g_type_name (itype)) |
1276 | 0 | g_critical (G_STRLOC ": unable to list signals for invalid type id '%"G_GUINTPTR_FORMAT"'", |
1277 | 0 | (guintptr) itype); |
1278 | 0 | else if (!G_TYPE_IS_INSTANTIATABLE (itype) && !G_TYPE_IS_INTERFACE (itype)) |
1279 | 0 | g_critical (G_STRLOC ": unable to list signals of non instantiatable type '%s'", |
1280 | 0 | g_type_name (itype)); |
1281 | 0 | else if (!g_type_class_peek (itype) && !G_TYPE_IS_INTERFACE (itype)) |
1282 | 0 | g_critical (G_STRLOC ": unable to list signals of unloaded type '%s'", |
1283 | 0 | g_type_name (itype)); |
1284 | 0 | } |
1285 | | |
1286 | 0 | return (guint*) g_array_free (result, FALSE); |
1287 | 0 | } |
1288 | | |
1289 | | /** |
1290 | | * g_signal_name: |
1291 | | * @signal_id: the signal's identifying number. |
1292 | | * |
1293 | | * Given the signal's identifier, finds its name. |
1294 | | * |
1295 | | * Two different signals may have the same name, if they have differing types. |
1296 | | * |
1297 | | * Returns: (nullable): the signal name, or %NULL if the signal number was invalid. |
1298 | | */ |
1299 | | const gchar * |
1300 | | g_signal_name (guint signal_id) |
1301 | 0 | { |
1302 | 0 | SignalNode *node; |
1303 | 0 | const gchar *name; |
1304 | | |
1305 | 0 | SIGNAL_LOCK (); |
1306 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
1307 | 0 | name = node ? node->name : NULL; |
1308 | 0 | SIGNAL_UNLOCK (); |
1309 | | |
1310 | 0 | return (char*) name; |
1311 | 0 | } |
1312 | | |
1313 | | /** |
1314 | | * g_signal_query: |
1315 | | * @signal_id: The signal id of the signal to query information for. |
1316 | | * @query: (out caller-allocates) (not optional): A user provided structure that is |
1317 | | * filled in with constant values upon success. |
1318 | | * |
1319 | | * Queries the signal system for in-depth information about a |
1320 | | * specific signal. This function will fill in a user-provided |
1321 | | * structure to hold signal-specific information. If an invalid |
1322 | | * signal id is passed in, the @signal_id member of the #GSignalQuery |
1323 | | * is 0. All members filled into the #GSignalQuery structure should |
1324 | | * be considered constant and have to be left untouched. |
1325 | | */ |
1326 | | void |
1327 | | g_signal_query (guint signal_id, |
1328 | | GSignalQuery *query) |
1329 | 0 | { |
1330 | 0 | SignalNode *node; |
1331 | | |
1332 | 0 | g_return_if_fail (query != NULL); |
1333 | | |
1334 | 0 | SIGNAL_LOCK (); |
1335 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
1336 | 0 | if (!node || node->destroyed) |
1337 | 0 | query->signal_id = 0; |
1338 | 0 | else |
1339 | 0 | { |
1340 | 0 | query->signal_id = node->signal_id; |
1341 | 0 | query->signal_name = node->name; |
1342 | 0 | query->itype = node->itype; |
1343 | 0 | query->signal_flags = node->flags; |
1344 | 0 | query->return_type = node->return_type; |
1345 | 0 | query->n_params = node->n_params; |
1346 | 0 | query->param_types = node->param_types; |
1347 | 0 | } |
1348 | 0 | SIGNAL_UNLOCK (); |
1349 | 0 | } |
1350 | | |
1351 | | /** |
1352 | | * g_signal_new: |
1353 | | * @signal_name: the name for the signal |
1354 | | * @itype: the type this signal pertains to. It will also pertain to |
1355 | | * types which are derived from this type. |
1356 | | * @signal_flags: a combination of #GSignalFlags specifying detail of when |
1357 | | * the default handler is to be invoked. You should at least specify |
1358 | | * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST. |
1359 | | * @class_offset: The offset of the function pointer in the class structure |
1360 | | * for this type. Used to invoke a class method generically. Pass 0 to |
1361 | | * not associate a class method slot with this signal. |
1362 | | * @accumulator: (nullable) (scope forever): the accumulator for this signal; may be %NULL. |
1363 | | * @accu_data: (nullable) (closure accumulator): user data for the @accumulator. |
1364 | | * @c_marshaller: (nullable): the function to translate arrays of parameter |
1365 | | * values to signal emissions into C language callback invocations or %NULL. |
1366 | | * @return_type: the type of return value, or %G_TYPE_NONE for a signal |
1367 | | * without a return value. |
1368 | | * @n_params: the number of parameter types to follow. |
1369 | | * @...: a list of types, one for each parameter. |
1370 | | * |
1371 | | * Creates a new signal. (This is usually done in the class initializer.) |
1372 | | * |
1373 | | * A signal name consists of segments consisting of ASCII letters and |
1374 | | * digits, separated by either the `-` or `_` character. The first |
1375 | | * character of a signal name must be a letter. Names which violate these |
1376 | | * rules lead to undefined behaviour. These are the same rules as for property |
1377 | | * naming (see g_param_spec_internal()). |
1378 | | * |
1379 | | * When registering a signal and looking up a signal, either separator can |
1380 | | * be used, but they cannot be mixed. Using `-` is considerably more efficient. |
1381 | | * Using `_` is discouraged. |
1382 | | * |
1383 | | * If 0 is used for @class_offset subclasses cannot override the class handler |
1384 | | * in their class_init method by doing super_class->signal_handler = my_signal_handler. |
1385 | | * Instead they will have to use g_signal_override_class_handler(). |
1386 | | * |
1387 | | * If @c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as |
1388 | | * the marshaller for this signal. In some simple cases, g_signal_new() |
1389 | | * will use a more optimized c_marshaller and va_marshaller for the signal |
1390 | | * instead of g_cclosure_marshal_generic(). |
1391 | | * |
1392 | | * If @c_marshaller is non-%NULL, you need to also specify a va_marshaller |
1393 | | * using g_signal_set_va_marshaller() or the generic va_marshaller will |
1394 | | * be used. |
1395 | | * |
1396 | | * Returns: the signal id |
1397 | | */ |
1398 | | guint |
1399 | | g_signal_new (const gchar *signal_name, |
1400 | | GType itype, |
1401 | | GSignalFlags signal_flags, |
1402 | | guint class_offset, |
1403 | | GSignalAccumulator accumulator, |
1404 | | gpointer accu_data, |
1405 | | GSignalCMarshaller c_marshaller, |
1406 | | GType return_type, |
1407 | | guint n_params, |
1408 | | ...) |
1409 | 5 | { |
1410 | 5 | va_list args; |
1411 | 5 | guint signal_id; |
1412 | | |
1413 | 5 | g_return_val_if_fail (signal_name != NULL, 0); |
1414 | | |
1415 | 5 | va_start (args, n_params); |
1416 | | |
1417 | 5 | signal_id = g_signal_new_valist (signal_name, itype, signal_flags, |
1418 | 5 | class_offset ? g_signal_type_cclosure_new (itype, class_offset) : NULL, |
1419 | 5 | accumulator, accu_data, c_marshaller, |
1420 | 5 | return_type, n_params, args); |
1421 | | |
1422 | 5 | va_end (args); |
1423 | | |
1424 | 5 | return signal_id; |
1425 | 5 | } |
1426 | | |
1427 | | /** |
1428 | | * g_signal_new_class_handler: |
1429 | | * @signal_name: the name for the signal |
1430 | | * @itype: the type this signal pertains to. It will also pertain to |
1431 | | * types which are derived from this type. |
1432 | | * @signal_flags: a combination of #GSignalFlags specifying detail of when |
1433 | | * the default handler is to be invoked. You should at least specify |
1434 | | * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST. |
1435 | | * @class_handler: (nullable) (scope forever): a #GCallback which acts as class implementation of |
1436 | | * this signal. Used to invoke a class method generically. Pass %NULL to |
1437 | | * not associate a class method with this signal. |
1438 | | * @accumulator: (nullable) (scope forever): the accumulator for this signal; may be %NULL. |
1439 | | * @accu_data: (nullable) (closure accumulator): user data for the @accumulator. |
1440 | | * @c_marshaller: (nullable): the function to translate arrays of parameter |
1441 | | * values to signal emissions into C language callback invocations or %NULL. |
1442 | | * @return_type: the type of return value, or %G_TYPE_NONE for a signal |
1443 | | * without a return value. |
1444 | | * @n_params: the number of parameter types to follow. |
1445 | | * @...: a list of types, one for each parameter. |
1446 | | * |
1447 | | * Creates a new signal. (This is usually done in the class initializer.) |
1448 | | * |
1449 | | * This is a variant of g_signal_new() that takes a C callback instead |
1450 | | * of a class offset for the signal's class handler. This function |
1451 | | * doesn't need a function pointer exposed in the class structure of |
1452 | | * an object definition, instead the function pointer is passed |
1453 | | * directly and can be overridden by derived classes with |
1454 | | * g_signal_override_class_closure() or |
1455 | | * g_signal_override_class_handler() and chained to with |
1456 | | * g_signal_chain_from_overridden() or |
1457 | | * g_signal_chain_from_overridden_handler(). |
1458 | | * |
1459 | | * See g_signal_new() for information about signal names. |
1460 | | * |
1461 | | * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as |
1462 | | * the marshaller for this signal. |
1463 | | * |
1464 | | * Returns: the signal id |
1465 | | * |
1466 | | * Since: 2.18 |
1467 | | */ |
1468 | | guint |
1469 | | g_signal_new_class_handler (const gchar *signal_name, |
1470 | | GType itype, |
1471 | | GSignalFlags signal_flags, |
1472 | | GCallback class_handler, |
1473 | | GSignalAccumulator accumulator, |
1474 | | gpointer accu_data, |
1475 | | GSignalCMarshaller c_marshaller, |
1476 | | GType return_type, |
1477 | | guint n_params, |
1478 | | ...) |
1479 | 0 | { |
1480 | 0 | va_list args; |
1481 | 0 | guint signal_id; |
1482 | |
|
1483 | 0 | g_return_val_if_fail (signal_name != NULL, 0); |
1484 | | |
1485 | 0 | va_start (args, n_params); |
1486 | |
|
1487 | 0 | signal_id = g_signal_new_valist (signal_name, itype, signal_flags, |
1488 | 0 | class_handler ? g_cclosure_new (class_handler, NULL, NULL) : NULL, |
1489 | 0 | accumulator, accu_data, c_marshaller, |
1490 | 0 | return_type, n_params, args); |
1491 | |
|
1492 | 0 | va_end (args); |
1493 | |
|
1494 | 0 | return signal_id; |
1495 | 0 | } |
1496 | | |
1497 | | static inline ClassClosure* |
1498 | | signal_find_class_closure (SignalNode *node, |
1499 | | GType itype) |
1500 | 0 | { |
1501 | 0 | GBSearchArray *bsa = node->class_closure_bsa; |
1502 | 0 | ClassClosure *cc; |
1503 | |
|
1504 | 0 | if (bsa) |
1505 | 0 | { |
1506 | 0 | ClassClosure key; |
1507 | | |
1508 | | /* cc->instance_type is 0 for default closure */ |
1509 | |
|
1510 | 0 | if (g_bsearch_array_get_n_nodes (bsa) == 1) |
1511 | 0 | { |
1512 | 0 | cc = g_bsearch_array_get_nth (bsa, &g_class_closure_bconfig, 0); |
1513 | 0 | if (cc && cc->instance_type == 0) /* check for default closure */ |
1514 | 0 | return cc; |
1515 | 0 | } |
1516 | | |
1517 | 0 | key.instance_type = itype; |
1518 | 0 | cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key); |
1519 | 0 | while (!cc && key.instance_type) |
1520 | 0 | { |
1521 | 0 | key.instance_type = g_type_parent (key.instance_type); |
1522 | 0 | cc = g_bsearch_array_lookup (bsa, &g_class_closure_bconfig, &key); |
1523 | 0 | } |
1524 | 0 | } |
1525 | 0 | else |
1526 | 0 | cc = NULL; |
1527 | 0 | return cc; |
1528 | 0 | } |
1529 | | |
1530 | | static inline GClosure* |
1531 | | signal_lookup_closure (SignalNode *node, |
1532 | | GTypeInstance *instance) |
1533 | 0 | { |
1534 | 0 | ClassClosure *cc; |
1535 | |
|
1536 | 0 | cc = signal_find_class_closure (node, G_TYPE_FROM_INSTANCE (instance)); |
1537 | 0 | return cc ? cc->closure : NULL; |
1538 | 0 | } |
1539 | | |
1540 | | static void |
1541 | | signal_add_class_closure (SignalNode *node, |
1542 | | GType itype, |
1543 | | GClosure *closure) |
1544 | 5 | { |
1545 | 5 | ClassClosure key; |
1546 | | |
1547 | 5 | node->single_va_closure_is_valid = FALSE; |
1548 | | |
1549 | 5 | if (!node->class_closure_bsa) |
1550 | 5 | node->class_closure_bsa = g_bsearch_array_create (&g_class_closure_bconfig); |
1551 | 5 | key.instance_type = itype; |
1552 | 5 | key.closure = g_closure_ref (closure); |
1553 | 5 | node->class_closure_bsa = g_bsearch_array_insert (node->class_closure_bsa, |
1554 | 5 | &g_class_closure_bconfig, |
1555 | 5 | &key); |
1556 | 5 | g_closure_sink (closure); |
1557 | 5 | if (node->c_marshaller && closure && G_CLOSURE_NEEDS_MARSHAL (closure)) |
1558 | 5 | { |
1559 | 5 | g_closure_set_marshal (closure, node->c_marshaller); |
1560 | 5 | if (node->va_marshaller) |
1561 | 5 | _g_closure_set_va_marshal (closure, node->va_marshaller); |
1562 | 5 | } |
1563 | 5 | } |
1564 | | |
1565 | | /** |
1566 | | * g_signal_newv: |
1567 | | * @signal_name: the name for the signal |
1568 | | * @itype: the type this signal pertains to. It will also pertain to |
1569 | | * types which are derived from this type |
1570 | | * @signal_flags: a combination of #GSignalFlags specifying detail of when |
1571 | | * the default handler is to be invoked. You should at least specify |
1572 | | * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST |
1573 | | * @class_closure: (nullable): The closure to invoke on signal emission; |
1574 | | * may be %NULL |
1575 | | * @accumulator: (nullable) (scope forever): the accumulator for this signal; may be %NULL |
1576 | | * @accu_data: (nullable) (closure accumulator): user data for the @accumulator |
1577 | | * @c_marshaller: (nullable): the function to translate arrays of |
1578 | | * parameter values to signal emissions into C language callback |
1579 | | * invocations or %NULL |
1580 | | * @return_type: the type of return value, or %G_TYPE_NONE for a signal |
1581 | | * without a return value |
1582 | | * @n_params: the length of @param_types |
1583 | | * @param_types: (array length=n_params) (nullable): an array of types, one for |
1584 | | * each parameter (may be %NULL if @n_params is zero) |
1585 | | * |
1586 | | * Creates a new signal. (This is usually done in the class initializer.) |
1587 | | * |
1588 | | * See g_signal_new() for details on allowed signal names. |
1589 | | * |
1590 | | * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as |
1591 | | * the marshaller for this signal. |
1592 | | * |
1593 | | * Returns: the signal id |
1594 | | */ |
1595 | | guint |
1596 | | g_signal_newv (const gchar *signal_name, |
1597 | | GType itype, |
1598 | | GSignalFlags signal_flags, |
1599 | | GClosure *class_closure, |
1600 | | GSignalAccumulator accumulator, |
1601 | | gpointer accu_data, |
1602 | | GSignalCMarshaller c_marshaller, |
1603 | | GType return_type, |
1604 | | guint n_params, |
1605 | | GType *param_types) |
1606 | 5 | { |
1607 | 5 | const gchar *name; |
1608 | 5 | gchar *signal_name_copy = NULL; |
1609 | 5 | guint signal_id, i; |
1610 | 5 | SignalNode *node; |
1611 | 5 | GSignalCMarshaller builtin_c_marshaller; |
1612 | 5 | GSignalCVaMarshaller builtin_va_marshaller; |
1613 | 5 | GSignalCVaMarshaller va_marshaller; |
1614 | | |
1615 | 5 | g_return_val_if_fail (signal_name != NULL, 0); |
1616 | 5 | g_return_val_if_fail (g_signal_is_valid_name (signal_name), 0); |
1617 | 5 | g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0); |
1618 | 5 | if (n_params) |
1619 | 5 | g_return_val_if_fail (param_types != NULL, 0); |
1620 | 5 | g_return_val_if_fail ((return_type & G_SIGNAL_TYPE_STATIC_SCOPE) == 0, 0); |
1621 | 5 | if (return_type == (G_TYPE_NONE & ~G_SIGNAL_TYPE_STATIC_SCOPE)) |
1622 | 5 | g_return_val_if_fail (accumulator == NULL, 0); |
1623 | 5 | if (!accumulator) |
1624 | 5 | g_return_val_if_fail (accu_data == NULL, 0); |
1625 | 5 | g_return_val_if_fail ((signal_flags & G_SIGNAL_ACCUMULATOR_FIRST_RUN) == 0, 0); |
1626 | | |
1627 | 5 | if (!is_canonical (signal_name)) |
1628 | 0 | { |
1629 | 0 | signal_name_copy = g_strdup (signal_name); |
1630 | 0 | canonicalize_key (signal_name_copy); |
1631 | 0 | name = signal_name_copy; |
1632 | 0 | } |
1633 | 5 | else |
1634 | 5 | { |
1635 | 5 | name = signal_name; |
1636 | 5 | } |
1637 | | |
1638 | 5 | SIGNAL_LOCK (); |
1639 | | |
1640 | 5 | signal_id = signal_id_lookup (name, itype); |
1641 | 5 | node = LOOKUP_SIGNAL_NODE (signal_id); |
1642 | 5 | if (node && !node->destroyed) |
1643 | 0 | { |
1644 | 0 | g_critical (G_STRLOC ": signal \"%s\" already exists in the '%s' %s", |
1645 | 0 | name, |
1646 | 0 | type_debug_name (node->itype), |
1647 | 0 | G_TYPE_IS_INTERFACE (node->itype) ? "interface" : "class ancestry"); |
1648 | 0 | g_free (signal_name_copy); |
1649 | 0 | SIGNAL_UNLOCK (); |
1650 | 0 | return 0; |
1651 | 0 | } |
1652 | 5 | if (node && node->itype != itype) |
1653 | 0 | { |
1654 | 0 | g_critical (G_STRLOC ": signal \"%s\" for type '%s' was previously created for type '%s'", |
1655 | 0 | name, |
1656 | 0 | type_debug_name (itype), |
1657 | 0 | type_debug_name (node->itype)); |
1658 | 0 | g_free (signal_name_copy); |
1659 | 0 | SIGNAL_UNLOCK (); |
1660 | 0 | return 0; |
1661 | 0 | } |
1662 | 10 | for (i = 0; i < n_params; i++) |
1663 | 5 | if (!G_TYPE_IS_VALUE (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE)) |
1664 | 0 | { |
1665 | 0 | g_critical (G_STRLOC ": parameter %d of type '%s' for signal \"%s::%s\" is not a value type", |
1666 | 0 | i + 1, type_debug_name (param_types[i]), type_debug_name (itype), name); |
1667 | 0 | g_free (signal_name_copy); |
1668 | 0 | SIGNAL_UNLOCK (); |
1669 | 0 | return 0; |
1670 | 0 | } |
1671 | 5 | if (return_type != G_TYPE_NONE && !G_TYPE_IS_VALUE (return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE)) |
1672 | 0 | { |
1673 | 0 | g_critical (G_STRLOC ": return value of type '%s' for signal \"%s::%s\" is not a value type", |
1674 | 0 | type_debug_name (return_type), type_debug_name (itype), name); |
1675 | 0 | g_free (signal_name_copy); |
1676 | 0 | SIGNAL_UNLOCK (); |
1677 | 0 | return 0; |
1678 | 0 | } |
1679 | | |
1680 | | /* setup permanent portion of signal node */ |
1681 | 5 | if (!node) |
1682 | 5 | { |
1683 | 5 | SignalKey key; |
1684 | | |
1685 | 5 | signal_id = g_n_signal_nodes++; |
1686 | 5 | node = g_new (SignalNode, 1); |
1687 | 5 | node->signal_id = signal_id; |
1688 | 5 | g_signal_nodes = g_renew (SignalNode*, g_signal_nodes, g_n_signal_nodes); |
1689 | 5 | g_signal_nodes[signal_id] = node; |
1690 | 5 | node->itype = itype; |
1691 | 5 | key.itype = itype; |
1692 | 5 | key.signal_id = signal_id; |
1693 | 5 | node->name = g_intern_string (name); |
1694 | 5 | key.quark = g_quark_from_string (name); |
1695 | 5 | g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key); |
1696 | | |
1697 | 5 | TRACE(GOBJECT_SIGNAL_NEW(signal_id, name, itype)); |
1698 | 5 | } |
1699 | 5 | node->destroyed = FALSE; |
1700 | | |
1701 | | /* setup reinitializable portion */ |
1702 | 5 | node->single_va_closure_is_valid = FALSE; |
1703 | 5 | node->flags = signal_flags & G_SIGNAL_FLAGS_MASK; |
1704 | 5 | node->n_params = n_params; |
1705 | 5 | node->param_types = g_memdup2 (param_types, sizeof (GType) * n_params); |
1706 | 5 | node->return_type = return_type; |
1707 | 5 | node->class_closure_bsa = NULL; |
1708 | 5 | if (accumulator) |
1709 | 0 | { |
1710 | 0 | node->accumulator = g_new (SignalAccumulator, 1); |
1711 | 0 | node->accumulator->func = accumulator; |
1712 | 0 | node->accumulator->data = accu_data; |
1713 | 0 | } |
1714 | 5 | else |
1715 | 5 | node->accumulator = NULL; |
1716 | | |
1717 | 5 | builtin_c_marshaller = NULL; |
1718 | 5 | builtin_va_marshaller = NULL; |
1719 | | |
1720 | | /* Pick up built-in va marshallers for standard types, and |
1721 | | instead of generic marshaller if no marshaller specified */ |
1722 | 5 | if (n_params == 0 && return_type == G_TYPE_NONE) |
1723 | 0 | { |
1724 | 0 | builtin_c_marshaller = g_cclosure_marshal_VOID__VOID; |
1725 | 0 | builtin_va_marshaller = g_cclosure_marshal_VOID__VOIDv; |
1726 | 0 | } |
1727 | 5 | else if (n_params == 1 && return_type == G_TYPE_NONE) |
1728 | 5 | { |
1729 | 5 | #define ADD_CHECK(__type__) \ |
1730 | 70 | else if (g_type_is_a (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, G_TYPE_ ##__type__)) \ |
1731 | 65 | { \ |
1732 | 5 | builtin_c_marshaller = g_cclosure_marshal_VOID__ ## __type__; \ |
1733 | 5 | builtin_va_marshaller = g_cclosure_marshal_VOID__ ## __type__ ##v; \ |
1734 | 5 | } |
1735 | | |
1736 | 5 | if (0) {} |
1737 | 5 | ADD_CHECK (BOOLEAN) |
1738 | 5 | ADD_CHECK (CHAR) |
1739 | 5 | ADD_CHECK (UCHAR) |
1740 | 5 | ADD_CHECK (INT) |
1741 | 5 | ADD_CHECK (UINT) |
1742 | 5 | ADD_CHECK (LONG) |
1743 | 5 | ADD_CHECK (ULONG) |
1744 | 5 | ADD_CHECK (ENUM) |
1745 | 5 | ADD_CHECK (FLAGS) |
1746 | 5 | ADD_CHECK (FLOAT) |
1747 | 5 | ADD_CHECK (DOUBLE) |
1748 | 5 | ADD_CHECK (STRING) |
1749 | 5 | ADD_CHECK (PARAM) |
1750 | 5 | ADD_CHECK (BOXED) |
1751 | 0 | ADD_CHECK (POINTER) |
1752 | 0 | ADD_CHECK (OBJECT) |
1753 | 0 | ADD_CHECK (VARIANT) |
1754 | 5 | } |
1755 | | |
1756 | 5 | if (c_marshaller == NULL) |
1757 | 5 | { |
1758 | 5 | if (builtin_c_marshaller) |
1759 | 5 | { |
1760 | 5 | c_marshaller = builtin_c_marshaller; |
1761 | 5 | va_marshaller = builtin_va_marshaller; |
1762 | 5 | } |
1763 | 0 | else |
1764 | 0 | { |
1765 | 0 | c_marshaller = g_cclosure_marshal_generic; |
1766 | 0 | va_marshaller = g_cclosure_marshal_generic_va; |
1767 | 0 | } |
1768 | 5 | } |
1769 | 0 | else |
1770 | 0 | va_marshaller = NULL; |
1771 | | |
1772 | 5 | node->c_marshaller = c_marshaller; |
1773 | 5 | node->va_marshaller = va_marshaller; |
1774 | 5 | node->emission_hooks = NULL; |
1775 | 5 | if (class_closure) |
1776 | 5 | signal_add_class_closure (node, 0, class_closure); |
1777 | | |
1778 | 5 | SIGNAL_UNLOCK (); |
1779 | | |
1780 | 5 | g_free (signal_name_copy); |
1781 | | |
1782 | 5 | return signal_id; |
1783 | 5 | } |
1784 | | |
1785 | | /** |
1786 | | * g_signal_set_va_marshaller: |
1787 | | * @signal_id: the signal id |
1788 | | * @instance_type: the instance type on which to set the marshaller. |
1789 | | * @va_marshaller: the marshaller to set. |
1790 | | * |
1791 | | * Change the #GSignalCVaMarshaller used for a given signal. This is a |
1792 | | * specialised form of the marshaller that can often be used for the |
1793 | | * common case of a single connected signal handler and avoids the |
1794 | | * overhead of #GValue. Its use is optional. |
1795 | | * |
1796 | | * Since: 2.32 |
1797 | | */ |
1798 | | void |
1799 | | g_signal_set_va_marshaller (guint signal_id, |
1800 | | GType instance_type, |
1801 | | GSignalCVaMarshaller va_marshaller) |
1802 | 0 | { |
1803 | 0 | SignalNode *node; |
1804 | | |
1805 | 0 | g_return_if_fail (signal_id > 0); |
1806 | 0 | g_return_if_fail (va_marshaller != NULL); |
1807 | | |
1808 | 0 | SIGNAL_LOCK (); |
1809 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
1810 | 0 | if (node) |
1811 | 0 | { |
1812 | 0 | node->va_marshaller = va_marshaller; |
1813 | 0 | if (node->class_closure_bsa) |
1814 | 0 | { |
1815 | 0 | ClassClosure *cc = g_bsearch_array_get_nth (node->class_closure_bsa, &g_class_closure_bconfig, 0); |
1816 | 0 | if (cc->closure->marshal == node->c_marshaller) |
1817 | 0 | _g_closure_set_va_marshal (cc->closure, va_marshaller); |
1818 | 0 | } |
1819 | |
|
1820 | 0 | node->single_va_closure_is_valid = FALSE; |
1821 | 0 | } |
1822 | |
|
1823 | 0 | SIGNAL_UNLOCK (); |
1824 | 0 | } |
1825 | | |
1826 | | |
1827 | | /** |
1828 | | * g_signal_new_valist: |
1829 | | * @signal_name: the name for the signal |
1830 | | * @itype: the type this signal pertains to. It will also pertain to |
1831 | | * types which are derived from this type. |
1832 | | * @signal_flags: a combination of #GSignalFlags specifying detail of when |
1833 | | * the default handler is to be invoked. You should at least specify |
1834 | | * %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST. |
1835 | | * @class_closure: (nullable): The closure to invoke on signal emission; may be %NULL. |
1836 | | * @accumulator: (nullable) (scope forever): the accumulator for this signal; may be %NULL. |
1837 | | * @accu_data: (nullable) (closure accumulator): user data for the @accumulator. |
1838 | | * @c_marshaller: (nullable): the function to translate arrays of parameter |
1839 | | * values to signal emissions into C language callback invocations or %NULL. |
1840 | | * @return_type: the type of return value, or %G_TYPE_NONE for a signal |
1841 | | * without a return value. |
1842 | | * @n_params: the number of parameter types in @args. |
1843 | | * @args: va_list of #GType, one for each parameter. |
1844 | | * |
1845 | | * Creates a new signal. (This is usually done in the class initializer.) |
1846 | | * |
1847 | | * See g_signal_new() for details on allowed signal names. |
1848 | | * |
1849 | | * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as |
1850 | | * the marshaller for this signal. |
1851 | | * |
1852 | | * Returns: the signal id |
1853 | | */ |
1854 | | guint |
1855 | | g_signal_new_valist (const gchar *signal_name, |
1856 | | GType itype, |
1857 | | GSignalFlags signal_flags, |
1858 | | GClosure *class_closure, |
1859 | | GSignalAccumulator accumulator, |
1860 | | gpointer accu_data, |
1861 | | GSignalCMarshaller c_marshaller, |
1862 | | GType return_type, |
1863 | | guint n_params, |
1864 | | va_list args) |
1865 | 5 | { |
1866 | | /* Somewhat arbitrarily reserve 200 bytes. That should cover the majority |
1867 | | * of cases where n_params is small and still be small enough for what we |
1868 | | * want to put on the stack. */ |
1869 | 5 | GType param_types_stack[200 / sizeof (GType)]; |
1870 | 5 | GType *param_types_heap = NULL; |
1871 | 5 | GType *param_types; |
1872 | 5 | guint i; |
1873 | 5 | guint signal_id; |
1874 | | |
1875 | 5 | param_types = param_types_stack; |
1876 | 5 | if (n_params > 0) |
1877 | 5 | { |
1878 | 5 | if (G_UNLIKELY (n_params > G_N_ELEMENTS (param_types_stack))) |
1879 | 0 | { |
1880 | 0 | param_types_heap = g_new (GType, n_params); |
1881 | 0 | param_types = param_types_heap; |
1882 | 0 | } |
1883 | | |
1884 | 10 | for (i = 0; i < n_params; i++) |
1885 | 5 | param_types[i] = va_arg (args, GType); |
1886 | 5 | } |
1887 | | |
1888 | 5 | signal_id = g_signal_newv (signal_name, itype, signal_flags, |
1889 | 5 | class_closure, accumulator, accu_data, c_marshaller, |
1890 | 5 | return_type, n_params, param_types); |
1891 | 5 | g_free (param_types_heap); |
1892 | | |
1893 | 5 | return signal_id; |
1894 | 5 | } |
1895 | | |
1896 | | static void |
1897 | | signal_destroy_R (SignalNode *signal_node) |
1898 | 0 | { |
1899 | 0 | SignalNode node = *signal_node; |
1900 | |
|
1901 | 0 | signal_node->destroyed = TRUE; |
1902 | | |
1903 | | /* reentrancy caution, zero out real contents first */ |
1904 | 0 | signal_node->single_va_closure_is_valid = FALSE; |
1905 | 0 | signal_node->n_params = 0; |
1906 | 0 | signal_node->param_types = NULL; |
1907 | 0 | signal_node->return_type = 0; |
1908 | 0 | signal_node->class_closure_bsa = NULL; |
1909 | 0 | signal_node->accumulator = NULL; |
1910 | 0 | signal_node->c_marshaller = NULL; |
1911 | 0 | signal_node->va_marshaller = NULL; |
1912 | 0 | signal_node->emission_hooks = NULL; |
1913 | | |
1914 | 0 | #ifdef G_ENABLE_DEBUG |
1915 | | /* check current emissions */ |
1916 | 0 | { |
1917 | 0 | Emission *emission; |
1918 | | |
1919 | 0 | for (emission = g_emissions; emission; emission = emission->next) |
1920 | 0 | if (emission->ihint.signal_id == node.signal_id) |
1921 | 0 | g_critical (G_STRLOC ": signal \"%s\" being destroyed is currently in emission (instance '%p')", |
1922 | 0 | node.name, emission->instance); |
1923 | 0 | } |
1924 | 0 | #endif |
1925 | | |
1926 | | /* free contents that need to |
1927 | | */ |
1928 | 0 | SIGNAL_UNLOCK (); |
1929 | 0 | g_free (node.param_types); |
1930 | 0 | if (node.class_closure_bsa) |
1931 | 0 | { |
1932 | 0 | guint i; |
1933 | |
|
1934 | 0 | for (i = 0; i < node.class_closure_bsa->n_nodes; i++) |
1935 | 0 | { |
1936 | 0 | ClassClosure *cc = g_bsearch_array_get_nth (node.class_closure_bsa, &g_class_closure_bconfig, i); |
1937 | |
|
1938 | 0 | g_closure_unref (cc->closure); |
1939 | 0 | } |
1940 | 0 | g_bsearch_array_free (node.class_closure_bsa, &g_class_closure_bconfig); |
1941 | 0 | } |
1942 | 0 | g_free (node.accumulator); |
1943 | 0 | if (node.emission_hooks) |
1944 | 0 | { |
1945 | 0 | g_hook_list_clear (node.emission_hooks); |
1946 | 0 | g_free (node.emission_hooks); |
1947 | 0 | } |
1948 | 0 | SIGNAL_LOCK (); |
1949 | 0 | } |
1950 | | |
1951 | | /** |
1952 | | * g_signal_override_class_closure: |
1953 | | * @signal_id: the signal id |
1954 | | * @instance_type: the instance type on which to override the class closure |
1955 | | * for the signal. |
1956 | | * @class_closure: the closure. |
1957 | | * |
1958 | | * Overrides the class closure (i.e. the default handler) for the given signal |
1959 | | * for emissions on instances of @instance_type. @instance_type must be derived |
1960 | | * from the type to which the signal belongs. |
1961 | | * |
1962 | | * See g_signal_chain_from_overridden() and |
1963 | | * g_signal_chain_from_overridden_handler() for how to chain up to the |
1964 | | * parent class closure from inside the overridden one. |
1965 | | */ |
1966 | | void |
1967 | | g_signal_override_class_closure (guint signal_id, |
1968 | | GType instance_type, |
1969 | | GClosure *class_closure) |
1970 | 0 | { |
1971 | 0 | SignalNode *node; |
1972 | | |
1973 | 0 | g_return_if_fail (signal_id > 0); |
1974 | 0 | g_return_if_fail (class_closure != NULL); |
1975 | | |
1976 | 0 | SIGNAL_LOCK (); |
1977 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
1978 | 0 | node_check_deprecated (node); |
1979 | 0 | if (!g_type_is_a (instance_type, node->itype)) |
1980 | 0 | g_critical ("%s: type '%s' cannot be overridden for signal id '%u'", G_STRLOC, type_debug_name (instance_type), signal_id); |
1981 | 0 | else |
1982 | 0 | { |
1983 | 0 | ClassClosure *cc = signal_find_class_closure (node, instance_type); |
1984 | | |
1985 | 0 | if (cc && cc->instance_type == instance_type) |
1986 | 0 | g_critical ("%s: type '%s' is already overridden for signal id '%u'", G_STRLOC, type_debug_name (instance_type), signal_id); |
1987 | 0 | else |
1988 | 0 | signal_add_class_closure (node, instance_type, class_closure); |
1989 | 0 | } |
1990 | 0 | SIGNAL_UNLOCK (); |
1991 | 0 | } |
1992 | | |
1993 | | /** |
1994 | | * g_signal_override_class_handler: |
1995 | | * @signal_name: the name for the signal |
1996 | | * @instance_type: the instance type on which to override the class handler |
1997 | | * for the signal. |
1998 | | * @class_handler: (scope forever): the handler. |
1999 | | * |
2000 | | * Overrides the class closure (i.e. the default handler) for the |
2001 | | * given signal for emissions on instances of @instance_type with |
2002 | | * callback @class_handler. @instance_type must be derived from the |
2003 | | * type to which the signal belongs. |
2004 | | * |
2005 | | * See g_signal_chain_from_overridden() and |
2006 | | * g_signal_chain_from_overridden_handler() for how to chain up to the |
2007 | | * parent class closure from inside the overridden one. |
2008 | | * |
2009 | | * Since: 2.18 |
2010 | | */ |
2011 | | void |
2012 | | g_signal_override_class_handler (const gchar *signal_name, |
2013 | | GType instance_type, |
2014 | | GCallback class_handler) |
2015 | 0 | { |
2016 | 0 | guint signal_id; |
2017 | |
|
2018 | 0 | g_return_if_fail (signal_name != NULL); |
2019 | 0 | g_return_if_fail (instance_type != G_TYPE_NONE); |
2020 | 0 | g_return_if_fail (class_handler != NULL); |
2021 | | |
2022 | 0 | signal_id = g_signal_lookup (signal_name, instance_type); |
2023 | |
|
2024 | 0 | if (signal_id) |
2025 | 0 | g_signal_override_class_closure (signal_id, instance_type, |
2026 | 0 | g_cclosure_new (class_handler, NULL, NULL)); |
2027 | 0 | else |
2028 | 0 | g_critical ("%s: signal name '%s' is invalid for type id '%"G_GUINTPTR_FORMAT"'", |
2029 | 0 | G_STRLOC, signal_name, (guintptr) instance_type); |
2030 | |
|
2031 | 0 | } |
2032 | | |
2033 | | /** |
2034 | | * g_signal_chain_from_overridden: |
2035 | | * @instance_and_params: (array): the argument list of the signal emission. |
2036 | | * The first element in the array is a #GValue for the instance the signal |
2037 | | * is being emitted on. The rest are any arguments to be passed to the signal. |
2038 | | * @return_value: Location for the return value. |
2039 | | * |
2040 | | * Calls the original class closure of a signal. This function should only |
2041 | | * be called from an overridden class closure; see |
2042 | | * g_signal_override_class_closure() and |
2043 | | * g_signal_override_class_handler(). |
2044 | | */ |
2045 | | void |
2046 | | g_signal_chain_from_overridden (const GValue *instance_and_params, |
2047 | | GValue *return_value) |
2048 | 0 | { |
2049 | 0 | GType chain_type = 0, restore_type = 0; |
2050 | 0 | Emission *emission = NULL; |
2051 | 0 | GClosure *closure = NULL; |
2052 | 0 | guint n_params = 0; |
2053 | 0 | gpointer instance; |
2054 | | |
2055 | 0 | g_return_if_fail (instance_and_params != NULL); |
2056 | 0 | instance = g_value_peek_pointer (instance_and_params); |
2057 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
2058 | | |
2059 | 0 | SIGNAL_LOCK (); |
2060 | 0 | emission = emission_find_innermost (instance); |
2061 | 0 | if (emission) |
2062 | 0 | { |
2063 | 0 | SignalNode *node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id); |
2064 | | |
2065 | 0 | g_assert (node != NULL); /* paranoid */ |
2066 | | |
2067 | | /* we should probably do the same parameter checks as g_signal_emit() here. |
2068 | | */ |
2069 | 0 | if (emission->chain_type != G_TYPE_NONE) |
2070 | 0 | { |
2071 | 0 | ClassClosure *cc = signal_find_class_closure (node, emission->chain_type); |
2072 | | |
2073 | 0 | g_assert (cc != NULL); /* closure currently in call stack */ |
2074 | | |
2075 | 0 | n_params = node->n_params; |
2076 | 0 | restore_type = cc->instance_type; |
2077 | 0 | cc = signal_find_class_closure (node, g_type_parent (cc->instance_type)); |
2078 | 0 | if (cc && cc->instance_type != restore_type) |
2079 | 0 | { |
2080 | 0 | closure = cc->closure; |
2081 | 0 | chain_type = cc->instance_type; |
2082 | 0 | } |
2083 | 0 | } |
2084 | 0 | else |
2085 | 0 | g_critical ("%s: signal id '%u' cannot be chained from current emission stage for instance '%p'", G_STRLOC, node->signal_id, instance); |
2086 | 0 | } |
2087 | 0 | else |
2088 | 0 | g_critical ("%s: no signal is currently being emitted for instance '%p'", G_STRLOC, instance); |
2089 | | |
2090 | 0 | if (closure) |
2091 | 0 | { |
2092 | 0 | emission->chain_type = chain_type; |
2093 | 0 | SIGNAL_UNLOCK (); |
2094 | 0 | g_closure_invoke (closure, |
2095 | 0 | return_value, |
2096 | 0 | n_params + 1, |
2097 | 0 | instance_and_params, |
2098 | 0 | &emission->ihint); |
2099 | 0 | SIGNAL_LOCK (); |
2100 | 0 | emission->chain_type = restore_type; |
2101 | 0 | } |
2102 | 0 | SIGNAL_UNLOCK (); |
2103 | 0 | } |
2104 | | |
2105 | | /** |
2106 | | * g_signal_chain_from_overridden_handler: (skip) |
2107 | | * @instance: (type GObject.TypeInstance): the instance the signal is being |
2108 | | * emitted on. |
2109 | | * @...: parameters to be passed to the parent class closure, followed by a |
2110 | | * location for the return value. If the return type of the signal |
2111 | | * is %G_TYPE_NONE, the return value location can be omitted. |
2112 | | * |
2113 | | * Calls the original class closure of a signal. This function should |
2114 | | * only be called from an overridden class closure; see |
2115 | | * g_signal_override_class_closure() and |
2116 | | * g_signal_override_class_handler(). |
2117 | | * |
2118 | | * Since: 2.18 |
2119 | | */ |
2120 | | void |
2121 | | g_signal_chain_from_overridden_handler (gpointer instance, |
2122 | | ...) |
2123 | 0 | { |
2124 | 0 | GType chain_type = 0, restore_type = 0; |
2125 | 0 | Emission *emission = NULL; |
2126 | 0 | GClosure *closure = NULL; |
2127 | 0 | SignalNode *node = NULL; |
2128 | 0 | guint n_params = 0; |
2129 | |
|
2130 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
2131 | | |
2132 | 0 | SIGNAL_LOCK (); |
2133 | 0 | emission = emission_find_innermost (instance); |
2134 | 0 | if (emission) |
2135 | 0 | { |
2136 | 0 | node = LOOKUP_SIGNAL_NODE (emission->ihint.signal_id); |
2137 | |
|
2138 | 0 | g_assert (node != NULL); /* paranoid */ |
2139 | | |
2140 | | /* we should probably do the same parameter checks as g_signal_emit() here. |
2141 | | */ |
2142 | 0 | if (emission->chain_type != G_TYPE_NONE) |
2143 | 0 | { |
2144 | 0 | ClassClosure *cc = signal_find_class_closure (node, emission->chain_type); |
2145 | |
|
2146 | 0 | g_assert (cc != NULL); /* closure currently in call stack */ |
2147 | | |
2148 | 0 | n_params = node->n_params; |
2149 | 0 | restore_type = cc->instance_type; |
2150 | 0 | cc = signal_find_class_closure (node, g_type_parent (cc->instance_type)); |
2151 | 0 | if (cc && cc->instance_type != restore_type) |
2152 | 0 | { |
2153 | 0 | closure = cc->closure; |
2154 | 0 | chain_type = cc->instance_type; |
2155 | 0 | } |
2156 | 0 | } |
2157 | 0 | else |
2158 | 0 | g_critical ("%s: signal id '%u' cannot be chained from current emission stage for instance '%p'", G_STRLOC, node->signal_id, instance); |
2159 | 0 | } |
2160 | 0 | else |
2161 | 0 | g_critical ("%s: no signal is currently being emitted for instance '%p'", G_STRLOC, instance); |
2162 | | |
2163 | 0 | if (closure) |
2164 | 0 | { |
2165 | 0 | GValue *instance_and_params; |
2166 | 0 | GType signal_return_type; |
2167 | 0 | GValue *param_values; |
2168 | 0 | va_list var_args; |
2169 | 0 | guint i; |
2170 | |
|
2171 | 0 | va_start (var_args, instance); |
2172 | |
|
2173 | 0 | signal_return_type = node->return_type; |
2174 | 0 | instance_and_params = g_newa0 (GValue, n_params + 1); |
2175 | 0 | param_values = instance_and_params + 1; |
2176 | |
|
2177 | 0 | for (i = 0; i < node->n_params; i++) |
2178 | 0 | { |
2179 | 0 | gchar *error; |
2180 | 0 | GType ptype = node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE; |
2181 | 0 | gboolean static_scope = node->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE; |
2182 | |
|
2183 | 0 | SIGNAL_UNLOCK (); |
2184 | 0 | G_VALUE_COLLECT_INIT (param_values + i, ptype, |
2185 | 0 | var_args, |
2186 | 0 | static_scope ? G_VALUE_NOCOPY_CONTENTS : 0, |
2187 | 0 | &error); |
2188 | 0 | if (error) |
2189 | 0 | { |
2190 | 0 | g_critical ("%s: %s", G_STRLOC, error); |
2191 | 0 | g_free (error); |
2192 | | |
2193 | | /* we purposely leak the value here, it might not be |
2194 | | * in a correct state if an error condition occurred |
2195 | | */ |
2196 | 0 | while (i--) |
2197 | 0 | g_value_unset (param_values + i); |
2198 | |
|
2199 | 0 | va_end (var_args); |
2200 | 0 | return; |
2201 | 0 | } |
2202 | 0 | SIGNAL_LOCK (); |
2203 | 0 | } |
2204 | | |
2205 | 0 | SIGNAL_UNLOCK (); |
2206 | 0 | g_value_init_from_instance (instance_and_params, instance); |
2207 | 0 | SIGNAL_LOCK (); |
2208 | |
|
2209 | 0 | emission->chain_type = chain_type; |
2210 | 0 | SIGNAL_UNLOCK (); |
2211 | |
|
2212 | 0 | if (signal_return_type == G_TYPE_NONE) |
2213 | 0 | { |
2214 | 0 | g_closure_invoke (closure, |
2215 | 0 | NULL, |
2216 | 0 | n_params + 1, |
2217 | 0 | instance_and_params, |
2218 | 0 | &emission->ihint); |
2219 | 0 | } |
2220 | 0 | else |
2221 | 0 | { |
2222 | 0 | GValue return_value = G_VALUE_INIT; |
2223 | 0 | gchar *error = NULL; |
2224 | 0 | GType rtype = signal_return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE; |
2225 | 0 | gboolean static_scope = signal_return_type & G_SIGNAL_TYPE_STATIC_SCOPE; |
2226 | |
|
2227 | 0 | g_value_init (&return_value, rtype); |
2228 | |
|
2229 | 0 | g_closure_invoke (closure, |
2230 | 0 | &return_value, |
2231 | 0 | n_params + 1, |
2232 | 0 | instance_and_params, |
2233 | 0 | &emission->ihint); |
2234 | |
|
2235 | 0 | G_VALUE_LCOPY (&return_value, |
2236 | 0 | var_args, |
2237 | 0 | static_scope ? G_VALUE_NOCOPY_CONTENTS : 0, |
2238 | 0 | &error); |
2239 | 0 | if (!error) |
2240 | 0 | { |
2241 | 0 | g_value_unset (&return_value); |
2242 | 0 | } |
2243 | 0 | else |
2244 | 0 | { |
2245 | 0 | g_critical ("%s: %s", G_STRLOC, error); |
2246 | 0 | g_free (error); |
2247 | | |
2248 | | /* we purposely leak the value here, it might not be |
2249 | | * in a correct state if an error condition occurred |
2250 | | */ |
2251 | 0 | } |
2252 | 0 | } |
2253 | | |
2254 | 0 | for (i = 0; i < n_params; i++) |
2255 | 0 | g_value_unset (param_values + i); |
2256 | 0 | g_value_unset (instance_and_params); |
2257 | |
|
2258 | 0 | va_end (var_args); |
2259 | |
|
2260 | 0 | SIGNAL_LOCK (); |
2261 | 0 | emission->chain_type = restore_type; |
2262 | 0 | } |
2263 | 0 | SIGNAL_UNLOCK (); |
2264 | 0 | } |
2265 | | |
2266 | | /** |
2267 | | * g_signal_get_invocation_hint: |
2268 | | * @instance: (type GObject.Object): the instance to query |
2269 | | * |
2270 | | * Returns the invocation hint of the innermost signal emission of instance. |
2271 | | * |
2272 | | * Returns: (transfer none) (nullable): the invocation hint of the innermost |
2273 | | * signal emission, or %NULL if not found. |
2274 | | */ |
2275 | | GSignalInvocationHint* |
2276 | | g_signal_get_invocation_hint (gpointer instance) |
2277 | 0 | { |
2278 | 0 | Emission *emission = NULL; |
2279 | | |
2280 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), NULL); |
2281 | | |
2282 | 0 | SIGNAL_LOCK (); |
2283 | 0 | emission = emission_find_innermost (instance); |
2284 | 0 | SIGNAL_UNLOCK (); |
2285 | | |
2286 | 0 | return emission ? &emission->ihint : NULL; |
2287 | 0 | } |
2288 | | |
2289 | | /** |
2290 | | * g_signal_connect_closure_by_id: |
2291 | | * @instance: (type GObject.Object): the instance to connect to. |
2292 | | * @signal_id: the id of the signal. |
2293 | | * @detail: the detail. |
2294 | | * @closure: (not nullable): the closure to connect. |
2295 | | * @after: whether the handler should be called before or after the |
2296 | | * default handler of the signal. |
2297 | | * |
2298 | | * Connects a closure to a signal for a particular object. |
2299 | | * |
2300 | | * If @closure is a floating reference (see g_closure_sink()), this function |
2301 | | * takes ownership of @closure. |
2302 | | * |
2303 | | * This function cannot fail. If the given signal name doesn’t exist, |
2304 | | * a critical warning is emitted. No validation is performed on the |
2305 | | * ‘detail’ string when specified in @detailed_signal, other than a |
2306 | | * non-empty check. |
2307 | | * |
2308 | | * Refer to the [signals documentation](signals.html) for more |
2309 | | * details. |
2310 | | * |
2311 | | * Returns: the handler ID (always greater than 0) |
2312 | | */ |
2313 | | gulong |
2314 | | g_signal_connect_closure_by_id (gpointer instance, |
2315 | | guint signal_id, |
2316 | | GQuark detail, |
2317 | | GClosure *closure, |
2318 | | gboolean after) |
2319 | 0 | { |
2320 | 0 | SignalNode *node; |
2321 | 0 | gulong handler_seq_no = 0; |
2322 | | |
2323 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); |
2324 | 0 | g_return_val_if_fail (signal_id > 0, 0); |
2325 | 0 | g_return_val_if_fail (closure != NULL, 0); |
2326 | | |
2327 | 0 | SIGNAL_LOCK (); |
2328 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
2329 | 0 | if (node) |
2330 | 0 | { |
2331 | 0 | if (detail && !(node->flags & G_SIGNAL_DETAILED)) |
2332 | 0 | g_critical ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail); |
2333 | 0 | else if (!g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype)) |
2334 | 0 | g_critical ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance); |
2335 | 0 | else |
2336 | 0 | { |
2337 | 0 | Handler *handler = handler_new (signal_id, instance, after); |
2338 | |
|
2339 | 0 | if (G_TYPE_IS_OBJECT (node->itype)) |
2340 | 0 | _g_object_set_has_signal_handler ((GObject *) instance, signal_id); |
2341 | |
|
2342 | 0 | handler_seq_no = handler->sequential_number; |
2343 | 0 | handler->detail = detail; |
2344 | 0 | handler->closure = g_closure_ref (closure); |
2345 | 0 | g_closure_sink (closure); |
2346 | 0 | add_invalid_closure_notify (handler, instance); |
2347 | 0 | handler_insert (signal_id, instance, handler); |
2348 | 0 | if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (closure)) |
2349 | 0 | { |
2350 | 0 | g_closure_set_marshal (closure, node->c_marshaller); |
2351 | 0 | if (node->va_marshaller) |
2352 | 0 | _g_closure_set_va_marshal (closure, node->va_marshaller); |
2353 | 0 | } |
2354 | 0 | } |
2355 | 0 | } |
2356 | 0 | else |
2357 | 0 | g_critical ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance); |
2358 | 0 | SIGNAL_UNLOCK (); |
2359 | | |
2360 | 0 | return handler_seq_no; |
2361 | 0 | } |
2362 | | |
2363 | | /** |
2364 | | * g_signal_connect_closure: |
2365 | | * @instance: (type GObject.Object): the instance to connect to. |
2366 | | * @detailed_signal: a string of the form "signal-name::detail". |
2367 | | * @closure: (not nullable): the closure to connect. |
2368 | | * @after: whether the handler should be called before or after the |
2369 | | * default handler of the signal. |
2370 | | * |
2371 | | * Connects a closure to a signal for a particular object. |
2372 | | * |
2373 | | * If @closure is a floating reference (see g_closure_sink()), this function |
2374 | | * takes ownership of @closure. |
2375 | | * |
2376 | | * This function cannot fail. If the given signal name doesn’t exist, |
2377 | | * a critical warning is emitted. No validation is performed on the |
2378 | | * ‘detail’ string when specified in @detailed_signal, other than a |
2379 | | * non-empty check. |
2380 | | * |
2381 | | * Refer to the [signals documentation](signals.html) for more |
2382 | | * details. |
2383 | | * |
2384 | | * Returns: the handler ID (always greater than 0) |
2385 | | */ |
2386 | | gulong |
2387 | | g_signal_connect_closure (gpointer instance, |
2388 | | const gchar *detailed_signal, |
2389 | | GClosure *closure, |
2390 | | gboolean after) |
2391 | 0 | { |
2392 | 0 | guint signal_id; |
2393 | 0 | gulong handler_seq_no = 0; |
2394 | 0 | GQuark detail = 0; |
2395 | 0 | GType itype; |
2396 | |
|
2397 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); |
2398 | 0 | g_return_val_if_fail (detailed_signal != NULL, 0); |
2399 | 0 | g_return_val_if_fail (closure != NULL, 0); |
2400 | | |
2401 | 0 | SIGNAL_LOCK (); |
2402 | 0 | itype = G_TYPE_FROM_INSTANCE (instance); |
2403 | 0 | signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE); |
2404 | 0 | if (signal_id) |
2405 | 0 | { |
2406 | 0 | SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id); |
2407 | |
|
2408 | 0 | if (detail && !(node->flags & G_SIGNAL_DETAILED)) |
2409 | 0 | g_critical ("%s: signal '%s' does not support details", G_STRLOC, detailed_signal); |
2410 | 0 | else if (!g_type_is_a (itype, node->itype)) |
2411 | 0 | g_critical ("%s: signal '%s' is invalid for instance '%p' of type '%s'", |
2412 | 0 | G_STRLOC, detailed_signal, instance, g_type_name (itype)); |
2413 | 0 | else |
2414 | 0 | { |
2415 | 0 | Handler *handler = handler_new (signal_id, instance, after); |
2416 | |
|
2417 | 0 | if (G_TYPE_IS_OBJECT (node->itype)) |
2418 | 0 | _g_object_set_has_signal_handler ((GObject *) instance, signal_id); |
2419 | |
|
2420 | 0 | handler_seq_no = handler->sequential_number; |
2421 | 0 | handler->detail = detail; |
2422 | 0 | handler->closure = g_closure_ref (closure); |
2423 | 0 | g_closure_sink (closure); |
2424 | 0 | add_invalid_closure_notify (handler, instance); |
2425 | 0 | handler_insert (signal_id, instance, handler); |
2426 | 0 | if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure)) |
2427 | 0 | { |
2428 | 0 | g_closure_set_marshal (handler->closure, node->c_marshaller); |
2429 | 0 | if (node->va_marshaller) |
2430 | 0 | _g_closure_set_va_marshal (handler->closure, node->va_marshaller); |
2431 | 0 | } |
2432 | 0 | } |
2433 | 0 | } |
2434 | 0 | else |
2435 | 0 | g_critical ("%s: signal '%s' is invalid for instance '%p' of type '%s'", |
2436 | 0 | G_STRLOC, detailed_signal, instance, g_type_name (itype)); |
2437 | 0 | SIGNAL_UNLOCK (); |
2438 | |
|
2439 | 0 | return handler_seq_no; |
2440 | 0 | } |
2441 | | |
2442 | | static void |
2443 | | node_check_deprecated (const SignalNode *node) |
2444 | 0 | { |
2445 | 0 | static const gchar * g_enable_diagnostic = NULL; |
2446 | |
|
2447 | 0 | if (G_UNLIKELY (!g_enable_diagnostic)) |
2448 | 0 | { |
2449 | 0 | g_enable_diagnostic = g_getenv ("G_ENABLE_DIAGNOSTIC"); |
2450 | 0 | if (!g_enable_diagnostic) |
2451 | 0 | g_enable_diagnostic = "0"; |
2452 | 0 | } |
2453 | |
|
2454 | 0 | if (g_enable_diagnostic[0] == '1') |
2455 | 0 | { |
2456 | 0 | if (node->flags & G_SIGNAL_DEPRECATED) |
2457 | 0 | { |
2458 | 0 | g_warning ("The signal %s::%s is deprecated and shouldn't be used " |
2459 | 0 | "anymore. It will be removed in a future version.", |
2460 | 0 | type_debug_name (node->itype), node->name); |
2461 | 0 | } |
2462 | 0 | } |
2463 | 0 | } |
2464 | | |
2465 | | /** |
2466 | | * g_signal_connect_data: |
2467 | | * @instance: (type GObject.Object): the instance to connect to. |
2468 | | * @detailed_signal: a string of the form "signal-name::detail". |
2469 | | * @c_handler: (not nullable): the #GCallback to connect. |
2470 | | * @data: (nullable) (closure c_handler): data to pass to @c_handler calls. |
2471 | | * @destroy_data: (nullable) (destroy data): a #GClosureNotify for @data. |
2472 | | * @connect_flags: a combination of #GConnectFlags. |
2473 | | * |
2474 | | * Connects a #GCallback function to a signal for a particular object. Similar |
2475 | | * to g_signal_connect(), but allows to provide a #GClosureNotify for the data |
2476 | | * which will be called when the signal handler is disconnected and no longer |
2477 | | * used. Specify @connect_flags if you need `..._after()` or |
2478 | | * `..._swapped()` variants of this function. |
2479 | | * |
2480 | | * This function cannot fail. If the given signal name doesn’t exist, |
2481 | | * a critical warning is emitted. No validation is performed on the |
2482 | | * ‘detail’ string when specified in @detailed_signal, other than a |
2483 | | * non-empty check. |
2484 | | * |
2485 | | * Refer to the [signals documentation](signals.html) for more |
2486 | | * details. |
2487 | | * |
2488 | | * Returns: the handler ID (always greater than 0) |
2489 | | */ |
2490 | | gulong |
2491 | | g_signal_connect_data (gpointer instance, |
2492 | | const gchar *detailed_signal, |
2493 | | GCallback c_handler, |
2494 | | gpointer data, |
2495 | | GClosureNotify destroy_data, |
2496 | | GConnectFlags connect_flags) |
2497 | 0 | { |
2498 | 0 | guint signal_id; |
2499 | 0 | gulong handler_seq_no = 0; |
2500 | 0 | GQuark detail = 0; |
2501 | 0 | GType itype; |
2502 | 0 | gboolean swapped, after; |
2503 | | |
2504 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); |
2505 | 0 | g_return_val_if_fail (detailed_signal != NULL, 0); |
2506 | 0 | g_return_val_if_fail (c_handler != NULL, 0); |
2507 | | |
2508 | 0 | swapped = (connect_flags & G_CONNECT_SWAPPED) != FALSE; |
2509 | 0 | after = (connect_flags & G_CONNECT_AFTER) != FALSE; |
2510 | |
|
2511 | 0 | SIGNAL_LOCK (); |
2512 | 0 | itype = G_TYPE_FROM_INSTANCE (instance); |
2513 | 0 | signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE); |
2514 | 0 | if (signal_id) |
2515 | 0 | { |
2516 | 0 | SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id); |
2517 | |
|
2518 | 0 | node_check_deprecated (node); |
2519 | |
|
2520 | 0 | if (detail && !(node->flags & G_SIGNAL_DETAILED)) |
2521 | 0 | g_critical ("%s: signal '%s' does not support details", G_STRLOC, detailed_signal); |
2522 | 0 | else if (!g_type_is_a (itype, node->itype)) |
2523 | 0 | g_critical ("%s: signal '%s' is invalid for instance '%p' of type '%s'", |
2524 | 0 | G_STRLOC, detailed_signal, instance, g_type_name (itype)); |
2525 | 0 | else |
2526 | 0 | { |
2527 | 0 | Handler *handler = handler_new (signal_id, instance, after); |
2528 | |
|
2529 | 0 | if (G_TYPE_IS_OBJECT (node->itype)) |
2530 | 0 | _g_object_set_has_signal_handler ((GObject *) instance, signal_id); |
2531 | |
|
2532 | 0 | handler_seq_no = handler->sequential_number; |
2533 | 0 | handler->detail = detail; |
2534 | 0 | handler->closure = g_closure_ref ((swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data)); |
2535 | 0 | g_closure_sink (handler->closure); |
2536 | 0 | handler_insert (signal_id, instance, handler); |
2537 | 0 | if (node->c_marshaller && G_CLOSURE_NEEDS_MARSHAL (handler->closure)) |
2538 | 0 | { |
2539 | 0 | g_closure_set_marshal (handler->closure, node->c_marshaller); |
2540 | 0 | if (node->va_marshaller) |
2541 | 0 | _g_closure_set_va_marshal (handler->closure, node->va_marshaller); |
2542 | 0 | } |
2543 | 0 | } |
2544 | 0 | } |
2545 | 0 | else |
2546 | 0 | g_critical ("%s: signal '%s' is invalid for instance '%p' of type '%s'", |
2547 | 0 | G_STRLOC, detailed_signal, instance, g_type_name (itype)); |
2548 | 0 | SIGNAL_UNLOCK (); |
2549 | |
|
2550 | 0 | return handler_seq_no; |
2551 | 0 | } |
2552 | | |
2553 | | static void |
2554 | | signal_handler_block_unlocked (gpointer instance, |
2555 | | gulong handler_id); |
2556 | | |
2557 | | /** |
2558 | | * g_signal_handler_block: |
2559 | | * @instance: (type GObject.Object): The instance to block the signal handler of. |
2560 | | * @handler_id: Handler id of the handler to be blocked. |
2561 | | * |
2562 | | * Blocks a handler of an instance so it will not be called during any |
2563 | | * signal emissions unless it is unblocked again. Thus "blocking" a |
2564 | | * signal handler means to temporarily deactivate it, a signal handler |
2565 | | * has to be unblocked exactly the same amount of times it has been |
2566 | | * blocked before to become active again. |
2567 | | * |
2568 | | * The @handler_id has to be a valid signal handler id, connected to a |
2569 | | * signal of @instance. |
2570 | | */ |
2571 | | void |
2572 | | g_signal_handler_block (gpointer instance, |
2573 | | gulong handler_id) |
2574 | 0 | { |
2575 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
2576 | 0 | g_return_if_fail (handler_id > 0); |
2577 | | |
2578 | 0 | SIGNAL_LOCK (); |
2579 | 0 | signal_handler_block_unlocked (instance, handler_id); |
2580 | 0 | SIGNAL_UNLOCK (); |
2581 | 0 | } |
2582 | | |
2583 | | static void |
2584 | | signal_handler_block_unlocked (gpointer instance, |
2585 | | gulong handler_id) |
2586 | 0 | { |
2587 | 0 | Handler *handler; |
2588 | |
|
2589 | 0 | handler = handler_lookup (instance, handler_id, NULL, NULL); |
2590 | 0 | if (handler) |
2591 | 0 | { |
2592 | 0 | #ifndef G_DISABLE_CHECKS |
2593 | 0 | if (handler->block_count >= HANDLER_MAX_BLOCK_COUNT - 1) |
2594 | 0 | g_error (G_STRLOC ": handler block_count overflow, %s", REPORT_BUG); |
2595 | 0 | #endif |
2596 | 0 | handler->block_count += 1; |
2597 | 0 | } |
2598 | 0 | else |
2599 | 0 | g_critical ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id); |
2600 | 0 | } |
2601 | | |
2602 | | static void |
2603 | | signal_handler_unblock_unlocked (gpointer instance, |
2604 | | gulong handler_id); |
2605 | | |
2606 | | /** |
2607 | | * g_signal_handler_unblock: |
2608 | | * @instance: (type GObject.Object): The instance to unblock the signal handler of. |
2609 | | * @handler_id: Handler id of the handler to be unblocked. |
2610 | | * |
2611 | | * Undoes the effect of a previous g_signal_handler_block() call. A |
2612 | | * blocked handler is skipped during signal emissions and will not be |
2613 | | * invoked, unblocking it (for exactly the amount of times it has been |
2614 | | * blocked before) reverts its "blocked" state, so the handler will be |
2615 | | * recognized by the signal system and is called upon future or |
2616 | | * currently ongoing signal emissions (since the order in which |
2617 | | * handlers are called during signal emissions is deterministic, |
2618 | | * whether the unblocked handler in question is called as part of a |
2619 | | * currently ongoing emission depends on how far that emission has |
2620 | | * proceeded yet). |
2621 | | * |
2622 | | * The @handler_id has to be a valid id of a signal handler that is |
2623 | | * connected to a signal of @instance and is currently blocked. |
2624 | | */ |
2625 | | void |
2626 | | g_signal_handler_unblock (gpointer instance, |
2627 | | gulong handler_id) |
2628 | 0 | { |
2629 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
2630 | 0 | g_return_if_fail (handler_id > 0); |
2631 | | |
2632 | 0 | SIGNAL_LOCK (); |
2633 | 0 | signal_handler_unblock_unlocked (instance, handler_id); |
2634 | 0 | SIGNAL_UNLOCK (); |
2635 | 0 | } |
2636 | | |
2637 | | static void |
2638 | | signal_handler_unblock_unlocked (gpointer instance, |
2639 | | gulong handler_id) |
2640 | 0 | { |
2641 | 0 | Handler *handler; |
2642 | |
|
2643 | 0 | handler = handler_lookup (instance, handler_id, NULL, NULL); |
2644 | 0 | if (handler) |
2645 | 0 | { |
2646 | 0 | if (handler->block_count) |
2647 | 0 | handler->block_count -= 1; |
2648 | 0 | else |
2649 | 0 | g_critical (G_STRLOC ": handler '%lu' of instance '%p' is not blocked", handler_id, instance); |
2650 | 0 | } |
2651 | 0 | else |
2652 | 0 | g_critical ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id); |
2653 | 0 | } |
2654 | | |
2655 | | static void |
2656 | | signal_handler_disconnect_unlocked (gpointer instance, |
2657 | | gulong handler_id); |
2658 | | |
2659 | | /** |
2660 | | * g_signal_handler_disconnect: |
2661 | | * @instance: (type GObject.Object): The instance to remove the signal handler from. |
2662 | | * @handler_id: Handler id of the handler to be disconnected. |
2663 | | * |
2664 | | * Disconnects a handler from an instance so it will not be called during |
2665 | | * any future or currently ongoing emissions of the signal it has been |
2666 | | * connected to. The @handler_id becomes invalid and may be reused. |
2667 | | * |
2668 | | * The @handler_id has to be a valid signal handler id, connected to a |
2669 | | * signal of @instance. |
2670 | | */ |
2671 | | void |
2672 | | g_signal_handler_disconnect (gpointer instance, |
2673 | | gulong handler_id) |
2674 | 0 | { |
2675 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
2676 | 0 | g_return_if_fail (handler_id > 0); |
2677 | | |
2678 | 0 | SIGNAL_LOCK (); |
2679 | 0 | signal_handler_disconnect_unlocked (instance, handler_id); |
2680 | 0 | SIGNAL_UNLOCK (); |
2681 | 0 | } |
2682 | | |
2683 | | static void |
2684 | | signal_handler_disconnect_unlocked (gpointer instance, |
2685 | | gulong handler_id) |
2686 | 0 | { |
2687 | 0 | Handler *handler; |
2688 | |
|
2689 | 0 | handler = handler_lookup (instance, handler_id, 0, 0); |
2690 | 0 | if (handler) |
2691 | 0 | { |
2692 | 0 | g_hash_table_remove (g_handlers, handler); |
2693 | 0 | handler->sequential_number = 0; |
2694 | 0 | handler->block_count = 1; |
2695 | 0 | remove_invalid_closure_notify (handler, instance); |
2696 | 0 | handler_unref_R (handler->signal_id, instance, handler); |
2697 | 0 | } |
2698 | 0 | else |
2699 | 0 | g_critical ("%s: instance '%p' has no handler with id '%lu'", G_STRLOC, instance, handler_id); |
2700 | 0 | } |
2701 | | |
2702 | | /** |
2703 | | * g_signal_handler_is_connected: |
2704 | | * @instance: (type GObject.Object): The instance where a signal handler is sought. |
2705 | | * @handler_id: the handler ID. |
2706 | | * |
2707 | | * Returns whether @handler_id is the ID of a handler connected to @instance. |
2708 | | * |
2709 | | * Returns: whether @handler_id identifies a handler connected to @instance. |
2710 | | */ |
2711 | | gboolean |
2712 | | g_signal_handler_is_connected (gpointer instance, |
2713 | | gulong handler_id) |
2714 | 0 | { |
2715 | 0 | Handler *handler; |
2716 | 0 | gboolean connected; |
2717 | |
|
2718 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE); |
2719 | | |
2720 | 0 | SIGNAL_LOCK (); |
2721 | 0 | handler = handler_lookup (instance, handler_id, NULL, NULL); |
2722 | 0 | connected = handler != NULL; |
2723 | 0 | SIGNAL_UNLOCK (); |
2724 | |
|
2725 | 0 | return connected; |
2726 | 0 | } |
2727 | | |
2728 | | /** |
2729 | | * g_signal_handlers_destroy: |
2730 | | * @instance: (type GObject.Object): The instance whose signal handlers are destroyed |
2731 | | * |
2732 | | * Destroy all signal handlers of a type instance. This function is |
2733 | | * an implementation detail of the #GObject dispose implementation, |
2734 | | * and should not be used outside of the type system. |
2735 | | */ |
2736 | | void |
2737 | | g_signal_handlers_destroy (gpointer instance) |
2738 | 75.3k | { |
2739 | 75.3k | GBSearchArray *hlbsa; |
2740 | | |
2741 | 75.3k | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
2742 | | |
2743 | 75.3k | SIGNAL_LOCK (); |
2744 | 75.3k | hlbsa = g_hash_table_lookup (g_handler_list_bsa_ht, instance); |
2745 | 75.3k | if (hlbsa) |
2746 | 0 | { |
2747 | 0 | guint i; |
2748 | | |
2749 | | /* reentrancy caution, delete instance trace first */ |
2750 | 0 | g_hash_table_remove (g_handler_list_bsa_ht, instance); |
2751 | | |
2752 | 0 | for (i = 0; i < hlbsa->n_nodes; i++) |
2753 | 0 | { |
2754 | 0 | HandlerList *hlist = g_bsearch_array_get_nth (hlbsa, &g_signal_hlbsa_bconfig, i); |
2755 | 0 | Handler *handler = hlist->handlers; |
2756 | | |
2757 | 0 | while (handler) |
2758 | 0 | { |
2759 | 0 | Handler *tmp = handler; |
2760 | | |
2761 | 0 | handler = tmp->next; |
2762 | 0 | tmp->block_count = 1; |
2763 | | /* cruel unlink, this works because _all_ handlers vanish */ |
2764 | 0 | tmp->next = NULL; |
2765 | 0 | tmp->prev = tmp; |
2766 | 0 | if (tmp->sequential_number) |
2767 | 0 | { |
2768 | 0 | g_hash_table_remove (g_handlers, tmp); |
2769 | 0 | remove_invalid_closure_notify (tmp, instance); |
2770 | 0 | tmp->sequential_number = 0; |
2771 | 0 | handler_unref_R (0, NULL, tmp); |
2772 | 0 | } |
2773 | 0 | } |
2774 | 0 | } |
2775 | 0 | g_bsearch_array_free (hlbsa, &g_signal_hlbsa_bconfig); |
2776 | 0 | } |
2777 | 75.3k | SIGNAL_UNLOCK (); |
2778 | 75.3k | } |
2779 | | |
2780 | | /** |
2781 | | * g_signal_handler_find: |
2782 | | * @instance: (type GObject.Object): The instance owning the signal handler to be found. |
2783 | | * @mask: Mask indicating which of @signal_id, @detail, @closure, @func |
2784 | | * and/or @data the handler has to match. |
2785 | | * @signal_id: Signal the handler has to be connected to. |
2786 | | * @detail: Signal detail the handler has to be connected to. |
2787 | | * @closure: (nullable): The closure the handler will invoke. |
2788 | | * @func: The C closure callback of the handler (useless for non-C closures). |
2789 | | * @data: (nullable) (closure closure): The closure data of the handler's closure. |
2790 | | * |
2791 | | * Finds the first signal handler that matches certain selection criteria. |
2792 | | * The criteria mask is passed as an OR-ed combination of #GSignalMatchType |
2793 | | * flags, and the criteria values are passed as arguments. |
2794 | | * The match @mask has to be non-0 for successful matches. |
2795 | | * If no handler was found, 0 is returned. |
2796 | | * |
2797 | | * Returns: A valid non-0 signal handler id for a successful match. |
2798 | | */ |
2799 | | gulong |
2800 | | g_signal_handler_find (gpointer instance, |
2801 | | GSignalMatchType mask, |
2802 | | guint signal_id, |
2803 | | GQuark detail, |
2804 | | GClosure *closure, |
2805 | | gpointer func, |
2806 | | gpointer data) |
2807 | 0 | { |
2808 | 0 | gulong handler_seq_no = 0; |
2809 | | |
2810 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); |
2811 | 0 | g_return_val_if_fail ((mask & (unsigned) ~G_SIGNAL_MATCH_MASK) == 0, 0); |
2812 | | |
2813 | 0 | if (mask & G_SIGNAL_MATCH_MASK) |
2814 | 0 | { |
2815 | 0 | HandlerMatch *mlist; |
2816 | | |
2817 | 0 | SIGNAL_LOCK (); |
2818 | 0 | mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, TRUE); |
2819 | 0 | if (mlist) |
2820 | 0 | { |
2821 | 0 | handler_seq_no = mlist->handler->sequential_number; |
2822 | 0 | handler_match_free1_R (mlist, instance); |
2823 | 0 | } |
2824 | 0 | SIGNAL_UNLOCK (); |
2825 | 0 | } |
2826 | | |
2827 | 0 | return handler_seq_no; |
2828 | 0 | } |
2829 | | |
2830 | | typedef void (*CallbackHandlerFunc) (gpointer instance, gulong handler_seq_no); |
2831 | | |
2832 | | static guint |
2833 | | signal_handlers_foreach_matched_unlocked_R (gpointer instance, |
2834 | | GSignalMatchType mask, |
2835 | | guint signal_id, |
2836 | | GQuark detail, |
2837 | | GClosure *closure, |
2838 | | gpointer func, |
2839 | | gpointer data, |
2840 | | CallbackHandlerFunc callback) |
2841 | 0 | { |
2842 | 0 | HandlerMatch *mlist; |
2843 | 0 | guint n_handlers = 0; |
2844 | |
|
2845 | 0 | mlist = handlers_find (instance, mask, signal_id, detail, closure, func, data, FALSE); |
2846 | 0 | while (mlist) |
2847 | 0 | { |
2848 | 0 | n_handlers++; |
2849 | 0 | if (mlist->handler->sequential_number) |
2850 | 0 | callback (instance, mlist->handler->sequential_number); |
2851 | |
|
2852 | 0 | mlist = handler_match_free1_R (mlist, instance); |
2853 | 0 | } |
2854 | |
|
2855 | 0 | return n_handlers; |
2856 | 0 | } |
2857 | | |
2858 | | /** |
2859 | | * g_signal_handlers_block_matched: |
2860 | | * @instance: (type GObject.Object): The instance to block handlers from. |
2861 | | * @mask: Mask indicating which of @signal_id, @detail, @closure, @func |
2862 | | * and/or @data the handlers have to match. |
2863 | | * @signal_id: Signal the handlers have to be connected to. |
2864 | | * @detail: Signal detail the handlers have to be connected to. |
2865 | | * @closure: (nullable): The closure the handlers will invoke. |
2866 | | * @func: The C closure callback of the handlers (useless for non-C closures). |
2867 | | * @data: (nullable) (closure closure): The closure data of the handlers' closures. |
2868 | | * |
2869 | | * Blocks all handlers on an instance that match a certain selection criteria. |
2870 | | * |
2871 | | * The criteria mask is passed as a combination of #GSignalMatchType flags, and |
2872 | | * the criteria values are passed as arguments. A handler must match on all |
2873 | | * flags set in @mask to be blocked (i.e. the match is conjunctive). |
2874 | | * |
2875 | | * Passing at least one of the %G_SIGNAL_MATCH_ID, %G_SIGNAL_MATCH_CLOSURE, |
2876 | | * %G_SIGNAL_MATCH_FUNC |
2877 | | * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches. |
2878 | | * If no handlers were found, 0 is returned, the number of blocked handlers |
2879 | | * otherwise. |
2880 | | * |
2881 | | * Support for %G_SIGNAL_MATCH_ID was added in GLib 2.78. |
2882 | | * |
2883 | | * Returns: The number of handlers that matched. |
2884 | | */ |
2885 | | guint |
2886 | | g_signal_handlers_block_matched (gpointer instance, |
2887 | | GSignalMatchType mask, |
2888 | | guint signal_id, |
2889 | | GQuark detail, |
2890 | | GClosure *closure, |
2891 | | gpointer func, |
2892 | | gpointer data) |
2893 | 0 | { |
2894 | 0 | guint n_handlers = 0; |
2895 | | |
2896 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); |
2897 | 0 | g_return_val_if_fail ((mask & (unsigned) ~G_SIGNAL_MATCH_MASK) == 0, 0); |
2898 | | |
2899 | 0 | if (mask & (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA)) |
2900 | 0 | { |
2901 | 0 | SIGNAL_LOCK (); |
2902 | 0 | n_handlers = |
2903 | 0 | signal_handlers_foreach_matched_unlocked_R (instance, mask, signal_id, detail, |
2904 | 0 | closure, func, data, |
2905 | 0 | signal_handler_block_unlocked); |
2906 | 0 | SIGNAL_UNLOCK (); |
2907 | 0 | } |
2908 | | |
2909 | 0 | return n_handlers; |
2910 | 0 | } |
2911 | | |
2912 | | /** |
2913 | | * g_signal_handlers_unblock_matched: |
2914 | | * @instance: (type GObject.Object): The instance to unblock handlers from. |
2915 | | * @mask: Mask indicating which of @signal_id, @detail, @closure, @func |
2916 | | * and/or @data the handlers have to match. |
2917 | | * @signal_id: Signal the handlers have to be connected to. |
2918 | | * @detail: Signal detail the handlers have to be connected to. |
2919 | | * @closure: (nullable): The closure the handlers will invoke. |
2920 | | * @func: The C closure callback of the handlers (useless for non-C closures). |
2921 | | * @data: (nullable) (closure closure): The closure data of the handlers' closures. |
2922 | | * |
2923 | | * Unblocks all handlers on an instance that match a certain selection |
2924 | | * criteria. |
2925 | | * |
2926 | | * The criteria mask is passed as a combination of #GSignalMatchType flags, and |
2927 | | * the criteria values are passed as arguments. A handler must match on all |
2928 | | * flags set in @mask to be unblocked (i.e. the match is conjunctive). |
2929 | | * |
2930 | | * Passing at least one of the %G_SIGNAL_MATCH_ID, %G_SIGNAL_MATCH_CLOSURE, |
2931 | | * %G_SIGNAL_MATCH_FUNC |
2932 | | * or %G_SIGNAL_MATCH_DATA match flags is required for successful matches. |
2933 | | * If no handlers were found, 0 is returned, the number of unblocked handlers |
2934 | | * otherwise. The match criteria should not apply to any handlers that are |
2935 | | * not currently blocked. |
2936 | | * |
2937 | | * Support for %G_SIGNAL_MATCH_ID was added in GLib 2.78. |
2938 | | * |
2939 | | * Returns: The number of handlers that matched. |
2940 | | */ |
2941 | | guint |
2942 | | g_signal_handlers_unblock_matched (gpointer instance, |
2943 | | GSignalMatchType mask, |
2944 | | guint signal_id, |
2945 | | GQuark detail, |
2946 | | GClosure *closure, |
2947 | | gpointer func, |
2948 | | gpointer data) |
2949 | 0 | { |
2950 | 0 | guint n_handlers = 0; |
2951 | | |
2952 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); |
2953 | 0 | g_return_val_if_fail ((mask & (unsigned) ~G_SIGNAL_MATCH_MASK) == 0, 0); |
2954 | | |
2955 | 0 | if (mask & (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA)) |
2956 | 0 | { |
2957 | 0 | SIGNAL_LOCK (); |
2958 | 0 | n_handlers = |
2959 | 0 | signal_handlers_foreach_matched_unlocked_R (instance, mask, signal_id, detail, |
2960 | 0 | closure, func, data, |
2961 | 0 | signal_handler_unblock_unlocked); |
2962 | 0 | SIGNAL_UNLOCK (); |
2963 | 0 | } |
2964 | | |
2965 | 0 | return n_handlers; |
2966 | 0 | } |
2967 | | |
2968 | | /** |
2969 | | * g_signal_handlers_disconnect_matched: |
2970 | | * @instance: (type GObject.Object): The instance to remove handlers from. |
2971 | | * @mask: Mask indicating which of @signal_id, @detail, @closure, @func |
2972 | | * and/or @data the handlers have to match. |
2973 | | * @signal_id: Signal the handlers have to be connected to. |
2974 | | * @detail: Signal detail the handlers have to be connected to. |
2975 | | * @closure: (nullable): The closure the handlers will invoke. |
2976 | | * @func: The C closure callback of the handlers (useless for non-C closures). |
2977 | | * @data: (nullable) (closure closure): The closure data of the handlers' closures. |
2978 | | * |
2979 | | * Disconnects all handlers on an instance that match a certain |
2980 | | * selection criteria. |
2981 | | * |
2982 | | * The criteria mask is passed as a combination of #GSignalMatchType flags, and |
2983 | | * the criteria values are passed as arguments. A handler must match on all |
2984 | | * flags set in @mask to be disconnected (i.e. the match is conjunctive). |
2985 | | * |
2986 | | * Passing at least one of the %G_SIGNAL_MATCH_ID, %G_SIGNAL_MATCH_CLOSURE, |
2987 | | * %G_SIGNAL_MATCH_FUNC or |
2988 | | * %G_SIGNAL_MATCH_DATA match flags is required for successful |
2989 | | * matches. If no handlers were found, 0 is returned, the number of |
2990 | | * disconnected handlers otherwise. |
2991 | | * |
2992 | | * Support for %G_SIGNAL_MATCH_ID was added in GLib 2.78. |
2993 | | * |
2994 | | * Returns: The number of handlers that matched. |
2995 | | */ |
2996 | | guint |
2997 | | g_signal_handlers_disconnect_matched (gpointer instance, |
2998 | | GSignalMatchType mask, |
2999 | | guint signal_id, |
3000 | | GQuark detail, |
3001 | | GClosure *closure, |
3002 | | gpointer func, |
3003 | | gpointer data) |
3004 | 0 | { |
3005 | 0 | guint n_handlers = 0; |
3006 | | |
3007 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); |
3008 | 0 | g_return_val_if_fail ((mask & (unsigned) ~G_SIGNAL_MATCH_MASK) == 0, 0); |
3009 | | |
3010 | 0 | if (mask & (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA)) |
3011 | 0 | { |
3012 | 0 | SIGNAL_LOCK (); |
3013 | 0 | n_handlers = |
3014 | 0 | signal_handlers_foreach_matched_unlocked_R (instance, mask, signal_id, detail, |
3015 | 0 | closure, func, data, |
3016 | 0 | signal_handler_disconnect_unlocked); |
3017 | 0 | SIGNAL_UNLOCK (); |
3018 | 0 | } |
3019 | | |
3020 | 0 | return n_handlers; |
3021 | 0 | } |
3022 | | |
3023 | | /** |
3024 | | * g_signal_has_handler_pending: |
3025 | | * @instance: (type GObject.Object): the object whose signal handlers are sought. |
3026 | | * @signal_id: the signal id. |
3027 | | * @detail: the detail. |
3028 | | * @may_be_blocked: whether blocked handlers should count as match. |
3029 | | * |
3030 | | * Returns whether there are any handlers connected to @instance for the |
3031 | | * given signal id and detail. |
3032 | | * |
3033 | | * If @detail is 0 then it will only match handlers that were connected |
3034 | | * without detail. If @detail is non-zero then it will match handlers |
3035 | | * connected both without detail and with the given detail. This is |
3036 | | * consistent with how a signal emitted with @detail would be delivered |
3037 | | * to those handlers. |
3038 | | * |
3039 | | * Since 2.46 this also checks for a non-default class closure being |
3040 | | * installed, as this is basically always what you want. |
3041 | | * |
3042 | | * One example of when you might use this is when the arguments to the |
3043 | | * signal are difficult to compute. A class implementor may opt to not |
3044 | | * emit the signal if no one is attached anyway, thus saving the cost |
3045 | | * of building the arguments. |
3046 | | * |
3047 | | * Returns: %TRUE if a handler is connected to the signal, %FALSE |
3048 | | * otherwise. |
3049 | | */ |
3050 | | gboolean |
3051 | | g_signal_has_handler_pending (gpointer instance, |
3052 | | guint signal_id, |
3053 | | GQuark detail, |
3054 | | gboolean may_be_blocked) |
3055 | 0 | { |
3056 | 0 | HandlerMatch *mlist; |
3057 | 0 | gboolean has_pending; |
3058 | 0 | SignalNode *node; |
3059 | | |
3060 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), FALSE); |
3061 | 0 | g_return_val_if_fail (signal_id > 0, FALSE); |
3062 | | |
3063 | 0 | SIGNAL_LOCK (); |
3064 | |
|
3065 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
3066 | 0 | if (detail) |
3067 | 0 | { |
3068 | 0 | if (!(node->flags & G_SIGNAL_DETAILED)) |
3069 | 0 | { |
3070 | 0 | g_critical ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail); |
3071 | 0 | SIGNAL_UNLOCK (); |
3072 | 0 | return FALSE; |
3073 | 0 | } |
3074 | 0 | } |
3075 | 0 | mlist = handlers_find (instance, |
3076 | 0 | (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | (may_be_blocked ? 0 : G_SIGNAL_MATCH_UNBLOCKED)), |
3077 | 0 | signal_id, detail, NULL, NULL, NULL, TRUE); |
3078 | 0 | if (mlist) |
3079 | 0 | { |
3080 | 0 | has_pending = TRUE; |
3081 | 0 | handler_match_free1_R (mlist, instance); |
3082 | 0 | } |
3083 | 0 | else |
3084 | 0 | { |
3085 | 0 | ClassClosure *class_closure = signal_find_class_closure (node, G_TYPE_FROM_INSTANCE (instance)); |
3086 | 0 | if (class_closure != NULL && class_closure->instance_type != 0) |
3087 | 0 | has_pending = TRUE; |
3088 | 0 | else |
3089 | 0 | has_pending = FALSE; |
3090 | 0 | } |
3091 | 0 | SIGNAL_UNLOCK (); |
3092 | |
|
3093 | 0 | return has_pending; |
3094 | 0 | } |
3095 | | |
3096 | | static void |
3097 | | signal_emitv_unlocked (const GValue *instance_and_params, |
3098 | | guint signal_id, |
3099 | | GQuark detail, |
3100 | | GValue *return_value); |
3101 | | |
3102 | | /** |
3103 | | * g_signal_emitv: |
3104 | | * @instance_and_params: (array): argument list for the signal emission. |
3105 | | * The first element in the array is a #GValue for the instance the signal |
3106 | | * is being emitted on. The rest are any arguments to be passed to the signal. |
3107 | | * @signal_id: the signal id |
3108 | | * @detail: the detail |
3109 | | * @return_value: (inout) (optional): Location to |
3110 | | * store the return value of the signal emission. This must be provided if the |
3111 | | * specified signal returns a value, but may be ignored otherwise. |
3112 | | * |
3113 | | * Emits a signal. Signal emission is done synchronously. |
3114 | | * The method will only return control after all handlers are called or signal emission was stopped. |
3115 | | * |
3116 | | * Note that g_signal_emitv() doesn't change @return_value if no handlers are |
3117 | | * connected, in contrast to g_signal_emit() and g_signal_emit_valist(). |
3118 | | */ |
3119 | | void |
3120 | | g_signal_emitv (const GValue *instance_and_params, |
3121 | | guint signal_id, |
3122 | | GQuark detail, |
3123 | | GValue *return_value) |
3124 | 0 | { |
3125 | 0 | SIGNAL_LOCK (); |
3126 | 0 | signal_emitv_unlocked (instance_and_params, signal_id, detail, return_value); |
3127 | 0 | SIGNAL_UNLOCK (); |
3128 | 0 | } |
3129 | | |
3130 | | static void |
3131 | | signal_emitv_unlocked (const GValue *instance_and_params, |
3132 | | guint signal_id, |
3133 | | GQuark detail, |
3134 | | GValue *return_value) |
3135 | 0 | { |
3136 | 0 | gpointer instance; |
3137 | 0 | SignalNode *node; |
3138 | 0 | #ifdef G_ENABLE_DEBUG |
3139 | 0 | const GValue *param_values; |
3140 | 0 | guint i; |
3141 | 0 | #endif |
3142 | | |
3143 | 0 | g_return_if_fail (instance_and_params != NULL); |
3144 | 0 | instance = g_value_peek_pointer (instance_and_params); |
3145 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
3146 | 0 | g_return_if_fail (signal_id > 0); |
3147 | | |
3148 | 0 | #ifdef G_ENABLE_DEBUG |
3149 | 0 | param_values = instance_and_params + 1; |
3150 | 0 | #endif |
3151 | |
|
3152 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
3153 | 0 | if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype)) |
3154 | 0 | { |
3155 | 0 | g_critical ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance); |
3156 | 0 | return; |
3157 | 0 | } |
3158 | 0 | #ifdef G_ENABLE_DEBUG |
3159 | 0 | if (detail && !(node->flags & G_SIGNAL_DETAILED)) |
3160 | 0 | { |
3161 | 0 | g_critical ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail); |
3162 | 0 | return; |
3163 | 0 | } |
3164 | 0 | for (i = 0; i < node->n_params; i++) |
3165 | 0 | if (!G_TYPE_CHECK_VALUE_TYPE (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE)) |
3166 | 0 | { |
3167 | 0 | g_critical ("%s: value for '%s' parameter %u for signal \"%s\" is of type '%s'", |
3168 | 0 | G_STRLOC, |
3169 | 0 | type_debug_name (node->param_types[i]), |
3170 | 0 | i, |
3171 | 0 | node->name, |
3172 | 0 | G_VALUE_TYPE_NAME (param_values + i)); |
3173 | 0 | return; |
3174 | 0 | } |
3175 | 0 | if (node->return_type != G_TYPE_NONE) |
3176 | 0 | { |
3177 | 0 | if (!return_value) |
3178 | 0 | { |
3179 | 0 | g_critical ("%s: return value '%s' for signal \"%s\" is (NULL)", |
3180 | 0 | G_STRLOC, |
3181 | 0 | type_debug_name (node->return_type), |
3182 | 0 | node->name); |
3183 | 0 | return; |
3184 | 0 | } |
3185 | 0 | else if (!node->accumulator && !G_TYPE_CHECK_VALUE_TYPE (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE)) |
3186 | 0 | { |
3187 | 0 | g_critical ("%s: return value '%s' for signal \"%s\" is of type '%s'", |
3188 | 0 | G_STRLOC, |
3189 | 0 | type_debug_name (node->return_type), |
3190 | 0 | node->name, |
3191 | 0 | G_VALUE_TYPE_NAME (return_value)); |
3192 | 0 | return; |
3193 | 0 | } |
3194 | 0 | } |
3195 | 0 | else |
3196 | 0 | return_value = NULL; |
3197 | 0 | #endif /* G_ENABLE_DEBUG */ |
3198 | | |
3199 | | /* optimize NOP emissions */ |
3200 | 0 | if (!node->single_va_closure_is_valid) |
3201 | 0 | node_update_single_va_closure (node); |
3202 | |
|
3203 | 0 | if (node->single_va_closure != NULL && |
3204 | 0 | (node->single_va_closure == SINGLE_VA_CLOSURE_EMPTY_MAGIC || |
3205 | 0 | _g_closure_is_void (node->single_va_closure, instance))) |
3206 | 0 | { |
3207 | 0 | HandlerList* hlist; |
3208 | | |
3209 | | /* single_va_closure is only true for GObjects, so fast path if no handler ever connected to the signal */ |
3210 | 0 | if (_g_object_has_signal_handler ((GObject *)instance)) |
3211 | 0 | hlist = handler_list_lookup (node->signal_id, instance); |
3212 | 0 | else |
3213 | 0 | hlist = NULL; |
3214 | |
|
3215 | 0 | if (hlist == NULL || hlist->handlers == NULL) |
3216 | 0 | { |
3217 | | /* nothing to do to emit this signal */ |
3218 | | /* g_printerr ("omitting emission of \"%s\"\n", node->name); */ |
3219 | 0 | return; |
3220 | 0 | } |
3221 | 0 | } |
3222 | | |
3223 | | /* Pass a stable node pointer, whose address can't change even if the |
3224 | | * g_signal_nodes array gets reallocated. */ |
3225 | 0 | SignalNode node_copy = *node; |
3226 | 0 | signal_emit_unlocked_R (&node_copy, detail, instance, return_value, instance_and_params); |
3227 | 0 | } |
3228 | | |
3229 | | static inline gboolean |
3230 | | accumulate (GSignalInvocationHint *ihint, |
3231 | | GValue *return_accu, |
3232 | | GValue *handler_return, |
3233 | | SignalAccumulator *accumulator) |
3234 | 0 | { |
3235 | 0 | gboolean continue_emission; |
3236 | |
|
3237 | 0 | if (!accumulator) |
3238 | 0 | return TRUE; |
3239 | | |
3240 | 0 | continue_emission = accumulator->func (ihint, return_accu, handler_return, accumulator->data); |
3241 | 0 | g_value_reset (handler_return); |
3242 | |
|
3243 | 0 | ihint->run_type &= (unsigned) ~G_SIGNAL_ACCUMULATOR_FIRST_RUN; |
3244 | |
|
3245 | 0 | return continue_emission; |
3246 | 0 | } |
3247 | | |
3248 | | static gboolean |
3249 | | signal_emit_valist_unlocked (gpointer instance, |
3250 | | guint signal_id, |
3251 | | GQuark detail, |
3252 | | va_list var_args); |
3253 | | |
3254 | | /** |
3255 | | * g_signal_emit_valist: (skip) |
3256 | | * @instance: (type GObject.TypeInstance): the instance the signal is being |
3257 | | * emitted on. |
3258 | | * @signal_id: the signal id |
3259 | | * @detail: the detail |
3260 | | * @var_args: a list of parameters to be passed to the signal, followed by a |
3261 | | * location for the return value. If the return type of the signal |
3262 | | * is %G_TYPE_NONE, the return value location can be omitted. |
3263 | | * |
3264 | | * Emits a signal. Signal emission is done synchronously. |
3265 | | * The method will only return control after all handlers are called or signal emission was stopped. |
3266 | | * |
3267 | | * Note that g_signal_emit_valist() resets the return value to the default |
3268 | | * if no handlers are connected, in contrast to g_signal_emitv(). |
3269 | | */ |
3270 | | void |
3271 | | g_signal_emit_valist (gpointer instance, |
3272 | | guint signal_id, |
3273 | | GQuark detail, |
3274 | | va_list var_args) |
3275 | 0 | { |
3276 | 0 | SIGNAL_LOCK (); |
3277 | 0 | if (signal_emit_valist_unlocked (instance, signal_id, detail, var_args)) |
3278 | 0 | SIGNAL_UNLOCK (); |
3279 | 0 | } |
3280 | | |
3281 | | /*<private> |
3282 | | * signal_emit_valist_unlocked: |
3283 | | * @instance: The instance to emit from |
3284 | | * @signal_id: Signal id to emit |
3285 | | * @detail: Signal detail |
3286 | | * @var_args: Call arguments |
3287 | | * |
3288 | | * Returns: %TRUE if the signal mutex has been left locked |
3289 | | */ |
3290 | | static gboolean |
3291 | | signal_emit_valist_unlocked (gpointer instance, |
3292 | | guint signal_id, |
3293 | | GQuark detail, |
3294 | | va_list var_args) |
3295 | 0 | { |
3296 | 0 | GValue *instance_and_params; |
3297 | 0 | GValue *param_values; |
3298 | 0 | SignalNode *node; |
3299 | 0 | guint i; |
3300 | |
|
3301 | 0 | g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), TRUE); |
3302 | 0 | g_return_val_if_fail (signal_id > 0, TRUE); |
3303 | | |
3304 | 0 | node = LOOKUP_SIGNAL_NODE (signal_id); |
3305 | 0 | if (!node || !g_type_is_a (G_TYPE_FROM_INSTANCE (instance), node->itype)) |
3306 | 0 | { |
3307 | 0 | g_critical ("%s: signal id '%u' is invalid for instance '%p'", G_STRLOC, signal_id, instance); |
3308 | 0 | return TRUE; |
3309 | 0 | } |
3310 | 0 | #ifndef G_DISABLE_CHECKS |
3311 | 0 | if (detail && !(node->flags & G_SIGNAL_DETAILED)) |
3312 | 0 | { |
3313 | 0 | g_critical ("%s: signal id '%u' does not support detail (%u)", G_STRLOC, signal_id, detail); |
3314 | 0 | return TRUE; |
3315 | 0 | } |
3316 | 0 | #endif /* !G_DISABLE_CHECKS */ |
3317 | | |
3318 | 0 | if (!node->single_va_closure_is_valid) |
3319 | 0 | node_update_single_va_closure (node); |
3320 | | |
3321 | | /* There's no need to deep copy this, because a SignalNode instance won't |
3322 | | * ever be destroyed, given that _g_signals_destroy() is not called in any |
3323 | | * real program, however the SignalNode pointer could change, so just store |
3324 | | * the struct contents references, so that we won't try to deference a |
3325 | | * potentially invalid (or changed) pointer; |
3326 | | */ |
3327 | 0 | SignalNode node_copy = *node; |
3328 | |
|
3329 | 0 | if (node->single_va_closure != NULL) |
3330 | 0 | { |
3331 | 0 | HandlerList* hlist; |
3332 | 0 | Handler *fastpath_handler = NULL; |
3333 | 0 | Handler *l; |
3334 | 0 | GClosure *closure = NULL; |
3335 | 0 | gboolean fastpath = TRUE; |
3336 | 0 | GSignalFlags run_type = G_SIGNAL_RUN_FIRST; |
3337 | |
|
3338 | 0 | if (node->single_va_closure != SINGLE_VA_CLOSURE_EMPTY_MAGIC && |
3339 | 0 | !_g_closure_is_void (node->single_va_closure, instance)) |
3340 | 0 | { |
3341 | 0 | if (_g_closure_supports_invoke_va (node->single_va_closure)) |
3342 | 0 | { |
3343 | 0 | closure = node->single_va_closure; |
3344 | 0 | if (node->single_va_closure_is_after) |
3345 | 0 | run_type = G_SIGNAL_RUN_LAST; |
3346 | 0 | else |
3347 | 0 | run_type = G_SIGNAL_RUN_FIRST; |
3348 | 0 | } |
3349 | 0 | else |
3350 | 0 | fastpath = FALSE; |
3351 | 0 | } |
3352 | | |
3353 | | /* single_va_closure is only true for GObjects, so fast path if no handler ever connected to the signal */ |
3354 | 0 | if (_g_object_has_signal_handler ((GObject *)instance)) |
3355 | 0 | hlist = handler_list_lookup (node->signal_id, instance); |
3356 | 0 | else |
3357 | 0 | hlist = NULL; |
3358 | |
|
3359 | 0 | for (l = hlist ? hlist->handlers : NULL; fastpath && l != NULL; l = l->next) |
3360 | 0 | { |
3361 | 0 | if (!l->block_count && |
3362 | 0 | (!l->detail || l->detail == detail)) |
3363 | 0 | { |
3364 | 0 | if (closure != NULL || !_g_closure_supports_invoke_va (l->closure)) |
3365 | 0 | { |
3366 | 0 | fastpath = FALSE; |
3367 | 0 | break; |
3368 | 0 | } |
3369 | 0 | else |
3370 | 0 | { |
3371 | 0 | fastpath_handler = l; |
3372 | 0 | closure = l->closure; |
3373 | 0 | if (l->after) |
3374 | 0 | run_type = G_SIGNAL_RUN_LAST; |
3375 | 0 | else |
3376 | 0 | run_type = G_SIGNAL_RUN_FIRST; |
3377 | 0 | } |
3378 | 0 | } |
3379 | 0 | } |
3380 | |
|
3381 | 0 | if (fastpath && closure == NULL && node_copy.return_type == G_TYPE_NONE) |
3382 | 0 | return TRUE; |
3383 | | |
3384 | | /* Don't allow no-recurse emission as we might have to restart, which means |
3385 | | we will run multiple handlers and thus must ref all arguments */ |
3386 | 0 | if (closure != NULL && (node_copy.flags & (G_SIGNAL_NO_RECURSE)) != 0) |
3387 | 0 | fastpath = FALSE; |
3388 | | |
3389 | 0 | if (fastpath) |
3390 | 0 | { |
3391 | 0 | Emission emission; |
3392 | 0 | GValue *return_accu, accu = G_VALUE_INIT; |
3393 | 0 | GType instance_type = G_TYPE_FROM_INSTANCE (instance); |
3394 | 0 | GValue emission_return = G_VALUE_INIT; |
3395 | 0 | GType rtype = node_copy.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE; |
3396 | 0 | gboolean static_scope = node_copy.return_type & G_SIGNAL_TYPE_STATIC_SCOPE; |
3397 | |
|
3398 | 0 | if (rtype == G_TYPE_NONE) |
3399 | 0 | return_accu = NULL; |
3400 | 0 | else if (node_copy.accumulator) |
3401 | 0 | return_accu = &accu; |
3402 | 0 | else |
3403 | 0 | return_accu = &emission_return; |
3404 | |
|
3405 | 0 | emission.instance = instance; |
3406 | 0 | emission.ihint.signal_id = signal_id; |
3407 | 0 | emission.ihint.detail = detail; |
3408 | 0 | emission.ihint.run_type = run_type | G_SIGNAL_ACCUMULATOR_FIRST_RUN; |
3409 | 0 | emission.state = EMISSION_RUN; |
3410 | 0 | emission.chain_type = instance_type; |
3411 | 0 | emission_push (&emission); |
3412 | |
|
3413 | 0 | if (fastpath_handler) |
3414 | 0 | handler_ref (fastpath_handler); |
3415 | |
|
3416 | 0 | if (closure != NULL) |
3417 | 0 | { |
3418 | 0 | TRACE(GOBJECT_SIGNAL_EMIT(signal_id, detail, instance, instance_type)); |
3419 | |
|
3420 | 0 | SIGNAL_UNLOCK (); |
3421 | |
|
3422 | 0 | if (rtype != G_TYPE_NONE) |
3423 | 0 | g_value_init (&emission_return, rtype); |
3424 | |
|
3425 | 0 | if (node_copy.accumulator) |
3426 | 0 | g_value_init (&accu, rtype); |
3427 | | |
3428 | | /* |
3429 | | * Coverity doesn’t understand the paired ref/unref here and seems |
3430 | | * to ignore the ref, thus reports every call to g_signal_emit() |
3431 | | * as causing a double-free. That’s incorrect, but I can’t get a |
3432 | | * model file to work for avoiding the false positives, so instead |
3433 | | * comment out the ref/unref when doing static analysis. |
3434 | | */ |
3435 | 0 | #ifndef __COVERITY__ |
3436 | 0 | g_object_ref (instance); |
3437 | 0 | #endif |
3438 | 0 | _g_closure_invoke_va (closure, |
3439 | 0 | return_accu, |
3440 | 0 | instance, |
3441 | 0 | var_args, |
3442 | 0 | node_copy.n_params, |
3443 | 0 | node_copy.param_types); |
3444 | 0 | accumulate (&emission.ihint, &emission_return, &accu, node_copy.accumulator); |
3445 | |
|
3446 | 0 | if (node_copy.accumulator) |
3447 | 0 | g_value_unset (&accu); |
3448 | |
|
3449 | 0 | SIGNAL_LOCK (); |
3450 | 0 | } |
3451 | |
|
3452 | 0 | emission.chain_type = G_TYPE_NONE; |
3453 | 0 | emission_pop (&emission); |
3454 | |
|
3455 | 0 | if (fastpath_handler) |
3456 | 0 | handler_unref_R (signal_id, instance, fastpath_handler); |
3457 | |
|
3458 | 0 | SIGNAL_UNLOCK (); |
3459 | |
|
3460 | 0 | if (rtype != G_TYPE_NONE) |
3461 | 0 | { |
3462 | 0 | gchar *error = NULL; |
3463 | 0 | for (i = 0; i < node_copy.n_params; i++) |
3464 | 0 | { |
3465 | 0 | GType ptype = node_copy.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE; |
3466 | 0 | G_VALUE_COLLECT_SKIP (ptype, var_args); |
3467 | 0 | } |
3468 | | |
3469 | 0 | if (closure == NULL) |
3470 | 0 | g_value_init (&emission_return, rtype); |
3471 | |
|
3472 | 0 | G_VALUE_LCOPY (&emission_return, |
3473 | 0 | var_args, |
3474 | 0 | static_scope ? G_VALUE_NOCOPY_CONTENTS : 0, |
3475 | 0 | &error); |
3476 | 0 | if (!error) |
3477 | 0 | g_value_unset (&emission_return); |
3478 | 0 | else |
3479 | 0 | { |
3480 | 0 | g_critical ("%s: %s", G_STRLOC, error); |
3481 | 0 | g_free (error); |
3482 | | /* we purposely leak the value here, it might not be |
3483 | | * in a correct state if an error condition occurred |
3484 | | */ |
3485 | 0 | } |
3486 | 0 | } |
3487 | | |
3488 | 0 | TRACE(GOBJECT_SIGNAL_EMIT_END(signal_id, detail, instance, instance_type)); |
3489 | | |
3490 | | /* See comment above paired ref above */ |
3491 | 0 | #ifndef __COVERITY__ |
3492 | 0 | if (closure != NULL) |
3493 | 0 | g_object_unref (instance); |
3494 | 0 | #endif |
3495 | |
|
3496 | 0 | return FALSE; |
3497 | 0 | } |
3498 | 0 | } |
3499 | | |
3500 | 0 | SIGNAL_UNLOCK (); |
3501 | |
|
3502 | 0 | instance_and_params = g_newa0 (GValue, node_copy.n_params + 1); |
3503 | 0 | param_values = instance_and_params + 1; |
3504 | |
|
3505 | 0 | for (i = 0; i < node_copy.n_params; i++) |
3506 | 0 | { |
3507 | 0 | gchar *error; |
3508 | 0 | GType ptype = node_copy.param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE; |
3509 | 0 | gboolean static_scope = node_copy.param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE; |
3510 | |
|
3511 | 0 | G_VALUE_COLLECT_INIT (param_values + i, ptype, |
3512 | 0 | var_args, |
3513 | 0 | static_scope ? G_VALUE_NOCOPY_CONTENTS : 0, |
3514 | 0 | &error); |
3515 | 0 | if (error) |
3516 | 0 | { |
3517 | 0 | g_critical ("%s: %s", G_STRLOC, error); |
3518 | 0 | g_free (error); |
3519 | | |
3520 | | /* we purposely leak the value here, it might not be |
3521 | | * in a correct state if an error condition occurred |
3522 | | */ |
3523 | 0 | while (i--) |
3524 | 0 | g_value_unset (param_values + i); |
3525 | |
|
3526 | 0 | return FALSE; |
3527 | 0 | } |
3528 | 0 | } |
3529 | | |
3530 | 0 | g_value_init_from_instance (instance_and_params, instance); |
3531 | 0 | if (node_copy.return_type == G_TYPE_NONE) |
3532 | 0 | { |
3533 | 0 | SIGNAL_LOCK (); |
3534 | 0 | signal_emit_unlocked_R (&node_copy, detail, instance, NULL, instance_and_params); |
3535 | 0 | SIGNAL_UNLOCK (); |
3536 | 0 | } |
3537 | 0 | else |
3538 | 0 | { |
3539 | 0 | GValue return_value = G_VALUE_INIT; |
3540 | 0 | gchar *error = NULL; |
3541 | 0 | GType rtype = node_copy.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE; |
3542 | 0 | gboolean static_scope = node_copy.return_type & G_SIGNAL_TYPE_STATIC_SCOPE; |
3543 | | |
3544 | 0 | g_value_init (&return_value, rtype); |
3545 | |
|
3546 | 0 | SIGNAL_LOCK (); |
3547 | 0 | signal_emit_unlocked_R (&node_copy, detail, instance, &return_value, instance_and_params); |
3548 | 0 | SIGNAL_UNLOCK (); |
3549 | |
|
3550 | 0 | G_VALUE_LCOPY (&return_value, |
3551 | 0 | var_args, |
3552 | 0 | static_scope ? G_VALUE_NOCOPY_CONTENTS : 0, |
3553 | 0 | &error); |
3554 | 0 | if (!error) |
3555 | 0 | g_value_unset (&return_value); |
3556 | 0 | else |
3557 | 0 | { |
3558 | 0 | g_critical ("%s: %s", G_STRLOC, error); |
3559 | 0 | g_free (error); |
3560 | | |
3561 | | /* we purposely leak the value here, it might not be |
3562 | | * in a correct state if an error condition occurred |
3563 | | */ |
3564 | 0 | } |
3565 | 0 | } |
3566 | 0 | for (i = 0; i < node_copy.n_params; i++) |
3567 | 0 | g_value_unset (param_values + i); |
3568 | 0 | g_value_unset (instance_and_params); |
3569 | |
|
3570 | 0 | return FALSE; |
3571 | 0 | } |
3572 | | |
3573 | | /** |
3574 | | * g_signal_emit: |
3575 | | * @instance: (type GObject.Object): the instance the signal is being emitted on. |
3576 | | * @signal_id: the signal id |
3577 | | * @detail: the detail |
3578 | | * @...: parameters to be passed to the signal, followed by a |
3579 | | * location for the return value. If the return type of the signal |
3580 | | * is %G_TYPE_NONE, the return value location can be omitted. |
3581 | | * |
3582 | | * Emits a signal. Signal emission is done synchronously. |
3583 | | * The method will only return control after all handlers are called or signal emission was stopped. |
3584 | | * |
3585 | | * Note that g_signal_emit() resets the return value to the default |
3586 | | * if no handlers are connected, in contrast to g_signal_emitv(). |
3587 | | */ |
3588 | | void |
3589 | | g_signal_emit (gpointer instance, |
3590 | | guint signal_id, |
3591 | | GQuark detail, |
3592 | | ...) |
3593 | 0 | { |
3594 | 0 | va_list var_args; |
3595 | |
|
3596 | 0 | va_start (var_args, detail); |
3597 | 0 | g_signal_emit_valist (instance, signal_id, detail, var_args); |
3598 | 0 | va_end (var_args); |
3599 | 0 | } |
3600 | | |
3601 | | /** |
3602 | | * g_signal_emit_by_name: |
3603 | | * @instance: (type GObject.Object): the instance the signal is being emitted on. |
3604 | | * @detailed_signal: a string of the form "signal-name::detail". |
3605 | | * @...: parameters to be passed to the signal, followed by a |
3606 | | * location for the return value. If the return type of the signal |
3607 | | * is %G_TYPE_NONE, the return value location can be omitted. The |
3608 | | * number of parameters to pass to this function is defined when creating the signal. |
3609 | | * |
3610 | | * Emits a signal. Signal emission is done synchronously. |
3611 | | * The method will only return control after all handlers are called or signal emission was stopped. |
3612 | | * |
3613 | | * Note that g_signal_emit_by_name() resets the return value to the default |
3614 | | * if no handlers are connected, in contrast to g_signal_emitv(). |
3615 | | */ |
3616 | | void |
3617 | | g_signal_emit_by_name (gpointer instance, |
3618 | | const gchar *detailed_signal, |
3619 | | ...) |
3620 | 0 | { |
3621 | 0 | GQuark detail = 0; |
3622 | 0 | guint signal_id; |
3623 | 0 | GType itype; |
3624 | |
|
3625 | 0 | g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); |
3626 | 0 | g_return_if_fail (detailed_signal != NULL); |
3627 | | |
3628 | 0 | itype = G_TYPE_FROM_INSTANCE (instance); |
3629 | |
|
3630 | 0 | SIGNAL_LOCK (); |
3631 | 0 | signal_id = signal_parse_name (detailed_signal, itype, &detail, TRUE); |
3632 | |
|
3633 | 0 | if (signal_id) |
3634 | 0 | { |
3635 | 0 | va_list var_args; |
3636 | |
|
3637 | 0 | va_start (var_args, detailed_signal); |
3638 | 0 | if (signal_emit_valist_unlocked (instance, signal_id, detail, var_args)) |
3639 | 0 | SIGNAL_UNLOCK (); |
3640 | 0 | va_end (var_args); |
3641 | 0 | } |
3642 | 0 | else |
3643 | 0 | { |
3644 | 0 | SIGNAL_UNLOCK (); |
3645 | |
|
3646 | 0 | g_critical ("%s: signal name '%s' is invalid for instance '%p' of type '%s'", |
3647 | 0 | G_STRLOC, detailed_signal, instance, g_type_name (itype)); |
3648 | 0 | } |
3649 | 0 | } |
3650 | | |
3651 | | G_ALWAYS_INLINE static inline GValue * |
3652 | | maybe_init_accumulator_unlocked (SignalNode *node, |
3653 | | GValue *emission_return, |
3654 | | GValue *accumulator_value) |
3655 | 0 | { |
3656 | 0 | if (node->accumulator) |
3657 | 0 | { |
3658 | 0 | if (accumulator_value->g_type) |
3659 | 0 | return accumulator_value; |
3660 | | |
3661 | 0 | g_value_init (accumulator_value, |
3662 | 0 | node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE); |
3663 | 0 | return accumulator_value; |
3664 | 0 | } |
3665 | | |
3666 | 0 | return emission_return; |
3667 | 0 | } |
3668 | | |
3669 | | static gboolean |
3670 | | signal_emit_unlocked_R (SignalNode *node, |
3671 | | GQuark detail, |
3672 | | gpointer instance, |
3673 | | GValue *emission_return, |
3674 | | const GValue *instance_and_params) |
3675 | 0 | { |
3676 | 0 | SignalAccumulator *accumulator; |
3677 | 0 | Emission emission; |
3678 | 0 | GClosure *class_closure; |
3679 | 0 | HandlerList *hlist; |
3680 | 0 | Handler *handler_list = NULL; |
3681 | 0 | GValue *return_accu, accu = G_VALUE_INIT; |
3682 | 0 | guint signal_id; |
3683 | 0 | gulong max_sequential_handler_number; |
3684 | 0 | gboolean return_value_altered = FALSE; |
3685 | 0 | guint n_params; |
3686 | |
|
3687 | 0 | TRACE(GOBJECT_SIGNAL_EMIT(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance))); |
3688 | | |
3689 | | /* We expect this function to be called with a stable SignalNode pointer |
3690 | | * that cannot change location, so accessing its stable members should |
3691 | | * always work even after a lock/unlock. |
3692 | | */ |
3693 | 0 | signal_id = node->signal_id; |
3694 | 0 | n_params = node->n_params + 1; |
3695 | |
|
3696 | 0 | if (node->flags & G_SIGNAL_NO_RECURSE) |
3697 | 0 | { |
3698 | 0 | Emission *emission_node = emission_find (signal_id, detail, instance); |
3699 | |
|
3700 | 0 | if (emission_node) |
3701 | 0 | { |
3702 | 0 | emission_node->state = EMISSION_RESTART; |
3703 | 0 | return return_value_altered; |
3704 | 0 | } |
3705 | 0 | } |
3706 | 0 | accumulator = node->accumulator; |
3707 | 0 | emission.instance = instance; |
3708 | 0 | emission.ihint.signal_id = node->signal_id; |
3709 | 0 | emission.ihint.detail = detail; |
3710 | 0 | emission.ihint.run_type = 0; |
3711 | 0 | emission.state = 0; |
3712 | 0 | emission.chain_type = G_TYPE_NONE; |
3713 | 0 | emission_push (&emission); |
3714 | 0 | class_closure = signal_lookup_closure (node, instance); |
3715 | | |
3716 | 0 | EMIT_RESTART: |
3717 | | |
3718 | 0 | if (handler_list) |
3719 | 0 | handler_unref_R (signal_id, instance, handler_list); |
3720 | 0 | max_sequential_handler_number = g_handler_sequential_number; |
3721 | 0 | hlist = handler_list_lookup (signal_id, instance); |
3722 | 0 | handler_list = hlist ? hlist->handlers : NULL; |
3723 | 0 | if (handler_list) |
3724 | 0 | handler_ref (handler_list); |
3725 | | |
3726 | 0 | emission.ihint.run_type = G_SIGNAL_RUN_FIRST | G_SIGNAL_ACCUMULATOR_FIRST_RUN; |
3727 | | |
3728 | 0 | if ((node->flags & G_SIGNAL_RUN_FIRST) && class_closure) |
3729 | 0 | { |
3730 | 0 | emission.state = EMISSION_RUN; |
3731 | |
|
3732 | 0 | emission.chain_type = G_TYPE_FROM_INSTANCE (instance); |
3733 | 0 | SIGNAL_UNLOCK (); |
3734 | 0 | return_accu = maybe_init_accumulator_unlocked (node, emission_return, &accu); |
3735 | 0 | g_closure_invoke (class_closure, |
3736 | 0 | return_accu, |
3737 | 0 | n_params, |
3738 | 0 | instance_and_params, |
3739 | 0 | &emission.ihint); |
3740 | 0 | if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) && |
3741 | 0 | emission.state == EMISSION_RUN) |
3742 | 0 | emission.state = EMISSION_STOP; |
3743 | 0 | SIGNAL_LOCK (); |
3744 | 0 | emission.chain_type = G_TYPE_NONE; |
3745 | 0 | return_value_altered = TRUE; |
3746 | | |
3747 | 0 | if (emission.state == EMISSION_STOP) |
3748 | 0 | goto EMIT_CLEANUP; |
3749 | 0 | else if (emission.state == EMISSION_RESTART) |
3750 | 0 | goto EMIT_RESTART; |
3751 | 0 | } |
3752 | | |
3753 | 0 | if (node->emission_hooks) |
3754 | 0 | { |
3755 | 0 | GHook *hook; |
3756 | 0 | GHook *static_emission_hooks[3]; |
3757 | 0 | size_t n_emission_hooks = 0; |
3758 | 0 | const gboolean may_recurse = TRUE; |
3759 | 0 | guint i; |
3760 | |
|
3761 | 0 | emission.state = EMISSION_HOOK; |
3762 | | |
3763 | | /* Quick check to determine whether any hooks match this emission, |
3764 | | * before committing to the more complex work of calling those hooks. |
3765 | | * We save a few of them into a static array, to try to avoid further |
3766 | | * allocations. |
3767 | | */ |
3768 | 0 | hook = g_hook_first_valid (node->emission_hooks, may_recurse); |
3769 | 0 | while (hook) |
3770 | 0 | { |
3771 | 0 | SignalHook *signal_hook = SIGNAL_HOOK (hook); |
3772 | |
|
3773 | 0 | if (!signal_hook->detail || signal_hook->detail == detail) |
3774 | 0 | { |
3775 | 0 | if (n_emission_hooks < G_N_ELEMENTS (static_emission_hooks)) |
3776 | 0 | { |
3777 | 0 | static_emission_hooks[n_emission_hooks] = |
3778 | 0 | g_hook_ref (node->emission_hooks, hook); |
3779 | 0 | } |
3780 | |
|
3781 | 0 | n_emission_hooks += 1; |
3782 | 0 | } |
3783 | |
|
3784 | 0 | hook = g_hook_next_valid (node->emission_hooks, hook, may_recurse); |
3785 | 0 | } |
3786 | | |
3787 | | /* Re-iterate back through the matching hooks and copy them into |
3788 | | * an array which won’t change when we unlock to call the |
3789 | | * user-provided hook functions. |
3790 | | * These functions may change hook configuration for this signal, |
3791 | | * add / remove signal handlers, etc. |
3792 | | */ |
3793 | 0 | if G_UNLIKELY (n_emission_hooks > 0) |
3794 | 0 | { |
3795 | 0 | guint8 static_hook_returns[G_N_ELEMENTS (static_emission_hooks)]; |
3796 | 0 | GHook **emission_hooks = NULL; |
3797 | 0 | guint8 *hook_returns = NULL; |
3798 | |
|
3799 | 0 | if G_LIKELY (n_emission_hooks <= G_N_ELEMENTS (static_emission_hooks)) |
3800 | 0 | { |
3801 | 0 | emission_hooks = static_emission_hooks; |
3802 | 0 | hook_returns = static_hook_returns; |
3803 | 0 | } |
3804 | 0 | else |
3805 | 0 | { |
3806 | 0 | emission_hooks = g_newa (GHook *, n_emission_hooks); |
3807 | 0 | hook_returns = g_newa (guint8, n_emission_hooks); |
3808 | | |
3809 | | /* We can't just memcpy the ones we have in the static array, |
3810 | | * to the alloca()'d one because otherwise we'd get an invalid |
3811 | | * ID assertion during unref |
3812 | | */ |
3813 | 0 | i = 0; |
3814 | 0 | for (hook = g_hook_first_valid (node->emission_hooks, may_recurse); |
3815 | 0 | hook != NULL; |
3816 | 0 | hook = g_hook_next_valid (node->emission_hooks, hook, may_recurse)) |
3817 | 0 | { |
3818 | 0 | SignalHook *signal_hook = SIGNAL_HOOK (hook); |
3819 | |
|
3820 | 0 | if (!signal_hook->detail || signal_hook->detail == detail) |
3821 | 0 | { |
3822 | 0 | if (i < G_N_ELEMENTS (static_emission_hooks)) |
3823 | 0 | { |
3824 | 0 | emission_hooks[i] = g_steal_pointer (&static_emission_hooks[i]); |
3825 | 0 | g_assert (emission_hooks[i] == hook); |
3826 | 0 | } |
3827 | 0 | else |
3828 | 0 | { |
3829 | 0 | emission_hooks[i] = g_hook_ref (node->emission_hooks, hook); |
3830 | 0 | } |
3831 | | |
3832 | 0 | i += 1; |
3833 | 0 | } |
3834 | 0 | } |
3835 | | |
3836 | 0 | g_assert (i == n_emission_hooks); |
3837 | 0 | } |
3838 | | |
3839 | 0 | SIGNAL_UNLOCK (); |
3840 | |
|
3841 | 0 | for (i = 0; i < n_emission_hooks; ++i) |
3842 | 0 | { |
3843 | 0 | GSignalEmissionHook hook_func; |
3844 | 0 | gboolean need_destroy; |
3845 | 0 | guint old_flags; |
3846 | |
|
3847 | 0 | hook = emission_hooks[i]; |
3848 | 0 | hook_func = (GSignalEmissionHook) hook->func; |
3849 | |
|
3850 | 0 | old_flags = g_atomic_int_or (&hook->flags, G_HOOK_FLAG_IN_CALL); |
3851 | 0 | need_destroy = !hook_func (&emission.ihint, n_params, |
3852 | 0 | instance_and_params, hook->data); |
3853 | |
|
3854 | 0 | if (!(old_flags & G_HOOK_FLAG_IN_CALL)) |
3855 | 0 | { |
3856 | 0 | g_atomic_int_compare_and_exchange ((gint *) &hook->flags, |
3857 | 0 | (gint) old_flags | G_HOOK_FLAG_IN_CALL, |
3858 | 0 | (gint) old_flags); |
3859 | 0 | } |
3860 | |
|
3861 | 0 | hook_returns[i] = !!need_destroy; |
3862 | 0 | } |
3863 | |
|
3864 | 0 | SIGNAL_LOCK (); |
3865 | |
|
3866 | 0 | for (i = 0; i < n_emission_hooks; i++) |
3867 | 0 | { |
3868 | 0 | hook = emission_hooks[i]; |
3869 | |
|
3870 | 0 | g_hook_unref (node->emission_hooks, hook); |
3871 | |
|
3872 | 0 | if (hook_returns[i]) |
3873 | 0 | g_hook_destroy_link (node->emission_hooks, hook); |
3874 | 0 | } |
3875 | 0 | } |
3876 | | |
3877 | 0 | if (emission.state == EMISSION_RESTART) |
3878 | 0 | goto EMIT_RESTART; |
3879 | 0 | } |
3880 | | |
3881 | 0 | if (handler_list) |
3882 | 0 | { |
3883 | 0 | Handler *handler = handler_list; |
3884 | | |
3885 | 0 | emission.state = EMISSION_RUN; |
3886 | 0 | handler_ref (handler); |
3887 | 0 | do |
3888 | 0 | { |
3889 | 0 | Handler *tmp; |
3890 | | |
3891 | 0 | if (handler->after) |
3892 | 0 | { |
3893 | 0 | handler_unref_R (signal_id, instance, handler_list); |
3894 | 0 | handler_list = handler; |
3895 | 0 | break; |
3896 | 0 | } |
3897 | 0 | else if (!handler->block_count && (!handler->detail || handler->detail == detail) && |
3898 | 0 | handler->sequential_number < max_sequential_handler_number) |
3899 | 0 | { |
3900 | 0 | SIGNAL_UNLOCK (); |
3901 | 0 | return_accu = maybe_init_accumulator_unlocked (node, emission_return, &accu); |
3902 | 0 | g_closure_invoke (handler->closure, |
3903 | 0 | return_accu, |
3904 | 0 | n_params, |
3905 | 0 | instance_and_params, |
3906 | 0 | &emission.ihint); |
3907 | 0 | if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) && |
3908 | 0 | emission.state == EMISSION_RUN) |
3909 | 0 | emission.state = EMISSION_STOP; |
3910 | 0 | SIGNAL_LOCK (); |
3911 | 0 | return_value_altered = TRUE; |
3912 | | |
3913 | 0 | tmp = emission.state == EMISSION_RUN ? handler->next : NULL; |
3914 | 0 | } |
3915 | 0 | else |
3916 | 0 | tmp = handler->next; |
3917 | | |
3918 | 0 | if (tmp) |
3919 | 0 | handler_ref (tmp); |
3920 | 0 | handler_unref_R (signal_id, instance, handler_list); |
3921 | 0 | handler_list = handler; |
3922 | 0 | handler = tmp; |
3923 | 0 | } |
3924 | 0 | while (handler); |
3925 | | |
3926 | 0 | if (emission.state == EMISSION_STOP) |
3927 | 0 | goto EMIT_CLEANUP; |
3928 | 0 | else if (emission.state == EMISSION_RESTART) |
3929 | 0 | goto EMIT_RESTART; |
3930 | 0 | } |
3931 | | |
3932 | 0 | emission.ihint.run_type &= (unsigned) ~G_SIGNAL_RUN_FIRST; |
3933 | 0 | emission.ihint.run_type |= G_SIGNAL_RUN_LAST; |
3934 | | |
3935 | 0 | if ((node->flags & G_SIGNAL_RUN_LAST) && class_closure) |
3936 | 0 | { |
3937 | 0 | emission.state = EMISSION_RUN; |
3938 | | |
3939 | 0 | emission.chain_type = G_TYPE_FROM_INSTANCE (instance); |
3940 | 0 | SIGNAL_UNLOCK (); |
3941 | 0 | return_accu = maybe_init_accumulator_unlocked (node, emission_return, &accu); |
3942 | 0 | g_closure_invoke (class_closure, |
3943 | 0 | return_accu, |
3944 | 0 | n_params, |
3945 | 0 | instance_and_params, |
3946 | 0 | &emission.ihint); |
3947 | 0 | if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) && |
3948 | 0 | emission.state == EMISSION_RUN) |
3949 | 0 | emission.state = EMISSION_STOP; |
3950 | 0 | SIGNAL_LOCK (); |
3951 | 0 | emission.chain_type = G_TYPE_NONE; |
3952 | 0 | return_value_altered = TRUE; |
3953 | | |
3954 | 0 | if (emission.state == EMISSION_STOP) |
3955 | 0 | goto EMIT_CLEANUP; |
3956 | 0 | else if (emission.state == EMISSION_RESTART) |
3957 | 0 | goto EMIT_RESTART; |
3958 | 0 | } |
3959 | | |
3960 | 0 | if (handler_list) |
3961 | 0 | { |
3962 | 0 | Handler *handler = handler_list; |
3963 | | |
3964 | 0 | emission.state = EMISSION_RUN; |
3965 | 0 | handler_ref (handler); |
3966 | 0 | do |
3967 | 0 | { |
3968 | 0 | Handler *tmp; |
3969 | | |
3970 | 0 | if (handler->after && !handler->block_count && (!handler->detail || handler->detail == detail) && |
3971 | 0 | handler->sequential_number < max_sequential_handler_number) |
3972 | 0 | { |
3973 | 0 | SIGNAL_UNLOCK (); |
3974 | 0 | return_accu = maybe_init_accumulator_unlocked (node, emission_return, &accu); |
3975 | 0 | g_closure_invoke (handler->closure, |
3976 | 0 | return_accu, |
3977 | 0 | n_params, |
3978 | 0 | instance_and_params, |
3979 | 0 | &emission.ihint); |
3980 | 0 | if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) && |
3981 | 0 | emission.state == EMISSION_RUN) |
3982 | 0 | emission.state = EMISSION_STOP; |
3983 | 0 | SIGNAL_LOCK (); |
3984 | 0 | return_value_altered = TRUE; |
3985 | | |
3986 | 0 | tmp = emission.state == EMISSION_RUN ? handler->next : NULL; |
3987 | 0 | } |
3988 | 0 | else |
3989 | 0 | tmp = handler->next; |
3990 | | |
3991 | 0 | if (tmp) |
3992 | 0 | handler_ref (tmp); |
3993 | 0 | handler_unref_R (signal_id, instance, handler); |
3994 | 0 | handler = tmp; |
3995 | 0 | } |
3996 | 0 | while (handler); |
3997 | | |
3998 | 0 | if (emission.state == EMISSION_STOP) |
3999 | 0 | goto EMIT_CLEANUP; |
4000 | 0 | else if (emission.state == EMISSION_RESTART) |
4001 | 0 | goto EMIT_RESTART; |
4002 | 0 | } |
4003 | | |
4004 | 0 | EMIT_CLEANUP: |
4005 | | |
4006 | 0 | emission.ihint.run_type &= (unsigned) ~G_SIGNAL_RUN_LAST; |
4007 | 0 | emission.ihint.run_type |= G_SIGNAL_RUN_CLEANUP; |
4008 | | |
4009 | 0 | if ((node->flags & G_SIGNAL_RUN_CLEANUP) && class_closure) |
4010 | 0 | { |
4011 | 0 | gboolean need_unset = FALSE; |
4012 | | |
4013 | 0 | emission.state = EMISSION_STOP; |
4014 | | |
4015 | 0 | emission.chain_type = G_TYPE_FROM_INSTANCE (instance); |
4016 | 0 | SIGNAL_UNLOCK (); |
4017 | 0 | if (node->return_type != G_TYPE_NONE && !accumulator) |
4018 | 0 | { |
4019 | 0 | g_value_init (&accu, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE); |
4020 | 0 | need_unset = TRUE; |
4021 | 0 | } |
4022 | 0 | g_closure_invoke (class_closure, |
4023 | 0 | node->return_type != G_TYPE_NONE ? &accu : NULL, |
4024 | 0 | n_params, |
4025 | 0 | instance_and_params, |
4026 | 0 | &emission.ihint); |
4027 | 0 | if (!accumulate (&emission.ihint, emission_return, &accu, accumulator) && |
4028 | 0 | emission.state == EMISSION_RUN) |
4029 | 0 | emission.state = EMISSION_STOP; |
4030 | 0 | if (need_unset) |
4031 | 0 | g_value_unset (&accu); |
4032 | 0 | SIGNAL_LOCK (); |
4033 | 0 | return_value_altered = TRUE; |
4034 | |
|
4035 | 0 | emission.chain_type = G_TYPE_NONE; |
4036 | | |
4037 | 0 | if (emission.state == EMISSION_RESTART) |
4038 | 0 | goto EMIT_RESTART; |
4039 | 0 | } |
4040 | | |
4041 | 0 | if (handler_list) |
4042 | 0 | handler_unref_R (signal_id, instance, handler_list); |
4043 | | |
4044 | 0 | emission_pop (&emission); |
4045 | 0 | if (accumulator) |
4046 | 0 | g_value_unset (&accu); |
4047 | |
|
4048 | 0 | TRACE(GOBJECT_SIGNAL_EMIT_END(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance))); |
4049 | |
|
4050 | 0 | return return_value_altered; |
4051 | 0 | } |
4052 | | |
4053 | | static void |
4054 | | add_invalid_closure_notify (Handler *handler, |
4055 | | gpointer instance) |
4056 | 0 | { |
4057 | 0 | g_closure_add_invalidate_notifier (handler->closure, instance, invalid_closure_notify); |
4058 | 0 | handler->has_invalid_closure_notify = 1; |
4059 | 0 | } |
4060 | | |
4061 | | static void |
4062 | | remove_invalid_closure_notify (Handler *handler, |
4063 | | gpointer instance) |
4064 | 0 | { |
4065 | 0 | if (handler->has_invalid_closure_notify) |
4066 | 0 | { |
4067 | 0 | g_closure_remove_invalidate_notifier (handler->closure, instance, invalid_closure_notify); |
4068 | 0 | handler->has_invalid_closure_notify = 0; |
4069 | 0 | } |
4070 | 0 | } |
4071 | | |
4072 | | static void |
4073 | | invalid_closure_notify (gpointer instance, |
4074 | | GClosure *closure) |
4075 | 0 | { |
4076 | 0 | Handler *handler; |
4077 | 0 | guint signal_id; |
4078 | |
|
4079 | 0 | SIGNAL_LOCK (); |
4080 | |
|
4081 | 0 | handler = handler_lookup (instance, 0, closure, &signal_id); |
4082 | | /* See https://bugzilla.gnome.org/show_bug.cgi?id=730296 for discussion about this... */ |
4083 | 0 | g_assert (handler != NULL); |
4084 | 0 | g_assert (handler->closure == closure); |
4085 | | |
4086 | 0 | g_hash_table_remove (g_handlers, handler); |
4087 | 0 | handler->sequential_number = 0; |
4088 | 0 | handler->block_count = 1; |
4089 | 0 | handler_unref_R (signal_id, instance, handler); |
4090 | |
|
4091 | 0 | SIGNAL_UNLOCK (); |
4092 | 0 | } |
4093 | | |
4094 | | static const gchar* |
4095 | | type_debug_name (GType type) |
4096 | 0 | { |
4097 | 0 | if (type) |
4098 | 0 | { |
4099 | 0 | const char *name = g_type_name (type & ~G_SIGNAL_TYPE_STATIC_SCOPE); |
4100 | 0 | return name ? name : "<unknown>"; |
4101 | 0 | } |
4102 | 0 | else |
4103 | 0 | return "<invalid>"; |
4104 | 0 | } |
4105 | | |
4106 | | /** |
4107 | | * g_signal_accumulator_true_handled: |
4108 | | * @ihint: standard #GSignalAccumulator parameter |
4109 | | * @return_accu: standard #GSignalAccumulator parameter |
4110 | | * @handler_return: standard #GSignalAccumulator parameter |
4111 | | * @dummy: standard #GSignalAccumulator parameter |
4112 | | * |
4113 | | * A predefined #GSignalAccumulator for signals that return a |
4114 | | * boolean values. The behavior that this accumulator gives is |
4115 | | * that a return of %TRUE stops the signal emission: no further |
4116 | | * callbacks will be invoked, while a return of %FALSE allows |
4117 | | * the emission to continue. The idea here is that a %TRUE return |
4118 | | * indicates that the callback handled the signal, and no further |
4119 | | * handling is needed. |
4120 | | * |
4121 | | * Since: 2.4 |
4122 | | * |
4123 | | * Returns: standard #GSignalAccumulator result |
4124 | | */ |
4125 | | gboolean |
4126 | | g_signal_accumulator_true_handled (GSignalInvocationHint *ihint, |
4127 | | GValue *return_accu, |
4128 | | const GValue *handler_return, |
4129 | | gpointer dummy) |
4130 | 0 | { |
4131 | 0 | gboolean continue_emission; |
4132 | 0 | gboolean signal_handled; |
4133 | | |
4134 | 0 | signal_handled = g_value_get_boolean (handler_return); |
4135 | 0 | g_value_set_boolean (return_accu, signal_handled); |
4136 | 0 | continue_emission = !signal_handled; |
4137 | | |
4138 | 0 | return continue_emission; |
4139 | 0 | } |
4140 | | |
4141 | | /** |
4142 | | * g_signal_accumulator_first_wins: |
4143 | | * @ihint: standard #GSignalAccumulator parameter |
4144 | | * @return_accu: standard #GSignalAccumulator parameter |
4145 | | * @handler_return: standard #GSignalAccumulator parameter |
4146 | | * @dummy: standard #GSignalAccumulator parameter |
4147 | | * |
4148 | | * A predefined #GSignalAccumulator for signals intended to be used as a |
4149 | | * hook for application code to provide a particular value. Usually |
4150 | | * only one such value is desired and multiple handlers for the same |
4151 | | * signal don't make much sense (except for the case of the default |
4152 | | * handler defined in the class structure, in which case you will |
4153 | | * usually want the signal connection to override the class handler). |
4154 | | * |
4155 | | * This accumulator will use the return value from the first signal |
4156 | | * handler that is run as the return value for the signal and not run |
4157 | | * any further handlers (ie: the first handler "wins"). |
4158 | | * |
4159 | | * Returns: standard #GSignalAccumulator result |
4160 | | * |
4161 | | * Since: 2.28 |
4162 | | **/ |
4163 | | gboolean |
4164 | | g_signal_accumulator_first_wins (GSignalInvocationHint *ihint, |
4165 | | GValue *return_accu, |
4166 | | const GValue *handler_return, |
4167 | | gpointer dummy) |
4168 | 0 | { |
4169 | 0 | g_value_copy (handler_return, return_accu); |
4170 | 0 | return FALSE; |
4171 | 0 | } |
4172 | | |
4173 | | /** |
4174 | | * g_clear_signal_handler: |
4175 | | * @handler_id_ptr: A pointer to a handler ID (of type #gulong) of the handler to be disconnected. |
4176 | | * @instance: (type GObject.Object): The instance to remove the signal handler from. |
4177 | | * This pointer may be %NULL or invalid, if the handler ID is zero. |
4178 | | * |
4179 | | * Disconnects a handler from @instance so it will not be called during |
4180 | | * any future or currently ongoing emissions of the signal it has been |
4181 | | * connected to. The @handler_id_ptr is then set to zero, which is never a valid handler ID value (see g_signal_connect()). |
4182 | | * |
4183 | | * If the handler ID is 0 then this function does nothing. |
4184 | | * |
4185 | | * There is also a macro version of this function so that the code |
4186 | | * will be inlined. |
4187 | | * |
4188 | | * Since: 2.62 |
4189 | | */ |
4190 | | void |
4191 | | (g_clear_signal_handler) (gulong *handler_id_ptr, |
4192 | | gpointer instance) |
4193 | 0 | { |
4194 | 0 | g_return_if_fail (handler_id_ptr != NULL); |
4195 | | |
4196 | | #ifndef g_clear_signal_handler |
4197 | | #error g_clear_signal_handler() macro is not defined |
4198 | | #endif |
4199 | | |
4200 | 0 | g_clear_signal_handler (handler_id_ptr, instance); |
4201 | 0 | } |