gobject: clear weak locations before calling dispose in g_object_run_dispose()

This changes behavior from commit [1].

The point of g_object_run_dispose() is to break reference cycles to
bring down an object. We don't expect the object to take new references
to keep it alive for longer. We probably also don't expect it to
register new weak references. We also don't expect the dispose()
callees to check g_weak_ref_get() for the object. In those situations,
this change makes no difference.

I wonder, whether we should clear GWeakRef at all, because during
g_object_run_dispose(), the real reference counter is not yet
going to NULL. Maybe the GWeakRef should honor that primarily, and
not clear out at g_object_run_dispose(). On the other hand, dispose()
will also emit weak notifications too, despite the object is not yet
going away for real. So maybe we indeed want this. And this is what we
did since [1] and before.

But compare to g_object_unref(), where we also clear GWeakRef *before*
calling dispose. That makes sense, because inside dispose() (and for
example during weak notifications), we probably want to see that
g_weak_ref_get() indicates the object is gone. For that reason, it seems
more correct to clear out the GWeakRef before calling dispose().

Also, the dispose() callees (e.g. the weak notifications) might refuse to
let the object die by intentionally keeping strong references around.
Not sure why they would do that, it is similar to resurrecting an object
during dispose(). But if they do, they might also want to register new
GWeakRef. In that case, we wouldn't want to unset those newly set
GWeakRef unconditionally right after.

In most cases, it shouldn't make a difference. In the case where it
does, this seems the more sensible order of things.

[1] commit 2952cfd7a7f2 ('gobject: drop clearing quark_weak_locations from g_object_real_dispose()')
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 9042c67..ff5eb11 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -1862,8 +1862,11 @@
  * This function temporarily acquires another strong reference while running
  * dispose.
  *
- * Note that this first calls #GObjectClass.dispose. Afterwards, all #GWeakRef
- * pointers are cleared.
+ * Note that this first clears all #GWeakRef pointers and then calls
+ * #GObjectClass.dispose.
+ *
+ * Note that before 2.86, #GWeakRef pointers were cleared after
+ * #GObjectClass.dispose.
  */
 void
 g_object_run_dispose (GObject *object)
@@ -1875,10 +1878,6 @@
 
   g_object_ref (object);
 
-  TRACE (GOBJECT_OBJECT_DISPOSE(object,G_TYPE_FROM_INSTANCE(object), 0));
-  G_OBJECT_GET_CLASS (object)->dispose (object);
-  TRACE (GOBJECT_OBJECT_DISPOSE_END(object,G_TYPE_FROM_INSTANCE(object), 0));
-
   if ((object_get_optional_flags (object) & OPTIONAL_FLAG_EVER_HAD_WEAK_REF))
     {
       wrdata = weak_ref_data_get_surely (object);
@@ -1887,6 +1886,10 @@
       weak_ref_data_unlock (wrdata);
     }
 
+  TRACE (GOBJECT_OBJECT_DISPOSE(object,G_TYPE_FROM_INSTANCE(object), 0));
+  G_OBJECT_GET_CLASS (object)->dispose (object);
+  TRACE (GOBJECT_OBJECT_DISPOSE_END(object,G_TYPE_FROM_INSTANCE(object), 0));
+
   g_object_unref (object);
 }