Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

understanding vala compilation warnings

Tags:

warnings

vala

The compilation warnings below are not so clear to me, appart from the deprecation warhing, but the signature of the method in the valadoc :

http://valadoc.org/#!api=gstreamer-1.0/Gst

shows no other method signature.

the other warning are more obscure.


max@max-ubuntu:~/mdev/cr valac --pkg gstreamer-0.10 gstpipe.vala 
/home/max/dev/main-sandbox/cr/gstpipe.vala.c: In function ‘application_message’:
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:64:2: warning: passing argument 1 of ‘_gst_structure_copy0’ discards ‘const’ qualifier from pointer target type [enabled by default]
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:26:17: note: expected ‘gpointer’ but argument is of type ‘const struct GstStructure *’
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:82:9: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default]
/home/max/dev/main-sandbox/cr/gstpipe.vala.c: In function ‘main’:
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:173:2: warning: ‘g_type_init’ is deprecated (declared at /usr/include/glib-2.0/gobject/gtype.h:669) [-Wdeprecated-declarations]


using Gst;


void application_message(Gst.Bus bus, Gst.Message msg) {

        var s = msg.get_structure();

        if(s == null)
            return;

        string msgtype = s.get_name();

        if(msgtype != "level")
            return;

        GLib.Value rms = s.get_value("rms");
        //GLib.Value st = s.get_value("stream-time");

        GLib.DateTime now = new GLib.DateTime.now_local();

        var sec = now.to_unix();
        var msec = (sec * 1000) + now.get_microsecond();        

        var z = rms.strdup_contents();

        //z = z.replace("{", "[").replace("}", "]");

        stdout.printf("%ld, %s \n", (long) msec, z);
}


void main (string[] args) {

    Gst.init (ref args);

    try {

        var pipeline = Gst.parse_launch(
          "pulsesrc device=\"alsa_input.usb-046d_08c9_674634A4-02-U0x46d0x8c9.analog-mono\" ! " +
          "level name=wavelevel interval=10000000 ! " +
          "wavenc ! filesink location=audioz.wav"
        );

        var bus = pipeline.get_bus();

        bus.add_signal_watch();
        bus.message.connect(application_message);

        // Set pipeline state to PLAYING
        pipeline.set_state (State.PLAYING);

        // Creating and starting a GLib main loop
        new MainLoop ().run ();        
    }
    catch(Error e) {
        print("%s\n", e.message);
    }
}
like image 261
Max L. Avatar asked Oct 19 '13 16:10

Max L.


1 Answers

You can generally ignore warnings from the C compiler when using Vala. Vala has better information than the C compiler, so it knows certain things are valid when the C compiler has no way of knowing that. Unfortunately we can't just add casts everywhere since there are situations where we can't generate a valid cast (and, what's more, no way to know what those situations are).

The final warning, about g_type_init being deprecated, is because g_type_init is no longer necessary as of glib 2.36. You can get rid of that warning by passing --target-glib=2.36 (or any later version of glib) to valac, but be warned that the generated code may no longer work with older versions of glib.

TBH, I often just pass -X -w to valac to get the C compiler to be quiet. Occasionally I miss a useful warning, but it gets rid of a lot of useless warnings.

like image 58
nemequ Avatar answered Nov 15 '22 10:11

nemequ