Menu

How to use GVariant ?

2010-10-15
2013-05-03
  • Tiago Katcipis

    Tiago Katcipis - 2010-10-15

    Hi (and sorry for the double post on the former luaforge forum),

    I'm trying to use lua gnome but it seems to be a problem when you try to use the new GVariant (http://library.gnome.org/devel/glib/2.26/glib-GVariant.html) , the following code gives a segmentation fault:

    local glib = require "glib"

    glib.type_init()

    local variant = glib.variant_new("(s)", "Variant string test !!!")
    print("g_variant_print: ", variant:print(true))

    variant = nil
    print("Collecting GVariant !!!!")
    collectgarbage("collect")
    print("Garbage collected !!!!")

    local loop = glib.main_loop_new(nil, false)
    loop:run()

    the segmentation fault occurs because luagnome tries to free the GVariant (it will happen between the Collecting and Collected prints).
    if you comment the collectgarbage call of the "variant = nil" then it enters the main loop and runs forever just fine.

    GVariant uses floating references, i tried to call a refsink on the GVariant:
    variant:ref_sink()

    the result is the same thing, even calling another ref:
    variant:ref_sink()
    variant:ref()

    …wont help… it always try to free the GVariant and gives a "*** glibc detected *** lua: free(): invalid pointer".

    am i using luagnome wrong? or luagnome has some problem with GVariant usage?

    also, I'm having trouble getting a string, if i try:

    print("Variant message: ", variant:get("(&s)"))
    print("Variant message: ", variant:get("(s)"))

    after creating the variant…i get no error…no warning… but nothing gets printed… ir prints:
    "Variant message: "

    any hint on what am i doing wrong?

    all tests have been run on Ubuntu 10.10 with glib 2.26.0 and luagnome 0.9 (installed on apt-get).

    best regards,
    Katcipis

     
  • Wolfgang Oertl

    Wolfgang Oertl - 2011-09-27

    GVariant has own reference handling functions, i.e. g_variant_ref and g_variant_unref.  This hasn't been supported yet, but now I added some code for that (in current GIT repository). Your example should now work with the exception of the :get() function, which would require an extra handler.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.