Skip to content

Commit 4338849

Browse files
committed
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.
1 parent 3a30ae3 commit 4338849

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

shell/platform/linux/fl_mouse_cursor_plugin.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,13 @@ static void method_call_cb(FlMethodChannel* channel,
140140
}
141141
}
142142

143-
static void view_weak_notify_cb(gpointer user_data,
144-
GObject* where_the_object_was) {
145-
FlMouseCursorPlugin* self = FL_MOUSE_CURSOR_PLUGIN(user_data);
146-
self->view = nullptr;
147-
}
148-
149143
static void fl_mouse_cursor_plugin_dispose(GObject* object) {
150144
FlMouseCursorPlugin* self = FL_MOUSE_CURSOR_PLUGIN(object);
151145

152146
g_clear_object(&self->channel);
153-
if (self->view != nullptr) {
154-
g_object_weak_unref(G_OBJECT(self->view), view_weak_notify_cb, self);
155-
self->view = nullptr;
156-
}
147+
g_object_remove_weak_pointer(G_OBJECT(self->view),
148+
reinterpret_cast<gpointer*>(&(self->view)));
149+
self->view = nullptr;
157150

158151
g_clear_pointer(&self->system_cursor_table, g_hash_table_unref);
159152

@@ -179,7 +172,10 @@ FlMouseCursorPlugin* fl_mouse_cursor_plugin_new(FlBinaryMessenger* messenger,
179172
fl_method_channel_set_method_call_handler(self->channel, method_call_cb, self,
180173
nullptr);
181174
self->view = view;
182-
g_object_weak_ref(G_OBJECT(view), view_weak_notify_cb, self);
175+
if (view != nullptr) {
176+
g_object_add_weak_pointer(G_OBJECT(view),
177+
reinterpret_cast<gpointer*>(&(self->view)));
178+
}
183179

184180
return self;
185181
}

shell/platform/linux/fl_plugin_registrar.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,12 @@ G_MODULE_EXPORT GType fl_plugin_registrar_get_type();
2222

2323
G_DEFINE_TYPE(FlPluginRegistrar, fl_plugin_registrar, G_TYPE_OBJECT)
2424

25-
static void view_weak_notify_cb(gpointer user_data,
26-
GObject* where_the_object_was) {
27-
FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(user_data);
28-
self->view = nullptr;
29-
}
30-
3125
static void fl_plugin_registrar_dispose(GObject* object) {
3226
FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(object);
3327

34-
if (self->view != nullptr) {
35-
g_object_weak_unref(G_OBJECT(self->view), view_weak_notify_cb, self);
36-
self->view = nullptr;
37-
}
38-
28+
g_object_remove_weak_pointer(G_OBJECT(self->view),
29+
reinterpret_cast<gpointer*>(&(self->view)));
30+
self->view = nullptr;
3931
g_clear_object(&self->messenger);
4032

4133
G_OBJECT_CLASS(fl_plugin_registrar_parent_class)->dispose(object);
@@ -56,8 +48,10 @@ FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
5648
g_object_new(fl_plugin_registrar_get_type(), nullptr));
5749

5850
self->view = view;
59-
if (view != nullptr)
60-
g_object_weak_ref(G_OBJECT(view), view_weak_notify_cb, self);
51+
if (view != nullptr) {
52+
g_object_add_weak_pointer(G_OBJECT(view),
53+
reinterpret_cast<gpointer*>(&(self->view)));
54+
}
6155
self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
6256

6357
return self;

0 commit comments

Comments
 (0)