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.
This commit is contained in:
Robert Ancell
2020-12-09 12:19:14 +13:00
committed by Robert Ancell
parent 3a18d39693
commit f128a93e70
2 changed files with 14 additions and 24 deletions

View File

@@ -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;
}

View File

@@ -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;