GNOME Bugzilla – Bug 746685
Doc: clarify that g_variant_get_data() can be used instead of g_variant_get_bytestring()
Last modified: 2018-01-17 16:32:13 UTC
I think the doc of g_variant_get_bytestring() should link to g_variant_get_data() for the case where the "ay" can be anything.
Created attachment 300195 [details] [review] Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring()
Created attachment 300196 [details] [review] Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring()
Review of attachment 300196 [details] [review]: ::: glib/gvariant.c @@ +1816,3 @@ + * g_variant_get_data() and g_variant_get_size() should be used instead if the + * array contains arbitrary data that could not be nul-terminated or could + * contain nul bytes. The docs already talk about non-nul-terminated arrays two paragraphs up. I think it makes more sense to add this snippet there.
Created attachment 311872 [details] [review] Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring()
Moved my snippet one paragraph up, so it follows all cases about nul-terminaison.
Review of attachment 311872 [details] [review]: I'd actually advise g_variant_get_fixed_array() for this case instead. g_variant_get_data()/g_variant_get_size() are really meant to be used as interfaces to the serialised blob, not its value.
can we just add g_variant_get_bytes()? ('ay' -> GBytes*) (and a corresponding format-string modifier glyph so you can use GBytes with g_variant_new(), g_variant_get(), etc) the fact that GVariant/GDBus assume that 'ay' always means "non-UTF-8 string" was really annoying in porting NetworkManager (where it never means that).
@Dan, there is already g_variant_get_data_as_bytes() but I guess Ryan would argue that i's the same as g_variant_get_data/size(). A modified for new/get would be nice indeed. @Ryan, I didn't even know about _get_fixed_array(), I'll change to that if it's the intended API for that use case.
Created attachment 311879 [details] [review] Doc: Clarify when g_variant_get_fixed_array() should be used instead of _get_bytestring()
Comment on attachment 311879 [details] [review] Doc: Clarify when g_variant_get_fixed_array() should be used instead of _get_bytestring() Attachment 311879 [details] pushed as fdd0ed1 - Doc: Clarify when g_variant_get_fixed_array() should be used instead of _get_bytestring()
Marking as fixed as per comment #10. If people want new API like g_variant_get_bytes(), as per comment #7, please open a new bug report with an example of the code which could be simplified by adding such new convenience API.