Skip to content

fromGVariant fails on empty arrays #91

@dashea

Description

@dashea

I have a GVariant I'm trying to unpack. The variant format string is (uuua(ayay)), and sometimes that a(ayay) is empty. The problem I'm hitting is that if I unpack it and that list is empty, I get an error message of:

GLib-CRITICAL **: g_variant_get_child_value: assertion 'index_ < g_variant_n_children (value)' failed

and it gets stuck printing errors forever. g_variant_get_child_value is getting called from gvariant_get_children in GVariant.hsc, and in this case the n_children is 0.

Here's a thing to reproduce:

import Data.ByteString(ByteString)
import Data.Word(Word32)
import GI.GLib

testData :: (Word32, Word32, Word32, [(ByteString, ByteString)])
testData = (1, 2, 3, [])

unpackTestData :: GVariant -> IO (Maybe (Word32, Word32, Word32, [(ByteString, ByteString)]))
unpackTestData = fromGVariant

main :: IO ()
main = do
    variant <- toGVariant testData
    type_string <- gvariantGetTypeString variant
    putStrLn $ "variant: " ++ show type_string

    unpacked <- unpackTestData variant
    putStrLn $ "unpacked data: " ++ show unpacked

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions