From 59c09eb02997549a096aebc1f4b85c530ebfbbe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 29 Jan 2024 19:47:11 +0000 Subject: [PATCH] gstobject: add CONSTRUCTED flag This can be used later by base class APIs to know whether they're called from a subclass instance init function (where the object isn't properly constructed yet and one should only really poke at the instance structure but not much else) or after object construction has been finished. Fix up GstBin unit test for CONSTRUCTED flag addition. See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2794 Part-of: --- girs/Gst-1.0.gir | 8 ++++++++ subprojects/gstreamer/gst/gstobject.c | 2 ++ subprojects/gstreamer/gst/gstobject.h | 20 +++++++++++++++++++ .../gstreamer/tests/check/gst/gstbin.c | 2 +- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/girs/Gst-1.0.gir b/girs/Gst-1.0.gir index ac19229358..478e1bce78 100644 --- a/girs/Gst-1.0.gir +++ b/girs/Gst-1.0.gir @@ -27929,6 +27929,14 @@ the elements contained in that bin. the object is expected to stay alive even after gst_deinit() has been called and so should be ignored by leak detection tools. (Since: 1.10) + + + Flag that's set when the object has been constructed. This can be used by +API such as base class setters to differentiate between the case where +they're called from a subclass's instance init function (and where the +object isn't fully constructed yet, and so one shouldn't do anything but +set values in the instance structure), and the case where the object is +constructed. subclasses can add additional flags starting from this flag diff --git a/subprojects/gstreamer/gst/gstobject.c b/subprojects/gstreamer/gst/gstobject.c index 2b7146dd54..1a57459b38 100644 --- a/subprojects/gstreamer/gst/gstobject.c +++ b/subprojects/gstreamer/gst/gstobject.c @@ -138,6 +138,8 @@ G_DEFINE_ABSTRACT_TYPE (GstObject, gst_object, G_TYPE_INITIALLY_UNOWNED); static void gst_object_constructed (GObject * object) { + GST_OBJECT_FLAG_SET (object, GST_OBJECT_FLAG_CONSTRUCTED); + GST_TRACER_OBJECT_CREATED (GST_OBJECT_CAST (object)); ((GObjectClass *) gst_object_parent_class)->constructed (object); diff --git a/subprojects/gstreamer/gst/gstobject.h b/subprojects/gstreamer/gst/gstobject.h index a7daf48e4e..a808522f88 100644 --- a/subprojects/gstreamer/gst/gstobject.h +++ b/subprojects/gstreamer/gst/gstobject.h @@ -39,11 +39,30 @@ G_BEGIN_DECLS #define GST_OBJECT_CAST(obj) ((GstObject*)(obj)) #define GST_OBJECT_CLASS_CAST(klass) ((GstObjectClass*)(klass)) +/** + * GST_OBJECT_FLAG_CONSTRUCTED: + * + * Flag that's set when the object has been constructed. This can be used by + * API such as base class setters to differentiate between the case where + * they're called from a subclass's instance init function (and where the + * object isn't fully constructed yet, and so one shouldn't do anything but + * set values in the instance structure), and the case where the object is + * constructed. + * + * Since: 1.24 + */ + /** * GstObjectFlags: * @GST_OBJECT_FLAG_MAY_BE_LEAKED: the object is expected to stay alive even * after gst_deinit() has been called and so should be ignored by leak * detection tools. (Since: 1.10) + * @GST_OBJECT_FLAG_CONSTRUCTED: flag that's set when the object has been + * constructed. This can be used by API such as base class setters to + * differentiate between the case where they're called from a subclass's + * instance init function (and where the object isn't fully constructed yet, + * and so one shouldn't do anything but set values in the instance structure), + * and the case where the object is constructed. (Since: 1.24) * @GST_OBJECT_FLAG_LAST: subclasses can add additional flags starting from this flag * * The standard flags that an gstobject may have. @@ -51,6 +70,7 @@ G_BEGIN_DECLS typedef enum { GST_OBJECT_FLAG_MAY_BE_LEAKED = (1 << 0), + GST_OBJECT_FLAG_CONSTRUCTED = (1 << 1), /* padding */ GST_OBJECT_FLAG_LAST = (1<<4) } GstObjectFlags; diff --git a/subprojects/gstreamer/tests/check/gst/gstbin.c b/subprojects/gstreamer/tests/check/gst/gstbin.c index 88ff44db0c..8341d6eff9 100644 --- a/subprojects/gstreamer/tests/check/gst/gstbin.c +++ b/subprojects/gstreamer/tests/check/gst/gstbin.c @@ -1919,7 +1919,7 @@ G_STMT_START { \ gst_bin_set_suppressed_flags (bin, suppressed_flags); \ gst_bin_add (bin, element); \ fail_unless ((natural_flags | GST_OBJECT_FLAGS (bin)) \ - == expected_flags); \ + == (expected_flags | GST_OBJECT_FLAG_CONSTRUCTED)); \ gst_object_unref (bin); \ } G_STMT_END