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 698455 - GVariant: add new g_variant_new_take_string() API
GVariant: add new g_variant_new_take_string() API
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gvariant
unspecified
Other All
: Normal normal
: ---
Assigned To: Allison Karlitskaya (desrt)
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-04-20 15:57 UTC by Allison Karlitskaya (desrt)
Modified: 2013-04-21 23:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GVariant: add new g_variant_new_take_string() API (3.28 KB, patch)
2013-04-20 15:57 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Allison Karlitskaya (desrt) 2013-04-20 15:57:27 UTC
See patch.
Comment 1 Allison Karlitskaya (desrt) 2013-04-20 15:57:28 UTC
Created attachment 242007 [details] [review]
GVariant: add new g_variant_new_take_string() API

Lots of people have variously asked for APIs like
g_variant_new_string_printf() in order to avoid having to use
g_strdup_printf(), create a GVariant using g_variant_new_string(), then
free the temporary string.

Instead of supporting that, plus a million other potential cases,
introduce g_variant_new_take_string() as a compromise.

It's not possible to write:

 v = g_variant_new_take_string (g_strdup_printf (....));

to get the desired result and avoid the extra copies.  In addition, it
works with many other functions.  An upcoming patch for GIcon intends to
do the same with g_strjoinv().
Comment 2 Dan Winship 2013-04-20 16:06:47 UTC
Comment on attachment 242007 [details] [review]
GVariant: add new g_variant_new_take_string() API

>It's not possible to write:

It's NOW possible

>+ * g_variant_new_take_string: (skip)

For any binding that is actually just wrapping GVariant rather than binding it specially, it would probably be better to mark g_variant_new_string() as (skip) and this as "Rename-To: g_variant_new_string".
Comment 3 Lars Karlitski 2013-04-20 16:22:55 UTC
Review of attachment 242007 [details] [review]:

::: glib/gvariant.c
@@ +1288,3 @@
+ * it to this function.  It is even possible that @string is immediately
+ * freed.
+ *

Returns: (transfer none): a floating reference to a new string #GVariant instance
Comment 4 Allison Karlitskaya (desrt) 2013-04-20 22:59:03 UTC
Attachment 242007 [details] pushed as dbb65b5 - GVariant: add new g_variant_new_take_string() API

Pushed with the change, thanks.
Comment 5 Allison Karlitskaya (desrt) 2013-04-20 23:00:58 UTC
Missed your review, Dan :(

I guess I have to live with the bad commit message forever....


Meanwhile, what do you mean about the rename-to business?  It seems that functions that consume their first argument are not the most bindings-friendly things....
Comment 6 Dan Winship 2013-04-21 17:12:02 UTC
um... yeah. not sure what i was thinking, but it was clearly wrong...
Comment 7 Allison Karlitskaya (desrt) 2013-04-21 23:54:01 UTC
FIXED, then.  Thanks.