From 5cab3fcec13f9b9b13ebb483498e3e50bc1a4b45 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 2 Dec 2013 11:59:30 -0500 Subject: [PATCH] gobject: re-allow finalization from constructor() Although returning NULL from constructor is strongly discouraged, some old libraries need to keep doing it for ABI-compatibility reasons. Given this, it's rude to forbid finalization from within constructor(), since it would otherwise work correctly now anyway (and the critical when returning NULL should discourage any new uses of returning NULL from constructor()). https://bugzilla.gnome.org/show_bug.cgi?id=661576 --- gobject/gobject.c | 4 ++-- gobject/tests/object.c | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gobject/gobject.c b/gobject/gobject.c index 29bcccd68..e12eb6ba9 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -1023,8 +1023,8 @@ g_object_finalize (GObject *object) { if (object_in_construction (object)) { - g_error ("object %s %p finalized while still in-construction", - G_OBJECT_TYPE_NAME (object), object); + g_critical ("object %s %p finalized while still in-construction", + G_OBJECT_TYPE_NAME (object), object); } g_datalist_clear (&object->qdata); diff --git a/gobject/tests/object.c b/gobject/tests/object.c index f6e75d50d..3e85995c2 100644 --- a/gobject/tests/object.c +++ b/gobject/tests/object.c @@ -104,7 +104,6 @@ my_infanticide_object_constructor (GType type, constructor (type, n_construct_properties, construct_params); g_object_unref (object); - g_assert_not_reached (); return NULL; } @@ -120,18 +119,21 @@ my_infanticide_object_class_init (MyInfanticideObjectClass *klass) static void test_object_constructor_infanticide (void) { + GObject *obj; + int i; + g_test_bug ("661576"); - if (g_test_subprocess ()) + for (i = 0; i < 1000; i++) { - g_object_new (my_infanticide_object_get_type (), NULL); - g_assert_not_reached (); - return; + g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_CRITICAL, + "*finalized while still in-construction*"); + g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_CRITICAL, + "*Custom constructor*returned NULL*"); + obj = g_object_new (my_infanticide_object_get_type (), NULL); + g_assert_null (obj); + g_test_assert_expected_messages (); } - g_test_trap_subprocess (NULL, 0, 0); - g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*finalized while still in-construction*"); - g_test_trap_assert_stderr_unmatched ("*reached*"); } /* --------------------------------- */