Re: [Vala] var does not honor weak?



NOTE: Sorry for the previous post! (ctrl+enter by incident in yahoo mail :( )

Im pretty new to both glib/gobject and vala so I might be missing something,
but creating a weak reference is supposed not to create a new reference to the object it points to.

On the other hand var is supposed to guess the type of the reference, so one will not have to type it explicitly.
But when using var on functions, returning a weak reference the ref_count is increased, which is not the case if the same if the that _expression_ is typed manually:

//***************manually typed**********

VALA-FILE:
using GLib;

public class WeakTest {
    static Object o = null;

    public static weak Object get_object () {
      o = new Object();
      return o;
    }

    static int main (string[] args) {
       
      weak Object localo = get_object();

      message("ref_count: %d",(int)localo.ref_count);
        return 0;
    }
}
RETURN:
** Message: weak_tst.vala:16: ref_count: 1

C-FILE:
...
static gint weak_test_main (char** args, int args_length1) {
    GObject* localo;
    localo = weak_test_get_object ();
    g_message ("weak_tst.vala:16: ref_count: %d", ((gint) (localo->ref_count)));
    return 0;
}
...

//**************** using var ************

VALA-FILE:
...
    static int main (string[] args) {
       
      var localo = get_object();

      message("ref_count: %d",(int)localo.ref_count);
        return 0;
    }
}
RETURN:
** Message: weak_tst.vala:16: ref_count: 2

C-FILE:
...
static gint weak_test_main (char** args, int args_length1) {
    GObject* _tmp0;
    GObject* localo;
    gint _tmp1;
    _tmp0 = NULL;
    localo = (_tmp0 = weak_test_get_object (), (_tmp0 == NULL ? NULL : g_object_ref (_tmp0)));
    g_message ("weak_tst.vala:16: ref_count: %d", ((gint) (localo->ref_count)));
    return (_tmp1 = 0, (localo == NULL ? NULL : (localo = (g_object_unref (localo), NULL))), _tmp1);
}
...


Is this a feature or a bug?
10x
MihailNaydenov



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]