📄 gclosure.c
字号:
}static inline gbooleanclosure_try_remove_fnotify (GClosure *closure, gpointer notify_data, GClosureNotify notify_func){ GClosureNotifyData *ndata, *nlast; nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1; for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++) if (ndata->notify == notify_func && ndata->data == notify_data) { closure->n_fnotifiers -= 1; if (ndata < nlast) *ndata = *nlast; if (closure->n_inotifiers) closure->notifiers[(CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers)]; return TRUE; } return FALSE;}GClosure*g_closure_ref (GClosure *closure){ g_return_val_if_fail (closure != NULL, NULL); g_return_val_if_fail (closure->ref_count > 0, NULL); g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL); closure->ref_count += 1; return closure;}voidg_closure_invalidate (GClosure *closure){ g_return_if_fail (closure != NULL); if (!closure->is_invalid) { closure->ref_count += 1; /* preserve floating flag */ closure->is_invalid = TRUE; closure_invoke_notifiers (closure, INOTIFY); g_closure_unref (closure); }}voidg_closure_unref (GClosure *closure){ g_return_if_fail (closure != NULL); g_return_if_fail (closure->ref_count > 0); if (closure->ref_count == 1) /* last unref, invalidate first */ g_closure_invalidate (closure); closure->ref_count -= 1; if (closure->ref_count == 0) { closure_invoke_notifiers (closure, FNOTIFY); g_free (closure->notifiers); g_free (closure); }}voidg_closure_sink (GClosure *closure){ g_return_if_fail (closure != NULL); g_return_if_fail (closure->ref_count > 0); /* floating is basically a kludge to avoid creating closures * with a ref_count of 0. so the intial ref_count a closure has * is unowned. with invoking g_closure_sink() code may * indicate that it takes over that intiial ref_count. */ if (closure->floating) { closure->floating = FALSE; if (closure->ref_count > 1) closure->ref_count -= 1; else g_closure_unref (closure); }}voidg_closure_remove_invalidate_notifier (GClosure *closure, gpointer notify_data, GClosureNotify notify_func){ g_return_if_fail (closure != NULL); g_return_if_fail (notify_func != NULL); if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while its called */ ((gpointer) closure->marshal) == ((gpointer) notify_func) && closure->data == notify_data) closure->marshal = NULL; else if (!closure_try_remove_inotify (closure, notify_data, notify_func)) g_warning (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)", notify_func, notify_data);}voidg_closure_remove_finalize_notifier (GClosure *closure, gpointer notify_data, GClosureNotify notify_func){ g_return_if_fail (closure != NULL); g_return_if_fail (notify_func != NULL); if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while its called */ ((gpointer) closure->marshal) == ((gpointer) notify_func) && closure->data == notify_data) closure->marshal = NULL; else if (!closure_try_remove_fnotify (closure, notify_data, notify_func)) g_warning (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)", notify_func, notify_data);}voidg_closure_invoke (GClosure *closure, GValue /*out*/ *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint){ g_return_if_fail (closure != NULL); if (!closure->is_invalid) { GClosureMarshal marshal; gpointer marshal_data; gboolean in_marshal = closure->in_marshal; g_return_if_fail (closure->marshal || closure->meta_marshal); closure->ref_count += 1; /* preserve floating flag */ closure->in_marshal = TRUE; if (closure->meta_marshal) { marshal_data = closure->notifiers[0].data; marshal = (GClosureMarshal) closure->notifiers[0].notify; } else { marshal_data = NULL; marshal = closure->marshal; } if (!in_marshal) closure_invoke_notifiers (closure, PRE_NOTIFY); marshal (closure, return_value, n_param_values, param_values, invocation_hint, marshal_data); if (!in_marshal) closure_invoke_notifiers (closure, POST_NOTIFY); closure->in_marshal = in_marshal; g_closure_unref (closure); }}voidg_closure_set_marshal (GClosure *closure, GClosureMarshal marshal){ g_return_if_fail (closure != NULL); g_return_if_fail (marshal != NULL); if (closure->marshal && closure->marshal != marshal) g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)", closure->marshal, marshal); else closure->marshal = marshal;}GClosure*g_cclosure_new (GCallback callback_func, gpointer user_data, GClosureNotify destroy_data){ GClosure *closure; g_return_val_if_fail (callback_func != NULL, NULL); closure = g_closure_new_simple (sizeof (GCClosure), user_data); if (destroy_data) g_closure_add_finalize_notifier (closure, user_data, destroy_data); ((GCClosure*) closure)->callback = (gpointer) callback_func; return closure;}GClosure*g_cclosure_new_swap (GCallback callback_func, gpointer user_data, GClosureNotify destroy_data){ GClosure *closure; g_return_val_if_fail (callback_func != NULL, NULL); closure = g_closure_new_simple (sizeof (GCClosure), user_data); if (destroy_data) g_closure_add_finalize_notifier (closure, user_data, destroy_data); ((GCClosure*) closure)->callback = (gpointer) callback_func; closure->derivative_flag = TRUE; return closure;}static voidg_type_class_meta_marshal (GClosure *closure, GValue /*out*/ *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint, gpointer marshal_data){ GTypeClass *class; gpointer callback; /* GType itype = (GType) closure->data; */ guint offset = GPOINTER_TO_UINT (marshal_data); class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass); callback = G_STRUCT_MEMBER (gpointer, class, offset); if (callback) closure->marshal (closure, return_value, n_param_values, param_values, invocation_hint, callback);}static voidg_type_iface_meta_marshal (GClosure *closure, GValue /*out*/ *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint, gpointer marshal_data){ GTypeClass *class; gpointer callback; GType itype = (GType) closure->data; guint offset = GPOINTER_TO_UINT (marshal_data); class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass); callback = G_STRUCT_MEMBER (gpointer, class, offset); if (callback) closure->marshal (closure, return_value, n_param_values, param_values, invocation_hint, callback);}GClosure*g_signal_type_cclosure_new (GType itype, guint struct_offset){ GClosure *closure; g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL); g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL); closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype); if (G_TYPE_IS_INTERFACE (itype)) g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal); else g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal); return closure;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -