After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 530817 - GLib.Value is awkward to use. Why do I need to define variables as pointers?
GLib.Value is awkward to use. Why do I need to define variables as pointers?
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings
0.3.x
Other All
: High normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
: 533681 (view as bug list)
Depends on: 526542 528436
Blocks:
 
 
Reported: 2008-04-30 23:01 UTC by Jaap A. Haitsma
Modified: 2008-05-31 08:25 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jaap A. Haitsma 2008-04-30 23:01:55 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?
Comment 1 Jaap A. Haitsma 2008-05-01 09:28:07 UTC
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"
Comment 2 Jaap A. Haitsma 2008-05-01 09:38:27 UTC
Sorry again. The above code does not compile. structure.get_value returns a Value why now I need it to be a Value*
Comment 3 Jaap A. Haitsma 2008-05-01 09:48:45 UTC
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))) {
}

Comment 4 Jürg Billeter 2008-05-10 22:05:07 UTC
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).
Comment 5 Jaap A. Haitsma 2008-05-18 11:49:15 UTC
*** Bug 533681 has been marked as a duplicate of this bug. ***
Comment 6 Jürg Billeter 2008-05-25 19:41:03 UTC
Blocking development of dvb-daemon, increasing priority.
Comment 7 Jaap A. Haitsma 2008-05-25 20:42:17 UTC
Thanks for the increase in priority. I also need it for the cheese port in vala. Though I now use some ugly workarounds.
Comment 8 Jürg Billeter 2008-05-30 23:40:43 UTC
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 ();
    }
Comment 9 Jürg Billeter 2008-05-31 08:23:44 UTC
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 ();
    }
Comment 10 Jürg Billeter 2008-05-31 08:25:46 UTC
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.