GNOME Bugzilla – Bug 115886
gst_caps_has_(fixed_)property() prints an assertion before returning false
Last modified: 2004-12-22 21:47:04 UTC
gst_caps_has_property() and gst_caps_has_fixed_property() are predicate macros which can be used to check if a given GstCaps object handles a named property. The problem here is that an assertion failure is printed each time these macros are called with a property name the caps does not handle. It is not critical since these macros return false anyway. Here is a test program which illustrates this problem: #include <gst/gst.h> int main(int argc, char *argv[]) { GstElementFactory *factory; GstPadTemplate *pad_template; GstCaps *caps; gst_init(&argc, &argv); factory = gst_element_factory_find("mad"); pad_template = (GstPadTemplate *) factory->padtemplates->data; caps = pad_template->caps; printf("%d\n", gst_caps_has_property(caps, "does_not_exist")); printf("%d\n", gst_caps_has_fixed_property(caps, "does_not_exist")); return 0; } And its output (on 0.6.2): INFO (10110: 0) Initializing GStreamer Core Library version 0.6.2 INFO (10110: 0) CPU features: (00000000) MMX SSE INFO (10110: 0) registry: loaded global_registry in 0.220729 seconds (/usr/X11R6/share/gnome/cache/gstreamer-0.6/registry.xml) (process:10110): GStreamer-CRITICAL **: file gstprops.c: line 1001 (gst_props_get_entry): assertion `props != NULL' failed 0 (process:10110): GStreamer-CRITICAL **: file gstprops.c: line 1001 (gst_props_get_entry): assertion `props != NULL' failed 0 This has been tested on both Gentoo GNU/Linux and FreeBSD.
Created attachment 17940 [details] [review] patch
There's several ways to fix this: * change gstprops.c gst_props_has_property*() functions to check for props != NULL. This is ugly, imho, because that's what the caller should check. * change the macros to caps->properties != NULL && ..., which is ugly because you should never use variables-in-macros twice, they could be functions * fix this by making the macros inline functions The above patch implements the third fixage method.
I vote for the third option, too. However, they should be real functions, not inline. We don't do inline functions in headers. I mostly got a consensus on IRC that gst_caps_*() code should properly handle caps==NULL and caps->properties==NULL, but gst_props_*() functions can expect (and assert) that they are called with props != NULL. This is because the props code is almost exclusively used by caps, whereas caps is used by plugins and apps.
I just had the thought that we might want to make it obligatory to make every caps have a GstProps, even though it might be empty (gst_props_new_empty ()). This would need some plugin fixage, but it'd fix the issue, too. If we want to stick to allowing NULL as valid caps->props, then here's a patch that does what dave asked for.
Created attachment 17951 [details] [review] this
Hm, the above has some typos. s/gst_caps_get_properties/gst_caps_get_props/ and s/gst_props_has_property_fixed/gst_props_has_fixed_property/ makes it compile. ;). Mental note: test patches before proposing them...
Created attachment 17952 [details] [review] that
Created attachment 17953 [details] [review] it's gst_caps_has_fixed_property, not property_fixed!
Applied to HEAD CVS.