After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 746685 - Doc: clarify that g_variant_get_data() can be used instead of g_variant_get_bytestring()
Doc: clarify that g_variant_get_data() can be used instead of g_variant_get_b...
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gvariant
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Allison Karlitskaya (desrt)
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-03-24 13:29 UTC by Xavier Claessens
Modified: 2018-01-17 16:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring() (1009 bytes, patch)
2015-03-24 13:29 UTC, Xavier Claessens
none Details | Review
Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring() (1001 bytes, patch)
2015-03-24 13:32 UTC, Xavier Claessens
none Details | Review
Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring() (960 bytes, patch)
2015-09-22 14:41 UTC, Xavier Claessens
none Details | Review
Doc: Clarify when g_variant_get_fixed_array() should be used instead of _get_bytestring() (943 bytes, patch)
2015-09-22 15:11 UTC, Xavier Claessens
committed Details | Review

Description Xavier Claessens 2015-03-24 13:29:41 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.
Comment 1 Xavier Claessens 2015-03-24 13:29:59 UTC
Created attachment 300195 [details] [review]
Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring()
Comment 2 Xavier Claessens 2015-03-24 13:32:48 UTC
Created attachment 300196 [details] [review]
Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring()
Comment 3 Lars Karlitski 2015-03-24 13:45:07 UTC
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.
Comment 4 Xavier Claessens 2015-09-22 14:41:04 UTC
Created attachment 311872 [details] [review]
Doc: Clarify when g_variant_get_data() should be used instead of _get_bytestring()
Comment 5 Xavier Claessens 2015-09-22 14:41:47 UTC
Moved my snippet one paragraph up, so it follows all cases about nul-terminaison.
Comment 6 Allison Karlitskaya (desrt) 2015-09-22 14:54:59 UTC
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.
Comment 7 Dan Winship 2015-09-22 15:03:54 UTC
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).
Comment 8 Xavier Claessens 2015-09-22 15:09:49 UTC
@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.
Comment 9 Xavier Claessens 2015-09-22 15:11:07 UTC
Created attachment 311879 [details] [review]
Doc: Clarify when g_variant_get_fixed_array() should be used instead of _get_bytestring()
Comment 10 Matthias Clasen 2016-07-17 02:15:03 UTC
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()
Comment 11 Philip Withnall 2018-01-17 16:32:13 UTC
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.