From e35dc31fda2fce5a65fd3df1ff141d5ff6d9cc44 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Sun, 4 Nov 2018 19:04:19 +0100 Subject: [PATCH] structure: add gst_clear_structure() 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 | 24 ++++++++++++++++++++++++ gst/gststructure.h | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/gst/gststructure.c b/gst/gststructure.c index 734b2d2..dae2b63 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -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 * diff --git a/gst/gststructure.h b/gst/gststructure.h index e366fea..624b6e6 100644 --- a/gst/gststructure.h +++ b/gst/gststructure.h @@ -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 -- 2.7.4