structure: add gst_clear_structure()
authorNiels De Graef <nielsdegraef@gmail.com>
Sun, 4 Nov 2018 18:04:19 +0000 (19:04 +0100)
committerSebastian Dröge <slomo@coaxion.net>
Mon, 5 Nov 2018 11:06:30 +0000 (11:06 +0000)
Basically, you can use this instead of using gst_structure_free (which
needs to be preceded by a NULL-check).

Also fixes #275

gst/gststructure.c
gst/gststructure.h

index 734b2d2..dae2b63 100644 (file)
@@ -395,6 +395,30 @@ gst_structure_free (GstStructure * structure)
 }
 
 /**
+ * gst_clear_structure: (skip)
+ * @structure_ptr: a pointer to a #GstStructure reference
+ *
+ * Clears a reference to a #GstStructure.
+ *
+ * @structure_ptr must not be %NULL.
+ *
+ * If the reference is %NULL then this function does nothing.
+ * Otherwise, the structure is free'd using gst_structure_free() and the
+ * pointer is set to %NULL.
+ *
+ * A macro is also included that allows this function to be used without
+ * pointer casts.
+ *
+ * Since: 1.16
+ **/
+#undef gst_clear_structure
+void
+gst_clear_structure (volatile GstStructure ** structure_ptr)
+{
+  g_clear_pointer (structure_ptr, gst_structure_free);
+}
+
+/**
  * gst_structure_get_name:
  * @structure: a #GstStructure
  *
index e366fea..624b6e6 100644 (file)
@@ -134,6 +134,10 @@ GST_API
 void                  gst_structure_free                 (GstStructure        * structure);
 
 GST_API
+void                  gst_clear_structure                (volatile GstStructure **structure_ptr);
+#define               gst_clear_structure(structure_ptr) g_clear_pointer ((structure_ptr), gst_structure_free)
+
+GST_API
 const gchar *         gst_structure_get_name             (const GstStructure  * structure);
 
 GST_API