提交 43388492 编写于 作者: R Robert Ancell 提交者: Robert Ancell

Replace g_object_weak_ref with g_object_add_weak_pointer

In these cases it is simpler to use the latter. Newer code is using this method.
上级 3a30ae3d
......@@ -140,20 +140,13 @@ static void method_call_cb(FlMethodChannel* channel,
}
}
static void view_weak_notify_cb(gpointer user_data,
GObject* where_the_object_was) {
FlMouseCursorPlugin* self = FL_MOUSE_CURSOR_PLUGIN(user_data);
self->view = nullptr;
}
static void fl_mouse_cursor_plugin_dispose(GObject* object) {
FlMouseCursorPlugin* self = FL_MOUSE_CURSOR_PLUGIN(object);
g_clear_object(&self->channel);
if (self->view != nullptr) {
g_object_weak_unref(G_OBJECT(self->view), view_weak_notify_cb, self);
self->view = nullptr;
}
g_object_remove_weak_pointer(G_OBJECT(self->view),
reinterpret_cast<gpointer*>(&(self->view)));
self->view = nullptr;
g_clear_pointer(&self->system_cursor_table, g_hash_table_unref);
......@@ -179,7 +172,10 @@ FlMouseCursorPlugin* fl_mouse_cursor_plugin_new(FlBinaryMessenger* messenger,
fl_method_channel_set_method_call_handler(self->channel, method_call_cb, self,
nullptr);
self->view = view;
g_object_weak_ref(G_OBJECT(view), view_weak_notify_cb, self);
if (view != nullptr) {
g_object_add_weak_pointer(G_OBJECT(view),
reinterpret_cast<gpointer*>(&(self->view)));
}
return self;
}
......@@ -22,20 +22,12 @@ G_MODULE_EXPORT GType fl_plugin_registrar_get_type();
G_DEFINE_TYPE(FlPluginRegistrar, fl_plugin_registrar, G_TYPE_OBJECT)
static void view_weak_notify_cb(gpointer user_data,
GObject* where_the_object_was) {
FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(user_data);
self->view = nullptr;
}
static void fl_plugin_registrar_dispose(GObject* object) {
FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(object);
if (self->view != nullptr) {
g_object_weak_unref(G_OBJECT(self->view), view_weak_notify_cb, self);
self->view = nullptr;
}
g_object_remove_weak_pointer(G_OBJECT(self->view),
reinterpret_cast<gpointer*>(&(self->view)));
self->view = nullptr;
g_clear_object(&self->messenger);
G_OBJECT_CLASS(fl_plugin_registrar_parent_class)->dispose(object);
......@@ -56,8 +48,10 @@ FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
g_object_new(fl_plugin_registrar_get_type(), nullptr));
self->view = view;
if (view != nullptr)
g_object_weak_ref(G_OBJECT(view), view_weak_notify_cb, self);
if (view != nullptr) {
g_object_add_weak_pointer(G_OBJECT(view),
reinterpret_cast<gpointer*>(&(self->view)));
}
self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
return self;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册