GNOME Bugzilla – Bug 530817
GLib.Value is awkward to use. Why do I need to define variables as pointers?
Last modified: 2008-05-31 08:25:46 UTC
See http://library.gnome.org/devel/gstreamer/unstable/gstreamer-GstStructure.html#gst-structure-get-value BTW usually vala bindings seem to know if they get a weak or a normal reference. E.g. vala seems to know somehow that gconf_client_get_default returns a weak reference. How does vala know this?
OK my initial bug report was not OK. I can get it to work with the following code //////////////////////////////// using GLib, Gst; public class Sample : GLib.Object{ static int main (string[] args) { Structure structure; Value* width; width = structure.get_value ("width"); return 0; } } ///////////////////////////////// However this make GValues very awkward to use. How do I know as a user that I should use "Value*" instead of "Value"
Sorry again. The above code does not compile. structure.get_value returns a Value why now I need it to be a Value*
I've now finally got it working :-), but it's very awkward to use In gstreamer-0.10.vapi I changed public GLib.Value get_value (string fieldname); to public GLib.Value* get_value (string fieldname); The example code in comment #1 now works. However doing operation on the returned value is very awkward. I now have stuff in my code like if ((*width).holds (typeof (int))) { }
The idea at the moment is to get that working with nullable types instead of pointers: In the VAPI: public GLib.Value? get_value (string fieldname); In the Code: Value? width = structure.get_value ("width"); or var width = structure.get_value ("width"); if (width.holds (typeof (int))) { int i = (int) width; } This won't work correctly yet as this depends on support for nullable structs (bug 526542) and GValue conversion operators (528436).
*** Bug 533681 has been marked as a duplicate of this bug. ***
Blocking development of dvb-daemon, increasing priority.
Thanks for the increase in priority. I also need it for the cheese port in vala. Though I now use some ugly workarounds.
The following should work now: Value? width = structure.get_value ("width"); or var width = structure.get_value ("width"); if (width.holds (typeof (int))) { int i = width.get_int (); }
The following should work now, too, i.e. I've added support for auto-unboxing: Value width = structure.get_value ("width"); if (width.holds (typeof (int))) { int i = width.get_int (); }
2008-05-31 Jürg Billeter <j@bitron.ch> * vapi/packages/gstreamer-0.10/: Fix gst_structure_get_value binding, fixes bug 530817 * vapi/gstreamer-0.10.vapi: regenerated Fixed in r1510.