*_get_name inconstancy

Tim Müller tim at centricular.com
Wed Apr 16 03:32:30 PDT 2014


On Wed, 2014-04-16 at 12:13 +0200, Eric Trousset wrote:

Hi,

> In gstreamer some _get_name function return const ghar*  and don’t
> need to be freed whereas some others (the one ending up calling
> gst_object_get_name thru a #define) returns a gchar* and do need to be
> freed.
>  
> 
> Wouldn’t it be better if all the _get_name function had the same
> behavior?

Well, yes, but at the same time it also doesn't seem like a good idea to
cause inconvenience (return value assignment + g_free) and
inefficiencies (g_strdup) for no good reason other than consistency :)

When we return a copy that's usually for thread-safety reasons, because
the value may change. This happens usually with refcounted GObjects
(pads, elements).

For others the return value is a const gchar * because it maps to a
constant string, like nick names for enum values.

For things like gst_structure_get_name() it's also convenience, since we
know the value can't be changed in another thread while we're looking at
the structure (bugs aside).

Cheers
 -Tim

-- 
Tim Müller, Centricular Ltd - http://www.centricular.com



More information about the gstreamer-devel mailing list